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