Example #1
0
 /**
  * @param array $data a set of elements
  * @param string $method (on_export|on_import)
  *
  * @return mixed
  */
 protected function process_export_import_data($data, $method)
 {
     return Plugin::instance()->db->iterate_data($data, function ($element) use($method) {
         if ('widget' === $element['elType']) {
             $element_class = Plugin::instance()->widgets_manager->get_widget_types($element['widgetType']);
         } else {
             $element_class = Plugin::instance()->elements_manager->get_element_types($element['elType']);
         }
         // If the widget/element isn't exist, like a plugin that creates a widget but deactivated
         if (!$element_class) {
             return $element;
         }
         if (method_exists($element_class, $method)) {
             $element = $element_class->{$method}($element);
         }
         foreach ($element_class->get_controls() as $control) {
             $control_class = Plugin::instance()->controls_manager->get_control($control['type']);
             // If the control isn't exist, like a plugin that creates the control but deactivated
             if (!$control_class) {
                 return $element;
             }
             if (method_exists($control_class, $method)) {
                 $element['settings'][$control['name']] = $control_class->{$method}($element['settings'][$control['name']]);
             }
         }
         return $element;
     });
 }
Example #2
0
 public function test_elementMethods()
 {
     foreach (\Elementor\Plugin::instance()->elements_manager->get_element_types() as $element) {
         $this->assertNotEmpty($element->get_title());
         $this->assertNotEmpty($element->get_type());
         $this->assertNotEmpty($element->get_name());
     }
 }
Example #3
0
 public function get_content($item_id, $context = 'display')
 {
     $db = Plugin::instance()->db;
     // TODO: Valid the data (in JS too!)
     if ('display' === $context) {
         $data = $db->get_builder($item_id);
     } else {
         $data = $db->get_plain_editor($item_id);
     }
     $data = $this->replace_elements_ids($data);
     return $data;
 }
Example #4
0
 public function test_getDefaultValue()
 {
     // Text Control
     $text_control = Elementor\Plugin::instance()->controls_manager->get_control(\Elementor\Controls_Manager::TEXT);
     $control_option = ['name' => 'key', 'default' => 'value'];
     $this->assertEquals('value', $text_control->get_value($control_option, []));
     // URL Control
     $url_control = Elementor\Plugin::instance()->controls_manager->get_control(\Elementor\Controls_Manager::URL);
     $control_option = ['name' => 'key', 'default' => ['url' => 'THE_LINK']];
     $this->assertEquals(['url' => 'THE_LINK', 'is_external' => ''], $url_control->get_value($control_option, ['key' => ['is_external' => '']]));
     // Repeater Control
     $repeater_control = \Elementor\Plugin::instance()->controls_manager->get_control(\Elementor\Controls_Manager::REPEATER);
     $control_option = ['name' => 'key', 'default' => [[]], 'fields' => [['name' => 'one', 'type' => \Elementor\Controls_Manager::TEXT, 'default' => 'value']]];
     $expected = [['one' => 'value']];
     $this->assertEquals($expected, $repeater_control->get_value($control_option, [[]]));
 }
Example #5
0
 /**
  * @expectedIncorrectUsage __wakeup
  */
 public function test_Wakeup()
 {
     unserialize(serialize(\Elementor\Plugin::instance()));
 }
Example #6
0
 public function get_template_content(array $args)
 {
     $validate_args = $this->ensure_args(['source', 'template_id'], $args);
     if (is_wp_error($validate_args)) {
         return $validate_args;
     }
     if (isset($args['edit_mode'])) {
         Plugin::instance()->editor->set_edit_mode($args['edit_mode']);
     }
     $source = $this->get_source($args['source']);
     if (!$source) {
         return new \WP_Error('template_error', 'Template source not found.');
     }
     return $source->get_content($args['template_id']);
 }