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