PluginProbe
Kadence Central – Site Management, Backups, Security, and Reporting / trunk
Kadence Central – Site Management, Backups, Security, and Reporting vtrunk
4.0.3 4.0.2 4.0.1 trunk 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.3 2.0.4 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 All 50 releases
ithemes-sync / admin.php

admin.php in Kadence Central – Site Management, Backups, Security, and Reporting trunk, at admin.php

333 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Set up admin interface.
5 Written by Chris Jean for iThemes.com
6 Version 1.2.0
7
8 Version History
9 1.0.0 - 2013-10-02 - Chris Jean
10 Initial version
11 1.1.0 - 2013-11-19 - Chris Jean
12 Added the ability for the show_sync option to control who sees the Sync interface and plugin.
13 1.2.0 - 2014-02-14 - Chris Jean
14 Added support for ?ithemes-sync-force-display=1 in the admin page to force a hidden Sync plugin to display for that specific user.
15 */
16
17
18 require_once $GLOBALS['ithemes_sync_path'] . '/load-translations.php';
19
20 class Ithemes_Sync_Admin {
21 private $page_name = 'solid-central';
22
23 private $page_ref;
24
25 private $package_details;
26
27 private $registration_link;
28
29
30 public function __construct() {
31 add_action( 'init', [ $this, 'init' ] );
32 add_action( 'wp_ajax_ithemes_sync_hide_notice', [ $this, 'hide_authenticate_notice' ] );
33 add_action( 'admin_init', [ $this, 'add_privacy_content' ] );
34 add_filter( 'heartbeat_received', [$this, 'central_ping' ], 10, 2 );
35 }
36
37 public function modify_plugins_page() {
38 add_filter( 'all_plugins', [ $this, 'remove_sync_plugin' ] );
39 }
40
41 public function remove_sync_plugin( $plugins ) {
42 unset( $plugins[ basename( $GLOBALS['ithemes_sync_path'] ) . '/init.php' ] );
43
44 return $plugins;
45 }
46
47 public function init() {
48 require_once $GLOBALS['ithemes_sync_path'] . '/settings.php';
49
50
51 $show_sync = $GLOBALS['ithemes-sync-settings']->get_option( 'show_sync' );
52
53 if ( is_array( $show_sync ) ) {
54 $show_sync = in_array( get_current_user_id(), $show_sync );
55 }
56
57 if ( ! $show_sync && current_user_can( 'manage_options' ) ) {
58 $user_id = get_current_user_id();
59
60 if ( isset( $_GET['ithemes-sync-force-display'] ) ) {
61 if ( ! empty( $_GET['ithemes-sync-force-display'] ) ) {
62 $show_sync = true;
63 set_site_transient( "ithemes-sync-force-display-$user_id", true, 600 );
64
65 if ( false === $this->silent_mode_enabled() ) {
66 add_action( 'all_admin_notices', [ $this, 'show_force_display_notice' ], 0 );
67 }
68 } else {
69 delete_site_transient( "ithemes-sync-force-display-$user_id" );
70
71 if ( false === $this->silent_mode_enabled() ) {
72 add_action( 'all_admin_notices', [ $this, 'show_force_display_disable_notice' ], 0 );
73 }
74 }
75 } elseif ( false !== get_site_transient( "ithemes-sync-force-display-$user_id" ) ) {
76 $show_sync = true;
77
78 if ( false === $this->silent_mode_enabled() ) {
79 add_action( 'all_admin_notices', [ $this, 'show_force_display_notice' ], 0 );
80 }
81 }
82 }
83
84
85 if ( $show_sync && ( false === $this->silent_mode_enabled() ) ) {
86 if ( ! is_multisite() || is_super_admin() ) {
87 add_action( 'admin_menu', [ $this, 'add_admin_pages' ] );
88 }
89
90 add_action( 'network_admin_menu', [ $this, 'add_network_admin_pages' ] );
91
92
93 if ( current_user_can( 'manage_options' ) ) {
94 if ( ! get_site_option( 'ithemes-sync-authenticated' ) && ( empty( $_GET['page'] ) || ( $this->page_name != $_GET['page'] ) ) && ! get_site_option( 'ithemes_sync_hide_authenticate_notice' ) ) {
95 require_once $GLOBALS['ithemes_sync_path'] . '/functions.php';
96
97 $path_url = Ithemes_Sync_Functions::get_url( $GLOBALS['ithemes_sync_path'] );
98 wp_enqueue_style( 'ithemes-updater-admin-notice-style', "$path_url/css/admin-notice.css", [], '3.0.0' );
99 wp_enqueue_script( 'ithemes-updater-admin-notice-script', "$path_url/js/admin-notice.js", [ 'jquery' ], '3.0.0' );
100 $params = [
101 'url' => wp_nonce_url( admin_url( 'admin-ajax.php' ), 'ithemes_sync_hide_notice' ),
102 ];
103 wp_add_inline_script( 'ithemes-updater-admin-notice-script', 'const ithemes_sync_notice = ' . wp_json_encode( $params ) . ';', 'before' );
104 if ( false === $this->silent_mode_enabled() ) {
105 add_action( 'all_admin_notices', [ $this, 'show_authenticate_notice' ], 0 );
106 }
107
108 delete_site_transient( 'ithemes-sync-activated' );
109 } elseif ( ! empty( $_GET['activate'] ) && get_site_transient( 'ithemes-sync-activated' ) ) {
110 require_once $GLOBALS['ithemes_sync_path'] . '/functions.php';
111
112 $path_url = Ithemes_Sync_Functions::get_url( $GLOBALS['ithemes_sync_path'] );
113 wp_enqueue_style( 'ithemes-updater-admin-notice-style', "$path_url/css/admin-notice.css", [], '3.0.0' );
114 wp_enqueue_script( 'ithemes-updater-admin-notice-script', "$path_url/js/admin-notice.js", [ 'jquery' ], '3.0.0' );
115
116 if ( false === $this->silent_mode_enabled() ) {
117 add_action( 'all_admin_notices', [ $this, 'show_activate_notice' ], 0 );
118 }
119
120 delete_site_transient( 'ithemes-sync-activated' );
121 }
122 }
123 } else {
124 add_action( 'load-plugins.php', [ $this, 'modify_plugins_page' ] );
125 }
126 }
127
128 public function show_activate_notice() {
129 if ( is_multisite() && is_network_admin() ) {
130 $url = network_admin_url( 'settings.php' ) . "?page={$this->page_name}";
131 } else {
132 $url = admin_url( 'options-general.php' ) . "?page={$this->page_name}";
133 }
134
135 ?>
136 <div class="updated" id="ithemes-sync-notice">
137 <?php printf( __( 'Kadence Central is active. <a class="ithemes-sync-notice-button" href="%s">Manage Central</a> <a class="ithemes-sync-notice-dismiss" href="#">×</a>', 'it-l10n-ithemes-sync' ), $url ); ?>
138 </div>
139 <?php
140 }
141
142 public function show_authenticate_notice() {
143 if ( is_multisite() && is_network_admin() ) {
144 $url = network_admin_url( 'settings.php' ) . "?page={$this->page_name}";
145 } else {
146 $url = admin_url( 'options-general.php' ) . "?page={$this->page_name}";
147 }
148
149 ?>
150 <div class="updated" id="ithemes-sync-notice">
151 <?php printf( __( 'Kadence Central is almost ready. <a class="ithemes-sync-notice-button" href="%s">Set Up Central</a> <a class="ithemes-sync-notice-hide" href="#">×</a>', 'it-l10n-ithemes-sync' ), $url ); ?>
152 </div>
153 <?php
154 }
155
156 public function show_force_display_notice() {
157 $user_id = get_current_user_id();
158 $time = get_site_option( "_site_transient_timeout_ithemes-sync-force-display-$user_id" );
159 $time_diff = human_time_diff( time(), $time );
160
161 $url = admin_url( 'index.php?ithemes-sync-force-display=0' );
162
163 ?>
164 <div class="updated">
165 <p><?php printf( __( 'Kadence Central will show for your user for the next %1$s. Click <a href="%2$s">here</a> to hide Kadence Central again.', 'it-l10n-ithemes-sync' ), $time_diff, $url ); ?></p>
166 </div>
167 <?php
168 }
169
170 public function show_force_display_disable_notice() {
171
172 ?>
173 <div class="updated">
174 <p><?php _e( 'Kadence Central is now hidden from your user again.', 'it-l10n-ithemes-sync' ); ?></p>
175 </div>
176 <?php
177 }
178
179 public function hide_authenticate_notice() {
180 check_admin_referer( 'ithemes_sync_hide_notice' );
181 if ( current_user_can( 'manage_options' ) ) {
182 update_site_option( 'ithemes_sync_hide_authenticate_notice', true );
183 } else {
184 wp_die();
185 }
186 }
187
188 public function add_admin_pages() {
189 $this->page_ref = add_options_page( __( 'Kadence Central', 'it-l10n-ithemes-sync' ), __( 'Kadence Central', 'it-l10n-ithemes-sync' ), 'manage_options', $this->page_name, [ $this, 'settings_index' ] );
190
191 add_action( "load-{$this->page_ref}", [ $this, 'load_settings_page' ] );
192 }
193
194 public function add_network_admin_pages() {
195 $this->page_ref = add_submenu_page( 'settings.php', __( 'Kadence Central', 'it-l10n-ithemes-sync' ), __( 'Kadence Central', 'it-l10n-ithemes-sync' ), 'manage_options', $this->page_name, [ $this, 'settings_index' ] );
196
197 add_action( "load-{$this->page_ref}", [ $this, 'load_settings_page' ] );
198 }
199
200 public function load_settings_page() {
201 require_once $GLOBALS['ithemes_sync_path'] . '/settings.php';
202
203 require $GLOBALS['ithemes_sync_path'] . '/settings-page.php';
204
205 do_action( 'ithemes_sync_settings_page_load' );
206 }
207
208 public function settings_index() {
209 do_action( 'ithemes_sync_settings_page_index' );
210 }
211
212 private function set_package_details() {
213 if ( false !== $this->package_details ) {
214 return;
215 }
216
217 require_once $GLOBALS['ithemes_updater_path'] . '/packages.php';
218 $this->package_details = Ithemes_Updater_Packages::get_local_details();
219 }
220
221 private function set_registration_link() {
222 if ( false !== $this->registration_link ) {
223 return;
224 }
225
226 $url = admin_url( 'options-general.php' ) . "?page={$this->page_name}";
227 $this->registration_link = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $url, __( 'Manage Kadence product licenses to receive automatic upgrade support', 'it-l10n-ithemes-sync' ), __( 'License', 'it-l10n-ithemes-sync' ) );
228 }
229
230 public function filter_plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {
231 $this->set_package_details();
232 $this->set_registration_link();
233
234 if ( isset( $this->package_details[ $plugin_file ] ) ) {
235 $actions[] = $this->registration_link;
236 }
237
238 return $actions;
239 }
240
241 public function filter_theme_action_links( $actions, $theme ) {
242 $this->set_package_details();
243 $this->set_registration_link();
244
245 if ( is_object( $theme ) ) {
246 $path = basename( $theme->get_stylesheet_directory() ) . '/style.css';
247 } elseif ( is_array( $theme ) && isset( $theme['Stylesheet Dir'] ) ) {
248 $path = $theme['Stylesheet Dir'] . '/style.css';
249 } else {
250 $path = '';
251 }
252
253 if ( isset( $this->package_details[ $path ] ) ) {
254 $actions[] = $this->registration_link;
255 }
256
257 return $actions;
258 }
259
260 /**
261 * Adds privacy content to wp-admin/tools.php?wp-privacy-policy-guide
262 *
263 * @since 2.0.9
264 * @return void
265 */
266 function add_privacy_content() {
267 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
268 return;
269 }
270
271 $content = '<div class="wp-suggested-text"><h2>' . __( 'Where we send your data', 'it-l10n-ithemes-sync' ) . '</h2>';
272 $content .= sprintf( __( '%1$s%2$sSuggested text:%3$s This web site uses a third party service to manage administrative tasks. If you leave a comment, submit personal information via a contact form, or otherwise exchange personal details with us, it is possible that we may use this service to manage that data. Please visit the %4$sKadence Privacy Policy%5$s for more information regarding the way they handle their data.%6$s%7$s', 'it-l10n-ithemes-sync' ), '<p>', '<strong class="privacy-policy-tutorial">', '</strong>', '<a href="https://ithemes.com/privacy-policy/">', '</a>', '</p>', '</div>' );
273
274 wp_add_privacy_policy_content( 'Kadence Central', wp_kses_post( wpautop( $content, false ) ) );
275 }
276
277 /**
278 * Returns boolean depending on whether silent mode is enabled or not.
279 *
280 * Silent mode kills all sync admin notices as well as the menu item and admin page.
281 *
282 * @since 2.0.14
283 * @return boolean
284 */
285 function silent_mode_enabled() {
286 return apply_filters( 'ithemes-sync-silent-mode-enabled', false );
287 }
288
289 /**
290 * Sends a ping to the Central server.
291 *
292 * The Central Server will respond with data about the Central
293 * account and site connection.
294 *
295 * @since 3.2.0
296 *
297 * @param array $response The response data to send back to the client.
298 * @param array $data The data sent from the client.
299 *
300 * @return array|WP_Error
301 */
302 public function central_ping( $response, $data ) {
303
304 // This value should contain the Central Site id.
305 if ( ! isset( $data['central_ping'] ) || ! is_array( $data['central_ping'] ) ) {
306 return $response;
307 }
308
309 if ( ! isset( $data['central_ping']['site_id'] ) ) {
310 return $response;
311 }
312
313 require_once $GLOBALS['ithemes_sync_path'] . '/settings.php';
314
315 $site_id = intval( $data['central_ping']['site_id'] );
316
317 $result = $GLOBALS['ithemes-sync-settings']->do_ping_check( $site_id );
318
319 if ( is_wp_error( $result ) ) {
320 return $response;
321 }
322
323 // Store in transient for one day.
324 set_transient( 'solid_central_ping_' . $site_id, $result, DAY_IN_SECONDS );
325
326 $response['central_ping'] = $result;
327
328 return $response;
329 }
330 }
331
332 new Ithemes_Sync_Admin();
333