PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / trunk
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid vtrunk
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 / RtTpg.php
the-post-grid / app Last commit date
Abstracts 1 year ago Controllers 1 month ago Divi 2 months ago Factory 1 year ago Helpers 1 month ago Migrations 3 months ago Models 8 months ago Widgets 1 month ago RtTpg.php 1 month ago
RtTpg.php
398 lines
1 <?php
2 /**
3 * Main initialization class.
4 *
5 * @package RT_TPG
6 */
7
8 // Do not allow directly accessing this file.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit( 'This script cannot be accessed directly.' );
11 }
12
13 require_once RT_THE_POST_GRID_PLUGIN_PATH . '/vendor/autoload.php';
14
15 use RT\ThePostGrid\Controllers\Api\RestApi;
16 use RT\ThePostGrid\Controllers\Admin\AdminAjaxController;
17 use RT\ThePostGrid\Controllers\Admin\MetaController;
18 use RT\ThePostGrid\Controllers\Admin\NoticeController;
19 use RT\ThePostGrid\Controllers\Admin\PostTypeController;
20 use RT\ThePostGrid\Controllers\Admin\SettingsController;
21 use RT\ThePostGrid\Controllers\AjaxController;
22 use RT\ThePostGrid\Controllers\ElementorController;
23 use RT\ThePostGrid\Controllers\BlocksController;
24 use RT\ThePostGrid\Controllers\GutenBergController;
25 use RT\ThePostGrid\Controllers\ScriptController;
26 use RT\ThePostGrid\Controllers\ShortcodeController;
27 use RT\ThePostGrid\Controllers\PageTemplateController;
28 use RT\ThePostGrid\Controllers\Hooks\FilterHooks;
29 use RT\ThePostGrid\Controllers\Hooks\ActionHooks;
30 use RT\ThePostGrid\Controllers\Hooks\InstallPlugins;
31 use RT\ThePostGrid\Controllers\WidgetController;
32 use RT\ThePostGrid\Helpers\Install;
33 use RT\ThePostGrid\Controllers\Admin\UpgradeController;
34 use RT\ThePostGrid\Controllers\Admin\SetupWizardController;
35 use RT\ThePostGrid\Controllers\DiviController;
36 use RT\ThePostGrid\Migrations\SettingsMigration;
37 use RT\ThePostGrid\Migrations\Tpg_Migration;
38
39 if ( ! class_exists( RtTpg::class ) ) {
40 /**
41 * Main initialization class.
42 */
43 final class RtTpg {
44
45 /**
46 * Post Type
47 *
48 * @var string
49 */
50 public $post_type = 'rttpg';
51
52 /**
53 * Options
54 *
55 * @var array
56 */
57 public $options = [
58 'settings' => 'rt_the_post_grid_settings',
59 'version' => RT_THE_POST_GRID_VERSION,
60 'installed_version' => 'rt_the_post_grid_current_version',
61 'slug' => RT_THE_POST_GRID_PLUGIN_SLUG,
62 ];
63
64 /**
65 * Defaut Settings
66 *
67 * @var array
68 */
69 public $defaultSettings = [
70 'tpg_block_type' => 'default',
71 'popup_fields' => [
72 'title',
73 'feature_img',
74 'content',
75 'post_date',
76 'author',
77 'categories',
78 'tags',
79 'social_share',
80 ],
81 'social_share_items' => [
82 'facebook',
83 'twitter',
84 'linkedin',
85 ],
86 ];
87
88 public $settings;
89 /**
90 * Store the singleton object.
91 *
92 * @var boolean
93 */
94 private static $singleton = false;
95
96 /**
97 * Create an inaccessible constructor.
98 */
99 private function __construct() {
100 $this->__init();
101 }
102
103 /**
104 * Fetch an instance of the class.
105 */
106 public static function getInstance() {
107 if ( false === self::$singleton ) {
108 self::$singleton = new self();
109 }
110
111 return self::$singleton;
112 }
113
114 /**
115 * Class init
116 *
117 * @return void
118 */
119 protected function __init() {
120 $settings = get_option( $this->options['settings'] );
121 $this->settings = $settings;
122
123 new UpgradeController();
124 new PostTypeController();
125 new AjaxController();
126 new ScriptController();
127 new WidgetController();
128 new PageTemplateController();
129
130 if ( is_admin() ) {
131 new AdminAjaxController();
132 new NoticeController();
133 new MetaController();
134 }
135
136 new GutenBergController();
137
138 new RestApi();
139
140 // SetupWizardController must be outside is_admin() for REST API routes to work.
141 new SetupWizardController();
142
143 FilterHooks::init();
144 ActionHooks::init();
145 InstallPlugins::init();
146
147 ( new SettingsController() )->init();
148
149 //Load Shortcode.
150 if ( ! isset( $settings['tpg_block_type'] ) || in_array( $settings['tpg_block_type'], [ 'default', 'shortcode' ] ) ) {
151 new ShortcodeController();
152 }
153
154 //Load Gutenberg and And Elementor.
155 if ( isset( $settings['tpg_block_type'] ) && in_array( $settings['tpg_block_type'], [ 'default', 'elementor' ] ) ) {
156 new ElementorController();
157 new BlocksController();
158 }
159
160 //Load Divi.
161 if ( isset( $settings['tpg_block_type'] ) && in_array( $settings['tpg_block_type'], [ 'default', 'divi' ] ) ) {
162 new DiviController();
163 }
164
165 SettingsMigration::init();
166 $this->load_hooks();
167 }
168
169 /**
170 * Load hooks
171 *
172 * @return void
173 */
174 private function load_hooks() {
175 register_activation_hook( RT_THE_POST_GRID_PLUGIN_FILE, [ Install::class, 'activate' ] );
176 register_deactivation_hook( RT_THE_POST_GRID_PLUGIN_FILE, [ Install::class, 'deactivate' ] );
177
178 add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ], - 1 );
179 add_action( 'init', [ $this, 'init_hooks' ], 0 );
180 }
181
182 /**
183 * Init hooks
184 *
185 * @return void
186 */
187 public function init_hooks() {
188 do_action( 'rttpg_before_init', $this );
189 Tpg_Migration::init();
190 if ( empty( $this->settings['tpg_enable_image_srcset'] ) && ! function_exists( 'et_setup_theme' ) ) {
191 add_filter( 'wp_calculate_image_srcset', function( $sources ) {
192 return is_array( $sources ) ? $sources : [];
193 } );
194 }
195
196 $this->load_language();
197 }
198
199 /**
200 * I18n
201 *
202 * @return void
203 */
204 public function load_language() {
205 do_action( 'rttpg_set_local', null );
206 $locale = determine_locale();
207 $locale = apply_filters( 'plugin_locale', $locale, 'the-post-grid' );
208 unload_textdomain( 'the-post-grid' );
209 load_textdomain( 'the-post-grid', WP_LANG_DIR . '/the-post-grid/the-post-grid-' . $locale . '.mo' );
210 load_plugin_textdomain( 'the-post-grid', false, plugin_basename( dirname( RT_THE_POST_GRID_PLUGIN_FILE ) ) . '/languages' );
211 }
212
213 /**
214 * Plugin loaded action
215 *
216 * @return void
217 */
218 public function on_plugins_loaded() {
219 do_action( 'rttpg_loaded', $this );
220 if ( is_user_logged_in() && current_user_can( 'deactivate_plugins' ) ) {
221 if ( isset( $_GET['rttpg'] ) && $_GET['rttpg'] == '0' ) {
222 $active_plugins = get_option( 'active_plugins' );
223
224 $plugins_to_deactivate = [
225 'the-post-grid/the-post-grid.php',
226 'the-post-grid-pro/the-post-grid-pro.php',
227 ];
228
229 foreach ( $plugins_to_deactivate as $plugin ) {
230 if ( in_array( $plugin, $active_plugins ) ) {
231 deactivate_plugins( $plugin );
232 }
233 }
234
235 wp_redirect( remove_query_arg( 'rttpg' ) );
236 exit;
237 }
238 }
239 }
240
241 /**
242 * Get the plugin path.
243 *
244 * @return string
245 */
246 public function plugin_path() {
247 return untrailingslashit( plugin_dir_path( RT_THE_POST_GRID_PLUGIN_FILE ) );
248 }
249
250 /**
251 * Plugin template path
252 *
253 * @return string
254 */
255 public function plugin_template_path() {
256 $plugin_template = $this->plugin_path() . '/templates/';
257
258 return apply_filters( 'tlp_tpg_template_path', $plugin_template );
259 }
260
261 /**
262 * Default template path
263 *
264 * @return string
265 */
266 public function default_template_path() {
267 return apply_filters( 'rttpg_default_template_path', untrailingslashit( plugin_dir_path( RT_THE_POST_GRID_PLUGIN_FILE ) ) );
268 }
269
270 /**
271 * Nonce text
272 *
273 * @return string
274 */
275 public static function nonceText() {
276 return 'rttpg_nonce_secret';
277 }
278
279 /**
280 * Nonce ID
281 *
282 * @return string
283 */
284 public static function nonceId() {
285 return 'rttpg_nonce';
286 }
287
288 /**
289 * Get assets URI
290 *
291 * @param string $file File.
292 *
293 * @return string
294 */
295 public function get_assets_uri( $file ) {
296 $file = ltrim( $file, '/' );
297
298 return trailingslashit( RT_THE_POST_GRID_PLUGIN_URL . '/assets' ) . $file;
299 }
300
301 /**
302 * RTL check.
303 *
304 * @param string $file File.
305 *
306 * @return string
307 */
308 public function tpg_can_be_rtl( $file ) {
309 $file = ltrim( str_replace( '.css', '', $file ), '/' );
310
311 if ( is_rtl() ) {
312 $file .= '.rtl';
313 }
314
315 return trailingslashit( RT_THE_POST_GRID_PLUGIN_URL . '/assets' ) . $file . '.min.css';
316 }
317
318 /**
319 * Get the template path.
320 *
321 * @return string
322 */
323 public function get_template_path() {
324 return apply_filters( 'rttpg_template_path', 'the-post-grid/' );
325 }
326
327 /**
328 * Pro check.
329 *
330 * @return boolean
331 */
332 public function hasPro() {
333 return class_exists( 'RtTpgPro' ) || class_exists( 'rtTPGP' );
334 }
335
336 /**
337 * Pro check.
338 *
339 * @return boolean
340 */
341 public function getProPath() {
342 if ( ! $this->hasPro() ) {
343 return false;
344 }
345 if ( ! function_exists( 'get_plugin_data' ) ) {
346 require_once ABSPATH . 'wp-admin/includes/plugin.php';
347 }
348
349 $path = WP_PLUGIN_DIR . '/the-post-grid-pro/';
350 if ( file_exists( $path ) ) {
351 return plugins_url() . '/the-post-grid-pro/';
352 }
353
354 return false;
355 }
356
357 /**
358 * Pro link.
359 *
360 * @return string
361 */
362 public function proLink() {
363 return '//www.radiustheme.com/downloads/the-post-grid-pro-for-wordpress/';
364 }
365
366 /**
367 * Doc link.
368 *
369 * @return string
370 */
371 public function docLink() {
372 return '//www.radiustheme.com/docs/the-post-grid/';
373 }
374
375 /**
376 * Demo link.
377 *
378 * @return string
379 */
380 public function demoLink() {
381 return '//www.radiustheme.com/demo/plugins/the-post-grid/';
382 }
383
384 }
385
386 /**
387 * Function for external use.
388 *
389 * @return rtTPG
390 */
391 function rtTPG() {
392 return rtTPG::getInstance();
393 }
394
395 // Init app.
396 rtTPG();
397 }
398