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/requirem...
File: class-wpml-integrations-requirements.php
<?php
[0] Fix | Delete
[1] Fix | Delete
use WPML\Core\Twig_Loader_Filesystem;
[2] Fix | Delete
use WPML\Core\Twig_Environment;
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* @author OnTheGo Systems
[6] Fix | Delete
*/
[7] Fix | Delete
class WPML_Integrations_Requirements {
[8] Fix | Delete
const NOTICE_GROUP = 'requirements';
[9] Fix | Delete
const CORE_REQ_NOTICE_ID = 'core-requirements';
[10] Fix | Delete
const MISSING_REQ_NOTICE_ID = 'missing-requirements';
[11] Fix | Delete
const EDITOR_NOTICE_ID = 'enable-translation-editor';
[12] Fix | Delete
const DOCUMENTATION_LINK = 'https://wpml.org/documentation/plugins-compatibility/page-builders/';
[13] Fix | Delete
const DOCUMENTATION_LINK_BLOCK_EDITOR = 'https://wpml.org/?page_id=2909360&utm_source=wpmlplugin&utm_campaign=gutenberg&utm_medium=translation-editor&utm_term=translating-content-created-using-gutenberg-editor';
[14] Fix | Delete
[15] Fix | Delete
private $core_issues = array();
[16] Fix | Delete
private $issues = array();
[17] Fix | Delete
private $tm_settings;
[18] Fix | Delete
private $should_create_editor_notice = false;
[19] Fix | Delete
private $integrations;
[20] Fix | Delete
private $requirements_scripts;
[21] Fix | Delete
[22] Fix | Delete
/** @var SitePress $sitepress */
[23] Fix | Delete
private $sitepress;
[24] Fix | Delete
[25] Fix | Delete
/** @var WPML_Third_Party_Dependencies $third_party_dependencies */
[26] Fix | Delete
private $third_party_dependencies;
[27] Fix | Delete
[28] Fix | Delete
/** @var WPML_Requirements_Notification $requirements_notification */
[29] Fix | Delete
private $requirements_notification;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* WPML_Integrations_Requirements constructor.
[33] Fix | Delete
*
[34] Fix | Delete
* @param SitePress $sitepress
[35] Fix | Delete
* @param WPML_Third_Party_Dependencies $third_party_dependencies
[36] Fix | Delete
* @param WPML_Requirements_Notification $requirements_notification
[37] Fix | Delete
* @param array $integrations
[38] Fix | Delete
*/
[39] Fix | Delete
public function __construct(
[40] Fix | Delete
SitePress $sitepress,
[41] Fix | Delete
WPML_Third_Party_Dependencies $third_party_dependencies = null,
[42] Fix | Delete
WPML_Requirements_Notification $requirements_notification = null,
[43] Fix | Delete
$integrations = null
[44] Fix | Delete
) {
[45] Fix | Delete
$this->sitepress = $sitepress;
[46] Fix | Delete
$this->third_party_dependencies = $third_party_dependencies;
[47] Fix | Delete
$this->requirements_notification = $requirements_notification;
[48] Fix | Delete
$this->tm_settings = $this->sitepress->get_setting( 'translation-management' );
[49] Fix | Delete
$this->integrations = $this->get_integrations();
[50] Fix | Delete
[51] Fix | Delete
if ( $integrations ) {
[52] Fix | Delete
$this->integrations = $integrations;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
public function init_hooks() {
[58] Fix | Delete
if ( $this->sitepress->get_setting( 'setup_complete' ) ) {
[59] Fix | Delete
add_action( 'admin_init', array( $this, 'init' ) );
[60] Fix | Delete
add_action( 'wp_ajax_wpml_set_translation_editor', array( $this, 'set_translation_editor_callback' ) );
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
public function init() {
[65] Fix | Delete
if ( $this->sitepress->get_wp_api()->is_back_end() ) {
[66] Fix | Delete
$this->update_issues();
[67] Fix | Delete
$this->update_notices();
[68] Fix | Delete
[69] Fix | Delete
if ( $this->core_issues || $this->issues ) {
[70] Fix | Delete
$requirements_scripts = $this->get_requirements_scripts();
[71] Fix | Delete
$requirements_scripts->add_plugins_activation_hook();
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
private function update_notices() {
[77] Fix | Delete
$wpml_admin_notices = wpml_get_admin_notices();
[78] Fix | Delete
[79] Fix | Delete
if ( ! $this->core_issues ) {
[80] Fix | Delete
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::CORE_REQ_NOTICE_ID );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( ! $this->issues ) {
[84] Fix | Delete
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::MISSING_REQ_NOTICE_ID );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
if ( ! $this->should_create_editor_notice ) {
[88] Fix | Delete
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::EDITOR_NOTICE_ID );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( $this->core_issues || $this->issues || $this->should_create_editor_notice ) {
[92] Fix | Delete
[93] Fix | Delete
$notice_model = $this->get_notice_model();
[94] Fix | Delete
$wp_api = $this->sitepress->get_wp_api();
[95] Fix | Delete
[96] Fix | Delete
$this->add_core_requirements_notice( $notice_model, $wpml_admin_notices, $wp_api );
[97] Fix | Delete
$this->add_requirements_notice( $notice_model, $wpml_admin_notices, $wp_api );
[98] Fix | Delete
$this->add_tm_editor_notice( $notice_model, $wpml_admin_notices, $wp_api );
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
private function update_issues() {
[104] Fix | Delete
$this->core_issues = $this->get_third_party_dependencies()->get_issues( WPML_Integrations::SCOPE_WP_CORE );
[105] Fix | Delete
$this->issues = $this->get_third_party_dependencies()->get_issues();
[106] Fix | Delete
$this->update_should_create_editor_notice();
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
private function update_should_create_editor_notice() {
[110] Fix | Delete
$editor_translation_set =
[111] Fix | Delete
isset( $this->tm_settings['doc_translation_method'] ) &&
[112] Fix | Delete
in_array( (string) $this->tm_settings['doc_translation_method'], array(
[113] Fix | Delete
(string) ICL_TM_TMETHOD_EDITOR,
[114] Fix | Delete
(string) ICL_TM_TMETHOD_ATE
[115] Fix | Delete
), true );
[116] Fix | Delete
$requires_tm_editor = false;
[117] Fix | Delete
[118] Fix | Delete
foreach ( $this->integrations as $integration_item ) {
[119] Fix | Delete
if ( in_array( 'wpml-translation-editor', $integration_item['notices-display'], true ) ) {
[120] Fix | Delete
$requires_tm_editor = true;
[121] Fix | Delete
break;
[122] Fix | Delete
}
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
$this->should_create_editor_notice = ! $editor_translation_set && ! $this->issues && $requires_tm_editor;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
public function set_translation_editor_callback() {
[129] Fix | Delete
if ( ! $this->is_valid_request() ) {
[130] Fix | Delete
wp_send_json_error( __( 'This action is not allowed', 'sitepress' ) );
[131] Fix | Delete
} else {
[132] Fix | Delete
$wpml_admin_notices = wpml_get_admin_notices();
[133] Fix | Delete
[134] Fix | Delete
$this->tm_settings['doc_translation_method'] = 1;
[135] Fix | Delete
$this->sitepress->set_setting( 'translation-management', $this->tm_settings, true );
[136] Fix | Delete
$this->sitepress->set_setting( 'doc_translation_method', 1, true );
[137] Fix | Delete
[138] Fix | Delete
$wpml_admin_notices->remove_notice( self::NOTICE_GROUP, self::EDITOR_NOTICE_ID );
[139] Fix | Delete
[140] Fix | Delete
wp_send_json_success();
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
private function is_valid_request() {
[145] Fix | Delete
$valid_request = true;
[146] Fix | Delete
if ( ! array_key_exists( 'nonce', $_POST ) ) {
[147] Fix | Delete
$valid_request = false;
[148] Fix | Delete
}
[149] Fix | Delete
if ( $valid_request ) {
[150] Fix | Delete
$nonce = $_POST['nonce'];
[151] Fix | Delete
[152] Fix | Delete
$nonce_is_valid = wp_verify_nonce( $nonce, 'wpml_set_translation_editor' );
[153] Fix | Delete
if ( ! $nonce_is_valid ) {
[154] Fix | Delete
$valid_request = false;
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
return $valid_request;
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
private function get_integrations() {
[162] Fix | Delete
$integrations = new WPML_Integrations( $this->sitepress->get_wp_api() );
[163] Fix | Delete
[164] Fix | Delete
return $integrations->get_results();
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* @param $notice_type
[169] Fix | Delete
*
[170] Fix | Delete
* @return array
[171] Fix | Delete
*/
[172] Fix | Delete
private function get_integrations_names( $notice_type ) {
[173] Fix | Delete
$names = array();
[174] Fix | Delete
[175] Fix | Delete
foreach ( $this->integrations as $integration ) {
[176] Fix | Delete
if ( in_array( $notice_type, $integration['notices-display'], true ) &&
[177] Fix | Delete
! in_array( $integration['name'], $names, true ) ) {
[178] Fix | Delete
$names[] = $integration['name'];
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
return $names;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* @return WPML_Requirements_Notification
[187] Fix | Delete
*/
[188] Fix | Delete
private function get_notice_model() {
[189] Fix | Delete
if ( ! $this->requirements_notification ) {
[190] Fix | Delete
$template_paths = array(
[191] Fix | Delete
WPML_PLUGIN_PATH . '/templates/warnings/',
[192] Fix | Delete
);
[193] Fix | Delete
$twig_loader = new Twig_Loader_Filesystem( $template_paths );
[194] Fix | Delete
$environment_args = array();
[195] Fix | Delete
if ( WP_DEBUG ) {
[196] Fix | Delete
$environment_args['debug'] = true;
[197] Fix | Delete
}
[198] Fix | Delete
$twig = new Twig_Environment( $twig_loader, $environment_args );
[199] Fix | Delete
$twig_service = new WPML_Twig_Template( $twig );
[200] Fix | Delete
[201] Fix | Delete
$this->requirements_notification = new WPML_Requirements_Notification( $twig_service );
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
return $this->requirements_notification;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* @param WPML_Notice $notice
[209] Fix | Delete
*/
[210] Fix | Delete
private function add_actions_to_notice( WPML_Notice $notice ) {
[211] Fix | Delete
$dismiss_action = new WPML_Notice_Action( __( 'Dismiss', 'sitepress' ), '#', true, false, true, false );
[212] Fix | Delete
$notice->add_action( $dismiss_action );
[213] Fix | Delete
[214] Fix | Delete
if ( $this->has_issues( 'page-builders' ) ) {
[215] Fix | Delete
$document_action = new WPML_Notice_Action( __( 'Translating content created with page builders', 'sitepress' ), self::DOCUMENTATION_LINK );
[216] Fix | Delete
$notice->add_action( $document_action );
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
private function add_actions_to_core_notice( WPML_Notice $notice ) {
[221] Fix | Delete
$dismiss_action = new WPML_Notice_Action( __( 'Dismiss', 'sitepress' ), '#', true, false, true, false );
[222] Fix | Delete
$notice->add_action( $dismiss_action );
[223] Fix | Delete
[224] Fix | Delete
if ( $this->has_issues( WPML_Integrations::SCOPE_WP_CORE ) ) {
[225] Fix | Delete
$document_action = new WPML_Notice_Action( __( 'How to translate Block editor content', 'sitepress' ), self::DOCUMENTATION_LINK_BLOCK_EDITOR );
[226] Fix | Delete
$document_action->set_link_target( '_blank' );
[227] Fix | Delete
$notice->add_action( $document_action );
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* @param string $type
[233] Fix | Delete
*
[234] Fix | Delete
* @return bool
[235] Fix | Delete
*/
[236] Fix | Delete
private function has_issues( $type ) {
[237] Fix | Delete
$issues = WPML_Integrations::SCOPE_WP_CORE === $type
[238] Fix | Delete
? $this->core_issues : $this->issues;
[239] Fix | Delete
[240] Fix | Delete
if ( array_key_exists( 'causes', $issues ) ) {
[241] Fix | Delete
foreach ( (array) $issues['causes'] as $cause ) {
[242] Fix | Delete
if ( $type === $cause['type'] ) {
[243] Fix | Delete
return true;
[244] Fix | Delete
}
[245] Fix | Delete
}
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
return false;
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
/**
[252] Fix | Delete
* @param WPML_Notice $notice
[253] Fix | Delete
* @param WPML_WP_API $wp_api
[254] Fix | Delete
*/
[255] Fix | Delete
private function add_callbacks( WPML_Notice $notice, WPML_WP_API $wp_api ) {
[256] Fix | Delete
if ( method_exists( $notice, 'add_display_callback' ) ) {
[257] Fix | Delete
$notice->add_display_callback( array( $wp_api, 'is_core_page' ) );
[258] Fix | Delete
$notice->add_display_callback( array( $wp_api, 'is_plugins_page' ) );
[259] Fix | Delete
$notice->add_display_callback( array( $wp_api, 'is_themes_page' ) );
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* @param WPML_Requirements_Notification $notice_model
[265] Fix | Delete
* @param WPML_Notices $wpml_admin_notices
[266] Fix | Delete
* @param WPML_WP_API $wp_api
[267] Fix | Delete
*/
[268] Fix | Delete
private function add_core_requirements_notice( WPML_Requirements_Notification $notice_model, WPML_Notices $wpml_admin_notices, WPML_WP_API $wp_api ) {
[269] Fix | Delete
if ( $this->core_issues ) {
[270] Fix | Delete
$message = $notice_model->get_core_message( $this->core_issues );
[271] Fix | Delete
[272] Fix | Delete
$requirements_notice = new WPML_Notice( self::CORE_REQ_NOTICE_ID, $message, self::NOTICE_GROUP );
[273] Fix | Delete
[274] Fix | Delete
$this->add_actions_to_core_notice( $requirements_notice );
[275] Fix | Delete
$requirements_notice->set_css_class_types( 'warning' );
[276] Fix | Delete
$wpml_admin_notices->add_notice( $requirements_notice, true );
[277] Fix | Delete
}
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* @param WPML_Requirements_Notification $notice_model
[282] Fix | Delete
* @param WPML_Notices $wpml_admin_notices
[283] Fix | Delete
* @param WPML_WP_API $wp_api
[284] Fix | Delete
*/
[285] Fix | Delete
private function add_requirements_notice( WPML_Requirements_Notification $notice_model, WPML_Notices $wpml_admin_notices, WPML_WP_API $wp_api ) {
[286] Fix | Delete
if ( $this->issues ) {
[287] Fix | Delete
$message = $notice_model->get_message( $this->issues, 1 );
[288] Fix | Delete
[289] Fix | Delete
$requirements_notice = new WPML_Notice( self::MISSING_REQ_NOTICE_ID, $message, self::NOTICE_GROUP );
[290] Fix | Delete
[291] Fix | Delete
$this->add_actions_to_notice( $requirements_notice );
[292] Fix | Delete
$this->add_callbacks( $requirements_notice, $wp_api );
[293] Fix | Delete
$wpml_admin_notices->add_notice( $requirements_notice, true );
[294] Fix | Delete
}
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* @param WPML_Requirements_Notification $notice_model
[299] Fix | Delete
* @param WPML_Notices $wpml_admin_notices
[300] Fix | Delete
* @param WPML_WP_API $wp_api
[301] Fix | Delete
*/
[302] Fix | Delete
private function add_tm_editor_notice( WPML_Requirements_Notification $notice_model, WPML_Notices $wpml_admin_notices, WPML_WP_API $wp_api ) {
[303] Fix | Delete
if ( $this->should_create_editor_notice ) {
[304] Fix | Delete
$requirements_scripts = $this->get_requirements_scripts();
[305] Fix | Delete
$requirements_scripts->add_translation_editor_notice_hook();
[306] Fix | Delete
[307] Fix | Delete
$integrations_names = $this->get_integrations_names( 'wpml-translation-editor' );
[308] Fix | Delete
$text = $notice_model->get_settings( $integrations_names );
[309] Fix | Delete
$notice = new WPML_TM_Editor_Notice( self::EDITOR_NOTICE_ID, $text, self::NOTICE_GROUP );
[310] Fix | Delete
$notice->set_css_class_types( 'info' );
[311] Fix | Delete
[312] Fix | Delete
$enable_action = new WPML_Notice_Action( _x( 'Enable it now', 'Integration requirement notice title for translation editor: enable action', 'sitepress' ), '#', false, false, true );
[313] Fix | Delete
$enable_action->set_js_callback( 'js-set-translation-editor' );
[314] Fix | Delete
$notice->add_action( $enable_action );
[315] Fix | Delete
[316] Fix | Delete
$this->add_callbacks( $notice, $wp_api );
[317] Fix | Delete
$this->add_actions_to_notice( $notice );
[318] Fix | Delete
$wpml_admin_notices->add_notice( $notice );
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
/**
[323] Fix | Delete
* @return WPML_Integrations_Requirements_Scripts
[324] Fix | Delete
*/
[325] Fix | Delete
private function get_requirements_scripts() {
[326] Fix | Delete
if ( ! $this->requirements_scripts ) {
[327] Fix | Delete
return new WPML_Integrations_Requirements_Scripts();
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
return $this->requirements_scripts;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* @return WPML_Third_Party_Dependencies
[335] Fix | Delete
*/
[336] Fix | Delete
private function get_third_party_dependencies() {
[337] Fix | Delete
if ( ! $this->third_party_dependencies ) {
[338] Fix | Delete
$integrations = new WPML_Integrations( $this->sitepress->get_wp_api() );
[339] Fix | Delete
$requirements = new WPML_Requirements();
[340] Fix | Delete
$this->third_party_dependencies = new WPML_Third_Party_Dependencies( $integrations, $requirements );
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
return $this->third_party_dependencies;
[344] Fix | Delete
}
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function