From 3f701c5bef81960ffdb70c45364af6301257d187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 15 May 2017 15:50:27 -0300 Subject: [PATCH 1/8] First pass of remediation on video-thumbnails.php --- video-thumbnails.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/video-thumbnails.php b/video-thumbnails.php index 6883bb6..558d9a3 100755 --- a/video-thumbnails.php +++ b/video-thumbnails.php @@ -109,7 +109,7 @@ function admin_menu() { */ function admin_scripts( $hook ) { // Bulk tool page - if ( 'tools_page_video-thumbnails-bulk' == $hook ) { + if ( 'tools_page_video-thumbnails-bulk' === $hook ) { wp_enqueue_script( 'video-thumbnails-bulk-js', plugins_url( '/js/bulk.js' , __FILE__ ), array( 'jquery' ), VIDEO_THUMBNAILS_VERSION ); wp_localize_script( 'video-thumbnails-bulk-js', 'video_thumbnails_bulk_language', array( 'working' => __( 'Working...', 'video-thumbnails' ), @@ -151,7 +151,7 @@ function meta_box() { add_thickbox(); ?>

'; } + echo '

'; } - if ( get_post_status() == 'publish' || get_post_status() == 'private' ) { + if ( get_post_status() === 'publish' || get_post_status() === 'private' ) { if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) { - echo '

' . __( 'Reset Video Thumbnail', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'Reset Video Thumbnail', 'video-thumbnails' ) . '

'; } else { - echo '

' . __( 'No video thumbnail for this post.', 'video-thumbnails' ) . '

'; - echo '

' . __( 'Search Again', 'video-thumbnails' ) . ' ' . __( 'Troubleshoot', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'No video thumbnail for this post.', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'Search Again', 'video-thumbnails' ) . ' ' . esc_html__( 'Troubleshoot', 'video-thumbnails' ) . '

'; } } else { if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) { - echo '

' . __( 'Reset Video Thumbnail', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'Reset Video Thumbnail', 'video-thumbnails' ) . '

'; } else { - echo '

' . __( 'A video thumbnail will be found for this post when it is published.', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'A video thumbnail will be found for this post when it is published.', 'video-thumbnails' ) . '

'; } } } @@ -496,7 +496,7 @@ function bulk_posts_query_callback() { $args = apply_filters( 'video_thumbnails/bulk_posts_query', $args, $form_data ); $query = new WP_Query( $args ); - echo json_encode( $query->posts ); + echo wp_json_encode( $query->posts ); die(); } @@ -505,7 +505,7 @@ function bulk_posts_query_callback() { */ function get_thumbnail_for_post_callback() { - $post_id = $_POST['post_id']; + $post_id = (int) $_POST['post_id']; $thumb = get_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD, true ); if ( $thumb == '' ) { @@ -527,7 +527,7 @@ function get_thumbnail_for_post_callback() { $result = array(); } - echo json_encode( $result ); + echo wp_json_encode( $result ); die(); } @@ -537,15 +537,15 @@ function get_thumbnail_for_post_callback() { function bulk_scanning_page() { if ( ! current_user_can( 'manage_options' ) ) { - wp_die( __( 'You do not have sufficient permissions to access this page.', 'video-thumbnails' ) ); + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'video-thumbnails' ) ); } ?>
-

+

-

+

@@ -569,9 +569,9 @@ function bulk_scanning_page() {
- - - + + + From 1d1c829fc61e3639e75146fb99e1e9c270296a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 15 May 2017 17:06:52 -0300 Subject: [PATCH 2/8] Second pass of remediation on video-thumbnails.php --- video-thumbnails.php | 63 +++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/video-thumbnails.php b/video-thumbnails.php index 558d9a3..868bac4 100755 --- a/video-thumbnails.php +++ b/video-thumbnails.php @@ -69,7 +69,7 @@ function __construct() { add_action( 'xmlrpc_publish_post', 'get_video_thumbnail', 10, 1 ); // Add action for Ajax reset script on edit pages - if ( in_array( basename( $_SERVER['PHP_SELF'] ), apply_filters( 'video_thumbnails_editor_pages', array( 'post-new.php', 'page-new.php', 'post.php', 'page.php' ) ) ) ) { + if ( in_array( basename( $_SERVER['PHP_SELF'] ), apply_filters( 'video_thumbnails_editor_pages', array( 'post-new.php', 'page-new.php', 'post.php', 'page.php' ) ), true ) ) { add_action( 'admin_head', array( &$this, 'ajax_reset_script' ) ); } @@ -158,18 +158,18 @@ function meta_box() { $custom = get_post_custom( $post->ID ); if ( isset( $custom[VIDEO_THUMBNAILS_FIELD][0] ) ) $video_thumbnail = $custom[VIDEO_THUMBNAILS_FIELD][0]; - if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) { + if ( isset( $video_thumbnail ) && '' !== $video_thumbnail ) { echo '

'; } if ( get_post_status() === 'publish' || get_post_status() === 'private' ) { - if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) { + if ( isset( $video_thumbnail ) && '' !== $video_thumbnail ) { echo '

' . esc_html__( 'Reset Video Thumbnail', 'video-thumbnails' ) . '

'; } else { echo '

' . esc_html__( 'No video thumbnail for this post.', 'video-thumbnails' ) . '

'; echo '

' . esc_html__( 'Search Again', 'video-thumbnails' ) . ' ' . esc_html__( 'Troubleshoot', 'video-thumbnails' ) . '

'; } } else { - if ( isset( $video_thumbnail ) && $video_thumbnail != '' ) { + if ( isset( $video_thumbnail ) && '' !== $video_thumbnail ) { echo '

' . esc_html__( 'Reset Video Thumbnail', 'video-thumbnails' ) . '

'; } else { echo '

' . esc_html__( 'A video thumbnail will be found for this post when it is published.', 'video-thumbnails' ) . '

'; @@ -182,13 +182,13 @@ function meta_box() { */ public static function no_video_thumbnail_troubleshooting_instructions() { ?> -

+

    -
  1. +
  2. settings page. If you don\'t know the name of the field your video is being saved in, please contact the developer of that theme or plugin.', 'video-thumbnails' ), admin_url( 'options-general.php?page=video_thumbnails' ) ); ?>
  3. Debugging page. If this doesn\'t find the thumbnail, you\'ll want to be sure to include the embed code you scanned when you request support. If it does find a thumbnail, please double check that you have the Custom Field set correctly in the settings page if you are using a a plugin or theme that stores videos in a special location.', 'video-thumbnails' ), admin_url( 'options-general.php?page=video_thumbnails&tab=debugging' ), admin_url( 'options-general.php?page=video_thumbnails' ) ); ?>
  4. Debugging page and click "Test Image Downloading" to test your server\'s ability to save an image from a video source.', 'video-thumbnails' ), admin_url( 'options-general.php?page=video_thumbnails&tab=debugging' ) ); ?>
  5. -
  6. +
  7. support threads to see if anyone has had the same issue.', 'video-thumbnails' ); ?>
  8. start a thread with a good descriptive title ("Error" or "No thumbnails" is a bad title) and be sure to include the results of your testing as well. Also be sure to include the name of your theme, any video plugins you\'re using, and any other details you can think of.', 'video-thumbnails' ); ?>
