Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Add Integration for Elementor plugin. (#134)
Browse files Browse the repository at this point in the history
Add Integration for Elementor plugin.
  • Loading branch information
VaLeXaR authored Dec 12, 2019
2 parents 709bdd5 + 978594e commit 12deec5
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 0 deletions.
7 changes: 7 additions & 0 deletions configs/plugins/elementor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"post_fields": {
"_elementor_data": {},
"_elementor_css": {},
"_elementor_controls_usage": {}
}
}
1 change: 1 addition & 0 deletions includes/class-wpm-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public function load_integrations() {
'woocommerce' => __NAMESPACE__ . '\Integrations\WPM_WooCommerce',
'wordpress-seo' => __NAMESPACE__ . '\Integrations\WPM_Yoast_Seo',
'seo-by-rank-math' => __NAMESPACE__ . '\Integrations\WPM_Rank_Math',
'elementor' => __NAMESPACE__ . '\Integrations\WPM_Elementor',
) );

$active_plugins = wp_cache_get( 'active_plugins', 'wpm' );
Expand Down
215 changes: 215 additions & 0 deletions includes/integrations/class-wpm-elementor.php
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;
}
}

2 comments on commit 12deec5

@DMax540
Copy link

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

@mefutu01
Copy link

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',

Please sign in to comment.