Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jetpack_Beta often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jetpack_Beta, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Jetpack_Beta { |
||
17 | |||
18 | /** |
||
19 | * Singleton Jetpack_Beta class instance. |
||
20 | * |
||
21 | * @var Jetpack_Beta |
||
22 | */ |
||
23 | protected static $instance = null; |
||
24 | |||
25 | /** |
||
26 | * WP Options string: jetpack_beta_active |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected static $option = 'jetpack_beta_active'; |
||
31 | |||
32 | /** |
||
33 | * WP Options string: jetpack_beta_dev_currently_installed |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected static $option_dev_installed = 'jetpack_beta_dev_currently_installed'; |
||
38 | |||
39 | /** |
||
40 | * WP Options string: jp_beta_autoupdate |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected static $option_autoupdate = 'jp_beta_autoupdate'; |
||
45 | |||
46 | /** |
||
47 | * WP Options string: jp_beta_email_notifications |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected static $option_email_notif = 'jp_beta_email_notifications'; |
||
52 | |||
53 | /** |
||
54 | * WP-Cron string: jetpack_beta_autoupdate_hourly_cron |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected static $auto_update_cron_hook = 'jetpack_beta_autoupdate_hourly_cron'; |
||
59 | |||
60 | /** |
||
61 | * Main Instance |
||
62 | */ |
||
63 | public static function instance() { |
||
70 | |||
71 | /** |
||
72 | * Constructor |
||
73 | */ |
||
74 | public function __construct() { |
||
75 | add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'maybe_plugins_update_transient' ) ); |
||
76 | add_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 3 ); |
||
77 | |||
78 | add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ) ); |
||
79 | add_action( 'deactivate_plugin', array( $this, 'plugin_deactivated' ), 10, 2 ); |
||
80 | |||
81 | add_action( 'upgrader_process_complete', array( $this, 'upgrader_process_complete' ), 10, 2 ); |
||
82 | |||
83 | add_filter( 'plugin_action_links_' . JETPACK_PLUGIN_FILE, array( $this, 'remove_activate_stable' ) ); |
||
84 | add_filter( 'plugin_action_links_' . JETPACK_DEV_PLUGIN_FILE, array( $this, 'remove_activate_dev' ) ); |
||
85 | |||
86 | add_filter( 'network_admin_plugin_action_links_' . JETPACK_PLUGIN_FILE, array( $this, 'remove_activate_stable' ) ); |
||
87 | add_filter( 'network_admin_plugin_action_links_' . JETPACK_DEV_PLUGIN_FILE, array( $this, 'remove_activate_dev' ) ); |
||
88 | |||
89 | add_filter( 'all_plugins', array( $this, 'update_all_plugins' ) ); |
||
90 | |||
91 | add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 ); |
||
92 | |||
93 | add_action( 'jetpack_beta_autoupdate_hourly_cron', array( 'Jetpack_Beta', 'run_autoupdate' ) ); |
||
94 | |||
95 | add_filter( 'jetpack_options_whitelist', array( $this, 'add_to_options_whitelist' ) ); |
||
96 | |||
97 | if ( is_admin() ) { |
||
98 | require JPBETA__PLUGIN_DIR . 'class-jetpack-beta-admin.php'; |
||
99 | self::maybe_schedule_autoupdate(); |
||
100 | Jetpack_Beta_Admin::init(); |
||
101 | } |
||
102 | |||
103 | $current_version = $this->get_branch_and_section(); |
||
104 | self::update_autoload_dev_constant( $current_version[1] ); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Fired when the upgrader process is complete; sets option jetpack_beta_dev_currently_installed |
||
109 | * |
||
110 | * @param WP_Upgrader $upgrader - An upgrader instance. |
||
111 | * @param array $updates_completed - Array of bulk item update data. |
||
112 | */ |
||
113 | public function upgrader_process_complete( $upgrader, $updates_completed ) { |
||
114 | if ( ! isset( $updates_completed['plugins'] ) ) { |
||
115 | return; |
||
116 | } |
||
117 | |||
118 | if ( 'update' === $updates_completed['action'] && |
||
119 | 'plugin' === $updates_completed['type'] && |
||
120 | in_array( JETPACK_DEV_PLUGIN_FILE, $updates_completed['plugins'], true ) ) { |
||
121 | list( $branch, $section ) = self::get_branch_and_section_dev(); |
||
122 | if ( self::should_update_dev_to_master() ) { |
||
123 | list( $branch, $section ) = array( 'master', 'master' ); |
||
124 | } |
||
125 | update_option( self::$option_dev_installed, array( $branch, $section, self::get_manifest_data( $branch, $section ) ) ); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * If Jetpack or JP Dev plugin is network activated, update active_plugins option. |
||
131 | */ |
||
132 | public static function is_network_enabled() { |
||
133 | if ( self::is_network_active() ) { |
||
134 | add_filter( 'option_active_plugins', array( 'Jetpack_Beta', 'override_active_plugins' ) ); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * This filter is only applied if Jetpack is network activated, |
||
140 | * makes sure that you can't have Jetpack or Jetpack Dev plugins versions loaded. |
||
141 | * |
||
142 | * @param array $active_plugins - Currently activated plugins. |
||
143 | * |
||
144 | * @return array Updated array of active plugins. |
||
145 | */ |
||
146 | public static function override_active_plugins( $active_plugins ) { |
||
147 | $new_active_plugins = array(); |
||
148 | foreach ( $active_plugins as $active_plugin ) { |
||
149 | if ( ! self::is_jetpack_plugin( $active_plugin ) ) { |
||
150 | $new_active_plugins[] = $active_plugin; |
||
151 | } |
||
152 | } |
||
153 | return $new_active_plugins; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Actions taken when the Jetpack Beta plugin is deactivated. |
||
158 | * |
||
159 | * @param string $plugin - Plugin path being deactivated. |
||
160 | */ |
||
161 | public function plugin_deactivated( $plugin ) { |
||
162 | if ( ! self::is_jetpack_plugin( $plugin ) ) { |
||
163 | return; |
||
164 | } |
||
165 | |||
166 | delete_option( self::$option ); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Checks if passed plugin matches JP or JP Dev paths. |
||
171 | * |
||
172 | * @param string $plugin - A plugin path. |
||
173 | */ |
||
174 | public static function is_jetpack_plugin( $plugin ) { |
||
175 | return in_array( $plugin, array( JETPACK_PLUGIN_FILE, JETPACK_DEV_PLUGIN_FILE ), true ); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Filter JP Dev plugin action links. |
||
180 | * |
||
181 | * @param array $actions - Array of plugin action links. |
||
182 | */ |
||
183 | public function remove_activate_dev( $actions ) { |
||
184 | View Code Duplication | if ( is_plugin_active( JETPACK_PLUGIN_FILE ) || self::is_network_active() ) { |
|
185 | $actions['activate'] = __( 'Plugin Already Active', 'jetpack-beta' ); |
||
186 | } |
||
187 | return $actions; |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Filter JP Stable plugin action links. |
||
192 | * |
||
193 | * @param array $actions - Array of plugin action links. |
||
194 | */ |
||
195 | public function remove_activate_stable( $actions ) { |
||
196 | View Code Duplication | if ( is_plugin_active( JETPACK_DEV_PLUGIN_FILE ) || self::is_network_active() ) { |
|
197 | $actions['activate'] = __( 'Plugin Already Active', 'jetpack-beta' ); |
||
198 | } |
||
199 | return $actions; |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Filters plugins to list in the Plugins list table. |
||
204 | * |
||
205 | * @param array $plugins - Array of arrays of plugin data. |
||
206 | * |
||
207 | * @return array Updated array of plugin data. |
||
208 | */ |
||
209 | public function update_all_plugins( $plugins ) { |
||
210 | // WP.com requests away show regular plugin. |
||
211 | if ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) { |
||
212 | // Ensure that Jetpack reports the version it's using on account of the Jetpack Beta plugin to Calypso. |
||
213 | if ( is_plugin_active( JETPACK_DEV_PLUGIN_FILE ) ) { |
||
214 | $plugins[ JETPACK_PLUGIN_FILE ]['Version'] = $plugins[ JETPACK_DEV_PLUGIN_FILE ]['Version']; |
||
215 | } |
||
216 | unset( $plugins[ JETPACK_DEV_PLUGIN_FILE ] ); |
||
217 | return $plugins; |
||
218 | } |
||
219 | |||
220 | if ( is_plugin_active( JETPACK_DEV_PLUGIN_FILE ) ) { |
||
221 | unset( $plugins[ JETPACK_PLUGIN_FILE ] ); |
||
222 | } else { |
||
223 | unset( $plugins[ JETPACK_DEV_PLUGIN_FILE ] ); |
||
224 | } |
||
225 | return $plugins; |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Filter WordPress.org Plugins API results. |
||
230 | * |
||
231 | * @param false|object|array $false - The result object or array. Default false. |
||
232 | * @param string $action - The type of information being requested from the Plugin Installation API. |
||
233 | * @param object $response - Plugin API arguments. |
||
234 | */ |
||
235 | public function get_plugin_info( $false, $action, $response ) { |
||
236 | |||
237 | // Check if this call API is for the right plugin. |
||
238 | if ( ! isset( $response->slug ) || JETPACK_DEV_PLUGIN_SLUG !== $response->slug ) { |
||
239 | return false; |
||
240 | } |
||
241 | $update_date = null; |
||
242 | $download_zip = null; |
||
243 | $dev_data = self::get_dev_installed(); |
||
244 | if ( isset( $dev_data[2] ) ) { |
||
245 | $update_date = $dev_data[2]->update_date; |
||
246 | $download_zip = $dev_data[2]->download_url; |
||
247 | } |
||
248 | // Update tags. |
||
249 | $response->slug = JETPACK_DEV_PLUGIN_SLUG; |
||
250 | $response->plugin = JETPACK_DEV_PLUGIN_SLUG; |
||
251 | $response->name = 'Jetpack | ' . self::get_jetpack_plugin_pretty_version( true ); |
||
252 | $response->plugin_name = 'Jetpack | ' . self::get_jetpack_plugin_pretty_version( true ); |
||
253 | $response->version = self::get_jetpack_plugin_version( true ); |
||
254 | $response->author = 'Automattic'; |
||
255 | $response->homepage = 'https://jetpack.com/contact-support/beta-group/'; |
||
256 | $response->downloaded = false; |
||
257 | $response->last_updated = $update_date; |
||
258 | $response->sections = array( 'description' => Jetpack_Beta_Admin::to_test_content() ); |
||
259 | $response->download_link = $download_zip; |
||
260 | return $response; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * Run on activation to flush update cache. |
||
265 | */ |
||
266 | public static function activate() { |
||
267 | // Don't do anyting funnly. |
||
268 | if ( defined( 'DOING_CRON' ) ) { |
||
269 | return; |
||
270 | } |
||
271 | delete_site_transient( 'update_plugins' ); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Returns active Jetpack plugin file partial path string (jetpack/jetpack.php|jetpack-dev/jetpack.php). |
||
276 | */ |
||
277 | public static function get_plugin_file() { |
||
278 | return self::get_plugin_slug() . '/jetpack.php'; |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * Returns active plugin slug string (jetpack|jetpack-dev). |
||
283 | */ |
||
284 | View Code Duplication | public static function get_plugin_slug() { |
|
285 | $installed = self::get_branch_and_section(); |
||
286 | if ( empty( $installed ) || 'stable' === $installed[1] || 'tags' === $installed[1] ) { |
||
287 | return 'jetpack'; |
||
288 | } |
||
289 | return JETPACK_DEV_PLUGIN_SLUG; |
||
290 | } |
||
291 | |||
292 | /** |
||
293 | * Handler ran for Jetpack Beta plugin deactivation hook. |
||
294 | */ |
||
295 | public static function deactivate() { |
||
296 | // Don't do anyting funnly. |
||
297 | if ( defined( 'DOING_CRON' ) ) { |
||
298 | return; |
||
299 | } |
||
300 | |||
301 | self::clear_autoupdate_cron(); |
||
302 | self::delete_all_transiants(); |
||
303 | add_action( 'shutdown', array( __CLASS__, 'switch_active' ), 5 ); |
||
304 | add_action( 'shutdown', array( __CLASS__, 'remove_dev_plugin' ), 20 ); |
||
305 | delete_option( self::$option ); |
||
306 | delete_option( 'jetpack_autoload_dev' ); |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * When Jetpack Beta plugin is deactivated, remove the jetpack-dev plugin directory and cleanup. |
||
311 | */ |
||
312 | public static function remove_dev_plugin() { |
||
337 | |||
338 | /** |
||
339 | * Builds URL to the admin area for the current site and specified query param. |
||
340 | * |
||
341 | * @param string $query - Path relative to the admin URL. |
||
342 | */ |
||
343 | public static function admin_url( $query = '?page=jetpack-beta' ) { |
||
348 | |||
349 | /** |
||
350 | * Build the "Jetpack Beta" admin bar menu items. |
||
351 | */ |
||
352 | public function admin_bar_menu() { |
||
406 | |||
407 | /** |
||
408 | * Filters `update_plugins` transient. |
||
409 | * |
||
410 | * @param object $transient - Plugin update data. |
||
411 | */ |
||
412 | public function maybe_plugins_update_transient( $transient ) { |
||
450 | |||
451 | /** |
||
452 | * Determine if JP dev version should be updated. |
||
453 | */ |
||
454 | public static function should_update_dev_version() { |
||
457 | |||
458 | /** |
||
459 | * Build plugin update data response for dev plugin. |
||
460 | */ |
||
461 | public static function get_jepack_dev_update_response() { |
||
471 | |||
472 | /** |
||
473 | * Build plugin update data response for JP dev master. |
||
474 | */ |
||
475 | public static function get_jepack_dev_master_update_response() { |
||
484 | |||
485 | /** |
||
486 | * Moves the newly downloaded folder into jetpack-dev. |
||
487 | * |
||
488 | * @param bool $worked - Installation response. |
||
489 | * @param array $hook_extras - Extra args passed to hooked filters. |
||
490 | * @param array $result - Installation result data. |
||
491 | * |
||
492 | * @return WP_Error |
||
493 | */ |
||
494 | public function upgrader_post_install( $worked, $hook_extras, $result ) { |
||
510 | |||
511 | /** |
||
512 | * Get the active JP or JP Dev plugin version. |
||
513 | * |
||
514 | * @param bool $is_dev_version - If dev plugin version is being queried. |
||
515 | * |
||
516 | * @return string|0 Plugin version. |
||
|
|||
517 | */ |
||
518 | public static function get_jetpack_plugin_version( $is_dev_version = false ) { |
||
527 | |||
528 | /** |
||
529 | * Get WP Option: jetpack_beta_active |
||
530 | */ |
||
531 | public static function get_option() { |
||
534 | |||
535 | /** |
||
536 | * Get WP Option: jetpack_beta_dev_currently_installed |
||
537 | */ |
||
538 | public static function get_dev_installed() { |
||
541 | |||
542 | /** |
||
543 | * Get active Jetpack branch/section. |
||
544 | */ |
||
545 | public static function get_branch_and_section() { |
||
546 | $option = (array) self::get_option(); |
||
547 | if ( false === $option[0] ) { |
||
548 | // See if the Jetpack plugin is enabled. |
||
549 | if ( ! function_exists( 'is_plugin_active' ) ) { |
||
550 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
||
551 | } |
||
552 | if ( is_plugin_active( JETPACK_PLUGIN_FILE ) ) { |
||
553 | return array( 'stable', 'stable' ); |
||
554 | } |
||
555 | return array( false, false ); |
||
560 | |||
561 | /** |
||
562 | * Check if Jetpack version is 'stable' version. |
||
563 | */ |
||
564 | View Code Duplication | public static function is_on_stable() { |
|
571 | |||
572 | /** |
||
573 | * Check if Jetpack active version is a tag version. |
||
574 | */ |
||
575 | public static function is_on_tag() { |
||
582 | |||
583 | /** |
||
584 | * Get active Jetpack Dev branch/section. |
||
585 | */ |
||
586 | public static function get_branch_and_section_dev() { |
||
596 | |||
597 | /** |
||
598 | * Massage JP plugin version string. |
||
599 | * |
||
600 | * @param bool $is_dev_version - If JP Dev version is being queried. |
||
601 | */ |
||
602 | public static function get_jetpack_plugin_pretty_version( $is_dev_version = false ) { |
||
640 | |||
641 | /** |
||
642 | * Fetch latest Jetpack version. |
||
643 | * |
||
644 | * @param bool $is_dev_version - If JP Dev version is being queried. |
||
645 | */ |
||
646 | public static function get_new_jetpack_version( $is_dev_version = false ) { |
||
670 | |||
671 | /** |
||
672 | * Get JP Dev plugin repo URL. |
||
673 | */ |
||
674 | public static function get_url_dev() { |
||
678 | |||
679 | /** |
||
680 | * Get JP plugin repo URL. |
||
681 | * |
||
682 | * @param string $branch - Branch. |
||
683 | * @param string $section - Section. |
||
684 | */ |
||
685 | public static function get_url( $branch = null, $section = null ) { |
||
706 | |||
707 | /** |
||
708 | * Get install URL for JP dev. |
||
709 | */ |
||
710 | public static function get_install_url_dev() { |
||
714 | |||
715 | /** |
||
716 | * Get install URL for JP. |
||
717 | * |
||
718 | * @param string $branch - Branch. |
||
719 | * @param string $section - Section. |
||
720 | */ |
||
721 | public static function get_install_url( $branch = null, $section = null ) { |
||
757 | |||
758 | /** |
||
759 | * Get stable JP version plugin data. |
||
760 | */ |
||
761 | public static function get_jetpack_plugin_info_stable() { |
||
764 | |||
765 | /** |
||
766 | * Get dev JP version plugin data. |
||
767 | */ |
||
768 | public static function get_jetpack_plugin_info_dev() { |
||
771 | |||
772 | /** |
||
773 | * Get JP plugin data. |
||
774 | * |
||
775 | * @param mixed $plugin_file - JP or JP Dev plugin path. |
||
776 | */ |
||
777 | public static function get_jetpack_plugin_info( $plugin_file = null ) { |
||
794 | |||
795 | /** |
||
796 | * Switch active JP plugin version when JP Beta plugin is deactivated. |
||
797 | * This needs to happen on `shutdown`, otherwise it doesn't work. |
||
798 | */ |
||
799 | public static function switch_active() { |
||
802 | |||
803 | /** |
||
804 | * Fetch the Jetpack beta manifest. |
||
805 | * |
||
806 | * @param bool $force_refresh - Whether to bypass cached response. |
||
807 | */ |
||
808 | public static function get_beta_manifest( $force_refresh = false ) { |
||
811 | |||
812 | /** |
||
813 | * Fetch WordPress.org Jetpack plugin info. |
||
814 | */ |
||
815 | public static function get_org_data() { |
||
818 | |||
819 | /** |
||
820 | * Helper function used to fetch remote data from WordPress.org, GitHub, and betadownload.jetpack.me |
||
821 | * |
||
822 | * @param string $url - Url being fetched. |
||
823 | * @param string $transient - Transient name (manifest|org_data|github_commits_). |
||
824 | * @param bool $bypass - Whether to bypass cached response. |
||
825 | */ |
||
826 | public static function get_remote_data( $url, $transient, $bypass = false ) { |
||
844 | |||
845 | /** |
||
846 | * Delete set transients when plugin is deactivated. |
||
847 | */ |
||
848 | public static function delete_all_transiants() { |
||
857 | |||
858 | /** |
||
859 | * Install & activate JP for the given branch/section. |
||
860 | * |
||
861 | * @param string $branch - Branch. |
||
862 | * @param string $section - Section. |
||
863 | */ |
||
864 | public static function install_and_activate( $branch, $section ) { |
||
911 | |||
912 | /** |
||
913 | * Update to the latest version. |
||
914 | * |
||
915 | * @param string $branch - Branch. |
||
916 | * @param string $section - Section. |
||
917 | */ |
||
918 | public static function update_plugin( $branch, $section ) { |
||
929 | |||
930 | /** |
||
931 | * Helper function to update installed version option. |
||
932 | * |
||
933 | * @param string $branch - Branch. |
||
934 | * @param string $section - Section. |
||
935 | */ |
||
936 | public static function update_option( $branch, $section ) { |
||
942 | |||
943 | /** |
||
944 | * Return manifest info for specififed branch/section. |
||
945 | * |
||
946 | * @param string $branch - Branch. |
||
947 | * @param string $section - Section. |
||
948 | */ |
||
949 | public static function get_manifest_data( $branch, $section ) { |
||
973 | |||
974 | /** |
||
975 | * Install specified plugin version. |
||
976 | * |
||
977 | * @param string $url - Url for plugin version. |
||
978 | * @param string $plugin_folder - Path JP or JP Dev plugin folder. |
||
979 | * @param string $section - Section. |
||
980 | */ |
||
981 | public static function proceed_to_install_and_activate( $url, $plugin_folder, $section ) { |
||
990 | |||
991 | /** |
||
992 | * Download plugin files. |
||
993 | * |
||
994 | * @param string $url - Url for plugin version. |
||
995 | * @param string $plugin_folder - Path JP or JP Dev plugin folder. |
||
996 | * @param string $section - Section. |
||
997 | */ |
||
998 | public static function proceed_to_install( $url, $plugin_folder, $section ) { |
||
1027 | |||
1028 | /** |
||
1029 | * Check if plugin is network activated. |
||
1030 | */ |
||
1031 | public static function is_network_active() { |
||
1046 | |||
1047 | /** |
||
1048 | * Swap plugin files. |
||
1049 | * |
||
1050 | * @param string $current_plugin - Current plugin path. |
||
1051 | * @param string $replace_with_plugin - Plugin path to replace with. |
||
1052 | * @param bool $force_activate - Whether to force activate plguin. |
||
1053 | */ |
||
1054 | public static function replace_active_plugin( $current_plugin, $replace_with_plugin = null, $force_activate = false ) { |
||
1085 | |||
1086 | /** |
||
1087 | * Check if `stable` should be updated. |
||
1088 | * |
||
1089 | * @return bool |
||
1090 | */ |
||
1091 | public static function should_update_stable_version() { |
||
1123 | |||
1124 | /** |
||
1125 | * Here we are checking if the DEV branch that we are currenly on is not something that is available in the manifest |
||
1126 | * Meaning that the DEV branch was merged into master and so we need to update it. |
||
1127 | * |
||
1128 | * @return bool |
||
1129 | */ |
||
1130 | public static function should_update_dev_to_master() { |
||
1139 | |||
1140 | /** |
||
1141 | * Get WP Option: jp_beta_autoupdate |
||
1142 | */ |
||
1143 | public static function is_set_to_autoupdate() { |
||
1146 | |||
1147 | /** |
||
1148 | * Get WP Option: jp_beta_email_notifications |
||
1149 | */ |
||
1150 | public static function is_set_to_email_notifications() { |
||
1153 | |||
1154 | /** |
||
1155 | * Clear scheduled WP-Cron jobs on plugin deactivation. |
||
1156 | */ |
||
1157 | public static function clear_autoupdate_cron() { |
||
1167 | |||
1168 | /** |
||
1169 | * Schedule plugin update jobs. |
||
1170 | */ |
||
1171 | public static function schedule_hourly_autoupdate() { |
||
1175 | |||
1176 | /** |
||
1177 | * Determine if plugin update jobs should be scheduled. |
||
1178 | */ |
||
1179 | public static function maybe_schedule_autoupdate() { |
||
1192 | |||
1193 | /** |
||
1194 | * Get "What changed" info for display. |
||
1195 | * |
||
1196 | * @return string|false |
||
1197 | */ |
||
1198 | public static function what_changed() { |
||
1234 | |||
1235 | /** |
||
1236 | * Get version commit if available. |
||
1237 | * |
||
1238 | * @return string|false |
||
1239 | */ |
||
1240 | public static function get_version_commit() { |
||
1247 | |||
1248 | /** |
||
1249 | * Fetch commit data from GitHub. |
||
1250 | * |
||
1251 | * @param string $commit - The commit to fetch. |
||
1252 | */ |
||
1253 | public static function get_commit_data_from_github( $commit ) { |
||
1256 | |||
1257 | /** |
||
1258 | * The jetpack_beta_autoupdate_hourly_cron job - does not update Stable. |
||
1259 | */ |
||
1260 | public static function run_autoupdate() { |
||
1318 | |||
1319 | /** |
||
1320 | * Builds and sends an email about succesfull plugin autoupdate. |
||
1321 | * |
||
1322 | * @param Array $plugins - List of plugins that were updated. |
||
1323 | * @param String $log - Upgrade message from core's plugin upgrader. |
||
1324 | */ |
||
1325 | private static function send_autoupdate_email( $plugins, $log ) { |
||
1402 | |||
1403 | /** |
||
1404 | * This checks intends to fix errors in our build server when Jetpack. |
||
1405 | * |
||
1406 | * @param string $source - Source path. |
||
1407 | * @param string $remote_source - Remote path. |
||
1408 | * |
||
1409 | * @return WP_Error |
||
1410 | */ |
||
1411 | public static function check_for_main_files( $source, $remote_source ) { |
||
1431 | |||
1432 | /** |
||
1433 | * Checks if a dir is empty. |
||
1434 | * |
||
1435 | * @param [type] $dir The absolute directory path to check. |
||
1436 | * @return boolean |
||
1437 | */ |
||
1438 | public static function is_dir_empty( $dir ) { |
||
1441 | |||
1442 | /** |
||
1443 | * Callback function to include Jetpack beta options into Jetpack sync whitelist. |
||
1444 | * |
||
1445 | * @param Array $whitelist List of whitelisted options to sync. |
||
1446 | */ |
||
1447 | public function add_to_options_whitelist( $whitelist ) { |
||
1454 | |||
1455 | /** |
||
1456 | * Custom error handler to intercept errors and log them using Jetpack's own logger. |
||
1457 | * |
||
1458 | * @param int $errno - Error code. |
||
1459 | * @param string $errstr - Error message. |
||
1460 | * @param string $errfile - File name where the error happened. |
||
1461 | * @param int $errline - Line in the code. |
||
1462 | * |
||
1463 | * @return bool Whether to make the default handler handle the error as well. |
||
1464 | */ |
||
1465 | public static function custom_error_handler( $errno, $errstr, $errfile, $errline ) { |
||
1490 | |||
1491 | /** |
||
1492 | * Clears the autoloader transient. |
||
1493 | */ |
||
1494 | public static function clear_autoloader_plugin_cache() { |
||
1497 | |||
1498 | /** |
||
1499 | * Sets the 'jetpack_autoload_dev' option when a Jetpack version is activated: |
||
1500 | * - Sets the option to true when a development version of Jetpack is activated. |
||
1501 | * - Sets the option to false when the stable or release candidate version is activated. |
||
1502 | * |
||
1503 | * This option is used to set the JETPACK_AUTOLOAD_DEV constant in jetpack-beta.php. The constant |
||
1504 | * is used by the Jetpack autoloader to determine whether stable or development versions of |
||
1505 | * packages should be preferred. |
||
1506 | * |
||
1507 | * @param string $section The section value for the activating Jetpack version. |
||
1508 | */ |
||
1509 | public static function update_autoload_dev_constant( $section ) { |
||
1517 | } |
||
1518 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.