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/utilitie...
File: wpml-languages-notices.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class WPML_Languages_Notices {
[2] Fix | Delete
const NOTICE_ID_MISSING_MENU_ITEMS = 'wpml-missing-menu-items';
[3] Fix | Delete
const NOTICE_GROUP = 'wpml-core';
[4] Fix | Delete
const NOTICE_ID_MISSING_DOWNLOADED_LANGUAGES = 'wpml-missing-downloaded-languages';
[5] Fix | Delete
/** @var WPML_Notices */
[6] Fix | Delete
private $admin_notices;
[7] Fix | Delete
private $translations = array();
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* WPML_Languages_Notices constructor.
[11] Fix | Delete
*
[12] Fix | Delete
* @param WPML_Notices $admin_notices
[13] Fix | Delete
*/
[14] Fix | Delete
public function __construct( WPML_Notices $admin_notices ) {
[15] Fix | Delete
$this->admin_notices = $admin_notices;
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
function maybe_create_notice_missing_menu_items( $languages_count ) {
[19] Fix | Delete
if ( 1 === $languages_count ) {
[20] Fix | Delete
$text = __( 'You need to configure at least one more language in order to access "Theme and plugins localization" and "Media translation".', 'sitepress' );
[21] Fix | Delete
$notice = new WPML_Notice( self::NOTICE_ID_MISSING_MENU_ITEMS, $text, self::NOTICE_GROUP );
[22] Fix | Delete
$notice->set_css_class_types( 'info' );
[23] Fix | Delete
$notice->set_dismissible( true );
[24] Fix | Delete
$this->admin_notices->add_notice( $notice );
[25] Fix | Delete
} else {
[26] Fix | Delete
$this->admin_notices->remove_notice( self::NOTICE_GROUP, self::NOTICE_ID_MISSING_MENU_ITEMS );
[27] Fix | Delete
}
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
public function missing_languages( $not_found_languages ) {
[31] Fix | Delete
$list_items = array();
[32] Fix | Delete
if ( $not_found_languages ) {
[33] Fix | Delete
$list_item_pattern = __( '%s (current locale: %s) - suggested locale(s): %s', 'sitepress' );
[34] Fix | Delete
[35] Fix | Delete
foreach ( (array) $not_found_languages as $not_found_language ) {
[36] Fix | Delete
$suggested_codes = $this->get_suggestions( $not_found_language );
[37] Fix | Delete
if ( $suggested_codes ) {
[38] Fix | Delete
$suggestions = '<strong>' . implode( '</strong>, <strong>', $suggested_codes ) . '</strong>';
[39] Fix | Delete
$current = $not_found_language['code'];
[40] Fix | Delete
if ( $not_found_language['default_locale'] ) {
[41] Fix | Delete
$current = $not_found_language['default_locale'];
[42] Fix | Delete
}
[43] Fix | Delete
$list_items[] = sprintf( $list_item_pattern, $not_found_language['display_name'], $current, $suggestions );
[44] Fix | Delete
}
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
if ( $list_items ) {
[48] Fix | Delete
$text = '';
[49] Fix | Delete
[50] Fix | Delete
$text .= '<p>';
[51] Fix | Delete
$text .= __( 'WordPress cannot automatically download translations for the following languages:', 'sitepress' );
[52] Fix | Delete
$text .= '</p>';
[53] Fix | Delete
[54] Fix | Delete
$text .= '<ul>';
[55] Fix | Delete
$text .= '<li>';
[56] Fix | Delete
$text .= implode( '</li><li>', $list_items );
[57] Fix | Delete
$text .= '</li>';
[58] Fix | Delete
$text .= '</ul>';
[59] Fix | Delete
[60] Fix | Delete
$languages_edit_url = admin_url( '?page=' . WPML_PLUGIN_FOLDER . '/menu/languages.php&trop=1' );
[61] Fix | Delete
$languages_edit_link = '<a href="' . $languages_edit_url . '">';
[62] Fix | Delete
$languages_edit_link .= __( 'Edit Languages', 'sitepress' );
[63] Fix | Delete
$languages_edit_link .= '</a>';
[64] Fix | Delete
[65] Fix | Delete
$text .= '<p>';
[66] Fix | Delete
$text .= sprintf( __( 'To fix, open "%s" and set the "default locale" values as shown above.', 'sitepress' ), $languages_edit_link );
[67] Fix | Delete
$text .= '</p>';
[68] Fix | Delete
[69] Fix | Delete
$notice = new WPML_Notice( self::NOTICE_ID_MISSING_DOWNLOADED_LANGUAGES, $text, self::NOTICE_GROUP );
[70] Fix | Delete
$notice->set_css_class_types( 'warning' );
[71] Fix | Delete
$notice->add_display_callback( array( $this, 'is_not_languages_edit_page' ) );
[72] Fix | Delete
$notice->set_dismissible( true );
[73] Fix | Delete
$this->admin_notices->add_notice( $notice, true );
[74] Fix | Delete
} else {
[75] Fix | Delete
$this->admin_notices->remove_notice( self::NOTICE_GROUP, self::NOTICE_ID_MISSING_DOWNLOADED_LANGUAGES );
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
public function is_not_languages_edit_page() {
[80] Fix | Delete
$result = isset( $_GET['page'], $_GET['trop'] ) && WPML_PLUGIN_FOLDER . '/menu/languages.php' === $_GET['page'] && 1 === (int) $_GET['trop'];
[81] Fix | Delete
[82] Fix | Delete
return ! $result;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
private function get_suggestions( array $language ) {
[86] Fix | Delete
$suggestions = array();
[87] Fix | Delete
if ( function_exists( 'translations_api' ) ) {
[88] Fix | Delete
if ( ! $this->translations ) {
[89] Fix | Delete
$api = translations_api( 'core', array( 'version' => $GLOBALS['wp_version'] ) );
[90] Fix | Delete
[91] Fix | Delete
if ( ! is_wp_error( $api ) ) {
[92] Fix | Delete
$this->translations = $api['translations'];
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
if ( $this->translations ) {
[98] Fix | Delete
foreach ( $this->translations as $translation ) {
[99] Fix | Delete
$default_locale = $this->get_matching_language( $language, $translation );
[100] Fix | Delete
if ( $default_locale ) {
[101] Fix | Delete
$suggestions[] = $default_locale;
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
return $suggestions;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* @param string $language_attribute
[111] Fix | Delete
* @param array $language
[112] Fix | Delete
* @param array $translation
[113] Fix | Delete
*
[114] Fix | Delete
* @return string|null
[115] Fix | Delete
*/
[116] Fix | Delete
private function find_matching_attribute( $language_attribute, array $language, array $translation ) {
[117] Fix | Delete
if ( $translation && $language[ $language_attribute ] ) {
[118] Fix | Delete
$attribute_value = $language[ $language_attribute ];
[119] Fix | Delete
$attribute_value = str_replace( '-', '_', $attribute_value );
[120] Fix | Delete
$attribute_value = strtolower( $attribute_value );
[121] Fix | Delete
$iso_1 = $iso_2 = '';
[122] Fix | Delete
[123] Fix | Delete
if ( array_key_exists( 1, $translation['iso'] ) ) {
[124] Fix | Delete
$iso_1 = strtolower( $translation['iso'][1] );
[125] Fix | Delete
}
[126] Fix | Delete
if ( array_key_exists( 2, $translation['iso'] ) ) {
[127] Fix | Delete
$iso_2 = strtolower( $translation['iso'][2] );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
if ( $iso_1 === $attribute_value ) {
[131] Fix | Delete
return $translation['language'];
[132] Fix | Delete
}
[133] Fix | Delete
if ( $iso_2 === $attribute_value ) {
[134] Fix | Delete
return $translation['language'];
[135] Fix | Delete
}
[136] Fix | Delete
if ( $iso_1 . '_' . $iso_2 === $attribute_value ) {
[137] Fix | Delete
return $translation['language'];
[138] Fix | Delete
}
[139] Fix | Delete
if ( $iso_2 . '_' . $iso_1 === $attribute_value ) {
[140] Fix | Delete
return $translation['language'];
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
return null;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* @param array $language
[149] Fix | Delete
* @param array $translation
[150] Fix | Delete
*
[151] Fix | Delete
* @return null|string
[152] Fix | Delete
*/
[153] Fix | Delete
private function get_matching_language( array $language, array $translation ) {
[154] Fix | Delete
$default_locale = $this->find_matching_attribute( 'default_locale', $language, $translation );
[155] Fix | Delete
if ( ! $default_locale ) {
[156] Fix | Delete
$default_locale = $this->find_matching_attribute( 'tag', $language, $translation );
[157] Fix | Delete
if ( ! $default_locale ) {
[158] Fix | Delete
$default_locale = $this->find_matching_attribute( 'code', $language, $translation );
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
return $default_locale;
[163] Fix | Delete
}
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function