PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.2.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.2.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 3 years ago Hooks 3 years ago AjaxController.php 3 years ago ElementorController.php 3 years ago GutenBergController.php 3 years ago ScriptController.php 3 years ago ShortcodeController.php 3 years ago WidgetController.php 3 years ago
ElementorController.php
196 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-elementor', $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 'default' => '\RtElementorWidget',
114 ];
115
116 $widgets = apply_filters( 'tpg_el_widget_register', $widgets );
117
118 foreach ( $widgets as $file_name => $class ) {
119 if ( ! rtTPG()->hasPro() && 'slider-layout' === $file_name ) {
120 continue;
121 }
122
123 $template_name = 'the-post-grid/elementor/' . $file_name . '.php';
124
125 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
126 $file = STYLESHEETPATH . $template_name;
127 } elseif ( file_exists( TEMPLATEPATH . $template_name ) ) {
128 $file = TEMPLATEPATH . $template_name;
129 } else {
130 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/app/Widgets/elementor/widgets/' . $file_name . '.php';
131 }
132
133 require_once $file;
134
135 $widgets_manager->register( new $class() );
136 }
137 }
138
139 /**
140 * Widget category
141 *
142 * @param object $elements_manager Manager.
143 * @return void
144 */
145 public function widget_category( $elements_manager ) {
146 $categories['tpg-elementor-builder-widgets'] = [
147 'title' => esc_html__( 'TPG Template Builder Element', 'the-post-grid' ),
148 'icon' => 'fa fa-plug',
149 ];
150
151 $categories[ RT_THE_POST_GRID_PLUGIN_SLUG . '-elements' ] = [
152 'title' => esc_html__( 'The Post Grid', 'the-post-grid' ),
153 'icon' => 'fa fa-plug',
154 ];
155
156 $get_all_categories = $elements_manager->get_categories();
157 $categories = array_merge( $categories, $get_all_categories );
158 $set_categories = function ( $categories ) {
159 $this->categories = $categories;
160 };
161
162 $set_categories->call( $elements_manager, $categories );
163 }
164
165 /**
166 * Promotion
167 *
168 * @param array $config Config.
169 * @return array
170 */
171 public function promotePremiumWidgets( $config ) {
172 if ( rtTPG()->hasPro() ) {
173 return $config;
174 }
175
176 if ( ! isset( $config['promotionWidgets'] ) || ! is_array( $config['promotionWidgets'] ) ) {
177 $config['promotionWidgets'] = [];
178 }
179
180 $pro_widgets = [
181 [
182 'name' => 'tpg-slider-layout',
183 'title' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
184 'description' => esc_html__( 'TPG - Slider Layout', 'the-post-grid' ),
185 'icon' => 'eicon-post-slider tpg-grid-icon tss-promotional-element',
186 'categories' => '[ "the-post-grid-elements" ]',
187 ],
188 ];
189
190 $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $pro_widgets );
191
192 return $config;
193 }
194 }
195 endif;
196