This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Integration for Elementor plugin. (#134)
Add Integration for Elementor plugin.
- Loading branch information
Showing
3 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"post_fields": { | ||
"_elementor_data": {}, | ||
"_elementor_css": {}, | ||
"_elementor_controls_usage": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
<?php | ||
/** | ||
* Class for capability with Elementor | ||
*/ | ||
|
||
namespace WPM\Includes\Integrations; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* @class WPM_Elementor | ||
* @package WPM/Includes/Integrations | ||
* @category Integrations | ||
* @author Auban le Grelle | ||
*/ | ||
class WPM_Elementor { | ||
|
||
const ELEMENTOR_DATA_META_KEY = '_elementor_data'; | ||
const ELEMENTOR_CSS_META_KEY = '_elementor_css'; | ||
const ELEMENTOR_CONTROLS_META_KEY = '_elementor_controls_usage'; | ||
|
||
private $object_id = 0; | ||
|
||
/** | ||
* WPM_Elementor constructor. | ||
*/ | ||
public function __construct() { | ||
|
||
$meta_keys = array( | ||
self::ELEMENTOR_DATA_META_KEY => array( | ||
'set_data_value', | ||
'get_data_value' | ||
), | ||
self::ELEMENTOR_CSS_META_KEY => array( | ||
'set_css_value', | ||
'get_css_value' | ||
), | ||
self::ELEMENTOR_CONTROLS_META_KEY => array( | ||
'set_controls_value', | ||
'get_controls_value' | ||
), | ||
); | ||
|
||
//Install meta Filters | ||
foreach ($meta_keys as $meta_key => $callbacks) { | ||
|
||
add_filter( "wpm_{$meta_key}_meta_config", array($this, 'config'), 10, 3 ); | ||
add_filter( "wpm_add_{$meta_key}_meta_value", array($this, $callbacks[0]), 10, 1 ); | ||
add_filter( "wpm_update_{$meta_key}_meta_value", array($this, $callbacks[0]), 10, 1 ); | ||
add_filter( "wpm_get_{$meta_key}_meta_value", array($this, $callbacks[1]), 10, 1 ); | ||
} | ||
|
||
add_filter( 'elementor/files/file_name', array($this, 'format_css_filename'), 10, 2); | ||
} | ||
|
||
/** | ||
* Set meta translate in base64 | ||
* | ||
* @param $key | ||
* @param $value | ||
* @return mixed | ||
*/ | ||
private function set_value($key, $value) { | ||
|
||
if (!$this->object_id) { | ||
return $value; | ||
} | ||
|
||
$current_value = get_post_meta($this->object_id, "{$key}_translate", true); | ||
|
||
update_post_meta($this->object_id, "{$key}_translate", wpm_set_new_value($current_value, base64_encode($value))); | ||
|
||
$this->object_id = 0; | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* Get meta translate from base64 | ||
* | ||
* @param $key | ||
* @param $value | ||
* @return false|string | ||
*/ | ||
private function get_value($key, $value) { | ||
|
||
if (!$this->object_id) { | ||
return $value; | ||
} | ||
|
||
$tr_value = base64_decode(wpm_translate_value(get_post_meta($this->object_id, "{$key}_translate", true)), true); | ||
|
||
$this->object_id = 0; | ||
|
||
return ($tr_value === false ? $value : $tr_value); | ||
} | ||
|
||
/** | ||
* Config meta keys | ||
* | ||
* @param $config | ||
* @param $meta_value | ||
* @param $object_id | ||
* @return mixed | ||
*/ | ||
public function config($config, $meta_value, $object_id) { | ||
|
||
$this->object_id = $object_id; | ||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* Set meta value data | ||
* | ||
* @param $value | ||
* @return mixed | ||
*/ | ||
public function set_data_value($value) { | ||
|
||
$key = self::ELEMENTOR_DATA_META_KEY; | ||
|
||
return $this->set_value($key, $value); | ||
} | ||
|
||
/** | ||
* Get meta value data | ||
* | ||
* @param $value | ||
* @return false|string | ||
*/ | ||
public function get_data_value($value) { | ||
|
||
$key = self::ELEMENTOR_DATA_META_KEY; | ||
|
||
return $this->get_value($key, $value); | ||
} | ||
|
||
/** | ||
* Set meta value css | ||
* | ||
* @param $value | ||
* @return mixed | ||
*/ | ||
public function set_css_value($value) { | ||
|
||
$key = self::ELEMENTOR_CSS_META_KEY; | ||
|
||
$this->set_value($key, maybe_serialize($value)); | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* Get meta value css | ||
* | ||
* @param $value | ||
* @return mixed | ||
*/ | ||
public function get_css_value($value) { | ||
|
||
$key = self::ELEMENTOR_CSS_META_KEY; | ||
|
||
return maybe_unserialize($this->get_value($key, $value)); | ||
} | ||
|
||
/** | ||
* Set meta value controls | ||
* | ||
* @param $value | ||
* @return mixed | ||
*/ | ||
public function set_controls_value($value) { | ||
|
||
$key = self::ELEMENTOR_CONTROLS_META_KEY; | ||
|
||
$this->set_value($key, maybe_serialize($value)); | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* Get meta value controls | ||
* | ||
* @param $value | ||
* @return mixed | ||
*/ | ||
public function get_controls_value($value) { | ||
|
||
$key = self::ELEMENTOR_CONTROLS_META_KEY; | ||
|
||
return maybe_unserialize($this->get_value($key, $value)); | ||
} | ||
|
||
/** | ||
* Format the css file name with the current language. | ||
* | ||
* @param $filename | ||
* @param $css | ||
* @return mixed | ||
*/ | ||
public function format_css_filename ($filename, $css) { | ||
|
||
$current_lang = wpm_get_language(); | ||
|
||
if (strpos($filename, 'post') === 0) { | ||
|
||
return str_replace('.css', "-{$current_lang}.css", $filename); | ||
} | ||
|
||
return $filename; | ||
} | ||
} |
12deec5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! I get an error.
Fatal error: Uncaught Error: Class 'WPM\Includes\Integrations\WPM_Elementor' not found in \wp-content\plugins\wp-multilang\includes\class-wpm-setup.php:541 Stack trace: #0
12deec5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DMax540 Hello!
Add this class to autoload
wp-content\plugins\wp-multilang\vendor\composer\autoload_classmap.php
'WPM\\Includes\\Widgets\\WPM_Widget_Language_Switcher' => $baseDir . '/includes/widgets/class-wpm-widget-language-switcher.php', 'WPM\\Includes\\Integrations\\WPM_Elementor' => $baseDir . '/includes/integrations/class-wpm-elementor.php',
wp-content\plugins\wp-multilang\vendor\composer\autoload_static.php
'WPM\\Includes\\Integrations\\WPM_Yoast_Seo' => __DIR__ . '/../..' . '/includes/integrations/class-wpm-yoast-seo.php', 'WPM\\Includes\\Integrations\\WPM_Elementor' => __DIR__ . '/../..' . '/includes/integrations/class-wpm-elementor.php',