PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.17
UiCore Elements – Free widgets and templates for Elementor v1.3.17
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
← All changes | includes/class-rest-api.php +79 -14 1.0.61.3.17 View file →
@@ -1,6 +1,8 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
4 +
3 5 use \Elementor\Plugin;
4 6 use UiCoreElements\Helper;
5 7 use UiCoreElements\Utils\Contact_Form_Service;
6 8
@@ -6,19 +8,22 @@
6 8
7 9 /**
8 10 * REST_API Handler
9 11 */
10 -class REST_API {
12 +class REST_API
13 +{
11 14
12 - public function __construct() {
15 + public function __construct()
16 + {
13 17 add_action('rest_api_init', [$this, 'register_routes']);
14 18 }
15 19
16 - public function register_routes(){
20 + public function register_routes()
21 + {
17 22 register_rest_route('uielem/v1', '/load_more/', [
18 23 'methods' => 'GET',
19 24 'show_in_index' => true,
20 - 'callback' => [$this, 'settings_update'],
25 + 'callback' => [$this, 'apg_load_more'],
21 26 'permission_callback' => '__return_true',
22 27 'args' => [
23 28 'widget_id' => [
24 29 'required' => true,
@@ -44,8 +49,19 @@
44 49 'methods' => 'POST',
45 50 'callback' => [$this, 'process_submission'],
46 51 'permission_callback' => '__return_true',
47 52 ]);
53 + register_rest_route('uielem/v1', '/prepare_template', [
54 + 'methods' => 'POST',
55 + 'callback' => [$this, 'prepare_template'],
56 + 'permission_callback' => [$this, 'check_for_permission'],
57 + ]);
58 +
59 + register_rest_route('uielem/v1', '/check_connection', [
60 + 'methods' => 'GET',
61 + 'callback' => [$this, 'check_connection'],
62 + 'permission_callback' => [$this, 'check_for_permission'],
63 + ]);
48 64 }
49 65
50 66 public function check_for_permission()
51 67 {
@@ -51,25 +67,46 @@
51 67 {
52 68 return current_user_can('manage_options');
53 69 }
54 70
55 - public function settings_update(\WP_REST_Request $request) {
71 + public function apg_load_more(\WP_REST_Request $request)
72 + {
73 + $current_query = false;
74 +
56 75 // Identify the widget
57 76 $widget_id = $request->get_param('widget_id');
58 77 $widget_type = $request->get_param('widget_type');
78 + $is_product = strpos($widget_type, 'product') !== false;
59 79
60 80 // Get widget settings
61 - $settings = get_transient('ui_elements_widgetdata_'.$widget_id);
81 + $settings = get_transient('ui_elements_widgetdata_' . $widget_id);
62 82
83 + // Check if is an "Advanced Product.." widget to determine the proper control slug
84 + $slug = $is_product ? 'product-filter' : 'posts-filter';
85 +
86 + // Set extra settings from request params
87 + $tax = $slug . '_' . $request->get_param('type') . '_ids';
88 + $settings[$tax] = $request->get_param('term');
63 89 $settings['__current_page'] = $request->get_param('page');
90 + $settings['__current_post_id'] = $request->get_param('current_post_id');
64 91
65 - $tax = 'posts-filter_' . $request->get_param('type') . '_ids';
66 - $settings[$tax] = $request->get_param('term');
92 + // Use load more qty (new option) if available
93 + if (isset($settings['load_more_qty']) && isset($settings['load_more_qty']['size']) && !empty($settings['load_more_qty']['size'])) {
94 + $settings['item_limit'] = $settings['load_more_qty'];
95 + }
67 96
97 + // Build current query if requested
98 + if ($settings[$slug . '_post_type'] == 'current') {
99 + $current_query = $request->get_param('current_query');
100 + $current_query = json_decode(urldecode($current_query), true); //decode url and transform to array
101 + $current_query['paged'] = $request->get_param('page');
102 + }
103 +
68 104 // Create the element data
69 105 $widget = [
70 106 'elType' => 'widget',
71 107 'widgetType' => $widget_type,
108 + 'id' => $widget_id,
72 109 ];
73 110
74 111 // Generate a new instance of the widget with those settings and return the markup
75 112 //$widget = new AdvancedPostGrid($widget, $settings); todo: discover why this method don't work
@@ -75,22 +112,23 @@
75 112 //$widget = new AdvancedPostGrid($widget, $settings); todo: discover why this method don't work
76 113 $widget = Plugin::instance()->elements_manager->create_element_instance($widget, $settings);
77 114 $widget->set_settings($settings);
78 115
79 - $markup = $widget->render_ajax();
116 + $data = $widget->render_ajax($current_query);
80 117
81 118 return [
82 - 'markup' => $markup,
83 - 'total_pages' => $widget->get_query()->max_num_pages,
119 + 'markup' => $data['markup'],
120 + 'total_pages' => $is_product ? $data['total_pages'] : $widget->get_query()->max_num_pages,
84 121 ];
85 122 }
86 123
87 - public function process_submission(\WP_REST_Request $request) {
124 + public function process_submission(\WP_REST_Request $request)
125 + {
88 126
89 127 // Get referer origin, form and widget data
90 128 $form_data = $request->get_params();
91 129 $files = $request->get_file_params();
92 - $settings = Helper::get_widget_settings($form_data['page_id'], $form_data['widget_id']);
130 + $settings = get_transient('ui_e_form_widget_settings_' . $form_data['widget_id']);
93 131
94 132 // Request the contact form service and return the response
95 133 $service = new Contact_Form_Service($form_data, $settings, $files);
96 134 $response = $service->handle();
@@ -95,5 +133,32 @@
95 133 $service = new Contact_Form_Service($form_data, $settings, $files);
96 134 $response = $service->handle();
97 135 return $response;
98 136 }
99 -}
137 +
138 +
139 + public function prepare_template(\WP_REST_Request $request)
140 + {
141 + $template = $request->get_param('data');
142 + $template = json_decode($template, true);
143 + $template = DesignCloud::import_content($template);
144 + return [
145 + 'success' => true,
146 + 'template' => $template,
147 + ];
148 + }
149 +
150 + public function check_connection()
151 + {
152 + $local_data = get_option('uicore_connect', [
153 + 'url' => '',
154 + 'token' => '',
155 + ]);
156 + return [
157 + 'success' => true,
158 + 'license' => [
159 + 'key' => $local_data['token'],
160 + 'url' => $local_data['url'],
161 + ],
162 + ];
163 + }
164 +}