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: abstract-aioseo-settings-importing-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 Exception;
[5] Fix | Delete
use Yoast\WP\SEO\Actions\Importing\Abstract_Aioseo_Importing_Action;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Import_Helper;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Abstract class for importing AIOSEO settings.
[10] Fix | Delete
*/
[11] Fix | Delete
abstract class Abstract_Aioseo_Settings_Importing_Action extends Abstract_Aioseo_Importing_Action {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The plugin the class deals with.
[15] Fix | Delete
*
[16] Fix | Delete
* @var string
[17] Fix | Delete
*/
[18] Fix | Delete
public const PLUGIN = null;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The type the class deals with.
[22] Fix | Delete
*
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
public const TYPE = null;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* The option_name of the AIOSEO option that contains the settings.
[29] Fix | Delete
*/
[30] Fix | Delete
public const SOURCE_OPTION_NAME = null;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The map of aioseo_options to yoast settings.
[34] Fix | Delete
*
[35] Fix | Delete
* @var array
[36] Fix | Delete
*/
[37] Fix | Delete
protected $aioseo_options_to_yoast_map = [];
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The tab of the aioseo settings we're working with, eg. taxonomies, posttypes.
[41] Fix | Delete
*
[42] Fix | Delete
* @var string
[43] Fix | Delete
*/
[44] Fix | Delete
protected $settings_tab = '';
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Additional mapping between AiOSEO replace vars and Yoast replace vars.
[48] Fix | Delete
*
[49] Fix | Delete
* @var array
[50] Fix | Delete
*
[51] Fix | Delete
* @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/
[52] Fix | Delete
*/
[53] Fix | Delete
protected $replace_vars_edited_map = [];
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* The import helper.
[57] Fix | Delete
*
[58] Fix | Delete
* @var Import_Helper
[59] Fix | Delete
*/
[60] Fix | Delete
protected $import_helper;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Builds the mapping that ties AOISEO option keys with Yoast ones and their data transformation method.
[64] Fix | Delete
*
[65] Fix | Delete
* @return void
[66] Fix | Delete
*/
[67] Fix | Delete
abstract protected function build_mapping();
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Sets the import helper.
[71] Fix | Delete
*
[72] Fix | Delete
* @required
[73] Fix | Delete
*
[74] Fix | Delete
* @param Import_Helper $import_helper The import helper.
[75] Fix | Delete
*
[76] Fix | Delete
* @return void
[77] Fix | Delete
*/
[78] Fix | Delete
public function set_import_helper( Import_Helper $import_helper ) {
[79] Fix | Delete
$this->import_helper = $import_helper;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Retrieves the source option_name.
[84] Fix | Delete
*
[85] Fix | Delete
* @return string The source option_name.
[86] Fix | Delete
*
[87] Fix | Delete
* @throws Exception If the SOURCE_OPTION_NAME constant is not set in the child class.
[88] Fix | Delete
*/
[89] Fix | Delete
public function get_source_option_name() {
[90] Fix | Delete
$source_option_name = static::SOURCE_OPTION_NAME;
[91] Fix | Delete
[92] Fix | Delete
if ( empty( $source_option_name ) ) {
[93] Fix | Delete
throw new Exception( 'Importing settings action without explicit source option_name' );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return $source_option_name;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Returns the total number of unimported objects.
[101] Fix | Delete
*
[102] Fix | Delete
* @return int The total number of unimported objects.
[103] Fix | Delete
*/
[104] Fix | Delete
public function get_total_unindexed() {
[105] Fix | Delete
return $this->get_unindexed_count();
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Returns the limited number of unimported objects.
[110] Fix | Delete
*
[111] Fix | Delete
* @param int $limit The maximum number of unimported objects to be returned.
[112] Fix | Delete
*
[113] Fix | Delete
* @return int The limited number of unindexed posts.
[114] Fix | Delete
*/
[115] Fix | Delete
public function get_limited_unindexed_count( $limit ) {
[116] Fix | Delete
return $this->get_unindexed_count( $limit );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Returns the number of unimported objects (limited if limit is applied).
[121] Fix | Delete
*
[122] Fix | Delete
* @param int|null $limit The maximum number of unimported objects to be returned.
[123] Fix | Delete
*
[124] Fix | Delete
* @return int The number of unindexed posts.
[125] Fix | Delete
*/
[126] Fix | Delete
protected function get_unindexed_count( $limit = null ) {
[127] Fix | Delete
if ( ! \is_int( $limit ) || $limit < 1 ) {
[128] Fix | Delete
$limit = null;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$settings_to_create = $this->query( $limit );
[132] Fix | Delete
[133] Fix | Delete
$number_of_settings_to_create = \count( $settings_to_create );
[134] Fix | Delete
$completed = $number_of_settings_to_create === 0;
[135] Fix | Delete
$this->set_completed( $completed );
[136] Fix | Delete
[137] Fix | Delete
return $number_of_settings_to_create;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Imports AIOSEO settings.
[142] Fix | Delete
*
[143] Fix | Delete
* @return array|false An array of the AIOSEO settings that were imported or false if aioseo data was not found.
[144] Fix | Delete
*/
[145] Fix | Delete
public function index() {
[146] Fix | Delete
$limit = $this->get_limit();
[147] Fix | Delete
$aioseo_settings = $this->query( $limit );
[148] Fix | Delete
$created_settings = [];
[149] Fix | Delete
[150] Fix | Delete
$completed = \count( $aioseo_settings ) === 0;
[151] Fix | Delete
$this->set_completed( $completed );
[152] Fix | Delete
[153] Fix | Delete
// Prepare the setting keys mapping.
[154] Fix | Delete
$this->build_mapping();
[155] Fix | Delete
[156] Fix | Delete
// Prepare the replacement var mapping.
[157] Fix | Delete
foreach ( $this->replace_vars_edited_map as $aioseo_var => $yoast_var ) {
[158] Fix | Delete
$this->replacevar_handler->compose_map( $aioseo_var, $yoast_var );
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
$last_imported_setting = '';
[162] Fix | Delete
try {
[163] Fix | Delete
foreach ( $aioseo_settings as $setting => $setting_value ) {
[164] Fix | Delete
// Map and import the values of the setting we're working with (eg. post, book-category, etc.) to the respective Yoast option.
[165] Fix | Delete
$this->map( $setting_value, $setting );
[166] Fix | Delete
[167] Fix | Delete
// Save the type of the settings that were just imported, so that we can allow chunked imports.
[168] Fix | Delete
$last_imported_setting = $setting;
[169] Fix | Delete
[170] Fix | Delete
$created_settings[] = $setting;
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
finally {
[174] Fix | Delete
$cursor_id = $this->get_cursor_id();
[175] Fix | Delete
$this->import_cursor->set_cursor( $cursor_id, $last_imported_setting );
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
return $created_settings;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
/**
[182] Fix | Delete
* Checks if the settings tab subsetting is set in the AIOSEO option.
[183] Fix | Delete
*
[184] Fix | Delete
* @param string $aioseo_settings The AIOSEO option.
[185] Fix | Delete
*
[186] Fix | Delete
* @return bool Whether the settings are set.
[187] Fix | Delete
*/
[188] Fix | Delete
public function isset_settings_tab( $aioseo_settings ) {
[189] Fix | Delete
return isset( $aioseo_settings['searchAppearance'][ $this->settings_tab ] );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Queries the database and retrieves unimported AiOSEO settings (in chunks if a limit is applied).
[194] Fix | Delete
*
[195] Fix | Delete
* @param int|null $limit The maximum number of unimported objects to be returned.
[196] Fix | Delete
*
[197] Fix | Delete
* @return array The (maybe chunked) unimported AiOSEO settings to import.
[198] Fix | Delete
*/
[199] Fix | Delete
protected function query( $limit = null ) {
[200] Fix | Delete
$aioseo_settings = \json_decode( \get_option( $this->get_source_option_name(), '' ), true );
[201] Fix | Delete
[202] Fix | Delete
if ( empty( $aioseo_settings ) ) {
[203] Fix | Delete
return [];
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
// We specifically want the setttings of the tab we're working with, eg. postTypes, taxonomies, etc.
[207] Fix | Delete
$settings_values = $aioseo_settings['searchAppearance'][ $this->settings_tab ];
[208] Fix | Delete
if ( ! \is_array( $settings_values ) ) {
[209] Fix | Delete
return [];
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
$flattened_settings = $this->import_helper->flatten_settings( $settings_values );
[213] Fix | Delete
[214] Fix | Delete
return $this->get_unimported_chunk( $flattened_settings, $limit );
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Retrieves (a chunk of, if limit is applied) the unimported AIOSEO settings.
[219] Fix | Delete
* To apply a chunk, we manipulate the cursor to the keys of the AIOSEO settings.
[220] Fix | Delete
*
[221] Fix | Delete
* @param array $importable_data All of the available AIOSEO settings.
[222] Fix | Delete
* @param int $limit The maximum number of unimported objects to be returned.
[223] Fix | Delete
*
[224] Fix | Delete
* @return array The (chunk of, if limit is applied)) unimported AIOSEO settings.
[225] Fix | Delete
*/
[226] Fix | Delete
protected function get_unimported_chunk( $importable_data, $limit ) {
[227] Fix | Delete
\ksort( $importable_data );
[228] Fix | Delete
[229] Fix | Delete
$cursor_id = $this->get_cursor_id();
[230] Fix | Delete
$cursor = $this->import_cursor->get_cursor( $cursor_id, '' );
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Filter 'wpseo_aioseo_<identifier>_import_cursor' - Allow filtering the value of the aioseo settings import cursor.
[234] Fix | Delete
*
[235] Fix | Delete
* @param int $import_cursor The value of the aioseo posttype default settings import cursor.
[236] Fix | Delete
*/
[237] Fix | Delete
$cursor = \apply_filters( 'wpseo_aioseo_' . $this->get_type() . '_import_cursor', $cursor );
[238] Fix | Delete
[239] Fix | Delete
if ( $cursor === '' ) {
[240] Fix | Delete
return \array_slice( $importable_data, 0, $limit, true );
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
// Let's find the position of the cursor in the alphabetically sorted importable data, so we can return only the unimported data.
[244] Fix | Delete
$keys = \array_flip( \array_keys( $importable_data ) );
[245] Fix | Delete
// If the stored cursor now no longer exists in the data, we have no choice but to start over.
[246] Fix | Delete
$position = ( isset( $keys[ $cursor ] ) ) ? ( $keys[ $cursor ] + 1 ) : 0;
[247] Fix | Delete
[248] Fix | Delete
return \array_slice( $importable_data, $position, $limit, true );
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* Returns the number of objects that will be imported in a single importing pass.
[253] Fix | Delete
*
[254] Fix | Delete
* @return int The limit.
[255] Fix | Delete
*/
[256] Fix | Delete
public function get_limit() {
[257] Fix | Delete
/**
[258] Fix | Delete
* Filter 'wpseo_aioseo_<identifier>_indexation_limit' - Allow filtering the number of settings imported during each importing pass.
[259] Fix | Delete
*
[260] Fix | Delete
* @param int $max_posts The maximum number of posts indexed.
[261] Fix | Delete
*/
[262] Fix | Delete
$limit = \apply_filters( 'wpseo_aioseo_' . $this->get_type() . '_indexation_limit', 25 );
[263] Fix | Delete
[264] Fix | Delete
if ( ! \is_int( $limit ) || $limit < 1 ) {
[265] Fix | Delete
$limit = 25;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
return $limit;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Maps/imports AIOSEO settings into the respective Yoast settings.
[273] Fix | Delete
*
[274] Fix | Delete
* @param string|array $setting_value The value of the AIOSEO setting at hand.
[275] Fix | Delete
* @param string $setting The setting at hand, eg. post or movie-category, separator etc.
[276] Fix | Delete
*
[277] Fix | Delete
* @return void
[278] Fix | Delete
*/
[279] Fix | Delete
protected function map( $setting_value, $setting ) {
[280] Fix | Delete
$aioseo_options_to_yoast_map = $this->aioseo_options_to_yoast_map;
[281] Fix | Delete
[282] Fix | Delete
if ( isset( $aioseo_options_to_yoast_map[ $setting ] ) ) {
[283] Fix | Delete
$this->import_single_setting( $setting, $setting_value, $aioseo_options_to_yoast_map[ $setting ] );
[284] Fix | Delete
}
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Imports a single setting in the db after transforming it to adhere to Yoast conventions.
[289] Fix | Delete
*
[290] Fix | Delete
* @param string $setting The name of the setting.
[291] Fix | Delete
* @param string $setting_value The values of the setting.
[292] Fix | Delete
* @param array $setting_mapping The mapping of the setting to Yoast formats.
[293] Fix | Delete
*
[294] Fix | Delete
* @return void
[295] Fix | Delete
*/
[296] Fix | Delete
protected function import_single_setting( $setting, $setting_value, $setting_mapping ) {
[297] Fix | Delete
$yoast_key = $setting_mapping['yoast_name'];
[298] Fix | Delete
[299] Fix | Delete
// Check if we're supposed to save the setting.
[300] Fix | Delete
if ( $this->options->get_default( 'wpseo_titles', $yoast_key ) !== null ) {
[301] Fix | Delete
// Then, do any needed data transfomation before actually saving the incoming data.
[302] Fix | Delete
$transformed_data = \call_user_func( [ $this, $setting_mapping['transform_method'] ], $setting_value, $setting_mapping );
[303] Fix | Delete
[304] Fix | Delete
$this->options->set( $yoast_key, $transformed_data );
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* Minimally transforms boolean data to be imported.
[310] Fix | Delete
*
[311] Fix | Delete
* @param bool $meta_data The boolean meta data to be imported.
[312] Fix | Delete
*
[313] Fix | Delete
* @return bool The transformed boolean meta data.
[314] Fix | Delete
*/
[315] Fix | Delete
public function simple_boolean_import( $meta_data ) {
[316] Fix | Delete
return $meta_data;
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* Imports the noindex setting, taking into consideration whether they defer to global defaults.
[321] Fix | Delete
*
[322] Fix | Delete
* @param bool $noindex The noindex of the type, without taking into consideration whether the type defers to global defaults.
[323] Fix | Delete
* @param array $mapping The mapping of the setting we're working with.
[324] Fix | Delete
*
[325] Fix | Delete
* @return bool The noindex setting.
[326] Fix | Delete
*/
[327] Fix | Delete
public function import_noindex( $noindex, $mapping ) {
[328] Fix | Delete
return $this->robots_transformer->transform_robot_setting( 'noindex', $noindex, $mapping );
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
/**
[332] Fix | Delete
* Returns a setting map of the robot setting for one subset of post types/taxonomies/archives.
[333] Fix | Delete
* For custom archives, it returns an empty array because AIOSEO excludes some custom archives from this option structure, eg. WooCommerce's products and we don't want to raise a false alarm.
[334] Fix | Delete
*
[335] Fix | Delete
* @return array The setting map of the robot setting for one subset of post types/taxonomies/archives or an empty array.
[336] Fix | Delete
*/
[337] Fix | Delete
public function pluck_robot_setting_from_mapping() {
[338] Fix | Delete
return [];
[339] Fix | Delete
}
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function