PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.6
JetFormBuilder — Dynamic Blocks Form Builder v3.1.6
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / admin / single-pages / base-page-updater.php
jetformbuilder / includes / admin / single-pages Last commit date
actions 2 years ago meta-boxes 2 years ago meta-containers 2 years ago base-page-updater.php 2 years ago base-single-page.php 2 years ago
base-page-updater.php
106 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin\Single_Pages;
5
6 use Jet_Form_Builder\Admin\Exceptions\Failed_Box_Update;
7 use Jet_Form_Builder\Admin\Pages\Pages_Manager;
8 use Jet_Form_Builder\Admin\Single_Pages\Meta_Boxes\Meta_Box_Update_Callback;
9 use Jet_Form_Builder\Db_Queries\Execution_Builder;
10 use Jet_Form_Builder\Exceptions\Repository_Exception;
11 use Jet_Form_Builder\Rest_Api\Rest_Api_Endpoint_Base;
12
13 // If this file is called directly, abort.
14 if ( ! defined( 'WPINC' ) ) {
15 die;
16 }
17
18 abstract class Base_Page_Updater extends Rest_Api_Endpoint_Base {
19
20 abstract public static function get_page_slug(): string;
21
22 public static function get_rest_base() {
23 return static::get_page_slug() . '/(?P<id>[\d]+)';
24 }
25
26 /**
27 * @param \WP_REST_Request $request
28 *
29 * @return mixed|\WP_REST_Response
30 */
31 public function get_resource( \WP_REST_Request $request ) {
32 return false;
33 }
34
35 /**
36 * @return mixed
37 */
38 public static function get_methods() {
39 return \WP_REST_Server::EDITABLE;
40 }
41
42 public function run_callback( \WP_REST_Request $request ) {
43 $box_resource = $this->get_resource( $request );
44
45 if ( $box_resource instanceof \WP_REST_Request ) {
46 return $box_resource;
47 }
48
49 Execution_Builder::instance()->transaction_start();
50
51 try {
52 $this->update_boxes( $request, $box_resource );
53 } catch ( Failed_Box_Update $exception ) {
54 Execution_Builder::instance()->transaction_rollback();
55
56 return new \WP_REST_Response(
57 array(
58 'message' => $exception->getMessage(),
59 'data' => $exception->get_additional(),
60 ),
61 503
62 );
63 }
64 Execution_Builder::instance()->transaction_commit();
65
66 return new \WP_REST_Response(
67 array(
68 'message' => __( 'Successfully updated!', 'jet-form-builder' ),
69 )
70 );
71 }
72
73 /**
74 * @param \WP_REST_Request $request
75 * @param $box_resource
76 *
77 * @throws Failed_Box_Update
78 */
79 protected function update_boxes( \WP_REST_Request $request, $box_resource ) {
80 $containers = $this->get_page()->get_prepared_containers();
81 $body = $request->get_json_params();
82 $boxes = $body['boxes'] ?? array();
83
84 foreach ( $containers as $container ) {
85 foreach ( $boxes as $scope => $state ) {
86 try {
87 $box = $container->get_box_by_scope( $scope );
88 } catch ( Repository_Exception $exception ) {
89 continue;
90 }
91 if ( ! ( $box instanceof Meta_Box_Update_Callback ) ) {
92 continue;
93 }
94 $box->on_update( $state, $request, $box_resource );
95 }
96 }
97 }
98
99 /**
100 * @return Base_Single_Page
101 */
102 public function get_page(): Base_Single_Page {
103 return Pages_Manager::instance()->single()->rep_get_item_or_die( static::get_page_slug() );
104 }
105 }
106