PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.3
UiCore Elements – Free widgets and templates for Elementor v1.0.3
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
uicore-elements / includes / class-rest-api.php

class-rest-api.php in UiCore Elements – Free widgets and templates for Elementor 1.0.3, at includes/class-rest-api.php

79 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3 use \Elementor\Plugin;
4
5 /**
6 * REST_API Handler
7 */
8 class REST_API {
9
10 public function __construct() {
11 add_action('rest_api_init', [$this, 'register_routes']);
12 }
13
14 public function register_routes(){
15 register_rest_route('uielem/v1', '/load_more/', [
16 'methods' => 'GET',
17 'show_in_index' => true,
18 'callback' => [$this, 'settings_update'],
19 'permission_callback' => '__return_true',
20 'args' => [
21 'widget_id' => [
22 'required' => true,
23 ],
24 'widget_type' => [
25 'required' => true,
26 ],
27 'page' => [
28 'required' => false,
29 'default' => 1,
30 ],
31 'type' => [
32 'required' => false,
33 'default' => '',
34 ],
35 'term' => [
36 'required' => false,
37 'default' => '',
38 ],
39 ],
40 ]);
41 }
42
43 public function check_for_permission()
44 {
45 return current_user_can('manage_options');
46 }
47
48 public function settings_update(\WP_REST_Request $request) {
49 // Identify the widget
50 $widget_id = $request->get_param('widget_id');
51 $widget_type = $request->get_param('widget_type');
52
53 // Get widget settings
54 $settings = get_transient('ui_elements_widgetdata_'.$widget_id);
55
56 $settings['__current_page'] = $request->get_param('page');
57
58 $tax = 'posts-filter_' . $request->get_param('type') . '_ids'; // todo: remove hard coded posts-filter_ and get the value set on widget
59 $settings[$tax] = $request->get_param('term');
60
61 // Create the element data
62 $widget = [
63 'elType' => 'widget',
64 'widgetType' => $widget_type,
65 ];
66
67 // Generate a new instance of the widget with those settings and return the markup
68 //$widget = new AdvancedPostGrid($widget, $settings); todo: discover why this method don't work
69 $widget = Plugin::instance()->elements_manager->create_element_instance($widget, $settings);
70 $widget->set_settings($settings);
71
72 $markup = $widget->render_ajax();
73
74 return [
75 'markup' => $markup,
76 'total_pages' => $widget->get_query()->max_num_pages,
77 ];
78 }
79 }