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.../compatib.../divi
File: class-wpml-compatibility-divi.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class WPML_Compatibility_Divi implements \IWPML_DIC_Action, \IWPML_Backend_Action, \IWPML_Frontend_Action {
[2] Fix | Delete
[3] Fix | Delete
const REGEX_REMOVE_OPENING_PARAGRAPH = '/(<p>[\n\r]*)([\n\r]{1}\[\/et_)/m';
[4] Fix | Delete
const REGEX_REMOVE_CLOSING_PARAGRAPH = '/(\[et_.*\][\n\r]{1})([\n\r]*<\/p>)/m';
[5] Fix | Delete
[6] Fix | Delete
/** @var SitePress */
[7] Fix | Delete
private $sitepress;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* @param SitePress $sitepress
[11] Fix | Delete
*/
[12] Fix | Delete
public function __construct( SitePress $sitepress ) {
[13] Fix | Delete
$this->sitepress = $sitepress;
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
public function add_hooks() {
[17] Fix | Delete
add_action( 'init', array( $this, 'load_resources_if_they_are_required' ), 10, 0 );
[18] Fix | Delete
[19] Fix | Delete
if ( $this->sitepress->is_setup_complete() ) {
[20] Fix | Delete
add_action( 'admin_init', array( $this, 'display_warning_notice' ), 10, 0 );
[21] Fix | Delete
add_filter( 'wpml_pb_should_handle_content', array( $this, 'should_handle_shortcode_content' ), 10, 2 );
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
add_filter( 'wpml_pb_shortcode_content_for_translation', array( $this, 'cleanup_global_layout_content' ), 10, 2 );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* @return bool
[29] Fix | Delete
*/
[30] Fix | Delete
private function is_standard_editor_used() {
[31] Fix | Delete
$tm_settings = $this->sitepress->get_setting( 'translation-management', array() );
[32] Fix | Delete
[33] Fix | Delete
return ! isset( $tm_settings['doc_translation_method'] ) ||
[34] Fix | Delete
ICL_TM_TMETHOD_MANUAL === $tm_settings['doc_translation_method'];
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public function display_warning_notice() {
[38] Fix | Delete
$notices = wpml_get_admin_notices();
[39] Fix | Delete
[40] Fix | Delete
if ( $this->is_standard_editor_used() ) {
[41] Fix | Delete
$notices->add_notice( new WPML_Compatibility_Divi_Notice() );
[42] Fix | Delete
} elseif ( $notices->get_notice( WPML_Compatibility_Divi_Notice::ID, WPML_Compatibility_Divi_Notice::GROUP ) ) {
[43] Fix | Delete
$notices->remove_notice( WPML_Compatibility_Divi_Notice::GROUP, WPML_Compatibility_Divi_Notice::ID );
[44] Fix | Delete
}
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
public function load_resources_if_they_are_required() {
[48] Fix | Delete
if ( ! isset( $_GET['page'] ) || ! is_admin() ) { /* phpcs:disable */
[49] Fix | Delete
return;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
$pages = array( self::get_duplication_action_page() );
[53] Fix | Delete
if ( self::is_tm_active() ) {
[54] Fix | Delete
$pages[] = self::get_translation_dashboard_page();
[55] Fix | Delete
$pages[] = self::get_translation_editor_page();
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
if ( in_array( $_GET['page'], $pages, true ) ) { /* phpcs:disable */
[59] Fix | Delete
$this->register_layouts();
[60] Fix | Delete
}
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
private static function get_translation_dashboard_page() {
[64] Fix | Delete
return constant( 'WPML_TM_FOLDER' ) . '/menu/main.php';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
private static function get_translation_editor_page() {
[68] Fix | Delete
return constant( 'WPML_TM_FOLDER' ) . '/menu/translations-queue.php';
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
private static function get_duplication_action_page() {
[72] Fix | Delete
return constant( 'WPML_PLUGIN_FOLDER' ) . '/menu/languages.php';
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
private static function is_tm_active() {
[76] Fix | Delete
return defined( 'WPML_TM_FOLDER' );
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
private function register_layouts() {
[80] Fix | Delete
if ( function_exists( 'et_builder_should_load_framework' ) && ! et_builder_should_load_framework() ) {
[81] Fix | Delete
if ( function_exists( 'et_builder_register_layouts' ) ) {
[82] Fix | Delete
et_builder_register_layouts();
[83] Fix | Delete
} else {
[84] Fix | Delete
$lib_file = ET_BUILDER_DIR . 'feature/Library.php';
[85] Fix | Delete
[86] Fix | Delete
if ( ! class_exists( 'ET_Builder_Library' )
[87] Fix | Delete
&& defined( 'ET_BUILDER_DIR' )
[88] Fix | Delete
&& file_exists( $lib_file )
[89] Fix | Delete
) {
[90] Fix | Delete
require_once $lib_file;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
if ( class_exists( 'ET_Builder_Library' ) ) {
[94] Fix | Delete
ET_Builder_Library::instance();
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* The global layout is not properly extracted from the page
[102] Fix | Delete
* because it adds <p> tags either not opened or not closed.
[103] Fix | Delete
*
[104] Fix | Delete
* See the global content below as an example:
[105] Fix | Delete
*
[106] Fix | Delete
* [et_pb_section prev_background_color="#000000" next_background_color="#000000"][et_pb_text]
[107] Fix | Delete
*
[108] Fix | Delete
* </p>
[109] Fix | Delete
* <p>Global text 1 EN5</p>
[110] Fix | Delete
* <p>
[111] Fix | Delete
*
[112] Fix | Delete
* [/et_pb_text][/et_pb_section]
[113] Fix | Delete
*
[114] Fix | Delete
* We also need to remove `prev_background` and `next_background` attributes which are added from the page.
[115] Fix | Delete
*
[116] Fix | Delete
* @param string $content
[117] Fix | Delete
* @param int $post_id
[118] Fix | Delete
*/
[119] Fix | Delete
public function cleanup_global_layout_content( $content, $post_id ) {
[120] Fix | Delete
if ( 'et_pb_layout' === get_post_type( $post_id ) ) {
[121] Fix | Delete
$content = preg_replace( self::REGEX_REMOVE_OPENING_PARAGRAPH, '$2', $content );
[122] Fix | Delete
$content = preg_replace( self::REGEX_REMOVE_CLOSING_PARAGRAPH, '$1', $content );
[123] Fix | Delete
$content = preg_replace( '/( prev_background_color="#[0-9a-f]*")/', '', $content );
[124] Fix | Delete
$content = preg_replace( '/( next_background_color="#[0-9a-f]*")/', '', $content );
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
return $content;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
public function should_handle_shortcode_content( $handle_content, $shortcode ) {
[131] Fix | Delete
if (
[132] Fix | Delete
strpos( $shortcode['tag'], 'et_' ) === 0 &&
[133] Fix | Delete
strpos( $shortcode['attributes'], 'global_module=' ) !== false
[134] Fix | Delete
) {
[135] Fix | Delete
// If a translatable attribute has been excluded from sync, we need to handle it.
[136] Fix | Delete
$handle_content = $this->is_excluded_from_sync( $shortcode );
[137] Fix | Delete
}
[138] Fix | Delete
return $handle_content;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Check if a global module has excluded any translatable text that we need to handle
[143] Fix | Delete
*
[144] Fix | Delete
* @param array $shortcode {
[145] Fix | Delete
* @type string $tag.
[146] Fix | Delete
* @type string $content.
[147] Fix | Delete
* @type string $attributes.
[148] Fix | Delete
* }
[149] Fix | Delete
* @return bool
[150] Fix | Delete
*/
[151] Fix | Delete
private function is_excluded_from_sync( $shortcode ) {
[152] Fix | Delete
$handle_content = false;
[153] Fix | Delete
[154] Fix | Delete
preg_match( '/global_module="([0-9]+)"/', $shortcode['attributes'], $matches );
[155] Fix | Delete
$excluded = json_decode( get_post_meta( $matches[1], '_et_pb_excluded_global_options', true ), true );
[156] Fix | Delete
[157] Fix | Delete
if ( is_array( $excluded ) && sizeof( $excluded ) > 0 ) {
[158] Fix | Delete
$attributes = $this->get_translatable_shortcode_attributes( $shortcode['tag'] );
[159] Fix | Delete
[160] Fix | Delete
foreach ( $excluded as $field ) {
[161] Fix | Delete
if ( in_array( $field, $attributes, true ) ) {
[162] Fix | Delete
$handle_content = true;
[163] Fix | Delete
break;
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return $handle_content;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Get a list of translatable attributes for a shortcode tag.
[173] Fix | Delete
* This includes the inner content and any attributes found in XML configuration.
[174] Fix | Delete
*
[175] Fix | Delete
* @param string $tag The shortcode tag.
[176] Fix | Delete
* @return array
[177] Fix | Delete
*/
[178] Fix | Delete
private function get_translatable_shortcode_attributes( $tag ) {
[179] Fix | Delete
$attributes = [ 'et_pb_content_field' ];
[180] Fix | Delete
$settings = get_option( 'icl_st_settings', [] );
[181] Fix | Delete
[182] Fix | Delete
if ( ! isset( $settings['pb_shortcode'] ) ) {
[183] Fix | Delete
return $attributes;
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
foreach ( $settings['pb_shortcode'] as $setting ) {
[187] Fix | Delete
if ( $tag === $setting['tag']['value'] ) {
[188] Fix | Delete
foreach ( $setting['attributes'] as $attribute ) {
[189] Fix | Delete
if ( empty( $attribute['type'] ) ) {
[190] Fix | Delete
$attributes[] = $attribute['value'];
[191] Fix | Delete
}
[192] Fix | Delete
}
[193] Fix | Delete
break;
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
return $attributes;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function