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/translat...
File: class-wpml-translation-element.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Use this class as parent class for translatable elements in WPML,
[3] Fix | Delete
* to have a common approach for retrieving and setting translation information.
[4] Fix | Delete
* @author OnTheGo Systems
[5] Fix | Delete
*/
[6] Fix | Delete
abstract class WPML_Translation_Element extends WPML_SP_User {
[7] Fix | Delete
/** @var int */
[8] Fix | Delete
protected $id;
[9] Fix | Delete
[10] Fix | Delete
/** @var stdClass */
[11] Fix | Delete
private $languages_details;
[12] Fix | Delete
/** @var array */
[13] Fix | Delete
private $element_translations;
[14] Fix | Delete
/** @var WPML_WP_Cache */
[15] Fix | Delete
protected $wpml_cache;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* WPML_Translation_Element constructor.
[19] Fix | Delete
*
[20] Fix | Delete
* @param int $id
[21] Fix | Delete
* @param SitePress $sitepress
[22] Fix | Delete
* @param WPML_WP_Cache $wpml_cache
[23] Fix | Delete
*/
[24] Fix | Delete
public function __construct( $id, SitePress $sitepress, WPML_WP_Cache $wpml_cache = null ) {
[25] Fix | Delete
if ( ! is_numeric( $id ) || $id <= 0 ) {
[26] Fix | Delete
throw new InvalidArgumentException( 'Argument ID must be numeric and greater than 0.' );
[27] Fix | Delete
}
[28] Fix | Delete
$this->id = (int) $id;
[29] Fix | Delete
$this->wpml_cache = $wpml_cache ? $wpml_cache : new WPML_WP_Cache( WPML_ELEMENT_TRANSLATIONS_CACHE_GROUP );
[30] Fix | Delete
parent::__construct( $sitepress );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
public function get_id() {
[34] Fix | Delete
return $this->id;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public function get_source_language_code() {
[38] Fix | Delete
$source_language_code = null;
[39] Fix | Delete
if ( $this->get_language_details() ) {
[40] Fix | Delete
$source_language_code = $this->get_language_details()->source_language_code;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
return $source_language_code;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* @return stdClass
[48] Fix | Delete
* @throws \UnexpectedValueException
[49] Fix | Delete
*/
[50] Fix | Delete
protected function get_language_details() {
[51] Fix | Delete
$this->init_language_details();
[52] Fix | Delete
return $this->languages_details;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
abstract function get_element_id();
[56] Fix | Delete
[57] Fix | Delete
abstract function get_wpml_element_type();
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* @return array
[61] Fix | Delete
*/
[62] Fix | Delete
private function get_element_translations() {
[63] Fix | Delete
return $this->sitepress->get_element_translations( $this->get_trid(), $this->get_wpml_element_type() );
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* @param string $language_code
[68] Fix | Delete
*
[69] Fix | Delete
* @return WPML_Translation_Element|null
[70] Fix | Delete
* @throws \InvalidArgumentException
[71] Fix | Delete
*/
[72] Fix | Delete
public function get_translation( $language_code ) {
[73] Fix | Delete
if ( ! $language_code ) {
[74] Fix | Delete
throw new InvalidArgumentException( 'Argument $language_code must be a non empty string.' );
[75] Fix | Delete
}
[76] Fix | Delete
$this->maybe_init_translations();
[77] Fix | Delete
[78] Fix | Delete
$translation = null;
[79] Fix | Delete
if ( $this->element_translations && array_key_exists( $language_code, $this->element_translations ) ) {
[80] Fix | Delete
$translation = $this->element_translations[ $language_code ];
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return $translation;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* @return WPML_Translation_Element[]
[88] Fix | Delete
*/
[89] Fix | Delete
public function get_translations() {
[90] Fix | Delete
return $this->maybe_init_translations();
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* @return WPML_Translation_Element[]
[95] Fix | Delete
*/
[96] Fix | Delete
public function maybe_init_translations() {
[97] Fix | Delete
if ( ! $this->element_translations ) {
[98] Fix | Delete
$this->element_translations = array();
[99] Fix | Delete
$translations = $this->get_element_translations();
[100] Fix | Delete
foreach ( $translations as $language_code => $element_data ) {
[101] Fix | Delete
[102] Fix | Delete
if ( ! isset( $element_data->element_id ) ) {
[103] Fix | Delete
continue;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
try {
[107] Fix | Delete
$this->element_translations[ $language_code ] = $this->get_new_instance( $element_data );
[108] Fix | Delete
} catch ( Exception $e ) {
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
return $this->element_translations;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
public function get_trid() {
[117] Fix | Delete
$trid = false;
[118] Fix | Delete
if ( $this->get_language_details() ) {
[119] Fix | Delete
$trid = $this->get_language_details()->trid;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
return $trid;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* @return string|WP_Error
[127] Fix | Delete
*/
[128] Fix | Delete
function get_wp_element_type() {
[129] Fix | Delete
$element = $this->get_wp_object();
[130] Fix | Delete
if ( is_wp_error( $element ) ) {
[131] Fix | Delete
return $element;
[132] Fix | Delete
}
[133] Fix | Delete
if ( false === (bool) $element ) {
[134] Fix | Delete
return new WP_Error( 1, 'Element does not exists.' );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
return $this->get_type( $element );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* @return mixed|WP_Error
[142] Fix | Delete
*/
[143] Fix | Delete
abstract function get_wp_object();
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* @param mixed $element
[147] Fix | Delete
*
[148] Fix | Delete
* @return string
[149] Fix | Delete
*/
[150] Fix | Delete
abstract function get_type( $element = null );
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* @param null|stdClass $element_data null, or a standard object containing at least the `translation_id`, `language_code`, `element_id`, `source_language_code`, `element_type`, and `original` properties.
[154] Fix | Delete
*
[155] Fix | Delete
* @return WPML_Translation_Element
[156] Fix | Delete
*/
[157] Fix | Delete
abstract function get_new_instance( $element_data );
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* @return null|WPML_Translation_Element
[161] Fix | Delete
*/
[162] Fix | Delete
public function get_source_element() {
[163] Fix | Delete
$this->maybe_init_translations();
[164] Fix | Delete
[165] Fix | Delete
$source_element = null;
[166] Fix | Delete
$source_language_code = $this->get_source_language_code();
[167] Fix | Delete
if ( $this->element_translations && $source_language_code && array_key_exists( $source_language_code, $this->element_translations ) ) {
[168] Fix | Delete
$source_element = $this->element_translations[ $source_language_code ];
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
return $source_element;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
public function get_language_code() {
[175] Fix | Delete
$language_code = null;
[176] Fix | Delete
if ( $this->get_language_details() ) {
[177] Fix | Delete
$language_code = $this->get_language_details()->language_code;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
return $language_code;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
protected function init_language_details() {
[184] Fix | Delete
if ( ! $this->languages_details ) {
[185] Fix | Delete
$this->languages_details = $this->sitepress->get_element_language_details( $this->get_element_id(), $this->get_wpml_element_type() );
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
public function flush_cache() {
[190] Fix | Delete
$this->languages_details = null;
[191] Fix | Delete
$this->element_translations = null;
[192] Fix | Delete
$this->wpml_cache->flush_group_cache();
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
/** @return bool */
[196] Fix | Delete
public function is_in_default_language() {
[197] Fix | Delete
return $this->get_language_code() === $this->sitepress->get_default_language();
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
abstract function is_translatable();
[201] Fix | Delete
abstract function is_display_as_translated();
[202] Fix | Delete
[203] Fix | Delete
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function