PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.7.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.7.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 / Controllers / Admin / SettingsController.php
the-post-grid / app / Controllers / Admin Last commit date
AdminAjaxController.php 2 years ago MetaController.php 2 years ago NoticeController.php 2 years ago PostTypeController.php 2 years ago SettingsController.php 2 years ago UpgradeController.php 2 years ago
SettingsController.php
230 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
12 // Do not allow directly accessing this file.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 'This script cannot be accessed directly.' );
15 }
16
17 /**
18 * Settings Controller class.
19 */
20 class SettingsController {
21 /**
22 * Shortcode tag
23 *
24 * @var string
25 */
26 private $sc_tag = 'rt_tpg_scg';
27
28 /**
29 * Class init.
30 *
31 * @return void
32 */
33 public function init() {
34 add_action( 'admin_menu', [ $this, 'register' ] );
35 add_filter( 'plugin_action_links_' . RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME, [ $this, 'marketing' ] );
36 add_action( 'admin_enqueue_scripts', [ $this, 'settings_admin_enqueue_scripts' ] );
37 add_action( 'wp_print_styles', [ $this, 'tpg_dequeue_unnecessary_styles' ], 99 );
38 add_action( 'admin_footer', [ $this, 'pro_alert_html' ] );
39 add_action( 'admin_head', [ $this, 'admin_head' ] );
40 }
41
42 /**
43 * Calls functions into the correct filters
44 *
45 * @return void
46 */
47 public function admin_head() {
48 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
49 return;
50 }
51
52 if ( 'true' == get_user_option( 'rich_editing' ) ) {
53 add_filter( 'mce_external_plugins', [ $this, 'mce_external_plugins' ] );
54 add_filter( 'mce_buttons', [ $this, 'mce_buttons' ] );
55 echo '<style>';
56 echo 'i.mce-i-rt_tpg_scg{';
57 echo "background: url('" . esc_url( rtTPG()->get_assets_uri( 'images/icon-20x20.png' ) ) . "');";
58 echo '}';
59 echo '</style>';
60 }
61 }
62
63 /**
64 * Adds tinymce plugin
65 *
66 * @param array $plugin_array Plugins.
67 *
68 * @return array
69 */
70 public function mce_external_plugins( $plugin_array ) {
71 $plugin_array[ $this->sc_tag ] = rtTPG()->get_assets_uri( 'js/mce-button.js' );
72
73 return $plugin_array;
74 }
75
76 /**
77 * Adds tinymce button
78 *
79 * @param array $buttons Buttons.
80 *
81 * @return array
82 */
83 public function mce_buttons( $buttons ) {
84 array_push( $buttons, $this->sc_tag );
85
86 return $buttons;
87 }
88
89 /**
90 * Pro alert
91 *
92 * @return void
93 */
94 public function pro_alert_html() {
95 global $typenow;
96
97 if ( rtTPG()->hasPro() ) {
98 return;
99 }
100
101 //phpcs:ignore WordPress.Security.NonceVerification.Recommended
102 if ( ( isset( $_GET['page'] ) && 'rttpg_settings' !== $_GET['page'] ) || rtTPG()->post_type !== $typenow ) {
103 return;
104 }
105
106 $html = '';
107 $html .= '<div class="rt-document-box rt-alert rt-pro-alert">
108 <div class="rt-box-icon"><i class="dashicons dashicons-lock"></i></div>
109 <div class="rt-box-content">
110 <h3 class="rt-box-title">' . esc_html__( 'Pro field alert!', 'the-post-grid' ) . '</h3>
111 <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>
112 <a href="' . esc_url( rtTpg()->proLink() ) . '" target="_blank" class="rt-admin-btn">' . esc_html__( 'Upgrade to Pro', 'the-post-grid' ) . '</a>
113 <a href="#" target="_blank" class="rt-alert-close rt-pro-alert-close">x</a>
114 </div>
115 </div>';
116
117 Fns::print_html( $html );
118 }
119
120 /**
121 * Dequeue styles
122 *
123 * @return void
124 */
125 public function tpg_dequeue_unnecessary_styles() {
126 $settings = get_option( rtTPG()->options['settings'] );
127
128 if ( isset( $settings['tpg_skip_fa'] ) ) {
129 wp_dequeue_style( 'rt-fontawsome' );
130 wp_deregister_style( 'rt-fontawsome' );
131 }
132 }
133
134 /**
135 * Admin scripts
136 *
137 * @return void
138 */
139 public function settings_admin_enqueue_scripts() {
140 global $pagenow, $typenow;
141
142 if ( ! in_array( $pagenow, [ 'edit.php' ], true ) ) {
143 return;
144 }
145 if ( rtTPG()->post_type !== $typenow ) {
146 return;
147 }
148
149 wp_enqueue_script( 'jquery' );
150 wp_enqueue_script( 'rt-tpg-admin' );
151
152 // styles.
153 wp_enqueue_style( 'rt-tpg-admin' );
154
155 $nonce = wp_create_nonce( rtTPG()->nonceText() );
156
157 wp_localize_script(
158 'rt-tpg-admin',
159 'rttpg',
160 [
161 'nonceID' => esc_attr( rtTPG()->nonceId() ),
162 'nonce' => esc_attr( $nonce ),
163 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
164 'uid' => get_current_user_id(),
165 ]
166 );
167 }
168
169 /**
170 * Marketing
171 *
172 * @param array $links Links.
173 * @return array
174 */
175 public function marketing( $links ) {
176 $links[] = '<a target="_blank" href="' . esc_url( rtTpg()->demoLink() ) . '">Demo</a>';
177 $links[] = '<a target="_blank" href="' . esc_url( rtTpg()->docLink() ) . '">Documentation</a>';
178
179 if ( ! rtTPG()->hasPro() ) {
180 $links[] = '<a target="_blank" style="color: #39b54a;font-weight: 700;" href="' . esc_url( rtTpg()->proLink() ) . '">Get Pro</a>';
181 }
182
183 return $links;
184 }
185
186 /**
187 * Submenu
188 *
189 * @return void
190 */
191 public function register() {
192 add_submenu_page(
193 'edit.php?post_type=' . rtTPG()->post_type,
194 esc_html__( 'Settings', 'the-post-grid' ),
195 esc_html__( 'Settings', 'the-post-grid' ),
196 'administrator',
197 'rttpg_settings',
198 [ $this, 'settings' ]
199 );
200
201 add_submenu_page(
202 'edit.php?post_type=' . rtTPG()->post_type,
203 esc_html__( 'Get Help', 'the-post-grid' ),
204 esc_html__( 'Get Help', 'the-post-grid' ),
205 'administrator',
206 'rttpg_get_help',
207 [ $this, 'get_help' ]
208 );
209 }
210
211 /**
212 * Get help view
213 *
214 * @return void
215 */
216 public function get_help() {
217 Fns::view( 'page.help' );
218 }
219
220 /**
221 * Settings view
222 *
223 * @return void
224 */
225 public function settings() {
226 Fns::view( 'settings.settings' );
227 }
228
229 }
230