Browse Source

pre-rebuild

windhamdavid 3 years ago
parent
commit
8dd6524726
2 changed files with 58 additions and 57 deletions
  1. 55 54
      metabox.php
  2. 3 3
      src/index.js

+ 55 - 54
metabox.php

@@ -2,62 +2,63 @@
 
 /////////////// Media URL (Custom Field - media) /////////////////
 
+add_action('init', 'dw_guten_register_media_meta');
 function dw_guten_register_media_meta() {
 	register_meta('post', 'media', array(
 		'show_in_rest' => true,
 		'type' => 'string',
 		'single' => true,
 		'sanitize_callback' => 'sanitize_text_field',
-		'auth_callback' => function() { 
+		'auth_callback' => function() {
 			return current_user_can('edit_posts');
 		}
 	));
 }
-add_action('init', 'dw_guten_register_media_meta');
 
+add_action( 'add_meta_boxes', 'dw_guten_add_media_meta_box' );
 function dw_guten_add_media_meta_box() {
-	add_meta_box( 
-		'dw_guten_post_options_metabox', 
-		'Post Options', 
-		'dw_guten_post_options_metabox_html', 
-		'post', 
-		'normal', 
+	add_meta_box(
+		'dw_guten_post_options_metabox',
+		'Post Options',
+		'dw_guten_post_options_metabox_html',
+		'post',
+		'normal',
 		'default',
 		array('__back_compat_meta_box' => true)
 	);
 }
-add_action( 'add_meta_boxes', 'dw_guten_add_media_meta_box' );
 
+add_action( 'save_post', 'dw_guten_save_post_metabox', 10, 2 );
 function dw_guten_post_options_metabox_html($post) {
-    $field_value = get_post_meta($post->ID, 'media', true);
-    wp_nonce_field( 'dw_guten_update_post_metabox', 'dw_guten_update_post_nonce' );
-    ?>
-    <p>
-        <label for="dw_guten_media_metafield"><?php esc_html_e( 'Media URL', 'textdomain' ); ?></label>
-        <br />
-        <input class="widefat" type="text" name="dw_guten_media_metafield" id="dw_guten_media_metafield" value="<?php echo esc_attr( $field_value ); ?>" />
-    </p>
-    <?php
+	$field_value = get_post_meta($post->ID, 'media', true);
+	wp_nonce_field( 'dw_guten_update_post_metabox', 'dw_guten_update_post_nonce' );
+	?>
+	<p>
+    <label for="dw_guten_media_metafield"><?php esc_html_e( 'Media URL', 'textdomain' ); ?></label>
+    <br />
+    <input class="widefat" type="text" name="dw_guten_media_metafield" id="dw_guten_media_metafield" value="<?php echo esc_attr( $field_value ); ?>" />
+	</p>
+	<?php
 }
 
 function dw_guten_save_post_metabox($post_id, $post) {
-    $edit_cap = get_post_type_object( $post->post_type )->cap->edit_post;
-    if( !current_user_can( $edit_cap, $post_id )) {
-        return;
-    }
-    if( !isset( $_POST['dw_guten_update_post_nonce']) || !wp_verify_nonce( $_POST['dw_guten_update_post_nonce'], 'dw_guten_update_post_metabox' )) {
-        return;
-    }
-
-    if(array_key_exists('dw_guten_media_metafield', $_POST)) {
-        update_post_meta( 
-            $post_id, 
-            'media', 
-            sanitize_text_field($_POST['dw_guten_media_metafield'])
-        );
-    }
+  $edit_cap = get_post_type_object( $post->post_type )->cap->edit_post;
+  if( !current_user_can( $edit_cap, $post_id )) {
+     return;
+  }
+  if( !isset( $_POST['dw_guten_update_post_nonce']) || !wp_verify_nonce( $_POST['dw_guten_update_post_nonce'], 'dw_guten_update_post_metabox' )) {
+     return;
+  }
+
+  if(array_key_exists('dw_guten_media_metafield', $_POST)) {
+    update_post_meta(
+      $post_id,
+      'media',
+      sanitize_text_field($_POST['dw_guten_media_metafield'])
+    );
+  }
 }
-add_action( 'save_post', 'dw_guten_save_post_metabox', 10, 2 );
+
 
 
 /////////  Feature Img URL (Custom Field - featured_image_url) ////////////
@@ -68,7 +69,7 @@ function dw_guten_register_featured_image_url_meta() {
 		'type' => 'string',
 		'single' => true,
 		'sanitize_callback' => 'sanitize_text_field',
-		'auth_callback' => function() { 
+		'auth_callback' => function() {
 			return current_user_can('edit_posts');
 		}
 	));
@@ -76,12 +77,12 @@ function dw_guten_register_featured_image_url_meta() {
 add_action('init', 'dw_guten_register_featured_image_url_meta');
 
 function dw_guten_add_featured_image_url_meta_box() {
-	add_meta_box( 
-		'dw_guten_post_options_metabox', 
-		'Post Options', 
-		'dw_guten_post_options_metabox_featured_image_url', 
-		'post', 
-		'normal', 
+	add_meta_box(
+		'dw_guten_post_options_metabox',
+		'Post Options',
+		'dw_guten_post_options_metabox_featured_image_url',
+		'post',
+		'normal',
 		'default',
 		array('__back_compat_meta_box' => true)
 	);
@@ -110,9 +111,9 @@ function dw_guten_save_post_metabox_featured_image_url($post_id, $post) {
     }
 
     if(array_key_exists('dw_guten_media_metafield', $_POST)) {
-        update_post_meta( 
-            $post_id, 
-            'featured_image_url', 
+        update_post_meta(
+            $post_id,
+            'featured_image_url',
             sanitize_text_field($_POST['dw_guten_featured_image_url_metafield'])
         );
     }
@@ -128,7 +129,7 @@ function dw_guten_register_desc_meta() {
 		'type' => 'string',
 		'single' => true,
 		'sanitize_callback' => 'sanitize_text_field',
-		'auth_callback' => function() { 
+		'auth_callback' => function() {
 			return current_user_can('edit_posts');
 		}
 	));
@@ -136,12 +137,12 @@ function dw_guten_register_desc_meta() {
 add_action('init', 'dw_guten_register_desc_meta');
 
 function dw_guten_add_desc_meta_box() {
-	add_meta_box( 
-		'dw_guten_post_options_metabox', 
-		'Post Options', 
-		'dw_guten_post_options_metabox_desc', 
-		'post', 
-		'normal', 
+	add_meta_box(
+		'dw_guten_post_options_metabox',
+		'Post Options',
+		'dw_guten_post_options_metabox_desc',
+		'post',
+		'normal',
 		'default',
 		array('__back_compat_meta_box' => true)
 	);
@@ -170,9 +171,9 @@ function dw_guten_save_post_metabox_desc($post_id, $post) {
     }
 
     if(array_key_exists('dw_guten_desc_metafield', $_POST)) {
-        update_post_meta( 
-            $post_id, 
-            'meta_desc', 
+        update_post_meta(
+            $post_id,
+            'meta_desc',
             sanitize_text_field($_POST['dw_guten_desc_metafield'])
         );
     }

+ 3 - 3
src/index.js

@@ -12,7 +12,7 @@ let PluginMetaFields = (props) => {
 			icon="format-video"
 			intialOpen={ true }
 		>
-		<TextControl 
+		<TextControl
 			value={props.text_metafield}
 			label={__("meta property og:video meta", "textdomain")}
 			help="postmeta:media absolute url to video"
@@ -31,7 +31,7 @@ let PluginMetaFields_featured_image_url = (props) => {
 			icon="format-image"
 			intialOpen={ true }
 		>
-		<TextControl 
+		<TextControl
 			value={props.text_metafield_featured_image_url}
 			label={__("meta property og:image", "textdomain")}
 			help="postmeta:featured_image_url absolute url to image"
@@ -50,7 +50,7 @@ let PluginMetaFields_desc = (props) => {
 			icon="format-aside"
 			intialOpen={ true }
 		>
-		<TextareaControl 
+		<TextareaControl
 			value={props.text_metafield_desc}
 			label={__("meta name=description", "textdomain")}
 			help="postmeta:meta-desc alternative to post excerpt from the function dw_good_excerpt"