Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/actions/importin.../aioseo
File: aioseo-validate-data-action.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
[2] Fix | Delete
namespace Yoast\WP\SEO\Actions\Importing\Aioseo;
[3] Fix | Delete
[4] Fix | Delete
use wpdb;
[5] Fix | Delete
use Yoast\WP\SEO\Actions\Importing\Abstract_Aioseo_Importing_Action;
[6] Fix | Delete
use Yoast\WP\SEO\Exceptions\Importing\Aioseo_Validation_Exception;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Importing action for validating AIOSEO data before the import occurs.
[11] Fix | Delete
*/
[12] Fix | Delete
class Aioseo_Validate_Data_Action extends Abstract_Aioseo_Importing_Action {
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* The plugin of the action.
[16] Fix | Delete
*/
[17] Fix | Delete
public const PLUGIN = 'aioseo';
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* The type of the action.
[21] Fix | Delete
*/
[22] Fix | Delete
public const TYPE = 'validate_data';
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The WordPress database instance.
[26] Fix | Delete
*
[27] Fix | Delete
* @var wpdb
[28] Fix | Delete
*/
[29] Fix | Delete
protected $wpdb;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The Post Importing action.
[33] Fix | Delete
*
[34] Fix | Delete
* @var Aioseo_Posts_Importing_Action
[35] Fix | Delete
*/
[36] Fix | Delete
protected $post_importing_action;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* The settings importing actions.
[40] Fix | Delete
*
[41] Fix | Delete
* @var array
[42] Fix | Delete
*/
[43] Fix | Delete
protected $settings_importing_actions;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Class constructor.
[47] Fix | Delete
*
[48] Fix | Delete
* @param wpdb $wpdb The WordPress database instance.
[49] Fix | Delete
* @param Options_Helper $options The options helper.
[50] Fix | Delete
* @param Aioseo_Custom_Archive_Settings_Importing_Action $custom_archive_action The Custom Archive Settings importing action.
[51] Fix | Delete
* @param Aioseo_Default_Archive_Settings_Importing_Action $default_archive_action The Default Archive Settings importing action.
[52] Fix | Delete
* @param Aioseo_General_Settings_Importing_Action $general_settings_action The General Settings importing action.
[53] Fix | Delete
* @param Aioseo_Posttype_Defaults_Settings_Importing_Action $posttype_defaults_settings_action The Posttype Defaults Settings importing action.
[54] Fix | Delete
* @param Aioseo_Taxonomy_Settings_Importing_Action $taxonomy_settings_action The Taxonomy Settings importing action.
[55] Fix | Delete
* @param Aioseo_Posts_Importing_Action $post_importing_action The Post importing action.
[56] Fix | Delete
*/
[57] Fix | Delete
public function __construct(
[58] Fix | Delete
wpdb $wpdb,
[59] Fix | Delete
Options_Helper $options,
[60] Fix | Delete
Aioseo_Custom_Archive_Settings_Importing_Action $custom_archive_action,
[61] Fix | Delete
Aioseo_Default_Archive_Settings_Importing_Action $default_archive_action,
[62] Fix | Delete
Aioseo_General_Settings_Importing_Action $general_settings_action,
[63] Fix | Delete
Aioseo_Posttype_Defaults_Settings_Importing_Action $posttype_defaults_settings_action,
[64] Fix | Delete
Aioseo_Taxonomy_Settings_Importing_Action $taxonomy_settings_action,
[65] Fix | Delete
Aioseo_Posts_Importing_Action $post_importing_action
[66] Fix | Delete
) {
[67] Fix | Delete
$this->wpdb = $wpdb;
[68] Fix | Delete
$this->options = $options;
[69] Fix | Delete
$this->post_importing_action = $post_importing_action;
[70] Fix | Delete
$this->settings_importing_actions = [
[71] Fix | Delete
$custom_archive_action,
[72] Fix | Delete
$default_archive_action,
[73] Fix | Delete
$general_settings_action,
[74] Fix | Delete
$posttype_defaults_settings_action,
[75] Fix | Delete
$taxonomy_settings_action,
[76] Fix | Delete
];
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Just checks if the action has been completed in the past.
[81] Fix | Delete
*
[82] Fix | Delete
* @return int 1 if it hasn't been completed in the past, 0 if it has.
[83] Fix | Delete
*/
[84] Fix | Delete
public function get_total_unindexed() {
[85] Fix | Delete
return ( ! $this->get_completed() ) ? 1 : 0;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Just checks if the action has been completed in the past.
[90] Fix | Delete
*
[91] Fix | Delete
* @param int $limit The maximum number of unimported objects to be returned. Not used, exists to comply with the interface.
[92] Fix | Delete
*
[93] Fix | Delete
* @return int 1 if it hasn't been completed in the past, 0 if it has.
[94] Fix | Delete
*/
[95] Fix | Delete
public function get_limited_unindexed_count( $limit ) {
[96] Fix | Delete
return ( ! $this->get_completed() ) ? 1 : 0;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Validates AIOSEO data.
[101] Fix | Delete
*
[102] Fix | Delete
* @return array An array of validated data or false if aioseo data did not pass validation.
[103] Fix | Delete
*
[104] Fix | Delete
* @throws Aioseo_Validation_Exception If the validation fails.
[105] Fix | Delete
*/
[106] Fix | Delete
public function index() {
[107] Fix | Delete
if ( $this->get_completed() ) {
[108] Fix | Delete
return [];
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
$validated_aioseo_table = $this->validate_aioseo_table();
[112] Fix | Delete
$validated_aioseo_settings = $this->validate_aioseo_settings();
[113] Fix | Delete
$validated_robot_settings = $this->validate_robot_settings();
[114] Fix | Delete
[115] Fix | Delete
if ( $validated_aioseo_table === false || $validated_aioseo_settings === false || $validated_robot_settings === false ) {
[116] Fix | Delete
throw new Aioseo_Validation_Exception();
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
$this->set_completed( true );
[120] Fix | Delete
[121] Fix | Delete
return [
[122] Fix | Delete
'validated_aioseo_table' => $validated_aioseo_table,
[123] Fix | Delete
'validated_aioseo_settings' => $validated_aioseo_settings,
[124] Fix | Delete
'validated_robot_settings' => $validated_robot_settings,
[125] Fix | Delete
];
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Validates the AIOSEO indexable table.
[130] Fix | Delete
*
[131] Fix | Delete
* @return bool Whether the AIOSEO table exists and has the structure we expect.
[132] Fix | Delete
*/
[133] Fix | Delete
public function validate_aioseo_table() {
[134] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[135] Fix | Delete
return false;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$table = $this->aioseo_helper->get_table();
[139] Fix | Delete
$needed_data = $this->post_importing_action->get_needed_data();
[140] Fix | Delete
[141] Fix | Delete
$aioseo_columns = $this->wpdb->get_col(
[142] Fix | Delete
"SHOW COLUMNS FROM {$table}", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input.
[143] Fix | Delete
0
[144] Fix | Delete
);
[145] Fix | Delete
[146] Fix | Delete
return $needed_data === \array_intersect( $needed_data, $aioseo_columns );
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Validates the AIOSEO settings from the options table.
[151] Fix | Delete
*
[152] Fix | Delete
* @return bool Whether the AIOSEO settings from the options table exist and have the structure we expect.
[153] Fix | Delete
*/
[154] Fix | Delete
public function validate_aioseo_settings() {
[155] Fix | Delete
foreach ( $this->settings_importing_actions as $settings_import_action ) {
[156] Fix | Delete
$aioseo_settings = \json_decode( \get_option( $settings_import_action->get_source_option_name(), '' ), true );
[157] Fix | Delete
[158] Fix | Delete
if ( ! $settings_import_action->isset_settings_tab( $aioseo_settings ) ) {
[159] Fix | Delete
return false;
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
return true;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Validates the AIOSEO robots settings from the options table.
[168] Fix | Delete
*
[169] Fix | Delete
* @return bool Whether the AIOSEO robots settings from the options table exist and have the structure we expect.
[170] Fix | Delete
*/
[171] Fix | Delete
public function validate_robot_settings() {
[172] Fix | Delete
if ( $this->validate_post_robot_settings() && $this->validate_default_robot_settings() ) {
[173] Fix | Delete
return true;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
return false;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Validates the post AIOSEO robots settings from the options table.
[181] Fix | Delete
*
[182] Fix | Delete
* @return bool Whether the post AIOSEO robots settings from the options table exist and have the structure we expect.
[183] Fix | Delete
*/
[184] Fix | Delete
public function validate_post_robot_settings() {
[185] Fix | Delete
$post_robot_mapping = $this->post_importing_action->enhance_mapping();
[186] Fix | Delete
// We're gonna validate against posttype robot settings only for posts, assuming the robot settings stay the same for other post types.
[187] Fix | Delete
$post_robot_mapping['subtype'] = 'post';
[188] Fix | Delete
[189] Fix | Delete
// Let's get both the aioseo_options and the aioseo_options_dynamic options.
[190] Fix | Delete
$aioseo_global_settings = $this->aioseo_helper->get_global_option();
[191] Fix | Delete
$aioseo_posts_settings = \json_decode( \get_option( $post_robot_mapping['option_name'], '' ), true );
[192] Fix | Delete
[193] Fix | Delete
$needed_robots_data = $this->post_importing_action->get_needed_robot_data();
[194] Fix | Delete
\array_push( $needed_robots_data, 'default', 'noindex' );
[195] Fix | Delete
[196] Fix | Delete
foreach ( $needed_robots_data as $robot_setting ) {
[197] Fix | Delete
// Validate against global settings.
[198] Fix | Delete
if ( ! isset( $aioseo_global_settings['searchAppearance']['advanced']['globalRobotsMeta'][ $robot_setting ] ) ) {
[199] Fix | Delete
return false;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
// Validate against posttype settings.
[203] Fix | Delete
if ( ! isset( $aioseo_posts_settings['searchAppearance'][ $post_robot_mapping['type'] ][ $post_robot_mapping['subtype'] ]['advanced']['robotsMeta'][ $robot_setting ] ) ) {
[204] Fix | Delete
return false;
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
return true;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Validates the default AIOSEO robots settings for search appearance settings from the options table.
[213] Fix | Delete
*
[214] Fix | Delete
* @return bool Whether the AIOSEO robots settings for search appearance settings from the options table exist and have the structure we expect.
[215] Fix | Delete
*/
[216] Fix | Delete
public function validate_default_robot_settings() {
[217] Fix | Delete
[218] Fix | Delete
foreach ( $this->settings_importing_actions as $settings_import_action ) {
[219] Fix | Delete
$robot_setting_map = $settings_import_action->pluck_robot_setting_from_mapping();
[220] Fix | Delete
[221] Fix | Delete
// Some actions return empty robot settings, let's not validate against those.
[222] Fix | Delete
if ( ! empty( $robot_setting_map ) ) {
[223] Fix | Delete
$aioseo_settings = \json_decode( \get_option( $robot_setting_map['option_name'], '' ), true );
[224] Fix | Delete
[225] Fix | Delete
if ( ! isset( $aioseo_settings['searchAppearance'][ $robot_setting_map['type'] ][ $robot_setting_map['subtype'] ]['advanced']['robotsMeta']['default'] ) ) {
[226] Fix | Delete
return false;
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
return true;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Used nowhere. Exists to comply with the interface.
[236] Fix | Delete
*
[237] Fix | Delete
* @return int The limit.
[238] Fix | Delete
*/
[239] Fix | Delete
public function get_limit() {
[240] Fix | Delete
/**
[241] Fix | Delete
* Filter 'wpseo_aioseo_cleanup_limit' - Allow filtering the number of validations during each action pass.
[242] Fix | Delete
*
[243] Fix | Delete
* @param int $limit The maximum number of validations.
[244] Fix | Delete
*/
[245] Fix | Delete
$limit = \apply_filters( 'wpseo_aioseo_validation_limit', 25 );
[246] Fix | Delete
[247] Fix | Delete
if ( ! \is_int( $limit ) || $limit < 1 ) {
[248] Fix | Delete
$limit = 25;
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
return $limit;
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function