Example #1
0
 /**
  * Method detect if we are in the preview mode (iFrame).
  *
  * @since 1.0.0
  * @return bool
  */
 public function is_preview_mode()
 {
     if (!User::is_current_user_can_edit()) {
         return false;
     }
     if (!isset($_GET['elementor-preview'])) {
         return false;
     }
     return true;
 }
Example #2
0
 public function is_edit_mode()
 {
     if (null !== $this->_is_edit_mode) {
         return $this->_is_edit_mode;
     }
     if (!User::is_current_user_can_edit()) {
         return false;
     }
     if (isset($_GET['elementor'])) {
         return true;
     }
     // Ajax request as Editor mode
     $actions = ['elementor_render_widget', 'elementor_get_templates', 'elementor_save_template', 'elementor_get_template', 'elementor_delete_template', 'elementor_export_template', 'elementor_import_template'];
     if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], $actions)) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Add edit link in outside edit post.
  *
  * @since 1.0.0
  * @param $actions
  * @param $post
  *
  * @return array
  */
 public function add_edit_in_dashboard($actions, $post)
 {
     if (User::is_current_user_can_edit($post->ID) && 'builder' === Plugin::instance()->db->get_edit_mode($post->ID)) {
         $actions['edit_with_elementor'] = sprintf('<a href="%s">%s</a>', Utils::get_edit_link($post->ID), __('Edit with Elementor', 'elementor'));
     }
     return $actions;
 }
Example #4
0
 public function ajax_render_widget()
 {
     if (empty($_POST['_nonce']) || !wp_verify_nonce($_POST['_nonce'], 'elementor-editing')) {
         wp_send_json_error(new \WP_Error('token_expired'));
     }
     if (empty($_POST['post_id'])) {
         wp_send_json_error(new \WP_Error('no_post_id', 'No post_id'));
     }
     if (!User::is_current_user_can_edit($_POST['post_id'])) {
         wp_send_json_error(new \WP_Error('no_access'));
     }
     // Override the global $post for the render
     $GLOBALS['post'] = get_post((int) $_POST['post_id']);
     $data = json_decode(stripslashes(html_entity_decode($_POST['data'])), true);
     // Start buffering
     ob_start();
     /** @var Widget_Base|Widget_WordPress $widget_type */
     $widget_type = $this->get_widget_types($data['widgetType']);
     $widget_class = $widget_type->get_class_name();
     /** @var Widget_Base $widget */
     $widget = new $widget_class($data, $widget_type->get_default_args());
     $widget->render_content();
     $render_html = ob_get_clean();
     wp_send_json_success(['render' => $render_html]);
 }
Example #5
0
 function add_menu_in_admin_bar(\WP_Admin_Bar $wp_admin_bar)
 {
     $post_id = get_the_ID();
     $is_not_builder_mode = !is_singular() || !User::is_current_user_can_edit($post_id) || 'builder' !== Plugin::instance()->db->get_edit_mode($post_id);
     if ($is_not_builder_mode) {
         return;
     }
     $wp_admin_bar->add_node(['id' => 'elementor_edit_page', 'title' => __('Edit with Elementor', 'elementor'), 'href' => Utils::get_edit_link($post_id)]);
 }