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 / Controllers / Admin / SettingsController.php
the-post-grid / app / Controllers / Admin Last commit date
Notice 3 months ago AdminAjaxController.php 1 year ago MetaController.php 1 year ago NoticeController.php 8 months ago PostTypeController.php 3 months ago SettingsController.php 1 year ago SetupWizardController.php 1 month ago UpgradeController.php 2 years ago
SettingsController.php
279 lines
1 <?php
2 /**
3 * Settings Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers\Admin;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGridPro\Helpers\Functions;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Settings Controller class.
20 */
21 class SettingsController {
22
23 /**
24 * Shortcode tag
25 *
26 * @var string
27 */
28 private $sc_tag = 'rt_tpg_scg';
29
30 /**
31 * Class init.
32 *
33 * @return void
34 */
35 public function init() {
36 add_action( 'admin_menu', [ $this, 'register' ] );
37 add_filter( 'plugin_action_links_' . RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME, [ $this, 'marketing' ] );
38 add_action( 'admin_enqueue_scripts', [ $this, 'settings_admin_enqueue_scripts' ], 99 );
39 add_action( 'wp_print_styles', [ $this, 'tpg_dequeue_unnecessary_styles' ], 99 );
40 add_action( 'admin_footer', [ $this, 'pro_alert_html' ] );
41 add_action( 'admin_head', [ $this, 'admin_head' ] );
42 }
43
44 /**
45 * Calls functions into the correct filters
46 *
47 * @return void
48 */
49 public function admin_head() {
50 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
51 return;
52 }
53
54 if ( 'true' == get_user_option( 'rich_editing' ) ) {
55 add_filter( 'mce_external_plugins', [ $this, 'mce_external_plugins' ] );
56 add_filter( 'mce_buttons', [ $this, 'mce_buttons' ] );
57 echo '<style>';
58 echo 'i.mce-i-rt_tpg_scg{';
59 echo "background: url('" . esc_url( rtTPG()->get_assets_uri( 'images/icon-20x20.png' ) ) . "');";
60 echo '}';
61 echo '</style>';
62 }
63
64 ?>
65 <style>
66 #adminmenu .wp-submenu li a[href="edit.php?post_type=rttpg&page=rttpg_our_plugins"] {
67 color: #32d716 !important;
68 font-weight: bold !important;
69 }
70 </style>
71 <?php
72
73 }
74
75 /**
76 * Adds tinymce plugin
77 *
78 * @param array $plugin_array Plugins.
79 *
80 * @return array
81 */
82 public function mce_external_plugins( $plugin_array ) {
83 $plugin_array[ $this->sc_tag ] = rtTPG()->get_assets_uri( 'js/mce-button.js' );
84
85 return $plugin_array;
86 }
87
88 /**
89 * Adds tinymce button
90 *
91 * @param array $buttons Buttons.
92 *
93 * @return array
94 */
95 public function mce_buttons( $buttons ) {
96 array_push( $buttons, $this->sc_tag );
97
98 return $buttons;
99 }
100
101 /**
102 * Pro alert
103 *
104 * @return void
105 */
106 public function pro_alert_html() {
107 global $typenow;
108
109 if ( rtTPG()->hasPro() ) {
110 return;
111 }
112
113 //phpcs:ignore WordPress.Security.NonceVerification.Recommended
114 if ( ( isset( $_GET['page'] ) && 'rttpg_settings' !== $_GET['page'] ) || rtTPG()->post_type !== $typenow ) {
115 return;
116 }
117
118 $html = '';
119 $html .= '<div class="rt-document-box rt-alert rt-pro-alert">
120 <div class="rt-box-icon"><i class="dashicons dashicons-lock"></i></div>
121 <div class="rt-box-content">
122 <h3 class="rt-box-title">' . esc_html__( 'Pro field alert!', 'the-post-grid' ) . '</h3>
123 <p><span></span>' . esc_html__( 'Sorry! this is a Pro field. To use this field, you need to use Pro plugin.', 'the-post-grid' ) . '</p>
124 <a href="' . esc_url( rtTpg()->proLink() ) . '" target="_blank" class="rt-admin-btn">' . esc_html__( 'Upgrade to Pro', 'the-post-grid' ) . '</a>
125 <a href="#" target="_blank" class="rt-alert-close rt-pro-alert-close">x</a>
126 </div>
127 </div>';
128
129 Fns::print_html( $html );
130 }
131
132 /**
133 * Dequeue styles
134 *
135 * @return void
136 */
137 public function tpg_dequeue_unnecessary_styles() {
138 $settings = get_option( rtTPG()->options['settings'] );
139
140 if ( isset( $settings['tpg_skip_fa'] ) ) {
141 wp_dequeue_style( 'rt-fontawsome' );
142 wp_deregister_style( 'rt-fontawsome' );
143 }
144 }
145
146 /**
147 * Admin scripts
148 *
149 * @return void
150 */
151 public function settings_admin_enqueue_scripts() {
152 global $pagenow, $typenow;
153
154 if ( ! in_array( $pagenow, [ 'edit.php' ], true ) ) {
155 return;
156 }
157 if ( rtTPG()->post_type !== $typenow ) {
158 return;
159 }
160
161 wp_enqueue_script( 'jquery' );
162 wp_enqueue_script( 'rt-tpg-admin' );
163
164 // styles.
165 wp_enqueue_style( 'rt-tpg-admin' );
166
167 $nonce = wp_create_nonce( rtTPG()->nonceText() );
168
169 wp_localize_script(
170 'rt-tpg-admin',
171 'rttpg',
172 [
173 'nonceID' => esc_attr( rtTPG()->nonceId() ),
174 'nonce' => esc_attr( $nonce ),
175 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
176 'uid' => get_current_user_id(),
177 ]
178 );
179 }
180
181 /**
182 * Marketing
183 *
184 * @param array $links Links.
185 *
186 * @return array
187 */
188 public function marketing( $links ) {
189 $links[] = '<a target="_blank" href="' . esc_url( rtTpg()->demoLink() ) . '">Demo</a>';
190 $links[] = '<a target="_blank" href="' . esc_url( rtTpg()->docLink() ) . '">Documentation</a>';
191
192 if ( ! rtTPG()->hasPro() ) {
193 $links[] = '<a target="_blank" style="color: #39b54a;font-weight: 700;" href="' . esc_url( rtTpg()->proLink() ) . '">Get Pro</a>';
194 }
195
196 return $links;
197 }
198
199 /**
200 * Submenu
201 *
202 * @return void
203 */
204 public function register() {
205 add_submenu_page(
206 'edit.php?post_type=' . rtTPG()->post_type,
207 esc_html__( 'Settings', 'the-post-grid' ),
208 esc_html__( 'Settings', 'the-post-grid' ),
209 'administrator',
210 'rttpg_settings',
211 [ $this, 'settings' ]
212 );
213
214 add_submenu_page(
215 'edit.php?post_type=' . rtTPG()->post_type,
216 esc_html__( 'Get Help', 'the-post-grid' ),
217 esc_html__( 'Get Help', 'the-post-grid' ),
218 'administrator',
219 'rttpg_get_help',
220 [ $this, 'get_help' ]
221 );
222
223 if ( rttpg()->hasPro() ) {
224 add_submenu_page(
225 'edit.php?post_type=' . rtTPG()->post_type,
226 esc_html__( 'Taxonomy Order', 'the-post-grid-pro' ),
227 esc_html__( 'Taxonomy Order', 'the-post-grid-pro' ),
228 'administrator',
229 'tgp_taxonomy_order',
230 [ $this, 'tpg_menu_page_taxonomy_order' ]
231 );
232 }
233
234 add_submenu_page(
235 'edit.php?post_type=' . rtTPG()->post_type,
236 esc_html__( 'Our Plugins', 'the-post-grid' ),
237 esc_html__( 'Our Plugins', 'the-post-grid' ),
238 'administrator',
239 'rttpg_our_plugins',
240 [ $this, 'our_plugins' ]
241 );
242 }
243
244 public function tpg_menu_page_taxonomy_order() {
245 if ( ! rttpg()->hasPro() ) {
246 return;
247 }
248 Functions::view( 'taxonomy-order' );
249 }
250
251 /**
252 * Get help view
253 *
254 * @return void
255 */
256 public function get_help() {
257 Fns::view( 'page.help' );
258 }
259
260 /**
261 * Settings view
262 *
263 * @return void
264 */
265 public function settings() {
266 Fns::view( 'settings.settings' );
267 }
268
269 /**
270 * Settings view
271 *
272 * @return void
273 */
274 public function our_plugins() {
275 Fns::view( 'page.our-plugins' );
276 }
277
278 }
279