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/wp-conte.../plugins/sitepres.../classes
File: class-wpml-site-id.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class for handling a unique ID of the site.
[3] Fix | Delete
*
[4] Fix | Delete
* @author OnTheGo Systems
[5] Fix | Delete
*/
[6] Fix | Delete
class WPML_Site_ID {
[7] Fix | Delete
/**
[8] Fix | Delete
* The name prefix of the option where the ID is stored.
[9] Fix | Delete
*/
[10] Fix | Delete
const SITE_ID_KEY = 'WPML_SITE_ID';
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* The default scope.
[14] Fix | Delete
*/
[15] Fix | Delete
const SITE_SCOPES_GLOBAL = 'global';
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Memory cache of the IDs.
[19] Fix | Delete
*
[20] Fix | Delete
* @var array
[21] Fix | Delete
*/
[22] Fix | Delete
private $site_ids = array();
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Read and, if needed, generate the site ID based on the scope.
[26] Fix | Delete
*
[27] Fix | Delete
* @param string $scope Defaults to "global".
[28] Fix | Delete
* Use a different value when the ID is used for specific scopes.
[29] Fix | Delete
*
[30] Fix | Delete
* @param bool $create_new Forces the creation of a new ID.
[31] Fix | Delete
*
[32] Fix | Delete
* @return string|null The generated/stored ID or null if it wasn't possible to generate/store the value.
[33] Fix | Delete
*/
[34] Fix | Delete
public function get_site_id( $scope = self::SITE_SCOPES_GLOBAL, $create_new = false ) {
[35] Fix | Delete
$generate = ! $this->read_value( $scope ) || $create_new;
[36] Fix | Delete
if ( $generate && ! $this->generate_site_id( $scope ) ) {
[37] Fix | Delete
return null;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
return $this->get_from_cache( $scope );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Geenrates the ID.
[45] Fix | Delete
*
[46] Fix | Delete
* @param string $scope The scope of the ID.
[47] Fix | Delete
*
[48] Fix | Delete
* @return bool
[49] Fix | Delete
*/
[50] Fix | Delete
private function generate_site_id( $scope ) {
[51] Fix | Delete
$site_url = get_site_url();
[52] Fix | Delete
$site_uuid = uuid_v5( $site_url, wp_generate_uuid4() );
[53] Fix | Delete
$time_uuid = uuid_v5( time(), wp_generate_uuid4() );
[54] Fix | Delete
[55] Fix | Delete
return $this->write_value( uuid_v5( $site_uuid, $time_uuid ), $scope );
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Read the value from cache, if present, or from the DB.
[60] Fix | Delete
*
[61] Fix | Delete
* @param string $scope The scope of the ID.
[62] Fix | Delete
*
[63] Fix | Delete
* @return string
[64] Fix | Delete
*/
[65] Fix | Delete
private function read_value( $scope ) {
[66] Fix | Delete
if ( ! $this->get_from_cache( $scope ) ) {
[67] Fix | Delete
$this->site_ids[ $scope ] = get_option( $this->get_option_key( $scope ), null );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
return $this->site_ids[ $scope ];
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Writes the value in DB and cache.
[75] Fix | Delete
*
[76] Fix | Delete
* @param string $value The value to write.
[77] Fix | Delete
* @param string $scope The scope of the ID.
[78] Fix | Delete
*
[79] Fix | Delete
* @return bool
[80] Fix | Delete
*/
[81] Fix | Delete
private function write_value( $value, $scope ) {
[82] Fix | Delete
if ( update_option( $this->get_option_key( $scope ), $value, false ) ) {
[83] Fix | Delete
$this->site_ids[ $scope ] = $value;
[84] Fix | Delete
[85] Fix | Delete
return true;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return false;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Gets the options key name based on the scope.
[93] Fix | Delete
*
[94] Fix | Delete
* @param string $scope The scope of the ID.
[95] Fix | Delete
*
[96] Fix | Delete
* @return string
[97] Fix | Delete
*/
[98] Fix | Delete
private function get_option_key( $scope ) {
[99] Fix | Delete
return self::SITE_ID_KEY . ':' . $scope;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Gets the value from the memory cache.
[104] Fix | Delete
*
[105] Fix | Delete
* @param string $scope The scope of the ID.
[106] Fix | Delete
*
[107] Fix | Delete
* @return mixed|null
[108] Fix | Delete
*/
[109] Fix | Delete
private function get_from_cache( $scope ) {
[110] Fix | Delete
if ( array_key_exists( $scope, $this->site_ids ) && $this->site_ids[ $scope ] ) {
[111] Fix | Delete
return $this->site_ids[ $scope ];
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return null;
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function