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