PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 5.0.3
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v5.0.3
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 3 years ago Api 3 years ago Blocks 3 years ago Hooks 3 years ago AjaxController.php 3 years ago BlocksController.php 3 years ago ElementorController.php 3 years ago GutenBergController.php 3 years ago PageTemplateController.php 3 years ago ScriptController.php 3 years ago ShortcodeController.php 3 years ago WidgetController.php 3 years ago
ElementorController.php
195 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 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 if ( ! class_exists( 'ElementorController' ) ) :
16 /**
17 * Elementor Controller class.
18 */
19 class ElementorController {
20 /**
21 * Category ID
22 *
23 * @var string
24 */
25 public $el_cat_id;
26
27 /**
28 * Version
29 *
30 * @var string
31 */
32 private $version;
33
34 /**
35 * Class constructor
36 */
37 public function __construct() {
38 $this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION;
39 $this->el_cat_id = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements';
40
41 if ( did_action( 'elementor/loaded' ) ) {
42 add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
43 add_action( 'elementor/elements/categories_registered', [ $this, 'widget_category' ] );
44 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'el_editor_script' ] );
45 add_action( 'wp_footer', [ $this, 'tpg_el_scripts' ] );
46 add_action( 'wp_enqueue_scripts', [ $this, 'tpg_el_style' ] );
47 add_filter( 'elementor/editor/localize_settings', [ $this, 'promotePremiumWidgets' ] );
48 }
49 }
50
51 /**
52 * Style
53 *
54 * @return void
55 */
56 public function tpg_el_style() {
57 // Custom CSS From Settings.
58 $css = isset( $settings['custom_css'] ) ? stripslashes( $settings['custom_css'] ) : null;
59 if ( $css ) {
60 wp_add_inline_style( 'rt-tpg-block', $css );
61 }
62 }
63
64 /**
65 * Scripts
66 *
67 * @return void
68 */
69 public function tpg_el_scripts() {
70 $ajaxurl = '';
71
72 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
73 $ajaxurl .= admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
74 } else {
75 $ajaxurl .= admin_url( 'admin-ajax.php' );
76 }
77
78 $variables = [
79 'nonceID' => esc_attr( rtTPG()->nonceId() ),
80 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
81 'ajaxurl' => esc_url( $ajaxurl ),
82 ];
83
84 wp_localize_script( 'rt-tpg', 'rttpg', $variables );
85 }
86
87 /**
88 * Editor Scripts
89 *
90 * @return void
91 */
92 public function el_editor_script() {
93 wp_enqueue_script( 'tgp-el-editor-scripts', rtTPG()->get_assets_uri( 'js/tpg-el-editor.js' ), [ 'jquery' ], $this->version, true );
94 wp_enqueue_style( 'tgp-el-editor-style', rtTPG()->get_assets_uri( 'css/admin/tpg-el-editor.css' ), [], $this->version );
95 }
96
97 /**
98 * Elementor widgets
99 *
100 * @param object $widgets_manager Manager.
101 * @return void
102 */
103 public function init_widgets( $widgets_manager ) {
104 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/base.php';
105 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/rtTPGElementorHelper.php';
106
107 // dir_name => class_name.
108 $widgets = [
109 'grid-layout' => '\TPGGridLayout',
110 'list-layout' => '\TPGListLayout',
111 'grid-hover-layout' => '\TPGGridHoverLayout',
112 'slider-layout' => '\TPGSliderLayout',
113 ];
114
115 $widgets = apply_filters( 'tpg_el_widget_register', $widgets );
116
117 foreach ( $widgets as $file_name => $class ) {
118 if ( ! rtTPG()->hasPro() && 'slider-layout' === $file_name ) {
119 continue;
120 }
121
122 $template_name = 'the-post-grid/elementor/' . $file_name . '.php';
123
124 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
125 $file = STYLESHEETPATH . $template_name;
126 } elseif ( file_exists( TEMPLATEPATH . $template_name ) ) {
127 $file = TEMPLATEPATH . $template_name;
128 } else {
129 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/widgets/' . $file_name . '.php';
130 }
131
132 require_once $file;
133
134 $widgets_manager->register( new $class() );
135 }
136 }
137
138 /**
139 * Widget category
140 *
141 * @param object $elements_manager Manager.
142 * @return void
143 */
144 public function widget_category( $elements_manager ) {
145 $categories['tpg-block-builder-widgets'] = [
146 'title' => esc_html__( 'TPG Template Builder Element', 'the-post-grid' ),
147 'icon' => 'fa fa-plug',
148 ];
149
150 $categories[ RT_THE_POST_GRID_PLUGIN_SLUG . '-elements' ] = [
151 'title' => esc_html__( 'The Post Grid', 'the-post-grid' ),
152 'icon' => 'fa fa-plug',
153 ];
154
155 $get_all_categories = $elements_manager->get_categories();
156 $categories = array_merge( $categories, $get_all_categories );
157 $set_categories = function ( $categories ) {
158 $this->categories = $categories;
159 };
160
161 $set_categories->call( $elements_manager, $categories );
162 }
163
164 /**
165 * Promotion
166 *
167 * @param array $config Config.
168 * @return array
169 */
170 public function promotePremiumWidgets( $config ) {
171 if ( rtTPG()->hasPro() ) {
172 return $config;
173 }
174
175 if ( ! isset( $config['promotionWidgets'] ) || ! is_array( $config['promotionWidgets'] ) ) {
176 $config['promotionWidgets'] = [];
177 }
178
179 $pro_widgets = [
180 [
181 'name' => 'tpg-slider-layout',
182 'title' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
183 'description' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
184 'icon' => 'eicon-post-slider tpg-grid-icon tss-promotional-element',
185 'categories' => '[ "the-post-grid-elements" ]',
186 ],
187 ];
188
189 $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $pro_widgets );
190
191 return $config;
192 }
193 }
194 endif;
195