@@ -246,7 +246,7 @@ function get_first_thumbnail_url( $markup ) { $videos = $this->find_videos( $markup ); foreach ( $videos as $video ) { $thumbnail = $this->providers[$video['provider']]->get_thumbnail_url( $video['id'] ); - if ( $thumbnail != null ) break; + if ( null !== $thumbnail ) break; } return $thumbnail; } @@ -259,10 +259,10 @@ function get_first_thumbnail_url( $markup ) { function get_video_thumbnail( $post_id = null ) { // Get the post ID if none is provided - if ( $post_id == null OR $post_id == '' ) $post_id = get_the_ID(); + if ( null === $post_id || '' ===$post_id ) $post_id = get_the_ID(); // Check to see if thumbnail has already been found - if( ( $thumbnail_meta = get_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD, true ) ) != '' ) { + if( ( $thumbnail_meta = get_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD, true ) ) !== '' ) { return $thumbnail_meta; } // If the thumbnail isn't stored in custom meta, fetch a thumbnail @@ -272,7 +272,7 @@ function get_video_thumbnail( $post_id = null ) { // Filter for extensions to set thumbnail $new_thumbnail = apply_filters( 'new_video_thumbnail_url', $new_thumbnail, $post_id ); - if ( $new_thumbnail == null ) { + if ( null === $new_thumbnail ) { // Get the post or custom field to search if ( $this->settings->options['custom_field'] ) { $markup = get_post_meta( $post_id, $this->settings->options['custom_field'], true ); @@ -289,10 +289,10 @@ function get_video_thumbnail( $post_id = null ) { } // Return the new thumbnail variable and update meta if one is found - if ( $new_thumbnail != null && !is_wp_error( $new_thumbnail ) ) { + if ( null !== $new_thumbnail && ! is_wp_error( $new_thumbnail ) ) { // Save as Attachment if enabled - if ( $this->settings->options['save_media'] == 1 ) { + if ( 1 === $this->settings->options['save_media'] ) { $attachment_id = $this->save_to_media_library( $new_thumbnail, $post_id ); if ( is_wp_error( $attachment_id ) ) { return $attachment_id; @@ -305,7 +305,7 @@ function get_video_thumbnail( $post_id = null ) { if ( !update_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD, $new_thumbnail ) ) add_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD, $new_thumbnail, true ); // Set attachment as featured image if enabled - if ( $this->settings->options['set_featured'] == 1 && $this->settings->options['save_media'] == 1 ) { + if ( 1 === $this->settings->options['set_featured'] && 1 === $this->settings->options['save_media'] ) { // Make sure there isn't already a post thumbnail if ( !ctype_digit( get_post_thumbnail_id( $post_id ) ) ) { set_post_thumbnail( $post_id, $attachment_id ); @@ -320,15 +320,18 @@ function get_video_thumbnail( $post_id = null ) { /** * Gets a video thumbnail when a published post is saved + * * @param int $post_id The post ID + * + * @return null */ function save_video_thumbnail( $post_id ) { // Don't save video thumbnails during autosave or for unpublished posts if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return null; - if ( get_post_status( $post_id ) != 'publish' ) return null; + if ( get_post_status( $post_id ) !== 'publish' ) return null; // Check that Video Thumbnails are enabled for current post type $post_type = get_post_type( $post_id ); - if ( in_array( $post_type, (array) $this->settings->options['post_types'] ) || $post_type == $this->settings->options['post_types'] ) { + if ( in_array( $post_type, (array) $this->settings->options['post_types'], true ) || $post_type === $this->settings->options['post_types'] ) { $this->get_video_thumbnail( $post_id ); } else { return null; @@ -348,7 +351,7 @@ static function construct_filename( $post_id ) { $filename = preg_replace( '/[^a-zA-Z0-9\-]/', '', $filename ); $filename = substr( $filename, 0, 32 ); $filename = trim( $filename, '-' ); - if ( $filename == '' ) $filename = (string) $post_id; + if ( '' === $filename ) $filename = (string) $post_id; return $filename; } @@ -356,7 +359,7 @@ static function construct_filename( $post_id ) { * Saves a remote image to the media library * @param string $image_url URL of the image to save * @param int $post_id ID of the post to attach image to - * @return int ID of the attachment + * @return int|WP_Error ID of the attachment */ public static function save_to_media_library( $image_url, $post_id ) { @@ -369,19 +372,19 @@ public static function save_to_media_library( $image_url, $post_id ) { $image_type = wp_remote_retrieve_header( $response, 'content-type' ); } - if ( $error != '' ) { + if ( '' !== $error ) { return $error; } else { // Translate MIME type into an extension - if ( $image_type == 'image/jpeg' ) { + if ( 'image/jpeg' === $image_type ) { $image_extension = '.jpg'; - } elseif ( $image_type == 'image/png' ) { + } elseif ( 'image/png' === $image_type ) { $image_extension = '.png'; - } elseif ( $image_type == 'image/gif' ) { + } elseif ( 'image/gif' === $image_type ) { $image_extension = '.gif'; } else { - return new WP_Error( 'thumbnail_upload', __( 'Unsupported MIME type:', 'video-thumbnails' ) . ' ' . $image_type ); + return new WP_Error( 'thumbnail_upload', esc_html__( 'Unsupported MIME type:', 'video-thumbnails' ) . ' ' . $image_type ); } // Construct a file name with extension @@ -462,7 +465,7 @@ function ajax_reset_script() { function ajax_reset_callback() { global $wpdb; // this is how you get access to the database - $post_id = $_POST['post_id']; + $post_id = (int) $_POST['post_id']; delete_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD ); @@ -470,10 +473,10 @@ function ajax_reset_callback() { if ( is_wp_error( $video_thumbnail ) ) { echo $video_thumbnail->get_error_message(); - } else if ( $video_thumbnail != null ) { - echo ''; + } else if ( null !== $video_thumbnail ) { + echo ''; } else { - echo __( 'No video thumbnail for this post.', 'video-thumbnails' ); + echo esc_html__( 'No video thumbnail for this post.', 'video-thumbnails' ); } die(); @@ -508,7 +511,7 @@ function get_thumbnail_for_post_callback() { $post_id = (int) $_POST['post_id']; $thumb = get_post_meta( $post_id, VIDEO_THUMBNAILS_FIELD, true ); - if ( $thumb == '' ) { + if ( '' === $thumb ) { global $video_thumbnails; $thumb = $video_thumbnails->get_video_thumbnail( $post_id ); if ( $thumb ) { @@ -518,7 +521,7 @@ function get_thumbnail_for_post_callback() { $type = 'existing'; } - if ( $thumb != '' ) { + if ( '' !== $thumb ) { $result = array( 'type' => $type, 'url' => $thumb @@ -604,7 +607,7 @@ function get_video_thumbnail( $post_id = null ) { // Echo thumbnail function video_thumbnail( $post_id = null ) { - if ( ( $video_thumbnail = get_video_thumbnail( $post_id ) ) == null ) { echo plugins_url() . '/video-thumbnails/default.jpg'; } + if ( ( $video_thumbnail = get_video_thumbnail( $post_id ) ) === null ) { echo esc_url( plugins_url() ) . '/video-thumbnails/default.jpg'; } else { echo $video_thumbnail; } } From f2939ebaa124417f9fd74a5232a6c8acd32294d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Mon, 15 May 2017 17:23:38 -0300 Subject: [PATCH 3/8] First pass on php/class-video-thumbnails-settings.php --- php/class-video-thumbnails-settings.php | 189 ++++++++++++------------ 1 file changed, 95 insertions(+), 94 deletions(-) diff --git a/php/class-video-thumbnails-settings.php b/php/class-video-thumbnails-settings.php index 7321648..f6d62c4 100755 --- a/php/class-video-thumbnails-settings.php +++ b/php/class-video-thumbnails-settings.php @@ -124,8 +124,8 @@ function upgrade_options( $options ) { function admin_menu() { add_options_page( - __( 'Video Thumbnails Options', 'video-thumbnails' ), - __( 'Video Thumbnails', 'video-thumbnails' ), + esc_html__( 'Video Thumbnails Options', 'video-thumbnails' ), + esc_html__( 'Video Thumbnails', 'video-thumbnails' ), 'manage_options', 'video_thumbnails', array( &$this, 'options_page' ) @@ -133,15 +133,15 @@ function admin_menu() { } function admin_scripts( $hook ) { - if ( 'settings_page_video_thumbnails' == $hook ) { + if ( 'settings_page_video_thumbnails' === $hook ) { wp_enqueue_style( 'video-thumbnails-settings-css', plugins_url( '/css/settings.css', VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ), false, VIDEO_THUMBNAILS_VERSION ); wp_enqueue_script( 'video_thumbnails_settings', plugins_url( 'js/settings.js' , VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php' ), array( 'jquery' ), VIDEO_THUMBNAILS_VERSION ); wp_localize_script( 'video_thumbnails_settings', 'video_thumbnails_settings_language', array( - 'detection_failed' => __( 'We were unable to find a video in the custom fields of your most recently updated post.', 'video-thumbnails' ), - 'working' => __( 'Working...', 'video-thumbnails' ), - 'retest' => __( 'Retest', 'video-thumbnails' ), - 'ajax_error' => __( 'AJAX Error:', 'video-thumbnails' ), - 'clear_all_confirmation' => __( 'Are you sure you want to clear all video thumbnails? This cannot be undone.', 'video-thumbnails' ), + 'detection_failed' => esc_html__( 'We were unable to find a video in the custom fields of your most recently updated post.', 'video-thumbnails' ), + 'working' => esc_html__( 'Working...', 'video-thumbnails' ), + 'retest' => esc_html__( 'Retest', 'video-thumbnails' ), + 'ajax_error' => esc_html__( 'AJAX Error:', 'video-thumbnails' ), + 'clear_all_confirmation' => esc_html__( 'Are you sure you want to clear all video thumbnails? This cannot be undone.', 'video-thumbnails' ), ) ); global $video_thumbnails; $provider_slugs = array(); @@ -194,10 +194,10 @@ function ajax_clear_all_callback() { foreach ( $media_library_items as $item ) { wp_delete_attachment( $item, true ); } - echo '

' . sprintf( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ), count( $media_library_items ) ) . '

'; + echo '

' . sprintf( esc_html( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ) ), count( $media_library_items ) ) . '

'; // Clear custom fields $custom_fields_cleared = $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key='_video_thumbnail'" ); - echo '

' . sprintf( _n( '1 custom field cleared', '%s custom fields cleared', $custom_fields_cleared, 'video-thumbnails' ), $custom_fields_cleared ) . '

'; + echo '

' . sprintf( esc_html( _n( '1 custom field cleared', '%s custom fields cleared', $custom_fields_cleared, 'video-thumbnails' ) ), $custom_fields_cleared ) . '

'; } else { echo '

' . __( 'Error: Could not verify nonce.', 'video-thumbnails' ) . '

'; } @@ -225,46 +225,47 @@ function provider_test_callback() {
- - - + + + providers[$_POST['provider_slug']]; + $failed = 0; foreach ( $provider->get_test_cases() as $test_case ) { echo ''; - echo ''; + echo ''; $markup = apply_filters( 'the_content', $test_case['markup'] ); $result = $video_thumbnails->get_first_thumbnail_url( $markup ); if ( is_wp_error( $result ) ) { $error_string = $result->get_error_message(); - echo ''; + echo ''; echo ''; $failed++; } else { $result_hash = false; - if ( $result == $test_case['expected'] ) { + if ( $result === $test_case['expected'] ) { $matched = true; } else { $result_hash = $this->get_file_hash( $result ); - $matched = ( $result_hash == $test_case['expected_hash'] ? true : false ); + $matched = ( $result_hash === $test_case['expected_hash'] ? true : false ); } if ( $matched ) { - echo ''; + echo ''; } else { - echo ''; + echo ''; } echo ''; } @@ -286,10 +287,10 @@ function image_download_test_callback() { } else { update_post_meta( $attachment_id, 'video_thumbnail_test_image', '1' ); $image = wp_get_attachment_image_src( $attachment_id, 'full' ); - echo ''; - echo '

' . __( 'Attachment created', 'video-thumbnails' ) . '

'; - echo '

' . __( 'View in Media Library', 'video-thumbnails' ) . '

'; - echo '' . __( 'View full size', 'video-thumbnails' ) . ''; + echo ''; + echo '

' . esc_html__( 'Attachment created', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'View in Media Library', 'video-thumbnails' ) . '

'; + echo '' . esc_html__( 'View full size', 'video-thumbnails' ) . ''; echo ''; } @@ -312,7 +313,7 @@ function delete_test_images_callback() { foreach ( $media_library_items as $item ) { wp_delete_attachment( $item, true ); } - echo '

' . sprintf( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ), count( $media_library_items ) ) . '

'; + echo '

' . sprintf( esc_html( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ) ), count( $media_library_items ) ) . '

'; die(); } // End delete test images callback @@ -325,31 +326,31 @@ function markup_detection_test_callback() { global $video_thumbnails; - $markup = apply_filters( 'the_content', stripslashes( $_POST['markup'] ) ); + $markup = apply_filters( 'the_content', wp_kses_post( $_POST['markup'] ) ); $new_thumbnail = $video_thumbnails->get_first_thumbnail_url( $markup ); - if ( $new_thumbnail == null ) { + if ( $new_thumbnail === null ) { // No thumbnail - echo '

' . __( 'No thumbnail found', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'No thumbnail found', 'video-thumbnails' ) . '

'; } elseif ( is_wp_error( $new_thumbnail ) ) { // Error finding thumbnail - echo '

' . __( 'Error Details:', 'video-thumbnails' ) . ' ' . $new_thumbnail->get_error_message() . '

'; + echo '

' . esc_html__( 'Error Details:', 'video-thumbnails' ) . ' ' . $new_thumbnail->get_error_message() . '

'; } else { // Found a thumbnail $remote_response = wp_remote_head( $new_thumbnail ); if ( is_wp_error( $remote_response ) ) { // WP Error trying to read image from remote server - echo '

' . __( 'Thumbnail found, but there was an error retrieving the URL.', 'video-thumbnails' ) . '

'; - echo '

' . __( 'Error Details:', 'video-thumbnails' ) . ' ' . $remote_response->get_error_message() . '

'; + echo '

' . esc_html__( 'Thumbnail found, but there was an error retrieving the URL.', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'Error Details:', 'video-thumbnails' ) . ' ' . $remote_response->get_error_message() . '

'; } elseif ( $remote_response['response']['code'] != '200' ) { // Response code isn't okay - echo '

' . __( 'Thumbnail found, but it may not exist on the source server. If opening the URL below in your web browser returns an error, the source is providing an invalid URL.', 'video-thumbnails' ) . '

'; - echo '

' . __( 'Thumbnail URL:', 'video-thumbnails' ) . ' ' . $new_thumbnail . ''; + echo '

' . esc_html__( 'Thumbnail found, but it may not exist on the source server. If opening the URL below in your web browser returns an error, the source is providing an invalid URL.', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'Thumbnail URL:', 'video-thumbnails' ) . ' ' . esc_html( $new_thumbnail ) . ''; } else { // Everything is okay! - echo '

' . __( 'Thumbnail found! Image should appear below.', 'video-thumbnails' ) . ' ' . __( 'View full size', 'video-thumbnails' ) . '

'; - echo '

'; + echo '

' . esc_html__( 'Thumbnail found! Image should appear below.', 'video-thumbnails' ) . ' ' . esc_html__( 'View full size', 'video-thumbnails' ) . '

'; + echo '

'; } } @@ -359,19 +360,19 @@ function markup_detection_test_callback() { function initialize_options() { add_settings_section( 'general_settings_section', - __( 'General Settings', 'video-thumbnails' ), + esc_html__( 'General Settings', 'video-thumbnails' ), array( &$this, 'general_settings_callback' ), 'video_thumbnails' ); $this->add_checkbox_setting( 'save_media', - __( 'Save Thumbnails to Media Library', 'video-thumbnails' ), - __( 'Checking this option will download video thumbnails to your server', 'video-thumbnails' ) + esc_html__( 'Save Thumbnails to Media Library', 'video-thumbnails' ), + esc_html__( 'Checking this option will download video thumbnails to your server', 'video-thumbnails' ) ); $this->add_checkbox_setting( 'set_featured', - __( 'Automatically Set Featured Image', 'video-thumbnails' ), - __( 'Check this option to automatically set video thumbnails as the featured image (requires saving to media library)', 'video-thumbnails' ) + esc_html__( 'Automatically Set Featured Image', 'video-thumbnails' ), + esc_html__( 'Check this option to automatically set video thumbnails as the featured image (requires saving to media library)', 'video-thumbnails' ) ); // Get post types $post_types = get_post_types( null, 'names' ); @@ -379,13 +380,13 @@ function initialize_options() { $post_types = array_diff( $post_types, array( 'attachment', 'revision', 'nav_menu_item' ) ); $this->add_multicheckbox_setting( 'post_types', - __( 'Post Types', 'video-thumbnails' ), + esc_html__( 'Post Types', 'video-thumbnails' ), $post_types ); $this->add_text_setting( 'custom_field', - __( 'Custom Field (optional)', 'video-thumbnails' ), - '' . __( 'Automatically Detect', 'video-thumbnails' ) . ' ' . __( 'Enter the name of the custom field where your embed code or video URL is stored.', 'video-thumbnails' ) + esc_html__( 'Custom Field (optional)', 'video-thumbnails' ), + '' . esc_html__( 'Automatically Detect', 'video-thumbnails' ) . ' ' . __( 'Enter the name of the custom field where your embed code or video URL is stored.', 'video-thumbnails' ) ); register_setting( 'video_thumbnails', 'video_thumbnails', array( &$this, 'sanitize_callback' ) ); } @@ -415,7 +416,7 @@ function sanitize_callback( $input ) { } function general_settings_callback() { - echo '

' . __( 'These options configure where the plugin will search for videos and what to do with thumbnails once found.', 'video-thumbnails' ) . '

'; + echo '

' . esc_html__( 'These options configure where the plugin will search for videos and what to do with thumbnails once found.', 'video-thumbnails' ) . '

'; } function add_checkbox_setting( $slug, $name, $description ) { @@ -433,7 +434,7 @@ function add_checkbox_setting( $slug, $name, $description ) { } function checkbox_callback( $args ) { - $html = ''; + $html = ''; echo $html; } @@ -459,8 +460,8 @@ function multicheckbox_callback( $args ) { } $html = ''; foreach ( $args['options'] as $option ) { - $checked = ( in_array( $option, $selected_types ) ? 'checked="checked"' : '' ); - $html .= '
'; + $checked = ( in_array( $option, $selected_types, true ) ? 'checked="checked"' : '' ); + $html .= '
'; } echo $html; } @@ -480,39 +481,39 @@ function add_text_setting( $slug, $name, $description ) { } function text_field_callback( $args ) { - $html = ''; - $html .= ''; + $html = ''; + $html .= ''; echo $html; } function options_page() { if ( ! current_user_can( 'manage_options' ) ) { - wp_die( __( 'You do not have sufficient permissions to access this page.', 'video-thumbnails' ) ); + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'video-thumbnails' ) ); } global $video_thumbnails; ?>
-

+

-

+

-

+

Video Thumbnails on the official plugin directory.', 'video-thumbnails' ); ?>

@@ -542,17 +543,17 @@ function options_page() { // Scan all posts if ( $active_tab == 'mass_actions' ) { ?> -

+

-

+

-

+

-

+

-

+

-

+

@@ -563,25 +564,25 @@ function options_page() { if ( $active_tab == 'debugging' ) { ?> -

+

- + -

+

-

+

- - + + - - + + - - + + - - + + - - + + - + @@ -718,8 +719,8 @@ public static function settings_footer() { ?>
-

-

+

+

Date: Wed, 17 May 2017 02:44:20 -0300 Subject: [PATCH 4/8] Fixing more PHPCS issues --- php/class-video-thumbnails-settings.php | 20 +++++++++---------- .../automatic-youtube-video-posts.php | 2 -- php/extensions/extensions.php | 2 -- php/extensions/simple-video-embedder.php | 2 -- php/extensions/wp-robot.php | 2 -- php/providers/class-blip-thumbnails.php | 2 -- .../class-collegehumor-thumbnails.php | 2 -- .../class-dailymotion-thumbnails.php | 2 -- php/providers/class-facebook-thumbnails.php | 2 -- php/providers/class-funnyordie-thumbnails.php | 2 -- .../class-googledrive-thumbnails.php | 2 -- php/providers/class-kaltura-thumbnails.php | 2 -- php/providers/class-livestream-thumbnails.php | 2 -- php/providers/class-metacafe-thumbnails.php | 2 -- php/providers/class-mpora-thumbnails.php | 2 -- php/providers/class-rutube-thumbnails.php | 2 -- php/providers/class-sapo-thumbnails.php | 2 -- php/providers/class-ted-thumbnails.php | 2 -- php/providers/class-tudou-thumbnails.php | 2 -- php/providers/class-twitch-thumbnails.php | 2 -- .../class-video-thumbnails-provider.php | 2 -- php/providers/class-vimeo-thumbnails.php | 2 -- php/providers/class-vine-thumbnails.php | 2 -- php/providers/class-vk-thumbnails.php | 2 -- php/providers/class-wistia-thumbnails.php | 2 -- .../class-yahooscreen-thumbnails.php | 2 -- php/providers/class-youku-thumbnails.php | 2 -- php/providers/class-youtube-thumbnails.php | 2 -- php/providers/providers.php | 2 -- video-thumbnails.php | 2 -- 30 files changed, 9 insertions(+), 69 deletions(-) diff --git a/php/class-video-thumbnails-settings.php b/php/class-video-thumbnails-settings.php index f6d62c4..3583870 100755 --- a/php/class-video-thumbnails-settings.php +++ b/php/class-video-thumbnails-settings.php @@ -86,7 +86,7 @@ function upgrade_options( $options ) { $post_types = get_option( 'video_thumbnails_post_types' ); // If there is a a post type option we know there should be others - if ( $post_types !== false ) { + if ( false !== $post_types ) { $options['post_types'] = $post_types; delete_option( 'video_thumbnails_post_types' ); @@ -330,7 +330,7 @@ function markup_detection_test_callback() { $new_thumbnail = $video_thumbnails->get_first_thumbnail_url( $markup ); - if ( $new_thumbnail === null ) { + if ( null === $new_thumbnail ) { // No thumbnail echo '

' . esc_html__( 'No thumbnail found', 'video-thumbnails' ) . '

'; } elseif ( is_wp_error( $new_thumbnail ) ) { @@ -343,7 +343,7 @@ function markup_detection_test_callback() { // WP Error trying to read image from remote server echo '

' . esc_html__( 'Thumbnail found, but there was an error retrieving the URL.', 'video-thumbnails' ) . '

'; echo '

' . esc_html__( 'Error Details:', 'video-thumbnails' ) . ' ' . $remote_response->get_error_message() . '

'; - } elseif ( $remote_response['response']['code'] != '200' ) { + } elseif ( '200' !== $remote_response['response']['code'] ) { // Response code isn't okay echo '

' . esc_html__( 'Thumbnail found, but it may not exist on the source server. If opening the URL below in your web browser returns an error, the source is providing an invalid URL.', 'video-thumbnails' ) . '

'; echo '

' . esc_html__( 'Thumbnail URL:', 'video-thumbnails' ) . ' ' . esc_html( $new_thumbnail ) . ''; @@ -397,7 +397,7 @@ function sanitize_callback( $input ) { // General settings if ( !isset( $input['provider_options'] ) ) { foreach( $current_settings as $key => $value ) { - if ( $key == 'version' OR $key == 'providers' ) { + if ( 'version' === $key || 'providers' === $key ) { $output[$key] = $current_settings[$key]; } elseif ( isset( $input[$key] ) ) { $output[$key] = $input[$key]; @@ -509,7 +509,7 @@ function options_page() {

@@ -527,7 +527,7 @@ function options_page() { // End main settings } // Provider Settings - if ( $active_tab == 'provider_settings' ) { + if ( 'provider_settings' === $active_tab ) { ?> @@ -541,7 +541,7 @@ function options_page() { // End provider settings } // Scan all posts - if ( $active_tab == 'mass_actions' ) { + if ( 'mass_actions' === $active_tab ) { ?>

@@ -561,7 +561,7 @@ function options_page() { // End scan all posts } // Debugging - if ( $active_tab == 'debugging' ) { + if ( 'debugging' === $active_tab ) { ?>

@@ -702,7 +702,7 @@ function options_page() { // End debugging } // Support - if ( $active_tab == 'support' ) { + if ( 'support' === $active_tab ) { Video_Thumbnails::no_video_thumbnail_troubleshooting_instructions(); @@ -727,5 +727,3 @@ public static function settings_footer() { } } - -?> \ No newline at end of file diff --git a/php/extensions/automatic-youtube-video-posts.php b/php/extensions/automatic-youtube-video-posts.php index 2d26bec..736331a 100755 --- a/php/extensions/automatic-youtube-video-posts.php +++ b/php/extensions/automatic-youtube-video-posts.php @@ -69,5 +69,3 @@ function ayvp_new_video_thumbnail_url_filter( $new_thumbnail, $post_id ) { remove_filter( 'post_thumbnail_html', 'WP_ayvpp_thumbnail' ); remove_filter( 'post_thumbnail_size', 'WP_ayvpp_thumbnail_size' ); } - -?> \ No newline at end of file diff --git a/php/extensions/extensions.php b/php/extensions/extensions.php index de562d7..9df576b 100644 --- a/php/extensions/extensions.php +++ b/php/extensions/extensions.php @@ -19,5 +19,3 @@ require_once( VIDEO_THUMBNAILS_PATH . '/php/extensions/automatic-youtube-video-posts.php' ); require_once( VIDEO_THUMBNAILS_PATH . '/php/extensions/simple-video-embedder.php' ); require_once( VIDEO_THUMBNAILS_PATH . '/php/extensions/wp-robot.php' ); - -?> \ No newline at end of file diff --git a/php/extensions/simple-video-embedder.php b/php/extensions/simple-video-embedder.php index b75cd98..67f697e 100755 --- a/php/extensions/simple-video-embedder.php +++ b/php/extensions/simple-video-embedder.php @@ -27,5 +27,3 @@ function simple_video_embedder_video_thumbnail_markup_filter( $markup, $post_id // Add filter to modify markup add_filter( 'video_thumbnail_markup', 'simple_video_embedder_video_thumbnail_markup_filter', 10, 2 ); - -?> \ No newline at end of file diff --git a/php/extensions/wp-robot.php b/php/extensions/wp-robot.php index 6c2e8b0..b8908e2 100644 --- a/php/extensions/wp-robot.php +++ b/php/extensions/wp-robot.php @@ -31,5 +31,3 @@ function video_thumbnails_wpr_after_post_action( $post_id ) { } add_action( 'wpr_after_post', 'video_thumbnails_wpr_after_post_action', 10, 1 ); - -?> \ No newline at end of file diff --git a/php/providers/class-blip-thumbnails.php b/php/providers/class-blip-thumbnails.php index bb8fc3f..66521f7 100755 --- a/php/providers/class-blip-thumbnails.php +++ b/php/providers/class-blip-thumbnails.php @@ -74,5 +74,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-collegehumor-thumbnails.php b/php/providers/class-collegehumor-thumbnails.php index bf0354c..d673d48 100755 --- a/php/providers/class-collegehumor-thumbnails.php +++ b/php/providers/class-collegehumor-thumbnails.php @@ -70,5 +70,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-dailymotion-thumbnails.php b/php/providers/class-dailymotion-thumbnails.php index fe8b29a..42246eb 100755 --- a/php/providers/class-dailymotion-thumbnails.php +++ b/php/providers/class-dailymotion-thumbnails.php @@ -72,5 +72,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-facebook-thumbnails.php b/php/providers/class-facebook-thumbnails.php index 6dec87e..ec5fab9 100755 --- a/php/providers/class-facebook-thumbnails.php +++ b/php/providers/class-facebook-thumbnails.php @@ -86,5 +86,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-funnyordie-thumbnails.php b/php/providers/class-funnyordie-thumbnails.php index e64cc19..96e8276 100755 --- a/php/providers/class-funnyordie-thumbnails.php +++ b/php/providers/class-funnyordie-thumbnails.php @@ -71,5 +71,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-googledrive-thumbnails.php b/php/providers/class-googledrive-thumbnails.php index 9a463c0..f3ed5c7 100644 --- a/php/providers/class-googledrive-thumbnails.php +++ b/php/providers/class-googledrive-thumbnails.php @@ -107,5 +107,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-kaltura-thumbnails.php b/php/providers/class-kaltura-thumbnails.php index 23075b4..ecaf92a 100755 --- a/php/providers/class-kaltura-thumbnails.php +++ b/php/providers/class-kaltura-thumbnails.php @@ -71,5 +71,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-livestream-thumbnails.php b/php/providers/class-livestream-thumbnails.php index 5880c5f..b2ecd1c 100644 --- a/php/providers/class-livestream-thumbnails.php +++ b/php/providers/class-livestream-thumbnails.php @@ -57,5 +57,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-metacafe-thumbnails.php b/php/providers/class-metacafe-thumbnails.php index 8eaf880..7d3d09b 100755 --- a/php/providers/class-metacafe-thumbnails.php +++ b/php/providers/class-metacafe-thumbnails.php @@ -66,5 +66,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-mpora-thumbnails.php b/php/providers/class-mpora-thumbnails.php index 13777cf..faae3ce 100755 --- a/php/providers/class-mpora-thumbnails.php +++ b/php/providers/class-mpora-thumbnails.php @@ -63,5 +63,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-rutube-thumbnails.php b/php/providers/class-rutube-thumbnails.php index fb8030c..7c7db17 100644 --- a/php/providers/class-rutube-thumbnails.php +++ b/php/providers/class-rutube-thumbnails.php @@ -74,5 +74,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-sapo-thumbnails.php b/php/providers/class-sapo-thumbnails.php index 329dd53..f96c444 100644 --- a/php/providers/class-sapo-thumbnails.php +++ b/php/providers/class-sapo-thumbnails.php @@ -74,5 +74,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-ted-thumbnails.php b/php/providers/class-ted-thumbnails.php index 450f603..944b5a6 100755 --- a/php/providers/class-ted-thumbnails.php +++ b/php/providers/class-ted-thumbnails.php @@ -70,5 +70,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-tudou-thumbnails.php b/php/providers/class-tudou-thumbnails.php index db3f407..a9b2723 100644 --- a/php/providers/class-tudou-thumbnails.php +++ b/php/providers/class-tudou-thumbnails.php @@ -88,5 +88,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-twitch-thumbnails.php b/php/providers/class-twitch-thumbnails.php index 2b25cbe..0878223 100644 --- a/php/providers/class-twitch-thumbnails.php +++ b/php/providers/class-twitch-thumbnails.php @@ -72,5 +72,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-video-thumbnails-provider.php b/php/providers/class-video-thumbnails-provider.php index 1305f57..69c210c 100755 --- a/php/providers/class-video-thumbnails-provider.php +++ b/php/providers/class-video-thumbnails-provider.php @@ -110,5 +110,3 @@ function construct_info_retrieval_error( $request, $response ) { // } } - -?> \ No newline at end of file diff --git a/php/providers/class-vimeo-thumbnails.php b/php/providers/class-vimeo-thumbnails.php index 759083f..ecfc4dc 100755 --- a/php/providers/class-vimeo-thumbnails.php +++ b/php/providers/class-vimeo-thumbnails.php @@ -673,5 +673,3 @@ public static function url_encode_rfc3986($input) if( !class_exists( 'VimeoAPIException' ) ) { class VimeoAPIException extends Exception {} } - -?> \ No newline at end of file diff --git a/php/providers/class-vine-thumbnails.php b/php/providers/class-vine-thumbnails.php index 385a952..236cd94 100644 --- a/php/providers/class-vine-thumbnails.php +++ b/php/providers/class-vine-thumbnails.php @@ -72,5 +72,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-vk-thumbnails.php b/php/providers/class-vk-thumbnails.php index da42fed..1ab9d3e 100644 --- a/php/providers/class-vk-thumbnails.php +++ b/php/providers/class-vk-thumbnails.php @@ -74,5 +74,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-wistia-thumbnails.php b/php/providers/class-wistia-thumbnails.php index 825acb5..865a4e0 100755 --- a/php/providers/class-wistia-thumbnails.php +++ b/php/providers/class-wistia-thumbnails.php @@ -94,5 +94,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-yahooscreen-thumbnails.php b/php/providers/class-yahooscreen-thumbnails.php index 90e36d7..84d953e 100644 --- a/php/providers/class-yahooscreen-thumbnails.php +++ b/php/providers/class-yahooscreen-thumbnails.php @@ -72,5 +72,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-youku-thumbnails.php b/php/providers/class-youku-thumbnails.php index d08a332..45bba4c 100755 --- a/php/providers/class-youku-thumbnails.php +++ b/php/providers/class-youku-thumbnails.php @@ -78,5 +78,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/class-youtube-thumbnails.php b/php/providers/class-youtube-thumbnails.php index 255576c..6c1bee9 100755 --- a/php/providers/class-youtube-thumbnails.php +++ b/php/providers/class-youtube-thumbnails.php @@ -85,5 +85,3 @@ public static function get_test_cases() { } } - -?> \ No newline at end of file diff --git a/php/providers/providers.php b/php/providers/providers.php index 1915535..3c0a248 100755 --- a/php/providers/providers.php +++ b/php/providers/providers.php @@ -63,5 +63,3 @@ add_filter( 'video_thumbnail_providers', array( 'Yahooscreen_Thumbnails', 'register_provider' ) ); add_filter( 'video_thumbnail_providers', array( 'Livestream_Thumbnails', 'register_provider' ) ); // add_filter( 'video_thumbnail_providers', array( 'Kaltura_Thumbnails', 'register_provider' ) ); - -?> \ No newline at end of file diff --git a/video-thumbnails.php b/video-thumbnails.php index 868bac4..3f34ac3 100755 --- a/video-thumbnails.php +++ b/video-thumbnails.php @@ -610,5 +610,3 @@ function video_thumbnail( $post_id = null ) { if ( ( $video_thumbnail = get_video_thumbnail( $post_id ) ) === null ) { echo esc_url( plugins_url() ) . '/video-thumbnails/default.jpg'; } else { echo $video_thumbnail; } } - -?> \ No newline at end of file From c56f0c5bddfde6a600d0c741a2fece599762f049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Wed, 17 May 2017 18:51:00 -0300 Subject: [PATCH 5/8] More escaping fixes --- php/providers/class-blip-thumbnails.php | 4 ++-- php/providers/class-collegehumor-thumbnails.php | 4 ++-- php/providers/class-dailymotion-thumbnails.php | 4 ++-- php/providers/class-facebook-thumbnails.php | 6 +++--- php/providers/class-funnyordie-thumbnails.php | 4 ++-- php/providers/class-googledrive-thumbnails.php | 8 ++++---- php/providers/class-kaltura-thumbnails.php | 2 +- php/providers/class-livestream-thumbnails.php | 2 +- php/providers/class-metacafe-thumbnails.php | 2 +- php/providers/class-mpora-thumbnails.php | 4 ++-- php/providers/class-rutube-thumbnails.php | 4 ++-- php/providers/class-sapo-thumbnails.php | 2 +- php/providers/class-ted-thumbnails.php | 4 ++-- php/providers/class-tudou-thumbnails.php | 2 +- php/providers/class-twitch-thumbnails.php | 4 ++-- php/providers/class-video-thumbnails-provider.php | 4 ++-- php/providers/class-vine-thumbnails.php | 2 +- php/providers/class-vk-thumbnails.php | 2 +- php/providers/class-wistia-thumbnails.php | 4 ++-- php/providers/class-yahooscreen-thumbnails.php | 2 +- php/providers/class-youku-thumbnails.php | 6 +++--- php/providers/class-youtube-thumbnails.php | 8 ++++---- 22 files changed, 42 insertions(+), 42 deletions(-) diff --git a/php/providers/class-blip-thumbnails.php b/php/providers/class-blip-thumbnails.php index 66521f7..fbe0236 100755 --- a/php/providers/class-blip-thumbnails.php +++ b/php/providers/class-blip-thumbnails.php @@ -62,13 +62,13 @@ public static function get_test_cases() { 'markup' => 'http://blip.tv/cranetv/illustrator-katie-scott-6617917', 'expected' => 'http://a.images.blip.tv/CraneTV-IllustratorKatieScott610.jpg', 'expected_hash' => '26a622f72bd4bdb3f8189f85598dd95d', - 'name' => __( 'Video URL', 'video-thumbnails' ) + 'name' => esc_html__( 'Video URL', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://a.images.blip.tv/GeekCrashCourse-TheAvengersMarvelMovieCatchUpGeekCrashCourse331.png', 'expected_hash' => '87efa9f6b0d9111b0826ae4fbdddec1b', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-collegehumor-thumbnails.php b/php/providers/class-collegehumor-thumbnails.php index d673d48..a8fc8ad 100755 --- a/php/providers/class-collegehumor-thumbnails.php +++ b/php/providers/class-collegehumor-thumbnails.php @@ -58,13 +58,13 @@ public static function get_test_cases() { 'markup' => '

CollegeHumor\'s Favorite Funny Videos

', 'expected' => 'http://2.media.collegehumor.cvcdn.com/62/99/20502ca0d5b2172421002b52f437dcf8-mitt-romney-style-gangnam-style-parody.jpg', 'expected_hash' => 'ceac16f6ee1fa5d8707e813226060a15', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => 'http://www.collegehumor.com/video/6830834/mitt-romney-style-gangnam-style-parody', 'expected' => 'http://2.media.collegehumor.cvcdn.com/62/99/20502ca0d5b2172421002b52f437dcf8-mitt-romney-style-gangnam-style-parody.jpg', 'expected_hash' => 'ceac16f6ee1fa5d8707e813226060a15', - 'name' => __( 'Video URL', 'video-thumbnails' ) + 'name' => esc_html__( 'Video URL', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-dailymotion-thumbnails.php b/php/providers/class-dailymotion-thumbnails.php index 42246eb..d204be5 100755 --- a/php/providers/class-dailymotion-thumbnails.php +++ b/php/providers/class-dailymotion-thumbnails.php @@ -60,13 +60,13 @@ public static function get_test_cases() { 'markup' => '
Adam Yauch of the Beastie Boys Dies at 47 by associatedpress', 'expected' => 'http://s1.dmcdn.net/AMjdy.jpg', 'expected_hash' => '077888b97839254892a377f51c06e642', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '
Adam Yauch of the Beastie Boys Dies at 47 by associatedpress', 'expected' => 'http://s1.dmcdn.net/AMjdy.jpg', 'expected_hash' => '077888b97839254892a377f51c06e642', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-facebook-thumbnails.php b/php/providers/class-facebook-thumbnails.php index ec5fab9..437f576 100755 --- a/php/providers/class-facebook-thumbnails.php +++ b/php/providers/class-facebook-thumbnails.php @@ -68,19 +68,19 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/v/t15.0-10/p160x160/50796_2560034672650_2560032632599_65313_313_b.jpg?oh=e8c767b1efafa6d8a4b672bad7be38d6&oe=55364081&__gda__=1428807476_a4d83140019b11ad602f2ef9960a364e', 'expected_hash' => '6b033d8f16dbf273048c5771d32ede64', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/v/t15.0-10/p160x160/50796_2560034672650_2560032632599_65313_313_b.jpg?oh=e8c767b1efafa6d8a4b672bad7be38d6&oe=55364081&__gda__=1428807476_a4d83140019b11ad602f2ef9960a364e', 'expected_hash' => '6b033d8f16dbf273048c5771d32ede64', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '
', 'expected' => 'https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xfa1/v/t15.0-10/p128x128/244423_10150326375786807_10150326323406807_4366_759_b.jpg?oh=013ce21bb54de51c383071598b269a91&oe=552CD270&__gda__=1428479462_339647870ec32227c391e98000935aec', 'expected_hash' => '184d20db21ac8edef9c9cee291be5ee6', - 'name' => __( 'FBML Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'FBML Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-funnyordie-thumbnails.php b/php/providers/class-funnyordie-thumbnails.php index 96e8276..64fbea2 100755 --- a/php/providers/class-funnyordie-thumbnails.php +++ b/php/providers/class-funnyordie-thumbnails.php @@ -59,13 +59,13 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://t.fod4.com/t/5325b03b52/c480x270_17.jpg', 'expected_hash' => '5aafa4a5f27bd4aead574db38a9e8b2b', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://t.fod4.com/t/5325b03b52/c480x270_17.jpg', 'expected_hash' => '5aafa4a5f27bd4aead574db38a9e8b2b', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-googledrive-thumbnails.php b/php/providers/class-googledrive-thumbnails.php index f3ed5c7..499badd 100644 --- a/php/providers/class-googledrive-thumbnails.php +++ b/php/providers/class-googledrive-thumbnails.php @@ -83,25 +83,25 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'https://lh3.googleusercontent.com/QL3d7Wh7V_qcXnMpXT6bio77RS0veyCZZ0zQbMX6gd-qH7aeIXBkXlcSJVDEyftiiA=s480', 'expected_hash' => '3bc674d8d77b342e633ab9e93e345462', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://lh6.googleusercontent.com/WeOdCsaplJ3am25To1uLZiVYkyrilAQ5rxzhjnyyFc5GAF4QeCF1eq3EMpbP7O5dFg=s480', 'expected_hash' => 'f120755bbd1d35e381cb84a829ac0dfa', - 'name' => __( 'iFrame Embed (Apps account)', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed (Apps account)', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://lh3.googleusercontent.com/U_lqaX1o7E9iU75XwCrHZ4pdSi-Vch2F_GK5Ib7WAxgwKTvTl0kMHXm2GxKo1Pcp3Q=s480', 'expected_hash' => '31cf8e05f981c1beb6e04823ad54d267', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://lh5.googleusercontent.com/mHn5gESachhZHi-kbPCRbR6RVXZm3bR7oNNXL97LyYjpzV3Eqty71J2Waw0DPnXKKw=s480', 'expected_hash' => '2d0ad4881e4b38de0510a103d2f40dd1', - 'name' => __( 'Flash Embed (YouTube player)', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed (YouTube player)', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-kaltura-thumbnails.php b/php/providers/class-kaltura-thumbnails.php index ecaf92a..9898870 100755 --- a/php/providers/class-kaltura-thumbnails.php +++ b/php/providers/class-kaltura-thumbnails.php @@ -65,7 +65,7 @@ public static function get_test_cases() { array( 'markup' => '', 'expected' => 'http://example.com/thumbnail.jpg', - 'name' => __( 'Auto Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Auto Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-livestream-thumbnails.php b/php/providers/class-livestream-thumbnails.php index b2ecd1c..4be2f53 100644 --- a/php/providers/class-livestream-thumbnails.php +++ b/php/providers/class-livestream-thumbnails.php @@ -51,7 +51,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://thumbnail.api.livestream.com/thumbnail?name=WFMZ_Traffic', 'expected_hash' => '1be02799b2fab7a4749b2187f7687412', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-metacafe-thumbnails.php b/php/providers/class-metacafe-thumbnails.php index 7d3d09b..e83c4c9 100755 --- a/php/providers/class-metacafe-thumbnails.php +++ b/php/providers/class-metacafe-thumbnails.php @@ -60,7 +60,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://s4.mcstatic.com/thumb/8456223/22479418/4/catalog_item5/0/1/men_in_black_3_trailer_2.jpg', 'expected_hash' => '977187bfb00df55b39724d7de284f617', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-mpora-thumbnails.php b/php/providers/class-mpora-thumbnails.php index faae3ce..8b33204 100755 --- a/php/providers/class-mpora-thumbnails.php +++ b/php/providers/class-mpora-thumbnails.php @@ -51,13 +51,13 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://ugc4.mporatrons.com/thumbs/wEr2CBooV_640x360_0000.jpg', 'expected_hash' => '95075bd4941251ebecbab3b436a90c49', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://ugc4.mporatrons.com/thumbs/AAdfegovdop0_640x360_0000.jpg', 'expected_hash' => '45db22a2ba5ef20163f52ba562b89259', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-rutube-thumbnails.php b/php/providers/class-rutube-thumbnails.php index 7c7db17..33812df 100644 --- a/php/providers/class-rutube-thumbnails.php +++ b/php/providers/class-rutube-thumbnails.php @@ -62,13 +62,13 @@ public static function get_test_cases() { 'markup' => 'http://rutube.ru/video/ca8607cd4f7ef28516e043dde0068564/', 'expected' => 'http://pic.rutube.ru/video/3a/c8/3ac8c1ded16501002d20fa3ba3ed3d61.jpg', 'expected_hash' => '85ad79c118ee82c7c2a756ba29a96354', - 'name' => __( 'Video URL', 'video-thumbnails' ) + 'name' => esc_html__( 'Video URL', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://pic.rutube.ru/video/3a/c8/3ac8c1ded16501002d20fa3ba3ed3d61.jpg', 'expected_hash' => '85ad79c118ee82c7c2a756ba29a96354', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-sapo-thumbnails.php b/php/providers/class-sapo-thumbnails.php index f96c444..af2ce16 100644 --- a/php/providers/class-sapo-thumbnails.php +++ b/php/providers/class-sapo-thumbnails.php @@ -68,7 +68,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://cache02.stormap.sapo.pt/vidstore14/thumbnais/e9/08/37/7038489_l5VMt.jpg', 'expected_hash' => 'd8a74c3d4e054263a37abe9ceed782fd', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-ted-thumbnails.php b/php/providers/class-ted-thumbnails.php index 944b5a6..048d9ac 100755 --- a/php/providers/class-ted-thumbnails.php +++ b/php/providers/class-ted-thumbnails.php @@ -58,13 +58,13 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://images.ted.com/images/ted/341053090f8bac8c324c75be3114b673b4355e8a_480x360.jpg?lang=en', 'expected_hash' => 'f2a5f6af49e841b4f9c7b95d6ca0372a', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://images.ted.com/images/ted/b1f1183311cda4df9e1b65f2b363e0b806bff914_480x360.jpg?lang=en', 'expected_hash' => 'ff47c99c9eb95e3d6c4b986b18991f22', - 'name' => __( 'Custom Language', 'video-thumbnails' ) + 'name' => esc_html__( 'Custom Language', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-tudou-thumbnails.php b/php/providers/class-tudou-thumbnails.php index a9b2723..ea87ecd 100644 --- a/php/providers/class-tudou-thumbnails.php +++ b/php/providers/class-tudou-thumbnails.php @@ -82,7 +82,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://g3.tdimg.com/83fedbc41cf9055dce9182a0c07da601/w_2.jpg', 'expected_hash' => '3a5e656f8c302ae5b23665f22d296ae1', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-twitch-thumbnails.php b/php/providers/class-twitch-thumbnails.php index 0878223..3178bbf 100644 --- a/php/providers/class-twitch-thumbnails.php +++ b/php/providers/class-twitch-thumbnails.php @@ -60,13 +60,13 @@ public static function get_test_cases() { 'markup' => 'http://www.twitch.tv/jodenstone/c/5793313', 'expected' => 'http://static-cdn.jtvnw.net/jtv.thumbs/archive-605904705-320x240.jpg', 'expected_hash' => '1b2c51fc7380c74d1b2d34751d73e4cb', - 'name' => __( 'Video URL', 'video-thumbnails' ) + 'name' => esc_html__( 'Video URL', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://static-cdn.jtvnw.net/jtv.thumbs/archive-605904705-320x240.jpg', 'expected_hash' => '1b2c51fc7380c74d1b2d34751d73e4cb', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-video-thumbnails-provider.php b/php/providers/class-video-thumbnails-provider.php index 69c210c..c05b3d7 100755 --- a/php/providers/class-video-thumbnails-provider.php +++ b/php/providers/class-video-thumbnails-provider.php @@ -58,8 +58,8 @@ function settings_section_callback() { function text_setting_callback( $args ) { $value = ( isset( $this->options[$args['slug']] ) ? $this->options[$args['slug']] : '' ); - $html = ''; - $html .= ''; + $html = ''; + $html .= ''; echo $html; } diff --git a/php/providers/class-vine-thumbnails.php b/php/providers/class-vine-thumbnails.php index 236cd94..ddb97e2 100644 --- a/php/providers/class-vine-thumbnails.php +++ b/php/providers/class-vine-thumbnails.php @@ -66,7 +66,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'https://v.cdn.vine.co/v/thumbs/D6DDE013-F8DA-4929-9BED-49568F424343-184-00000008A20C1AEC_1.0.6.mp4.jpg', 'expected_hash' => '7cca5921108abe15b8c1c1f884a5b3ac', - 'name' => __( 'iFrame Embed/Video URL', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed/Video URL', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-vk-thumbnails.php b/php/providers/class-vk-thumbnails.php index 1ab9d3e..71268de 100644 --- a/php/providers/class-vk-thumbnails.php +++ b/php/providers/class-vk-thumbnails.php @@ -68,7 +68,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://cs540302.vk.me/u220943440/video/l_afc9770f.jpg', 'expected_hash' => 'fd8c2af4ad5cd4e55afe129d80b42d8b', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-wistia-thumbnails.php b/php/providers/class-wistia-thumbnails.php index 865a4e0..ed20831 100755 --- a/php/providers/class-wistia-thumbnails.php +++ b/php/providers/class-wistia-thumbnails.php @@ -82,13 +82,13 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'https://embed-ssl.wistia.com/deliveries/6928fcba8355e38de4d95863a659e1de23cb2071.jpg', 'expected_hash' => 'bc4a2cec9ac97e2ccdae2c7387a01cb4', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '
', 'expected' => 'https://embed-ssl.wistia.com/deliveries/a086707fe096e7f3fbefef1d1dcba1488d23a3e9.jpg', 'expected_hash' => '4c63d131604bfc07b5178413ab245813', - 'name' => __( 'JavaScript Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'JavaScript Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-yahooscreen-thumbnails.php b/php/providers/class-yahooscreen-thumbnails.php index 84d953e..13ca986 100644 --- a/php/providers/class-yahooscreen-thumbnails.php +++ b/php/providers/class-yahooscreen-thumbnails.php @@ -66,7 +66,7 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://media.zenfs.com/en-US/video/video.abcnewsplus.com/7c70071008e3711818517f19b6ad9629', 'expected_hash' => '22c2b172b297cf09511d832ddab7b9f5', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-youku-thumbnails.php b/php/providers/class-youku-thumbnails.php index 45bba4c..47ac418 100755 --- a/php/providers/class-youku-thumbnails.php +++ b/php/providers/class-youku-thumbnails.php @@ -60,19 +60,19 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://g1.ykimg.com/1100641F464F0FB57407E2053DFCBC802FBBC4-E4C5-7A58-0394-26C366F10493', 'expected_hash' => 'deac7bb89058a8c46ae2350da9d33ba8', - 'name' => __( 'iFrame Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://g1.ykimg.com/1100641F464F0FB57407E2053DFCBC802FBBC4-E4C5-7A58-0394-26C366F10493', 'expected_hash' => 'deac7bb89058a8c46ae2350da9d33ba8', - 'name' => __( 'Flash Embed', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed', 'video-thumbnails' ) ), array( 'markup' => 'http://v.youku.com/v_show/id_XMzQyMzk5MzQ4.html', 'expected' => 'http://g1.ykimg.com/1100641F464F0FB57407E2053DFCBC802FBBC4-E4C5-7A58-0394-26C366F10493', 'expected_hash' => 'deac7bb89058a8c46ae2350da9d33ba8', - 'name' => __( 'Video URL', 'video-thumbnails' ) + 'name' => esc_html__( 'Video URL', 'video-thumbnails' ) ), ); } diff --git a/php/providers/class-youtube-thumbnails.php b/php/providers/class-youtube-thumbnails.php index 6c1bee9..5d18466 100755 --- a/php/providers/class-youtube-thumbnails.php +++ b/php/providers/class-youtube-thumbnails.php @@ -61,25 +61,25 @@ public static function get_test_cases() { 'markup' => '', 'expected' => 'http://img.youtube.com/vi/Fp0U2Vglkjw/maxresdefault.jpg', 'expected_hash' => 'c66256332969c38790c2b9f26f725e7a', - 'name' => __( 'iFrame Embed HD', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed HD', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://img.youtube.com/vi/Fp0U2Vglkjw/maxresdefault.jpg', 'expected_hash' => 'c66256332969c38790c2b9f26f725e7a', - 'name' => __( 'Flash Embed HD', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed HD', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://img.youtube.com/vi/vv_AitYPjtc/0.jpg', 'expected_hash' => '6c00b9ab335a6ea00b0fb964c39a6dc9', - 'name' => __( 'iFrame Embed SD', 'video-thumbnails' ) + 'name' => esc_html__( 'iFrame Embed SD', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'http://img.youtube.com/vi/vv_AitYPjtc/0.jpg', 'expected_hash' => '6c00b9ab335a6ea00b0fb964c39a6dc9', - 'name' => __( 'Flash Embed SD', 'video-thumbnails' ) + 'name' => esc_html__( 'Flash Embed SD', 'video-thumbnails' ) ), ); } From 38c2f571169a14cd50aad831652c1d30bc2762a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Thu, 18 May 2017 11:30:58 -0300 Subject: [PATCH 6/8] Fixes an escaping issue and only deletes plugin options on unistall --- php/class-video-thumbnails-settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/php/class-video-thumbnails-settings.php b/php/class-video-thumbnails-settings.php index 3583870..e69a30d 100755 --- a/php/class-video-thumbnails-settings.php +++ b/php/class-video-thumbnails-settings.php @@ -30,7 +30,7 @@ class Video_Thumbnails_Settings { function __construct() { // Activation and deactivation hooks register_activation_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_activation' ) ); - register_deactivation_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_deactivation' ) ); + register_uninstall_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_deactivation' ) ); // Set current options add_action( 'plugins_loaded', array( &$this, 'set_options' ) ); // Add options page to menu @@ -385,8 +385,8 @@ function initialize_options() { ); $this->add_text_setting( 'custom_field', - esc_html__( 'Custom Field (optional)', 'video-thumbnails' ), - '' . esc_html__( 'Automatically Detect', 'video-thumbnails' ) . ' ' . __( 'Enter the name of the custom field where your embed code or video URL is stored.', 'video-thumbnails' ) + __( 'Custom Field (optional)', 'video-thumbnails' ), + '' . esc_html__( 'Automatically Detect', 'video-thumbnails' ) . ' ' . esc_html__( 'Enter the name of the custom field where your embed code or video URL is stored.', 'video-thumbnails' ) ); register_setting( 'video_thumbnails', 'video_thumbnails', array( &$this, 'sanitize_callback' ) ); } @@ -482,7 +482,7 @@ function add_text_setting( $slug, $name, $description ) { function text_field_callback( $args ) { $html = ''; - $html .= ''; + $html .= ''; echo $html; } From 17ab77b2605bedac005a01d9353cbf7d3db7bbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Thu, 18 May 2017 12:13:57 -0300 Subject: [PATCH 7/8] Running the clear_all_callback in a better way --- php/class-video-thumbnails-settings.php | 115 +++++++++++++++++++++--- 1 file changed, 105 insertions(+), 10 deletions(-) diff --git a/php/class-video-thumbnails-settings.php b/php/class-video-thumbnails-settings.php index e69a30d..b30c8c8 100755 --- a/php/class-video-thumbnails-settings.php +++ b/php/class-video-thumbnails-settings.php @@ -30,7 +30,7 @@ class Video_Thumbnails_Settings { function __construct() { // Activation and deactivation hooks register_activation_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_activation' ) ); - register_uninstall_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_deactivation' ) ); + register_uninstall_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( 'Video_Thumbnails_Settings', 'plugin_deactivation' ) ); // Set current options add_action( 'plugins_loaded', array( &$this, 'set_options' ) ); // Add options page to menu @@ -58,7 +58,7 @@ function plugin_activation() { } // Deactivation hook - function plugin_deactivation() { + public static function plugin_deactivation() { delete_option( 'video_thumbnails' ); } @@ -161,6 +161,99 @@ function custom_field_detection_callback() { die(); } + /** + * Frees up memory for long running processes. + */ + function stop_the_insanity() { + global $wpdb, $wp_actions, $wp_filter, $wp_object_cache; + //reset queries + $wpdb->queries = array(); + // Prevent wp_actions from growing out of control + $wp_actions = array(); + if ( is_object( $wp_object_cache ) ) { + $wp_object_cache->group_ops = array(); + $wp_object_cache->stats = array(); + $wp_object_cache->memcache_debug = array(); + $wp_object_cache->cache = array(); + if ( method_exists( $wp_object_cache, '__remoteset' ) ) { + $wp_object_cache->__remoteset(); + } + } + /* + * The WP_Query class hooks a reference to one of its own methods + * onto filters if update_post_term_cache or + * update_post_meta_cache are true, which prevents PHP's garbage + * collector from cleaning up the WP_Query instance on long- + * running processes. + * + * By manually removing these callbacks (often created by things + * like get_posts()), we're able to properly unallocate memory + * once occupied by a WP_Query object. + * + */ + if ( isset( $wp_filter['get_term_metadata'] ) ) { + /* + * WordPress 4.7 has a new Hook infrastructure, so we need to make sure + * we're accessing the global array properly. + */ + if ( class_exists( 'WP_Hook' ) && $wp_filter['get_term_metadata'] instanceof \WP_Hook ) { + $filter_callbacks = &$wp_filter['get_term_metadata']->callbacks; + } else { + $filter_callbacks = &$wp_filter['get_term_metadata']; + } + if ( isset( $filter_callbacks[10] ) ) { + foreach ( $filter_callbacks[10] as $hook => $content ) { + if ( preg_match( '#^[0-9a-f]{32}lazyload_term_meta$#', $hook ) ) { + unset( $filter_callbacks[10][ $hook ] ); + } + } + } + } + } + + /** + * Runs through all posts and executes the provided callback for each post. + * + * @param array $query_args + * @param callable $callback + * + * @return int + */ + protected function all_posts( $query_args, $callback) { + if ( ! is_callable( $callback ) ) { + return; + } + + $default_args = array( + 'post_type' => 'post', + 'posts_per_page' => 200, + 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private' ), + 'cache_results ' => false, + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false, + 'offset' => 0, + ); + + $query_args = wp_parse_args( $query_args, $default_args ); + $query = new \WP_Query( $query_args ); + $counter = 0; + + while ( $query->have_posts() ) { + $query->the_post(); + $callback(); + + $counter++; + if ( 0 === $counter % $query_args['posts_per_page'] ) { + $this->stop_the_insanity(); + $query_args['offset'] += $query_args['posts_per_page']; + $query = new \WP_Query( $query_args ); + } + } + wp_reset_postdata(); + + return $counter; + } + function detect_custom_field() { global $video_thumbnails; $latest_post = get_posts( array( @@ -180,21 +273,23 @@ function detect_custom_field() { } function ajax_clear_all_callback() { - if ( !current_user_can( 'manage_options' ) ) die(); + if ( ! current_user_can( 'manage_options' ) ) { + die(); + } if ( wp_verify_nonce( $_POST['nonce'], 'clear_all_video_thumbnails' ) ) { global $wpdb; + // Clear images from media library - $media_library_items = get_posts( array( - 'showposts' => -1, + $media_library_items = $this->all_posts( array( 'post_type' => 'attachment', 'meta_key' => 'video_thumbnail', 'meta_value' => '1', 'fields' => 'ids' - ) ); - foreach ( $media_library_items as $item ) { - wp_delete_attachment( $item, true ); - } - echo '

' . sprintf( esc_html( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ) ), count( $media_library_items ) ) . '

'; + ), function () { + wp_delete_attachment( get_the_ID(), true ); + } ); + + echo '

' . sprintf( esc_html( _n( '1 attachment deleted', '%s attachments deleted', $media_library_items, 'video-thumbnails' ) ), $media_library_items ) . '

'; // Clear custom fields $custom_fields_cleared = $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key='_video_thumbnail'" ); echo '

' . sprintf( esc_html( _n( '1 custom field cleared', '%s custom fields cleared', $custom_fields_cleared, 'video-thumbnails' ) ), $custom_fields_cleared ) . '

'; From 30720ab1801c8d10c0c99ac6312f59e1eaaee039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Thu, 18 May 2017 12:24:58 -0300 Subject: [PATCH 8/8] Revert "Running the clear_all_callback in a better way" The get_posts returns only the ids and not full posts objects, so this is fine. This reverts commit 17ab77b2605bedac005a01d9353cbf7d3db7bbea. --- php/class-video-thumbnails-settings.php | 115 +++--------------------- 1 file changed, 10 insertions(+), 105 deletions(-) diff --git a/php/class-video-thumbnails-settings.php b/php/class-video-thumbnails-settings.php index b30c8c8..e69a30d 100755 --- a/php/class-video-thumbnails-settings.php +++ b/php/class-video-thumbnails-settings.php @@ -30,7 +30,7 @@ class Video_Thumbnails_Settings { function __construct() { // Activation and deactivation hooks register_activation_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_activation' ) ); - register_uninstall_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( 'Video_Thumbnails_Settings', 'plugin_deactivation' ) ); + register_uninstall_hook( VIDEO_THUMBNAILS_PATH . '/video-thumbnails.php', array( &$this, 'plugin_deactivation' ) ); // Set current options add_action( 'plugins_loaded', array( &$this, 'set_options' ) ); // Add options page to menu @@ -58,7 +58,7 @@ function plugin_activation() { } // Deactivation hook - public static function plugin_deactivation() { + function plugin_deactivation() { delete_option( 'video_thumbnails' ); } @@ -161,99 +161,6 @@ function custom_field_detection_callback() { die(); } - /** - * Frees up memory for long running processes. - */ - function stop_the_insanity() { - global $wpdb, $wp_actions, $wp_filter, $wp_object_cache; - //reset queries - $wpdb->queries = array(); - // Prevent wp_actions from growing out of control - $wp_actions = array(); - if ( is_object( $wp_object_cache ) ) { - $wp_object_cache->group_ops = array(); - $wp_object_cache->stats = array(); - $wp_object_cache->memcache_debug = array(); - $wp_object_cache->cache = array(); - if ( method_exists( $wp_object_cache, '__remoteset' ) ) { - $wp_object_cache->__remoteset(); - } - } - /* - * The WP_Query class hooks a reference to one of its own methods - * onto filters if update_post_term_cache or - * update_post_meta_cache are true, which prevents PHP's garbage - * collector from cleaning up the WP_Query instance on long- - * running processes. - * - * By manually removing these callbacks (often created by things - * like get_posts()), we're able to properly unallocate memory - * once occupied by a WP_Query object. - * - */ - if ( isset( $wp_filter['get_term_metadata'] ) ) { - /* - * WordPress 4.7 has a new Hook infrastructure, so we need to make sure - * we're accessing the global array properly. - */ - if ( class_exists( 'WP_Hook' ) && $wp_filter['get_term_metadata'] instanceof \WP_Hook ) { - $filter_callbacks = &$wp_filter['get_term_metadata']->callbacks; - } else { - $filter_callbacks = &$wp_filter['get_term_metadata']; - } - if ( isset( $filter_callbacks[10] ) ) { - foreach ( $filter_callbacks[10] as $hook => $content ) { - if ( preg_match( '#^[0-9a-f]{32}lazyload_term_meta$#', $hook ) ) { - unset( $filter_callbacks[10][ $hook ] ); - } - } - } - } - } - - /** - * Runs through all posts and executes the provided callback for each post. - * - * @param array $query_args - * @param callable $callback - * - * @return int - */ - protected function all_posts( $query_args, $callback) { - if ( ! is_callable( $callback ) ) { - return; - } - - $default_args = array( - 'post_type' => 'post', - 'posts_per_page' => 200, - 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private' ), - 'cache_results ' => false, - 'update_post_meta_cache' => false, - 'update_post_term_cache' => false, - 'offset' => 0, - ); - - $query_args = wp_parse_args( $query_args, $default_args ); - $query = new \WP_Query( $query_args ); - $counter = 0; - - while ( $query->have_posts() ) { - $query->the_post(); - $callback(); - - $counter++; - if ( 0 === $counter % $query_args['posts_per_page'] ) { - $this->stop_the_insanity(); - $query_args['offset'] += $query_args['posts_per_page']; - $query = new \WP_Query( $query_args ); - } - } - wp_reset_postdata(); - - return $counter; - } - function detect_custom_field() { global $video_thumbnails; $latest_post = get_posts( array( @@ -273,23 +180,21 @@ function detect_custom_field() { } function ajax_clear_all_callback() { - if ( ! current_user_can( 'manage_options' ) ) { - die(); - } + if ( !current_user_can( 'manage_options' ) ) die(); if ( wp_verify_nonce( $_POST['nonce'], 'clear_all_video_thumbnails' ) ) { global $wpdb; - // Clear images from media library - $media_library_items = $this->all_posts( array( + $media_library_items = get_posts( array( + 'showposts' => -1, 'post_type' => 'attachment', 'meta_key' => 'video_thumbnail', 'meta_value' => '1', 'fields' => 'ids' - ), function () { - wp_delete_attachment( get_the_ID(), true ); - } ); - - echo '

' . sprintf( esc_html( _n( '1 attachment deleted', '%s attachments deleted', $media_library_items, 'video-thumbnails' ) ), $media_library_items ) . '

'; + ) ); + foreach ( $media_library_items as $item ) { + wp_delete_attachment( $item, true ); + } + echo '

' . sprintf( esc_html( _n( '1 attachment deleted', '%s attachments deleted', count( $media_library_items ), 'video-thumbnails' ) ), count( $media_library_items ) ) . '

'; // Clear custom fields $custom_fields_cleared = $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key='_video_thumbnail'" ); echo '

' . sprintf( esc_html( _n( '1 custom field cleared', '%s custom fields cleared', $custom_fields_cleared, 'video-thumbnails' ) ), $custom_fields_cleared ) . '

';
' . $test_case['name'] . '' . esc_html( $test_case['name'] ) . '✗ ' . __( 'Failed', 'video-thumbnails' ) . '✗ ' . esc_html__( 'Failed', 'video-thumbnails' ) . ''; - echo '

' . $error_string . '

'; + echo '

' . esc_html( $error_string ) . '

'; echo '
✔ ' . __( 'Passed', 'video-thumbnails' ) . '✔ ' . esc_html__( 'Passed', 'video-thumbnails' ) . '✗ ' . __( 'Failed', 'video-thumbnails' ) . '✗ ' . esc_html__( 'Failed', 'video-thumbnails' ) . ''; if ( $result ) { - echo '' . __( 'View Image', 'video-thumbnails' ) . ''; + echo '' . esc_html__( 'View Image', 'video-thumbnails' ) . ''; } if ( $result_hash ) { - echo ' ' . $result_hash . ''; + echo ' ' . esc_html( $result_hash ) . ''; } echo '
options['version']; ?>options['version'] ); ?>
More info', 'video-thumbnails' ); ?> More info', 'video-thumbnails' ); ?>
providers as $provider ) { $provider_names[] = $provider->service_name; }; ?> - providers ); ?>: + providers ); ?>: