PluginProbe
Elementor Website Builder – more than just a page builder / 3.11.2
Elementor Website Builder – more than just a page builder v3.11.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | core/documents-manager.php +21 -118 4.1.43.11.2 View file →
@@ -9,9 +9,9 @@
9 9 use Elementor\TemplateLibrary\Source_Local;
10 10 use Elementor\Utils;
11 11
12 12 if ( ! defined( 'ABSPATH' ) ) {
13 - exit; // Exit if accessed directly.
13 + exit; // Exit if accessed directly
14 14 }
15 15
16 16 /**
17 17 * Elementor documents manager.
@@ -87,9 +87,8 @@
87 87 add_filter( 'post_row_actions', [ $this, 'filter_post_row_actions' ], 11, 2 );
88 88 add_filter( 'page_row_actions', [ $this, 'filter_post_row_actions' ], 11, 2 );
89 89 add_filter( 'user_has_cap', [ $this, 'remove_user_edit_cap' ], 10, 3 );
90 90 add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );
91 - add_action( 'rest_api_init', [ $this, 'register_rest_routes' ] );
92 91 }
93 92
94 93 /**
95 94 * Register ajax actions.
@@ -136,18 +135,18 @@
136 135 *
137 136 * @since 2.0.0
138 137 * @access public
139 138 *
140 - * @param string $type Document type name.
141 - * @param string $class_name The name of the class that registers the document type.
142 - * Full name with the namespace.
139 + * @param string $type Document type name.
140 + * @param string $class The name of the class that registers the document type.
141 + * Full name with the namespace.
143 142 *
144 143 * @return Documents_Manager The updated document manager instance.
145 144 */
146 - public function register_document_type( $type, $class_name ) {
147 - $this->types[ $type ] = $class_name;
145 + public function register_document_type( $type, $class ) {
146 + $this->types[ $type ] = $class;
148 147
149 - $cpt = $class_name::get_property( 'cpt' );
148 + $cpt = $class::get_property( 'cpt' );
150 149
151 150 if ( $cpt ) {
152 151 foreach ( $cpt as $post_type ) {
153 152 $this->cpt[ $post_type ] = $type;
@@ -153,9 +152,9 @@
153 152 $this->cpt[ $post_type ] = $type;
154 153 }
155 154 }
156 155
157 - if ( $class_name::get_property( 'register_type' ) ) {
156 + if ( $class::get_property( 'register_type' ) ) {
158 157 Source_Local::add_template_type( $type );
159 158 }
160 159
161 160 return $this;
@@ -206,41 +205,8 @@
206 205 return $this->documents[ $post_id ];
207 206 }
208 207
209 208 /**
210 - * Retrieve a document after checking it exist and allowed to edit.
211 - *
212 - * @param string $id
213 - * @return Document
214 - * @throws \Exception If the document is not found or the current user is not allowed to edit it.
215 - * @since 3.13.0
216 - */
217 - public function get_with_permissions( $id ): Document {
218 - $document = $this->get( $id );
219 -
220 - if ( ! $document ) {
221 - throw new \Exception( 'Not found.' );
222 - }
223 -
224 - if ( ! $document->is_editable_by_current_user() ) {
225 - throw new \Exception( 'Access denied.' );
226 - }
227 -
228 - return $document;
229 - }
230 -
231 - /**
232 - * A `void` version for `get_with_permissions`.
233 - *
234 - * @param string $id
235 - * @return void
236 - * @throws \Exception If the document is not found or the current user is not allowed to edit it.
237 - */
238 - public function check_permissions( $id ) {
239 - $this->get_with_permissions( $id );
240 - }
241 -
242 - /**
243 209 * Get document or autosave.
244 210 *
245 211 * Retrieve either the document or the autosave.
246 212 *
@@ -273,13 +239,9 @@
273 239 *
274 240 * @return false|Document The document if it exist, False otherwise.
275 241 */
276 242 public function get_doc_for_frontend( $post_id ) {
277 - $preview_id = (int) Utils::get_super_global_value( $_GET, 'preview_id' );
278 - $is_preview = is_preview();
279 - $is_nonce_verify = wp_verify_nonce( Utils::get_super_global_value( $_GET, 'preview_nonce' ), 'post_preview_' . $preview_id );
280 -
281 - if ( ( $is_preview && $is_nonce_verify ) || Plugin::$instance->preview->is_preview_mode() ) {
243 + if ( is_preview() || Plugin::$instance->preview->is_preview_mode() ) {
282 244 $document = $this->get_doc_or_auto_save( $post_id, get_current_user_id() );
283 245 } else {
284 246 $document = $this->get( $post_id );
285 247 }
@@ -322,10 +284,10 @@
322 284 *
323 285 * @since 2.0.0
324 286 * @access public
325 287 *
326 - * @param array $args Optional. An array of key => value arguments to match against
327 - * the properties. Default is empty array.
288 + * @param array $args Optional. An array of key => value arguments to match against
289 + * the properties. Default is empty array.
328 290 * @param string $operator Optional. The logical operation to perform. 'or' means only one
329 291 * element from the array needs to match; 'and' means all elements
330 292 * must match; 'not' means no elements may match. Default 'and'.
331 293 *
@@ -478,9 +440,9 @@
478 440 * Filter Post Row Actions.
479 441 *
480 442 * Let the Document to filter the array of row action links on the Posts list table.
481 443 *
482 - * @param array $actions
444 + * @param array $actions
483 445 * @param \WP_Post $post
484 446 *
485 447 * @return array
486 448 */
@@ -501,9 +463,9 @@
501 463 *
502 464 * @since 2.0.0
503 465 * @access public
504 466 *
505 - * @param array $request Post ID.
467 + * @param $request Post ID.
506 468 *
507 469 * @throws \Exception If current user don't have permissions to edit the post or the post is not using Elementor.
508 470 *
509 471 * @return array The document data after saving.
@@ -546,16 +508,13 @@
546 508 ];
547 509
548 510 $document->save( $data );
549 511
550 - $post = $document->get_post();
551 - $main_post = $document->get_main_post();
552 -
553 512 // Refresh after save.
554 - $document = $this->get( $post->ID, false );
513 + $document = $this->get( $document->get_post()->ID, false );
555 514
556 515 $return_data = [
557 - 'status' => $post->post_status,
516 + 'status' => $document->get_post()->post_status,
558 517 'config' => [
559 518 'document' => [
560 519 'last_edited' => $document->get_last_edited(),
561 520 'urls' => [
@@ -564,17 +523,8 @@
564 523 ],
565 524 ],
566 525 ];
567 526
568 - $post_status_object = get_post_status_object( $main_post->post_status );
569 -
570 - if ( $post_status_object ) {
571 - $return_data['config']['document']['status'] = [
572 - 'value' => $post_status_object->name,
573 - 'label' => $post_status_object->label,
574 - ];
575 - }
576 -
577 527 /**
578 528 * Returned documents ajax saved data.
579 529 *
580 530 * Filters the ajax data returned when saving the post on the builder.
@@ -593,18 +543,17 @@
593 543 * Ajax discard changes.
594 544 *
595 545 * Load the document data from an autosave, deleting unsaved changes.
596 546 *
597 - * @param array $request
547 + * @since 2.0.0
548 + * @access public
598 549 *
550 + * @param $request
551 + *
599 552 * @return bool True if changes discarded, False otherwise.
600 - * @throws \Exception If current user don't have permissions to edit the post or the post is not using Elementor.
601 - *
602 - * @since 2.0.0
603 - * @access public
604 553 */
605 554 public function ajax_discard_changes( $request ) {
606 - $document = $this->get_with_permissions( $request['editor_post_id'] );
555 + $document = $this->get( $request['editor_post_id'] );
607 556
608 557 $autosave = $document->get_autosave();
609 558
610 559 if ( $autosave ) {
@@ -731,9 +680,9 @@
731 680 * Get create new post URL.
732 681 *
733 682 * Retrieve a custom URL for creating a new post/page using Elementor.
734 683 *
735 - * @param string $post_type Optional. Post type slug. Default is 'page'.
684 + * @param string $post_type Optional. Post type slug. Default is 'page'.
736 685 * @param string|null $template_type Optional. Query arg 'template_type'. Default is null.
737 686 *
738 687 * @return string A URL for creating new post using Elementor.
739 688 */
@@ -770,52 +719,6 @@
770 719 // Elementor installation on a site with existing content (which doesn't contain Elementor's meta).
771 720 $post_type = get_post_type( $post_id );
772 721
773 722 return $this->cpt[ $post_type ] ?? 'post';
774 - }
775 -
776 - public function register_rest_routes() {
777 - register_rest_route('elementor/v1/documents', '/(?P<id>\d+)/media/import', [
778 - 'methods' => \WP_REST_Server::CREATABLE,
779 - 'callback' => function( $request ) {
780 - $post_id = $request->get_param( 'id' );
781 -
782 - try {
783 - $document = $this->get_with_permissions( $post_id );
784 -
785 - $elements_data = $document->get_elements_data();
786 -
787 - $import_data = $document->get_import_data( [
788 - 'content' => $elements_data,
789 - ] );
790 -
791 - $document->save( [
792 - 'elements' => $import_data['content'],
793 - ] );
794 -
795 - return new \WP_REST_Response( [
796 - 'success' => true,
797 - 'document_saved' => true,
798 - ], 200 );
799 -
800 - } catch ( \Exception $e ) {
801 - return new \WP_Error(
802 - 'elementor_import_error',
803 - $e->getMessage(),
804 - [ 'status' => 500 ]
805 - );
806 - }
807 - },
808 - 'permission_callback' => function() {
809 - return current_user_can( 'manage_options' );
810 - },
811 - 'args' => [
812 - 'id' => [
813 - 'required' => true,
814 - 'validate_callback' => function( $param ) {
815 - return is_numeric( $param );
816 - },
817 - ],
818 - ],
819 - ]);
820 723 }
821 724 }