PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.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 / Controllers / Admin / SettingsController.php
the-post-grid / app / Controllers / Admin Last commit date
AdminAjaxController.php 3 years ago MetaController.php 3 years ago NoticeController.php 3 years ago PostTypeController.php 3 years ago SettingsController.php 3 years ago UpgradeController.php 3 years ago
SettingsController.php
228 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 if ( ( isset( $_GET['page'] ) && 'rttpg_settings' !== $_GET['page'] ) || rtTPG()->post_type !== $typenow ) {
102 return;
103 }
104
105 $html = '';
106 $html .= '<div class="rt-document-box rt-alert rt-pro-alert">
107 <div class="rt-box-icon"><i class="dashicons dashicons-lock"></i></div>
108 <div class="rt-box-content">
109 <h3 class="rt-box-title">' . esc_html__( 'Pro field alert!', 'the-post-grid' ) . '</h3>
110 <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>
111 <a href="' . esc_url( rtTpg()->proLink() ) . '" target="_blank" class="rt-admin-btn">' . esc_html__( 'Upgrade to Pro', 'the-post-grid' ) . '</a>
112 <a href="#" target="_blank" class="rt-alert-close rt-pro-alert-close">x</a>
113 </div>
114 </div>';
115
116 Fns::print_html( $html );
117 }
118
119 /**
120 * Dequeue styles
121 *
122 * @return void
123 */
124 public function tpg_dequeue_unnecessary_styles() {
125 $settings = get_option( rtTPG()->options['settings'] );
126
127 if ( isset( $settings['tpg_skip_fa'] ) ) {
128 wp_dequeue_style( 'rt-fontawsome' );
129 wp_deregister_style( 'rt-fontawsome' );
130 }
131 }
132
133 /**
134 * Admin scripts
135 *
136 * @return void
137 */
138 public function settings_admin_enqueue_scripts() {
139 global $pagenow, $typenow;
140
141 if ( ! in_array( $pagenow, [ 'edit.php' ], true ) ) {
142 return;
143 }
144 if ( rtTPG()->post_type !== $typenow ) {
145 return;
146 }
147
148 wp_enqueue_script( 'jquery' );
149 wp_enqueue_script( 'rt-tpg-admin' );
150
151 // styles.
152 wp_enqueue_style( 'rt-tpg-admin' );
153
154 $nonce = wp_create_nonce( rtTPG()->nonceText() );
155
156 wp_localize_script(
157 'rt-tpg-admin',
158 'rttpg',
159 [
160 'nonceID' => esc_attr( rtTPG()->nonceId() ),
161 'nonce' => esc_attr( $nonce ),
162 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
163 ]
164 );
165 }
166
167 /**
168 * Marketing
169 *
170 * @param array $links Links.
171 * @return array
172 */
173 public function marketing( $links ) {
174 $links[] = '<a target="_blank" href="' . esc_url( rtTpg()->demoLink() ) . '">Demo</a>';
175 $links[] = '<a target="_blank" href="' . esc_url( rtTpg()->docLink() ) . '">Documentation</a>';
176
177 if ( ! rtTPG()->hasPro() ) {
178 $links[] = '<a target="_blank" style="color: #39b54a;font-weight: 700;" href="' . esc_url( rtTpg()->proLink() ) . '">Get Pro</a>';
179 }
180
181 return $links;
182 }
183
184 /**
185 * Submenu
186 *
187 * @return void
188 */
189 public function register() {
190 add_submenu_page(
191 'edit.php?post_type=' . rtTPG()->post_type,
192 esc_html__( 'Settings', 'the-post-grid' ),
193 esc_html__( 'Settings', 'the-post-grid' ),
194 'administrator',
195 'rttpg_settings',
196 [ $this, 'settings' ]
197 );
198
199 add_submenu_page(
200 'edit.php?post_type=' . rtTPG()->post_type,
201 esc_html__( 'Get Help', 'the-post-grid' ),
202 esc_html__( 'Get Help', 'the-post-grid' ),
203 'administrator',
204 'rttpg_get_help',
205 [ $this, 'get_help' ]
206 );
207 }
208
209 /**
210 * Get help view
211 *
212 * @return void
213 */
214 public function get_help() {
215 Fns::view( 'page.help' );
216 }
217
218 /**
219 * Settings view
220 *
221 * @return void
222 */
223 public function settings() {
224 Fns::view( 'settings.settings' );
225 }
226
227 }
228