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 / load.php

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

235 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Load the Sync plugin components.
5 */
6
7 use SolidWP\Central\Admin_Post\Admin_Post_Handler;
8 use SolidWP\Central\Central_Server\Central_Server_Notifier;
9
10 if ( ! defined( 'SOLID_CENTRAL_APP_ID' ) ) {
11 define( 'SOLID_CENTRAL_APP_ID', 'aff8ad0a-3359-5385-9bbd-c11b5655814a' );
12 }
13
14 /**
15 * @return void
16 */
17 function ithemes_sync_load_request_handler() {
18 require_once $GLOBALS['ithemes_sync_path'] . '/request-handler.php';
19 Ithemes_Sync_Request_Handler::for_legacy_request();
20 }
21
22 if ( ! empty( $_GET['ithemes-sync-request'] ) ) {
23 add_action( 'plugins_loaded', 'ithemes_sync_load_request_handler' );
24 }
25
26 if ( is_admin() ) {
27 require $GLOBALS['ithemes_sync_path'] . '/admin.php';
28 }
29
30 require_once $GLOBALS['ithemes_sync_path'] . '/functions.php';
31 require_once $GLOBALS['ithemes_sync_path'] . '/client-dashboard.php';
32 require_once $GLOBALS['ithemes_sync_path'] . '/notices.php';
33 require_once $GLOBALS['ithemes_sync_path'] . '/src/Admin_Post/Admin_Post_Handler.php';
34 require_once $GLOBALS['ithemes_sync_path'] . '/src/Central_Server/Central_Server_Client.php';
35 require_once $GLOBALS['ithemes_sync_path'] . '/src/Central_Server/Central_Server_Notifier.php';
36 require_once $GLOBALS['ithemes_sync_path'] . '/src/REST/Auth.php';
37 require_once $GLOBALS['ithemes_sync_path'] . '/src/REST/Verb.php';
38
39 // Load the REST API routes.
40 add_action(
41 'rest_api_init',
42 function () {
43 require_once $GLOBALS['ithemes_sync_path'] . '/settings.php';
44 require_once $GLOBALS['ithemes_sync_path'] . '/api.php';
45 require_once $GLOBALS['ithemes_sync_path'] . '/request-handler.php';
46
47 ( new SolidWP\Central\REST\Auth( $GLOBALS['ithemes-sync-settings'] ) )->register_routes();
48 ( new SolidWP\Central\Rest\Verb( $GLOBALS['ithemes-sync-api'] ) )->register_routes();
49 }
50 );
51
52 require_once $GLOBALS['ithemes_sync_path'] . '/settings.php';
53 $GLOBALS['solid_central_notifier'] = new Central_Server_Notifier( $GLOBALS['ithemes-sync-settings'] );
54 $GLOBALS['solid_central_notifier']->init();
55
56 add_action(
57 'init',
58 static function () {
59 if ( ! wp_next_scheduled( Central_Server_Notifier::SEND_QUEUED_NOTICES_ACTION ) ) {
60 wp_schedule_event( time(), 'hourly', Central_Server_Notifier::SEND_QUEUED_NOTICES_ACTION );
61 }
62
63 (new Admin_Post_Handler( $GLOBALS['ithemes-sync-settings'] ))->init();
64 }
65 );
66
67 /**
68 * Notify the Central server immediately.
69 *
70 * @param string $type Notice type. Must be one of the `Central_Server_Notifier::NOTICE_*` constants.
71 * @param array<string, mixed> $payload Notice payload.
72 *
73 * @phpstan-param Central_Server_Notifier::NOTICE_* $type
74 *
75 * @return true|WP_Error
76 */
77 function solid_central_notify_server( string $type, array $payload ) {
78 return $GLOBALS['solid_central_notifier']->notify( $type, $payload );
79 }
80
81 /**
82 * Add notice to the queue. Notices will be sent by the cron schedule.
83 *
84 * @see Central_Server_Notifier::send_queued_notices()
85 *
86 * @param string $type Notice type. Must be one of the `Central_Server_Notifier::NOTICE_*` constants.
87 * @param array<string, mixed> $payload Notice payload.
88 *
89 * @phpstan-param Central_Server_Notifier::NOTICE_* $type
90 *
91 * @return void
92 */
93 function solid_central_add_notice( string $type, array $payload ) {
94 $GLOBALS['solid_central_notifier']->add_notice( $type, $payload );
95 }
96
97 /**
98 * @return void
99 */
100 function ithemes_sync_handle_activation_hook() {
101 set_site_transient( 'ithemes-sync-activated', true, 120 );
102 delete_site_option( 'ithemes_sync_hide_authenticate_notice' );
103 }
104 register_activation_hook( __FILE__, 'ithemes_sync_handle_activation_hook' );
105
106 /**
107 * @return void
108 */
109 function ithemes_sync_handle_deactivation_hook() {
110 delete_site_option( 'ithemes_sync_hide_authenticate_notice' );
111 delete_site_transient( 'ithemes-sync-activated' );
112 }
113 register_deactivation_hook( __FILE__, 'ithemes_sync_handle_deactivation_hook' );
114
115 /**
116 * The Kadence Updater register action callback.
117 *
118 * @param mixed $updater An instance of the Kadence Updater.
119 *
120 * @return void
121 */
122 function ithemes_sync_updater_register( $updater ) {
123 $updater->register( 'ithemes-sync', __FILE__ );
124 }
125 add_action( 'ithemes_updater_register', 'ithemes_sync_updater_register' );
126
127 require $GLOBALS['ithemes_sync_path'] . '/lib/updater/load.php';
128
129 /**
130 * Trust the Central Server IP addresses in Kadence Security to allow
131 * Central to perform requests to the customer's site
132 *
133 * @param array<int,string> $trusted_ips The IPs to filter.
134 *
135 * @return array<int,string> The filtered Kadence Security trusted IPs.
136 */
137 function solid_central_solid_security_trusted_ips( array $trusted_ips ): array {
138 $trusted_ips[] = '207.246.254.118';
139 $trusted_ips[] = '207.246.255.233';
140 $trusted_ips[] = '207.246.255.133';
141 $trusted_ips[] = '207.246.255.60';
142 return $trusted_ips;
143 }
144 add_filter( 'solid_security_trusted_ips', 'solid_central_solid_security_trusted_ips' );
145
146 /**
147 * Kadence Central login `init` action callback.
148 *
149 * @return false|void
150 */
151 function ithemes_sync_login() {
152 if ( ! empty( $_GET['sync-login'] ) ) {
153 $option = get_option( 'sync_login_' . sanitize_key( $_GET['sync-login'] ) );
154 delete_option( 'sync_login_' . sanitize_key( $_GET['sync-login'] ) );
155 $current_time = time();
156
157 if ( $option['expires'] > $current_time ) {
158 wp_set_current_user( $option['user_id'] );
159 wp_set_auth_cookie( $option['user_id'], false, is_ssl() );
160 }
161
162 if ( ! empty( $option['path'] ) ) {
163 switch ( $option['path'] ) {
164 case 'addpost':
165 if ( empty( $option['path_data'] ) ) {
166 $post_type = 'post';
167 } else {
168 $post_type = $option['path_data'];
169 }
170 $path = 'post-new.php?post_type=' . $option['path_data'];
171 break;
172 case 'editpost':
173 $path = 'post.php?post=' . $option['path_data'] . '&action=edit';
174 break;
175 case 'addpage':
176 $path = 'post-new.php?post_type=page';
177 break;
178 case 'cd':
179 $path = '';
180 add_user_meta( $option['user_id'], 'it-sync-refresh-cd', true );
181 break;
182 default:
183 $path = '';
184 }
185 } else {
186 $path = '';
187 }
188 wp_safe_redirect( admin_url( $path ) );
189 die();
190 }
191 return false;
192 }
193 add_action( 'init', 'ithemes_sync_login' );
194
195 /**
196 * @return void
197 */
198 function ithemes_sync_daily_schedule() {
199 global $wpdb;
200
201 $results = $wpdb->get_results(
202 $wpdb->prepare(
203 "
204 SELECT option_name, option_value
205 FROM $wpdb->options
206 WHERE option_name LIKE %s
207 ",
208 'sync_login_%'
209 )
210 );
211
212 $current_time = time();
213 foreach ( $results as $result ) {
214 $data = maybe_unserialize( $result->option_value );
215 if ( $data['expires'] < $current_time ) {
216 delete_option( $result->option_name );
217 }
218 }
219 }
220 add_action( 'ithemes_sync_daily_schedule', 'ithemes_sync_daily_schedule' );
221
222 /**
223 * @return void
224 */
225 function ithemes_sync_google_site_verification() {
226 $option = get_option( 'ithemes-sync-googst' );
227 if ( ! empty( $option ) ) {
228 echo "\n\n" . esc_html( $option['code'] ) . "\n\n";
229 if ( $option['expiry'] <= time() ) {
230 delete_option( 'ithemes-sync-googst' );
231 }
232 }
233 }
234 add_action( 'wp_head', 'ithemes_sync_google_site_verification' );
235