ID, 'array-video', true ); echo ' '; echo ''; echo '

'; printf( __( 'Add video to your page by entering the video\'s embed code in the box above (optional). ', 'array-toolkit' ) ); } /** * Saves the video embed code on post save */ function array_save_video_meta( $post_id ) { global $post; // Return early if this is a newly created post that hasn't been saved yet. if( 'auto-draft' == get_post_status( $post_id ) ) { return $post_id; } // Check if the user intended to change this value. if ( ! isset( $_POST['array_video_box_nonce'] ) || ! wp_verify_nonce( $_POST['array_video_box_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id; // Get post type object $post_type = get_post_type_object( $post->post_type ); // Check if user has permission if( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { return $post_id; } // Get posted data and sanitize it $new_video = ( isset( $_POST['array_video_field'] ) ? $_POST['array_video_field'] : '' ); // Get existing video $video = get_post_meta( $post_id, 'array-video', true ); // If a new video was submitted and there was no previous one, add it if( $new_video && '' == $video ) { add_post_meta( $post_id, 'array-video', $new_video, true ); } // If the new video doesn't match the old video, update it. elseif( $new_video && $new_video != $video ) { update_post_meta( $post_id, 'array-video', $new_video ); } // If there's no new video and an old one exists, delete it. elseif( '' == $new_video && $video ) { delete_post_meta( $post_id, 'array-video', $video ); } } add_action( 'save_post', 'array_save_video_meta' );