Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/schema-and-structured-data-for-wp/admin_section/add-schema/add-new.php
+++ b/schema-and-structured-data-for-wp/admin_section/add-schema/add-new.php
@@ -204,9 +204,18 @@
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php echo esc_html( $current_step); ?></title>
- <?php do_action( 'admin_print_styles' ); ?>
- <?php do_action( 'admin_print_scripts' ); ?>
- <?php do_action( 'admin_head' ); ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_styles hook intentionally.
+ do_action( 'admin_print_styles' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_scripts hook intentionally.
+ do_action( 'admin_print_scripts' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_head hook intentionally.
+ do_action( 'admin_head' );
+ ?>
</head>
<body class="merlin__body merlin__body--<?php echo esc_attr( $current_step ); ?>">
<?php
@@ -412,6 +421,7 @@
update_post_meta(
$post_id,
'saswp_review_item_reviewed_'.$post_id,
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
sanitize_text_field($_POST['saswp_review_item_reviewed_'])
);
}
@@ -514,6 +524,7 @@
// If it exists, include it.
if ( file_exists( $svg ) ) {
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_styles hook intentionally.
require_once apply_filters( 'merlin_svg_sprite', $svg );
}
}
@@ -551,9 +562,18 @@
?>
<title><?php echo esc_html__( 'Welcome', 'schema-and-structured-data-for-wp' ); ?></title>
<?php } ?>
- <?php do_action( 'admin_print_styles' ); ?>
- <?php do_action( 'admin_print_scripts' ); ?>
- <?php do_action( 'admin_head' ); ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_styles hook intentionally.
+ do_action( 'admin_print_styles' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_scripts hook intentionally.
+ do_action( 'admin_print_scripts' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_head hook intentionally.
+ do_action( 'admin_head' );
+ ?>
</head>
<body class="merlin__body merlin__body--<?php echo esc_attr( $current_step ); ?>">
<?php
@@ -563,8 +583,14 @@
function saswp_add_new_install_footer() {
?>
</body>
- <?php do_action( 'admin_footer' ); ?>
- <?php do_action( 'admin_print_footer_scripts' ); ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_footer hook intentionally.
+ do_action( 'admin_footer' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_footer_scripts hook intentionally.
+ do_action( 'admin_print_footer_scripts' );
+ ?>
</html>
<?php
}
--- a/schema-and-structured-data-for-wp/admin_section/class-saswp-fields-generator.php
+++ b/schema-and-structured-data-for-wp/admin_section/class-saswp-fields-generator.php
@@ -549,7 +549,7 @@
if ( isset( $settings[$meta_field['id']]) ) {
if($meta_field['id'] == 'saswp_site_navigation_menu' && function_exists('icl_object_id') ) {
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core wpml_object_id hook intentionally.
$settings_meta_field = apply_filters( 'wpml_object_id', $settings[$meta_field['id']], 'nav_menu', FALSE,ICL_LANGUAGE_CODE );
if(!$settings_meta_field){
$settings_meta_field = $settings[$meta_field['id']];
--- a/schema-and-structured-data-for-wp/admin_section/common-function.php
+++ b/schema-and-structured-data-for-wp/admin_section/common-function.php
@@ -94,7 +94,18 @@
if(empty($sanitized_post) ) {
continue;
}
- if(get_post_status( $schema_post['post']['ID'] ) ) {
+
+ // Security: Restrict imported post types to the plugin's own post types only
+ $allowed_post_types = array( 'saswp', 'saswp_reviews', 'saswp-collections' );
+ if ( ! isset( $sanitized_post['post_type'] ) || ! in_array( $sanitized_post['post_type'], $allowed_post_types, true ) ) {
+ continue;
+ }
+
+ $existing_post_id = isset( $schema_post['post']['ID'] ) ? intval( $schema_post['post']['ID'] ) : 0;
+ $existing_post = $existing_post_id ? get_post( $existing_post_id ) : null;
+
+ // Security: Only update if the existing post exists, belongs to an allowed plugin post type, and the importing user has permission to edit it
+ if ( $existing_post && in_array( $existing_post->post_type, $allowed_post_types, true ) && current_user_can( 'edit_post', $existing_post_id ) ) {
$post_id = wp_update_post($sanitized_post);
@@ -2138,11 +2149,12 @@
function saswp_defaultSettings() {
global $sd_data;
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Prefix has been added
$sd_data = get_option( 'sd_data', saswp_default_settings_array());
// If data is not set for custom schema option then set default data to 1
if ( is_array( $sd_data ) && ! array_key_exists( 'saswp-for-cschema', $sd_data ) ) {
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Prefix has been added
$sd_data['saswp-for-cschema'] = 1;
}
@@ -2371,7 +2383,7 @@
$post_content = wp_strip_all_tags(strip_shortcodes($post->post_content));
$post_content = preg_replace('/[.*?]/','', $post_content);
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core excerpt_length hook intentionally.
$excerpt_length = apply_filters( 'excerpt_length', 55 );
$excerpt_more = '';
$excerpt = wp_trim_words( $post_content, $excerpt_length, $excerpt_more );
@@ -2513,7 +2525,7 @@
$post_content = wp_strip_all_tags( strip_shortcodes( $post_excerpt_content ) );
$post_content = preg_replace( '/[.*?]/','', $post_content );
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core excerpt_length hook intentionally.
$excerpt_length = apply_filters( 'excerpt_length', 55 );
$excerpt_more = '';
$excerpt = wp_trim_words( $post_content, $excerpt_length, $excerpt_more );
@@ -4397,16 +4409,17 @@
$image_details = wp_get_attachment_image_src($image_id);
if( isset($sd_data['saswp-video-thumbnails']) && $sd_data['saswp-video-thumbnails'] == 1 && class_exists('Video_Thumbnails') ){
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$thumbnail = get_video_thumbnail();
}elseif (isset($image_details[0]) ) {
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$thumbnail = $image_details[0];
}else{
if ( isset( $sd_data['sd_default_image']['thumbnail']) ) {
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$thumbnail = $sd_data['sd_default_image']['thumbnail'];
}
@@ -5622,19 +5635,8 @@
return $content;
}
- // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
- $translations = $wpdb->get_results(
- $wpdb->prepare(
- "
- SELECT d.original, d.translated
- FROM {$meta_table} m
- INNER JOIN {$dict_table} d
- ON d.original_id = m.original_id
- WHERE m.meta_value = %d
- ",
- $post_id
- )
- );
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
+ $translations = $wpdb->get_results( $wpdb->prepare( "SELECT d.original, d.translated FROM {$meta_table} m INNER JOIN {$dict_table} d ON d.original_id = m.original_id WHERE m.meta_value = %d ", $post_id) );
if ( empty( $translations ) ) {
wp_cache_set( $cache_key, $content, 'saswp', HOUR_IN_SECONDS );
@@ -5699,13 +5701,8 @@
return '';
}
- // Fetch original value
- $original = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT {$field} FROM {$wpdb->posts} WHERE ID = %d LIMIT 1",
- $post_id
- )
- );
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery,PluginCheck.Security.DirectDB.UnescapedDBParameter
+ $original = $wpdb->get_var( $wpdb->prepare( "SELECT {$field} FROM {$wpdb->posts} WHERE ID = %d LIMIT 1", $post_id ) );
if ( empty( $original ) ) {
return '';
@@ -5739,13 +5736,8 @@
return $original;
}
- // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
- $translated = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT translated FROM {$dictionary_table} WHERE original = %s LIMIT 1",
- $original
- )
- );
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
+ $translated = $wpdb->get_var( $wpdb->prepare( "SELECT translated FROM {$dictionary_table} WHERE original = %s LIMIT 1", $original ) );
if ( empty( $translated ) ) {
wp_cache_set( $cache_key, $original, 'saswp', HOUR_IN_SECONDS );
--- a/schema-and-structured-data-for-wp/admin_section/plugin-installer/install.php
+++ b/schema-and-structured-data-for-wp/admin_section/plugin-installer/install.php
@@ -499,6 +499,7 @@
// If it exists, include it.
if ( file_exists( $svg ) ) {
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core merlin_svg_sprite hook intentionally.
require_once apply_filters( 'merlin_svg_sprite', $svg );
}
}
@@ -545,9 +546,18 @@
?>
<title><?php echo esc_html__( 'Welcome', 'schema-and-structured-data-for-wp' ); ?></title>
<?php } ?>
- <?php do_action( 'admin_print_styles' ); ?>
- <?php do_action( 'admin_print_scripts' ); ?>
- <?php do_action( 'admin_head' ); ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_styles hook intentionally.
+ do_action( 'admin_print_styles' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_scripts hook intentionally.
+ do_action( 'admin_print_scripts' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_head hook intentionally.
+ do_action( 'admin_head' );
+ ?>
</head>
<body class="merlin__body merlin__body--<?php echo esc_attr( $current_step ); ?>">
<?php
@@ -557,8 +567,14 @@
function saswp_install_footer() {
?>
</body>
- <?php do_action( 'admin_footer' ); ?>
- <?php do_action( 'admin_print_footer_scripts' ); ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_footer hook intentionally.
+ do_action( 'admin_footer' );
+ ?>
+ <?php
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core admin_print_footer_scripts hook intentionally.
+ do_action( 'admin_print_footer_scripts' );
+ ?>
</html>
<?php
}
--- a/schema-and-structured-data-for-wp/admin_section/settings.php
+++ b/schema-and-structured-data-for-wp/admin_section/settings.php
@@ -80,7 +80,7 @@
add_action( 'admin_menu', 'saswp_add_menu_links' );
function saswp_premium_interface_render() {
-
+ // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Hardcoded external link to official plugin pricing page.
wp_redirect( 'https://structured-data-for-wp.com/pricing/' );
exit;
@@ -5251,8 +5251,9 @@
function saswp_dequeue_publishpress_scripts( $scripts ) {
$post_type = null;
-
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason nonce not needed here
if ( function_exists( 'presspermit' ) && function_exists( 'is_admin' ) && is_admin() && ! empty( $_GET['post'] )) {
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason nonce not needed here
$post_id = absint( $_GET['post'] );
if ( $post_id > 0 ) {
$post = get_post( $post_id );
--- a/schema-and-structured-data-for-wp/admin_section/structure-admin.php
+++ b/schema-and-structured-data-for-wp/admin_section/structure-admin.php
@@ -56,7 +56,7 @@
if ( function_exists( 'pll_register_string') ) {
$args['lang'] = '';
}
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$all_schemas = get_posts($args);
}
@@ -148,7 +148,7 @@
add_action( 'wp_ajax_saswp_reset_all_settings', 'saswp_reset_all_settings' );
function saswp_load_plugin_textdomain() {
-
+ // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Retained for backward compatibility with custom translation directories.
load_plugin_textdomain( 'schema-and-structured-data-for-wp', false, dirname( plugin_basename( SASWP_DIR_NAME_FILE ) ) . '/languages/' );
}
@@ -524,6 +524,7 @@
if(is_object($post) ) {
if(!$cat_id_obj){
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$cat_id_obj = get_the_category( $post->ID );
}
@@ -1176,7 +1177,7 @@
}
// Add VideoObject schema meta options data
- if ( ! empty( $_POST['saswp_schema_type_meta_options_nonce'] ) && wp_verify_nonce( $_POST['saswp_schema_type_meta_options_nonce'], 'saswp_schema_type_meta_action_nonce' ) ) {
+ if ( ! empty( $_POST['saswp_schema_type_meta_options_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['saswp_schema_type_meta_options_nonce'] ) ), 'saswp_schema_type_meta_action_nonce' ) ) {
if ( ! empty( $_POST['saswp_enable_video_object_details'] ) ) {
add_post_meta( $post_id, 'saswp_enable_video_object_details', 1 );
@@ -2600,9 +2601,9 @@
add_filter( 'script_loader_tag', 'saswp_script_loader_tag', 10, 3);
//user Custom Schema filed start
-add_action( 'show_user_profile', 'extra_user_profile_fields', 10, 1 );
-add_action( 'edit_user_profile', 'extra_user_profile_fields', 10, 1 );
-function extra_user_profile_fields( $user ) {
+add_action( 'show_user_profile', 'saswp_extra_user_profile_fields', 10, 1 );
+add_action( 'edit_user_profile', 'saswp_extra_user_profile_fields', 10, 1 );
+function saswp_extra_user_profile_fields( $user ) {
$user_id = $user->ID;
$custom_markp = get_user_meta($user_id, 'saswp_user_custom_schema_field', true);
@@ -2623,16 +2624,16 @@
//user Custom Schema filed end
//user Custom Schema filed save start
-add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
-add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
+add_action( 'personal_options_update', 'saswp_save_extra_user_profile_fields' );
+add_action( 'edit_user_profile_update', 'saswp_save_extra_user_profile_fields' );
-function save_extra_user_profile_fields( $user_id ) {
+function saswp_save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information but only used inside core edit_user_profile_update hook.
if ( ! empty( $_POST['saswp_custom_schema_field']) ) {
- // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information but only used inside core edit_user_profile_update hook.
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information but only used inside core edit_user_profile_update hook.
$custom_schema = saswp_sanitize_custom_schema(wp_unslash($_POST['saswp_custom_schema_field']));
update_user_meta( $user_id, 'saswp_user_custom_schema_field', $custom_schema );
}else{
@@ -2725,6 +2726,7 @@
$item_title = $post->post_title;
$dynamic_text = sprintf(
+ /* translators: %1$s: Title of the item being duplicated. */
esc_html__( 'Duplicate %s', 'schema-and-structured-data-for-wp' ),
$item_title
);
@@ -2792,7 +2794,7 @@
// --- DIRECT DB INSERT FOR METADATA ---
global $wpdb;
-
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query required to retrieve post metadata in the existing format.
$post_meta_infos = $wpdb->get_results(
$wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id = %d", $post_id )
);
@@ -2803,12 +2805,14 @@
if ( in_array( $meta_info->meta_key, array( '_wp_old_slug', '_edit_lock', '_edit_last' ), true ) ) {
continue;
}
-
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Direct database insertion required to duplicate existing post metadata.
$wpdb->insert(
$wpdb->postmeta,
array(
'post_id' => $new_post_id,
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'meta_key' => $meta_info->meta_key,
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
'meta_value' => $meta_info->meta_value
),
array( '%d', '%s', '%s' ) // WP Standard: explicitly declare data types for DB insertion
@@ -2838,10 +2842,10 @@
add_action( 'admin_notices', 'saswp_duplication_success_notice' );
function saswp_duplication_success_notice() {
- // WP Standard: Unslash and sanitize GET variables before comparison
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended --Reason nonce not needed here
if ( isset( $_GET['saswp_duplicated'], $_GET['post_type'] ) && 'saswp' === sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) ) {
-
- $duplicated_id = absint( wp_unslash( $_GET['saswp_duplicated'] ) );
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended --Reason nonce not needed here
+ $duplicated_id = absint( $_GET['saswp_duplicated'] );
// Prevent notice from firing if the ID is 0
if ( 0 === $duplicated_id ) {
@@ -2855,6 +2859,7 @@
<p>
<?php
printf(
+ /* translators: %s: url of the item being duplicated. */
wp_kses_post( __( 'Item successfully duplicated. <a href="%s">Edit the new item</a>.', 'schema-and-structured-data-for-wp' ) ),
esc_url( $edit_url )
);
--- a/schema-and-structured-data-for-wp/admin_section/tracking/class-saswp-plugin-usage-tracker.php
+++ b/schema-and-structured-data-for-wp/admin_section/tracking/class-saswp-plugin-usage-tracker.php
@@ -703,7 +703,7 @@
/* translators: %s: product type */
$notice_text = sprintf(__( 'Thank you for installing our %1$s. We'd like your permission to track its usage on your site and subscribe you to our newsletter. We won't record any sensitive data, only information regarding the WordPress environment and %1$s settings, which we will use to help us make improvements to the %1$s. Tracking is completely optional.', 'schema-and-structured-data-for-wp' ),$this->what_am_i);
}
- // And we allow you to filter the text anyway
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core wisdom_notice_text_ hook intentionally.
$notice_text = apply_filters( 'wisdom_notice_text_' . esc_attr( $this->plugin_name ), $notice_text ); ?>
<div class="notice notice-info updated put-dismiss-notice">
@@ -751,6 +751,7 @@
) );
/* translators: %s: product type */
$marketing_text = sprintf(__( 'Thank you for opting in to tracking. Would you like to receive occasional news about this %s, including details of new features and special offers?', 'schema-and-structured-data-for-wp' ),$this->what_am_i);
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core wisdom_marketing_text_ hook intentionally.
$marketing_text = apply_filters( 'wisdom_marketing_text_' . esc_attr( $this->plugin_name ), $marketing_text ); ?>
<div class="notice notice-info updated put-dismiss-notice">
@@ -810,6 +811,7 @@
*/
public function form_filterable_text() {
$form = $this->form_default_text();
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking the WordPress core wisdom_form_text_ hook intentionally.
return apply_filters( 'wisdom_form_text_' . esc_attr( $this->plugin_name ), $form );
}
--- a/schema-and-structured-data-for-wp/admin_section/tracking/deactivate-feedback.php
+++ b/schema-and-structured-data-for-wp/admin_section/tracking/deactivate-feedback.php
@@ -4,7 +4,7 @@
exit;
}
-$reasons = array(
+$saswp_reasons = array(
1 => '<li><label><input type="radio" name="saswp_disable_reason" value="temporary"/>' . esc_html__('It is only temporary', 'schema-and-structured-data-for-wp' ) . '</label></li>',
2 => '<li><label><input type="radio" name="saswp_disable_reason" value="stopped"/>' . esc_html__('I stopped using Schema plugin on my site', 'schema-and-structured-data-for-wp' ) . '</label></li>',
3 => '<li><label><input type="radio" name="saswp_disable_reason" value="missing"/>' . esc_html__('I miss a feature', 'schema-and-structured-data-for-wp' ) . '</label></li>
@@ -17,7 +17,7 @@
<li><textarea class="mb-box other" name="saswp_disable_text[]" placeholder="' . esc_attr__('Please specify, if possible', 'schema-and-structured-data-for-wp' ) . '"></textarea></li>',
);
-shuffle( $reasons );
+shuffle( $saswp_reasons );
?>
@@ -27,9 +27,9 @@
<h3><strong><?php echo esc_html__( 'If you have a moment, please let us know why you are deactivating:', 'schema-and-structured-data-for-wp' ); ?></strong></h3>
<ul>
<?php
- foreach ( $reasons as $reason_escaped ){
+ foreach ( $saswp_reasons as $saswp_reason ){
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- all html inside this variable already escaped above in $reasons variable
- echo $reason_escaped;
+ echo $saswp_reason;
}
?>
</ul>
--- a/schema-and-structured-data-for-wp/core/3rd-party/class-amp-review-form-blacklist.php
+++ b/schema-and-structured-data-for-wp/core/3rd-party/class-amp-review-form-blacklist.php
@@ -5,18 +5,18 @@
}
if(defined('AMP__DIR__') ) {
- $amp_blacklist_sanitizer = realpath( AMP__DIR__ . 'includes/sanitizers/class-amp-blacklist-sanitizer.php') ;
+ $saswp_amp_blacklist_sanitizer = realpath( AMP__DIR__ . 'includes/sanitizers/class-amp-blacklist-sanitizer.php') ;
}
elseif(defined('AMP__VENDOR__DIR__') ) {
- $amp_blacklist_sanitizer = realpath( AMP__VENDOR__DIR__ . 'includes/sanitizers/class-amp-blacklist-sanitizer.php') ;
+ $saswp_amp_blacklist_sanitizer = realpath( AMP__VENDOR__DIR__ . 'includes/sanitizers/class-amp-blacklist-sanitizer.php') ;
}
-if ( $amp_blacklist_sanitizer ) {
- include_once $amp_blacklist_sanitizer;
+if ( $saswp_amp_blacklist_sanitizer ) {
+ include_once $saswp_amp_blacklist_sanitizer;
}
if ( class_exists( 'AMP_Blacklist_Sanitizer' ) ) {
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Class name retained for backward compatibility with existing AMP integration.
class AMP_Review_Form_Blacklist extends AMP_Blacklist_Sanitizer {
const PATTERN_REL_WP_ATTACHMENT = '#wp-att-([d]+)#';
--- a/schema-and-structured-data-for-wp/core/array-list/schema-properties.php
+++ b/schema-and-structured-data-for-wp/core/array-list/schema-properties.php
@@ -12809,7 +12809,7 @@
'type' => 'text',
),
array(
- 'label' => esc_html__( esc_html__( 'Name', 'schema-and-structured-data-for-wp' ), 'schema-and-structured-data-for-wp' ),
+ 'label' => esc_html__( 'Name', 'schema-and-structured-data-for-wp' ),
'id' => 'saswp_profile_page_schema_performerin_end_date_'.$schema_id,
'type' => 'text',
),
--- a/schema-and-structured-data-for-wp/core/global.php
+++ b/schema-and-structured-data-for-wp/core/global.php
@@ -5,6 +5,7 @@
}
$saswp_divi_faq = array();
$saswp_divi_render_faq = array();
+// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$with_aggregate = array(
'Car',
'Vehicle',
@@ -39,6 +40,7 @@
'Guide',
'SportsTeam',
);
+// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$without_aggregate = array(
'Apartment',
'HotelRoom',
@@ -104,6 +106,7 @@
'EventVenue',
'DefinedTermSet',
);
+// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$translation_labels = array(
'translation-pros' => 'Pros',
'translation-cons' => 'Cons',
--- a/schema-and-structured-data-for-wp/modules/ai-integration/ai-integration-setup.php
+++ b/schema-and-structured-data-for-wp/modules/ai-integration/ai-integration-setup.php
@@ -241,8 +241,8 @@
wp_send_json_error(array('error' => esc_html__('Unauthorized capability.', 'schema-and-structured-data-for-wp')));
}
- $provider = isset($_POST['provider']) ? sanitize_text_field($_POST['provider']) : '';
- $api_key = isset($_POST['api_key']) ? sanitize_text_field($_POST['api_key']) : '';
+ $provider = isset($_POST['provider']) ? sanitize_text_field( wp_unslash( $_POST['provider'] ) ) : '';
+ $api_key = isset($_POST['api_key']) ? sanitize_text_field( wp_unslash( $_POST['api_key'] ) ) : '';
if (empty($provider) || empty($api_key)) {
wp_send_json_error(array('error' => esc_html__('Provider and API key are required to fetch models.', 'schema-and-structured-data-for-wp')));
@@ -268,7 +268,7 @@
}
$post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
- $target_type = isset($_POST['target_type']) ? sanitize_text_field($_POST['target_type']) : 'auto';
+ $target_type = isset($_POST['target_type']) ? sanitize_text_field( wp_unslash( $_POST['target_type'] ) ) : 'auto';
if (!$post_id) {
wp_send_json_error(array('error' => esc_html__('Invalid post ID.', 'schema-and-structured-data-for-wp')));
--- a/schema-and-structured-data-for-wp/modules/ai-integration/class-saswp-ai-service.php
+++ b/schema-and-structured-data-for-wp/modules/ai-integration/class-saswp-ai-service.php
@@ -27,6 +27,7 @@
class SASWP_Gemini_Provider implements SASWP_AI_Provider_Interface {
public function get_api_url($api_key, $model) {
$model = !empty($model) ? $model : 'gemini-1.5-flash';
+ // phpcs:ignore PluginCheck.CodeAnalysis.AIProvider.DirectIntegration -- Direct Gemini API integration retained for backward compatibility and support for custom API key configuration
return "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent?key=" . rawurlencode($api_key);
}
@@ -60,6 +61,7 @@
if (empty($api_key)) {
return array('success' => false, 'error' => esc_html__('Gemini API Key is required.', 'schema-and-structured-data-for-wp'));
}
+ // phpcs:ignore PluginCheck.CodeAnalysis.AIProvider.DirectIntegration -- Direct Gemini API integration retained for backward compatibility and support for custom API key configuration
$url = "https://generativelanguage.googleapis.com/v1beta/models?key=" . rawurlencode($api_key);
$response = wp_remote_get($url, array('timeout' => 15, 'sslverify' => false));
@@ -106,6 +108,7 @@
*/
class SASWP_OpenAI_Provider implements SASWP_AI_Provider_Interface {
public function get_api_url($api_key, $model) {
+ // phpcs:ignore PluginCheck.CodeAnalysis.AIProvider.DirectIntegration -- Direct OpenAI integration retained for backward compatibility and support for custom API key configuration
return 'https://api.openai.com/v1/chat/completions';
}
@@ -141,6 +144,7 @@
if (empty($api_key)) {
return array('success' => false, 'error' => esc_html__('OpenAI API Key is required.', 'schema-and-structured-data-for-wp'));
}
+ // phpcs:ignore PluginCheck.CodeAnalysis.AIProvider.DirectIntegration -- Direct OpenAI integration retained for backward compatibility and support for custom API key configuration
$url = 'https://api.openai.com/v1/models';
$response = wp_remote_get($url, array(
'headers' => array(
@@ -348,7 +352,7 @@
if (!empty($site_url)) {
$clean_json = str_replace(
array('https://example.com', 'http://example.com', 'example.com'),
- array($site_url, $site_url, parse_url($site_url, PHP_URL_HOST)),
+ array($site_url, $site_url, wp_parse_url($site_url, PHP_URL_HOST)),
$clean_json
);
}
--- a/schema-and-structured-data-for-wp/modules/divi-builder/includes/loader.php
+++ b/schema-and-structured-data-for-wp/modules/divi-builder/includes/loader.php
@@ -8,9 +8,9 @@
return;
}
-$module_files = glob( __DIR__ . '/modules/*/*.php' );
+$saswp_module_files = glob( __DIR__ . '/modules/*/*.php' );
// Load custom Divi Builder modules
-foreach ( (array) $module_files as $module_file ) {
- require_once $module_file;
+foreach ( (array) $saswp_module_files as $saswp_module_file ) {
+ require_once $saswp_module_file;
}
No newline at end of file
--- a/schema-and-structured-data-for-wp/modules/rating-box/class-saswp-rating-box-frontend.php
+++ b/schema-and-structured-data-for-wp/modules/rating-box/class-saswp-rating-box-frontend.php
@@ -375,6 +375,6 @@
}
if (class_exists('SASWP_Rating_Box_Frontend')) {
- $object = new SASWP_Rating_Box_Frontend();
- $object->saswp_review_hooks();
+ $saswp_object = new SASWP_Rating_Box_Frontend();
+ $saswp_object->saswp_review_hooks();
};
No newline at end of file
--- a/schema-and-structured-data-for-wp/modules/reviews/class-saswp-review-feature-admin.php
+++ b/schema-and-structured-data-for-wp/modules/reviews/class-saswp-review-feature-admin.php
@@ -104,7 +104,7 @@
public function set_default_data() {
global $sd_data;
-
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$sd_data = get_option( 'sd_rf_data', $this->deafult_options() );
return $sd_data;
@@ -137,7 +137,7 @@
}
if ( $hook == 'comment.php' ) {
-
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading comment ID only to conditionally enqueue admin scripts; no data is modified.
$comment_id = isset( $_GET['c'] ) ? intval( $_GET['c'] ) : 0;
$post_id = 0;
@@ -207,16 +207,10 @@
<a href="#saswp-rf-page-style-tab" class="nav-tab"><?php echo esc_html__( 'Style', 'schema-and-structured-data-for-wp' ); ?></a>
</h2>
</div>
-
- <!-- <form method="post" action="<?php echo admin_url('admin-post.php'); ?>" class="saswp-settings-form"> -->
- <div class="form-wrap saswp-settings-form-wrap">
-
- <?php $this->saswp_review_feature_box_callback(); ?>
- </div>
- <?php //submit_button(); ?>
- <!-- <input type="hidden" name="action" value="saswp_review_feature_form_submission"> -->
- <?php //wp_nonce_field('saswp_rf_page_action_nonce', 'saswp_rf_page_nonce'); ?>
- <!-- </form> -->
+ <div class="form-wrap saswp-settings-form-wrap">
+
+ <?php $this->saswp_review_feature_box_callback(); ?>
+ </div>
</div>
<?php
@@ -270,7 +264,7 @@
$reeview_layout = 'two';
}
}
-
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab is only to conditionally check; no data is modified.
$tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'review';
$hide_Class = 'saswp_hide';
if ( $tab == 'review' ) {
@@ -1230,8 +1224,8 @@
if ( ! isset( $_POST['saswp_rf_page_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_page_nonce'], 'saswp_rf_page_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_page_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_page_action_nonce') ) {
return;
}
@@ -1240,11 +1234,13 @@
$settings_data = array();
if ( ! empty( $_POST['saswp-rf-page-post-type'] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason actions are performed below in array_map
$settings_data['saswp-rf-page-post-type'] = array_map( 'sanitize_text_field' , $_POST['saswp-rf-page-post-type'] );
}else{
$settings_data['saswp-rf-page-post-type'] = array();
}
if ( ! empty( $_POST['saswp-rf-page-criteria-multiple'] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason actions are performed below in array_map
$settings_data['saswp-rf-page-criteria-multiple'] = array_map( 'sanitize_text_field' , $_POST['saswp-rf-page-criteria-multiple'] );
}else{
$settings_data['saswp-rf-page-criteria-multiple'] = array();
@@ -1302,12 +1298,13 @@
case 'text':
case 'color_picker':
if ( isset( $_POST[ $field['name'] ] ) ) {
- $settings_data[ $field['name'] ] = sanitize_text_field( $_POST[ $field['name'] ] );
+ $settings_data[ $field['name'] ] = sanitize_text_field( wp_unslash( $_POST[ $field['name'] ] ) );
}
break;
case 'multi-columns':
if ( isset( $_POST[ $field['name'] ] ) && is_array( $_POST[ $field['name'] ] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason sanitization is done below
$settings_data[ $field['name'] ] = array_map( 'sanitize_text_field', $_POST[ $field['name'] ] );
}
break;
@@ -1316,6 +1313,7 @@
}
if ( isset( $_POST['filter_option'] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason sanitization is done below
$settings_data['saswp-rf-page-settings-filter-options'] = array_map( 'sanitize_text_field' , $_POST['filter_option'] );
}
@@ -1328,7 +1326,8 @@
update_option( 'sd_rf_data', $merge_options );
}
- wp_redirect( admin_url( 'edit.php?post_type=saswp&page=structured_data_review_feature&tab='.$tab ) );
+ wp_safe_redirect( admin_url( 'edit.php?post_type=saswp&page=structured_data_review_feature&tab='.$tab ) );
+ exit();
}
@@ -1586,8 +1585,8 @@
if ( ! isset( $_POST['saswp_rf_edit_comment_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_edit_comment_nonce'], 'saswp_rf_edit_comment_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_edit_comment_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_edit_comment_action_nonce') ) {
return;
}
@@ -1612,11 +1611,13 @@
}
if ( isset( $_POST['saswp_rf_form_pros'] ) && is_array( $_POST['saswp_rf_form_pros'] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$comment_pros = array_map( 'sanitize_text_field', $_POST['saswp_rf_form_pros'] );
update_comment_meta( $comment_id, 'saswp_rf_form_pros', $comment_pros );
}
if ( isset( $_POST['saswp_rf_form_cons'] ) && is_array( $_POST['saswp_rf_form_cons'] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
$comment_cons = array_map( 'sanitize_text_field', $_POST['saswp_rf_form_cons'] );
update_comment_meta( $comment_id, 'saswp_rf_form_cons', $comment_cons );
}
--- a/schema-and-structured-data-for-wp/modules/reviews/class-saswp-review-feature-frontend.php
+++ b/schema-and-structured-data-for-wp/modules/reviews/class-saswp-review-feature-frontend.php
@@ -395,7 +395,9 @@
return;
}
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
@@ -432,13 +434,15 @@
}
}
-
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason sanitization is done below here in if
if ( ! empty( $_POST['saswp_rf_form_pros'] ) && is_array( $_POST['saswp_rf_form_pros'] ) && ! empty( $_POST['saswp_rf_form_pros'][0] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason sanitization is performed below
$comment_pros = array_map( 'sanitize_text_field', $_POST['saswp_rf_form_pros'] );
update_comment_meta( $comment_id, 'saswp_rf_form_pros', $comment_pros );
}
-
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason sanitization is done below here in if
if ( ! empty( $_POST['saswp_rf_form_cons'] ) && is_array( $_POST['saswp_rf_form_cons'] ) && ! empty( $_POST['saswp_rf_form_cons'][0] ) ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Reason sanitization is performed below
$comment_cons = array_map( 'sanitize_text_field', $_POST['saswp_rf_form_cons'] );
update_comment_meta( $comment_id, 'saswp_rf_form_cons', $comment_cons );
}
@@ -454,9 +458,11 @@
$attachments['videos'] = array_map( 'absint', $_POST['saswp_rf_form_attachment']['videos'] );
$attachments['video_source'] = 'self';
}
- } elseif ( isset( $_POST['saswp-rf-form-video-source'] ) && $_POST['saswp-rf-form-video-source'] == 'external' ) {
- if ( isset( $_POST['saswp-rf-form-external-video'] ) && ( '' !== $_POST['saswp-rf-form-video-source'] ) ) {
- $attachments['videos'] = [ esc_url( $_POST['saswp-rf-form-external-video'] ) ];
+ } elseif ( isset( $_POST['saswp-rf-form-video-source'] ) && sanitize_text_field( wp_unslash( $_POST['saswp-rf-form-video-source'] ) ) == 'external' ) {
+ $video_source = sanitize_text_field( wp_unslash( $_POST['saswp-rf-form-video-source'] ) );
+ if ( isset( $_POST['saswp-rf-form-external-video'] ) && ( '' !== $video_source ) ) {
+ $external_video = esc_url_raw( wp_unslash( $_POST['saswp-rf-form-external-video'] ) );
+ $attachments['videos'] = [ $external_video ];
$attachments['video_source'] = 'external';
}
}
@@ -502,6 +508,7 @@
public static function get_all_ratings( $post_id ) {
$args = [
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve approved review comments containing rating metadata.
'meta_query' => array(
array(
'key' => 'rating',
@@ -658,6 +665,7 @@
if( $human_readable_time ){
$time = human_time_diff( strtotime( $comment->comment_date ), current_time( 'timestamp') ) . ' ' . esc_html__('ago', 'schema-and-structured-data-for-wp' );
}else{
+ // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date --Reason need date function here
$time = date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) , strtotime( $comment->comment_date ) ); ;
}
return $time ;
@@ -674,8 +682,8 @@
wp_send_json_error( [ 'msg' => esc_html__( 'Invalid request.', 'schema-and-structured-data-for-wp' ) ] );
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
wp_send_json_error( [ 'msg' => esc_html__( 'Security check failed.', 'schema-and-structured-data-for-wp' ) ] );
return;
}
@@ -687,8 +695,8 @@
}
$img_max_size = 1024;
-
- $file = $_FILES['saswp-rf-form-image'];
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason sanitization is performed below
+ $file = isset( $_FILES['saswp-rf-form-image'] ) ? $_FILES['saswp-rf-form-image'] : [];
if ( empty( $file['name'] ) || empty( $file['tmp_name'] ) ) {
wp_send_json_error( [ 'msg' => esc_html__( 'Please upload file.', 'schema-and-structured-data-for-wp' ) ] );
@@ -714,18 +722,23 @@
$valid_types = implode( ', ', array_map( fn( $m ) => str_replace( 'image/', '', $m ), array_values( $allowed_mimes ) ) );
$detected_type = ! empty( $checked['type'] ) ? str_replace( 'image/', '', $checked['type'] ) : esc_html__( 'unknown', 'schema-and-structured-data-for-wp' );
- wp_send_json_error( [
- 'msg' => sprintf(
- esc_html__( 'Invalid file type: %s. Supported file types: %s', 'schema-and-structured-data-for-wp' ),
- $detected_type,
- $valid_types
- ),
- ] );
+ wp_send_json_error( [
+ 'msg' => sprintf(
+ /* translators: 1: Detected file type, 2: Supported file types. */
+ esc_html__(
+ 'Invalid file type: %1$s. Supported file types: %2$s',
+ 'schema-and-structured-data-for-wp'
+ ),
+ $detected_type,
+ $valid_types
+ ),
+ ] );
return;
}
// Check file size
if ($file['size'] > $allowed_file_size) {
+ /* translators: %s: Allowed file size of the file. */
wp_send_json_error(['msg' => sprintf(esc_html__('File is too large. Max. upload file size is %s', 'schema-and-structured-data-for-wp'), self::format_bytes($allowed_file_size))]);
}
@@ -806,8 +819,8 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
@@ -835,16 +848,17 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
- $video_url = isset($_REQUEST['video_url']) ? esc_url($_REQUEST['video_url']) : null;
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized --Reason actions performed below
+ $video_url = isset($_REQUEST['video_url']) ? $_REQUEST['video_url'] : null;
ob_start();
echo '<div class="saswp-rf-modal">';
echo '<div class="saswp-rf-form saswp-rf-review-popup">';
- echo '<div class="saswp-rf-form-self-video"><video src="' . $video_url . '" autoplay controls /></div>';
+ echo '<div class="saswp-rf-form-self-video"><video src="' . esc_url( $video_url ) . '" autoplay controls /></div>';
echo '</div>';
echo '</div>'; //modal
@@ -862,8 +876,8 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
@@ -871,7 +885,7 @@
wp_send_json_error( [ 'msg' => esc_html__( 'You do not have permission to upload files.', 'schema-and-structured-data-for-wp' ) ] );
return;
}
-
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$file = isset( $_FILES['saswp-rf-form-video'] ) ? $_FILES['saswp-rf-form-video'] : null;
if ( empty( $file['name'] ) || empty( $file['tmp_name'] ) ) {
return;
@@ -897,17 +911,22 @@
: esc_html__( 'unknown', 'schema-and-structured-data-for-wp' );
wp_send_json_error( [
- 'msg' => sprintf(
- esc_html__( 'Invalid file type: %s. Supported file types: %s', 'schema-and-structured-data-for-wp' ),
- $detected_type,
- $valid_types
- ),
- ] );
+ 'msg' => sprintf(
+ /* translators: 1: Detected file type, 2: Supported file types. */
+ esc_html__(
+ 'Invalid file type: %1$s. Supported file types: %2$s',
+ 'schema-and-structured-data-for-wp'
+ ),
+ $detected_type,
+ $valid_types
+ ),
+ ] );
return;
}
// Check file size
if ($file['size'] > $allowed_file_size) {
+ /* translators: %s: Allowed file size of the file. */
wp_send_json_error(['msg' => sprintf(esc_html__('File is too large. Max. upload file size is %s', 'schema-and-structured-data-for-wp'), self::format_bytes($allowed_file_size))]);
}
@@ -965,18 +984,60 @@
* Filter reviews
* @since 1.45
* */
+
+ /**
+ * Verify whether a post is public and viewable by the current visitor
+ * @param int $post_id
+ * @return bool
+ */
+ public function is_post_viewable_by_current_user( $post_id ) {
+ if ( empty( $post_id ) ) {
+ return false;
+ }
+
+ $post = get_post( $post_id );
+ if ( ! $post || ! is_object( $post ) || empty( $post->post_status ) ) {
+ return false;
+ }
+
+ // If the post is password protected and the password cookie is not supplied/valid
+ if ( post_password_required( $post ) ) {
+ return false;
+ }
+
+ // Check if publicly viewable (WP 5.7+) or fallback to publish status check
+ if ( function_exists( 'is_post_publicly_viewable' ) ) {
+ if ( is_post_publicly_viewable( $post ) ) {
+ return true;
+ }
+ } elseif ( 'publish' === $post->post_status ) {
+ return true;
+ }
+
+ // For non-published posts (private, draft, pending), allow only if the user has permission to read it
+ if ( current_user_can( 'read_post', $post_id ) ) {
+ return true;
+ }
+
+ return false;
+ }
public function saswp_review_filter() {
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
- $sort_by = isset( $_REQUEST['sort_by'] ) ? sanitize_text_field( $_REQUEST['sort_by'] ) : '';
- $filter_by = isset( $_REQUEST['filter_by'] ) ? sanitize_text_field( $_REQUEST['filter_by'] ) : '';
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
+ if ( empty( $post_id ) || ! $this->is_post_viewable_by_current_user( $post_id ) ) {
+ wp_send_json_error( array( 'message' => esc_html__( 'Invalid post or permission denied.', 'schema-and-structured-data-for-wp' ) ) );
+ }
+
+ $sort_by = isset( $_REQUEST['sort_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['sort_by'] ) ) : '';
+ $filter_by = isset( $_REQUEST['filter_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['filter_by'] ) ) : '';
$cur_page = isset( $_REQUEST['current_page'] ) ? absint( $_REQUEST['current_page'] ) : 1;
$max_page = $this->get_sorted_reviews( $sort_by, $filter_by );
@@ -997,8 +1058,11 @@
* @since 1.45
* */
public function get_sorted_reviews( $sort_by, $filter_by ) {
-
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : null;
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason nonce has been checked in function call
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
+ if ( empty( $post_id ) || ! $this->is_post_viewable_by_current_user( $post_id ) ) {
+ return 0;
+ }
$args = [
'post_id' => $post_id,
@@ -1007,7 +1071,7 @@
switch ($sort_by) {
case 'top_rated':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Required to retrieve approved review comments containing rating metadata.
$args['meta_key'] = 'rating';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
@@ -1015,7 +1079,7 @@
break;
case 'low_rated':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Required to retrieve approved review comments containing rating metadata.
$args['meta_key'] = 'rating';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
@@ -1023,7 +1087,7 @@
break;
case 'recommended':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve recommended review comments containing rating metadata.
$args['meta_query'] = [
'relation' => 'OR',
[
@@ -1036,7 +1100,7 @@
break;
case 'highlighted':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve highlight review comments containing rating metadata.
$args['meta_query'] = [
'relation' => 'OR',
[
@@ -1064,7 +1128,7 @@
case '2': $filter_by_value = [1.01, 2]; break;
case '1': $filter_by_value = [0.01, 0.99]; break;
}
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve highlight review comments containing rating metadata.
$args['meta_query'] = [
[
'key' => 'rating',
@@ -1089,15 +1153,18 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
$per_page = get_option( 'comments_per_page' );
$cur_page = isset( $_REQUEST['current_page'] ) ? absint( $_REQUEST['current_page'] ) : 1;
- $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : null;
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
+ if ( empty( $post_id ) || ! $this->is_post_viewable_by_current_user( $post_id ) ) {
+ return;
+ }
$cur_page = isset( $_REQUEST['pagi_num'] ) ? ( $cur_page - 1) : $cur_page;
$offset = $cur_page * $per_page;
@@ -1115,7 +1182,7 @@
switch ($sort_by) {
case 'top_rated':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Required to retrieve rating review comments containing rating metadata.
$args['meta_key'] = 'rating';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
@@ -1123,7 +1190,7 @@
break;
case 'low_rated':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Required to retrieve rating review comments containing rating metadata.
$args['meta_key'] = 'rating';
$args['orderby'] = 'meta_value_num';
$args['order'] = 'ASC';
@@ -1131,7 +1198,7 @@
break;
case 'recommended':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve recommended review comments containing rating metadata.
$args['meta_query'] = [
'relation' => 'OR',
[
@@ -1144,7 +1211,7 @@
break;
case 'highlighted':
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve highlight review comments containing rating metadata.
$args['meta_query'] = [
'relation' => 'OR',
[
@@ -1172,7 +1239,7 @@
case '2': $filter_by_value = [1.01, 2]; break;
case '1': $filter_by_value = [1, 1.99]; break;
}
-
+ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to retrieve recommended review comments containing rating metadata.
$args['meta_query'] = [
[
'key' => 'rating',
@@ -1206,7 +1273,7 @@
global $wp_rewrite;
$args = ['prev_text' => '<i class="dashicons dashicons-arrow-left-alt2"></i>', 'next_text' => '<i class="dashicons dashicons-arrow-right-alt2"></i>'];
-
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason nonce has been checked in function call
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : null;
$defaults = [
@@ -1238,13 +1305,18 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
- $sort_by = isset( $_REQUEST['sort_by'] ) ? sanitize_text_field( $_REQUEST['sort_by'] ) : '';
- $filter_by = isset( $_REQUEST['filter_by'] ) ? sanitize_text_field( $_REQUEST['filter_by'] ) : '';
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
+ if ( empty( $post_id ) || ! $this->is_post_viewable_by_current_user( $post_id ) ) {
+ wp_send_json_error( array( 'message' => esc_html__( 'Invalid post or permission denied.', 'schema-and-structured-data-for-wp' ) ) );
+ }
+
+ $sort_by = isset( $_REQUEST['sort_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['sort_by'] ) ) : '';
+ $filter_by = isset( $_REQUEST['filter_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['filter_by'] ) ) : '';
$cur_page = isset( $_REQUEST['current_page'] ) ? absint( $_REQUEST['current_page'] ) : 1;
if ( $sort_by ) {
$max_page = $this->get_sorted_reviews( $sort_by, $filter_by );
@@ -1270,8 +1342,8 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
@@ -1527,12 +1599,12 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
- $comment_id = absint($_POST['comment_ID']);
+ $comment_id = isset( $_POST['comment_ID'] ) ? absint($_POST['comment_ID'] ) : 0;
if ( ! current_user_can( 'edit_comment', $comment_id ) ){
$comment = get_comment( $comment_id );
if( get_current_user_id() != $comment->user_id ){
@@ -1546,7 +1618,7 @@
// comment data
$commentarr = [
'comment_ID' => intval( $comment_id ),
- 'comment_content' => sanitize_text_field( $_POST['comment'] ),
+ 'comment_content' => sanitize_text_field( wp_unslash( $_POST['comment'] ) ),
];
// update data in the database
$updated = wp_update_comment( $commentarr );
@@ -1677,8 +1749,8 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
@@ -1752,8 +1824,8 @@
if ( ! isset( $_POST['saswp_rf_form_nonce'] ) ) {
return;
}
-
- if ( ! wp_verify_nonce( $_POST['saswp_rf_form_nonce'], 'saswp_rf_form_action_nonce') ) {
+ $nonce = sanitize_text_field( wp_unslash( $_POST['saswp_rf_form_nonce'] ) );
+ if ( ! wp_verify_nonce( $nonce, 'saswp_rf_form_action_nonce') ) {
return;
}
--- a/schema-and-structured-data-for-wp/modules/reviews/class-saswp-reviews-collection.php
+++ b/schema-and-structured-data-for-wp/modules/reviews/class-saswp-reviews-collection.php
@@ -615,7 +615,9 @@
$col_average = $this->_service->saswp_get_collection_average_rating($saswp_total_re);
if($col_average){
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$collection_aggregate['count'] = $total_reviews_count;
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Existing global variable retained for backward compatibility.
$collection_aggregate['average'] = $col_average;
}
--- a/schema-and-structured-data-for-wp/modules/reviews/class-saswp-reviews-form.php
+++ b/schema-and-structured-data-for-wp/modules/reviews/class-saswp-reviews-form.php
@@ -174,7 +174,8 @@
if($is_amp){
header("AMP-Redirect-To: ".$rv_link);
header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
- }else{
+ }else{
+ // phpcs:ignore Wo