PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.7.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.7.0
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / ElementorController.php
the-post-grid / app / Controllers Last commit date
Admin 2 years ago Api 2 years ago Blocks 2 years ago Hooks 2 years ago AjaxController.php 2 years ago BlocksController.php 2 years ago ElementorController.php 2 years ago GutenBergController.php 2 years ago MyAccountController.php 2 years ago PageTemplateController.php 2 years ago ScriptController.php 2 years ago ShortcodeController.php 2 years ago WidgetController.php 2 years ago
ElementorController.php
342 lines
1 <?php
2 /**
3 * Elementor Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers;
9
10 // Do not allow directly accessing this file.
11 use RT\ThePostGrid\Helpers\Fns;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 'This script cannot be accessed directly.' );
15 }
16
17 if ( ! class_exists( 'ElementorController' ) ) :
18 /**
19 * Elementor Controller class.
20 */
21 class ElementorController {
22 /**
23 * Category ID
24 *
25 * @var string
26 */
27 public $el_cat_id;
28
29 /**
30 * Version
31 *
32 * @var string
33 */
34 private $version;
35
36 /**
37 * Class constructor
38 */
39 public function __construct() {
40 $this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION;
41 $this->el_cat_id = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements';
42
43 if ( did_action( 'elementor/loaded' ) ) {
44 add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
45 add_action( 'elementor/elements/categories_registered', [ $this, 'widget_category' ] );
46 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'el_editor_script' ] );
47 add_action( 'wp_footer', [ $this, 'tpg_el_scripts' ] );
48 add_action( 'wp_enqueue_scripts', [ $this, 'tpg_el_style' ] );
49 add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] );
50 }
51 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'editor_el_enqueue' ] );
52 add_action( 'wp_ajax_rttpg_get_el_layouts', [ $this, 'rttpg_get_el_layouts' ] );
53 add_action( 'wp_ajax_rttpg_el_layout_count', [ $this, 'rttpg_el_layout_count' ] );
54 }
55
56 // TODO Import
57
58 public function editor_el_enqueue() {
59
60 //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
61 wp_enqueue_style(
62 'rttpg-elementor-edition',
63 rtTPG()->get_assets_uri( 'elementor/main.css' ) .
64 null,
65 $this->version
66 );
67
68 wp_enqueue_script(
69 'rttpg-elementor-import',
70 rtTPG()->get_assets_uri( 'elementor/main.js' ),
71 [
72 'wp-block-editor',
73 'wp-blocks',
74 'wp-i18n',
75 'wp-element',
76 'wp-hooks',
77 'wp-util',
78 'wp-components',
79 'elementor-editor',
80 'jquery',
81 ],
82 $this->version,
83 true
84 );
85
86 wp_localize_script(
87 'rttpg-elementor-import',
88 'rttpgParams',
89 [
90 'nonce' => wp_create_nonce( 'rttpg_nonce' ),
91 'hasPro' => rtTPG()->hasPro(),
92 'current_user_id' => get_current_user_id(),
93 'ajaxurl' => admin_url( 'admin-ajax.php' ),
94 'site_url' => site_url(),
95 'plugin_url' => RT_THE_POST_GRID_PLUGIN_URL,
96 'admin_url' => admin_url(),
97 'plugin_pro_url' => rtTPG()->getProPath(),
98 'post_type' => Fns::get_post_types(),
99 'all_term_list' => Fns::get_all_taxonomy_guten(),
100 ]
101 );
102 }
103
104 public function rttpg_el_layout_count() {
105
106 $BASE_URL = 'https://www.radiustheme.com/demo/plugins/the-post-grid-elementor/wp-json/rttpgapi/v1/layoutinfo/';
107 // Verify the request.
108 check_ajax_referer( 'rttpg_nonce', 'nonce' );
109
110 // It's good let's do some capability check.
111 $user = wp_get_current_user();
112 $allowed_roles = [ 'editor', 'administrator', 'author' ];
113
114 if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
115 wp_die( esc_html__( 'You don\'t have permission to perform this action', 'the-post-grid' ) );
116 }
117
118 // Cool, we're almost there, let's check the user authenticity a little bit, shall we!
119 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
120 wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'the-post-grid' ) );
121 }
122
123 $status = $_REQUEST['status'] ?? '';
124 $layout_id = $_REQUEST['layout_id'] ?? '';
125
126 $post_args = [ 'timeout' => 120 ];
127 $post_args['body'] = [
128 'status' => $status,
129 'layout_id' => $layout_id,
130 ];
131 $layoutRequest = wp_remote_post( $BASE_URL, $post_args );
132 if ( is_wp_error( $layoutRequest ) ) {
133 wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
134 }
135 $layoutData = json_decode( $layoutRequest['body'], true );
136
137 wp_send_json_success( $layoutData );
138 }
139
140
141 /**
142 * @return void
143 */
144 public function rttpg_get_el_layouts() {
145
146 $BASE_URL = 'https://www.radiustheme.com/demo/plugins/the-post-grid-elementor/wp-json/rttpgelapi/v1/layouts/';
147
148 // Verify the request.
149 check_ajax_referer( 'rttpg_nonce', 'nonce' );
150
151 // It's good let's do some capability check.
152 $user = wp_get_current_user();
153 $allowed_roles = [ 'editor', 'administrator', 'author' ];
154
155 if ( ! array_intersect( $allowed_roles, $user->roles ) ) {
156 wp_die( esc_html__( 'You don\'t have permission to perform this action', 'the-post-grid' ) );
157 }
158
159 // Cool, we're almost there, let's check the user authenticity a little bit, shall we!
160 if ( ! is_user_logged_in() && $user->ID !== sanitize_text_field( $_REQUEST['user_id'] ) ) {
161 wp_die( esc_html__( 'You don\'t have proper authorization to perform this action', 'the-post-grid' ) );
162 }
163
164 $status = isset( $_REQUEST['status'] ) ? $_REQUEST['status'] : '';
165 $post_args = [ 'timeout' => 120 ];
166 $post_args['body'] = [ 'status' => $status ];
167 $layoutRequest = wp_remote_post( $BASE_URL, $post_args );
168 if ( is_wp_error( $layoutRequest ) ) {
169 wp_send_json_error( [ 'messages' => $layoutRequest->get_error_messages() ] );
170 }
171 $layoutData = json_decode( $layoutRequest['body'], true );
172
173 wp_send_json_success( $layoutData );
174 }
175
176
177 /**
178 * Style
179 *
180 * @return void
181 */
182 public function tpg_el_style() {
183 // Custom CSS From Settings.
184 $css = isset( $settings['custom_css'] ) ? stripslashes( $settings['custom_css'] ) : null;
185 if ( $css ) {
186 wp_add_inline_style( 'rt-tpg-block', $css );
187 }
188 }
189
190 /**
191 * Scripts
192 *
193 * @return void
194 */
195 public function tpg_el_scripts() {
196 $ajaxurl = '';
197
198 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
199 $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
200 } else {
201 $ajaxurl .= admin_url( 'admin-ajax.php' );
202 }
203
204 $variables = [
205 'nonceID' => esc_attr( rtTPG()->nonceId() ),
206 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
207 'ajaxurl' => esc_url( $ajaxurl ),
208 'uid' => get_current_user_id(),
209 ];
210
211 wp_localize_script( 'rt-tpg', 'rttpg', $variables );
212 }
213
214 /**
215 * Editor Scripts
216 *
217 * @return void
218 */
219 public function el_editor_script() {
220 wp_enqueue_script( 'tgp-el-editor-scripts', rtTPG()->get_assets_uri( 'js/tpg-el-editor.js' ), [ 'jquery' ], $this->version, true );
221 wp_enqueue_style( 'tgp-el-editor-style', rtTPG()->get_assets_uri( 'css/admin/tpg-el-editor.css' ), [], $this->version );
222 }
223
224 /**
225 * Elementor widgets
226 *
227 * @param object $widgets_manager Manager.
228 *
229 * @return void
230 */
231 public function init_widgets( $widgets_manager ) {
232 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/base.php';
233 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/rtTPGElementorHelper.php';
234
235 // dir_name => class_name.
236 $widgets = [
237 'grid-layout' => '\TPGGridLayout',
238 'list-layout' => '\TPGListLayout',
239 'grid-hover-layout' => '\TPGGridHoverLayout',
240 'slider-layout' => '\TPGSliderLayout',
241 'category-block' => '\TPGCategoryBlock',
242 'section-title' => '\SectionTitle',
243 ];
244
245 if ( rtTPG()->hasPro() && defined( 'RT_THE_POST_GRID_PRO_PLUGIN_PATH' ) ) {
246 $proFileCheck = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/app/Widgets/elementor/category-block.php';
247 if ( file_exists( $proFileCheck ) ) {
248 unset( $widgets['category-block'] );
249 }
250 }
251
252 $widgets = apply_filters( 'tpg_el_widget_register', $widgets );
253
254 foreach ( $widgets as $file_name => $class ) {
255
256 if ( ! rtTPG()->hasPro() && in_array( $file_name, [ 'slider-layout', 'category-block' ] ) ) {
257 continue;
258 }
259
260 $template_name = 'the-post-grid/elementor/' . $file_name . '.php';
261
262 if ( file_exists( get_stylesheet_directory() . $template_name ) ) {
263 $file = get_stylesheet_directory() . $template_name;
264 } elseif ( file_exists( get_template_directory() . $template_name ) ) {
265 $file = get_template_directory() . $template_name;
266 } else {
267 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/widgets/' . $file_name . '.php';
268 }
269
270 require_once $file;
271
272 $widgets_manager->register( new $class() );
273 }
274 }
275
276 /**
277 * Widget category
278 *
279 * @param object $elements_manager Manager.
280 *
281 * @return void
282 */
283 public function widget_category( $elements_manager ) {
284 $categories['tpg-block-builder-widgets'] = [
285 'title' => esc_html__( 'TPG Template Builder Element', 'the-post-grid' ),
286 'icon' => 'fa fa-plug',
287 ];
288
289 $categories[ RT_THE_POST_GRID_PLUGIN_SLUG . '-elements' ] = [
290 'title' => esc_html__( 'The Post Grid', 'the-post-grid' ),
291 'icon' => 'fa fa-plug',
292 ];
293
294 $get_all_categories = $elements_manager->get_categories();
295 $categories = array_merge( $categories, $get_all_categories );
296 $set_categories = function ( $categories ) {
297 $this->categories = $categories;
298 };
299
300 $set_categories->call( $elements_manager, $categories );
301 }
302
303 /**
304 * Promotion
305 *
306 * @param array $config Config.
307 *
308 * @return array
309 */
310 public function promotePremiumWidgets( $config ) {
311 if ( rtTPG()->hasPro() ) {
312 return $config;
313 }
314
315 if ( ! isset( $config['promotionWidgets'] ) || ! is_array( $config['promotionWidgets'] ) ) {
316 $config['promotionWidgets'] = [];
317 }
318
319 $pro_widgets = [
320 [
321 'name' => 'tpg-slider-layout',
322 'title' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
323 'description' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
324 'icon' => 'eicon-post-slider tpg-grid-icon tss-promotional-element',
325 'categories' => '[ "the-post-grid-elements" ]',
326 ],
327 [
328 'name' => 'tpg-category-block',
329 'title' => esc_html__( 'TPG - Category Block', 'the-post-grid' ),
330 'description' => esc_html__( 'TPG - Category Block', 'the-post-grid' ),
331 'icon' => 'eicon-folder-o tpg-grid-icon tss-promotional-element',
332 'categories' => '[ "the-post-grid-elements" ]',
333 ],
334 ];
335
336 $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $pro_widgets );
337
338 return $config;
339 }
340 }
341 endif;
342