Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | class Jetpack_Sync_Functions { |
||
| 4 | |||
| 5 | static $functions = array( |
||
| 6 | 'wp_version' => array( 'Jetpack', 'get_wp_version' ), |
||
| 7 | 'wp_max_upload_size' => 'wp_max_upload_size', |
||
| 8 | 'featured_images_enabled' => array( 'Jetpack', 'featured_images_enabled' ), |
||
| 9 | ); |
||
| 10 | |||
| 11 | static $multi_site_functions = array( |
||
| 12 | 'network_name' => array( 'Jetpack', 'network_name' ), |
||
| 13 | 'network_allow_new_registrations' => array( 'Jetpack', 'network_allow_new_registrations' ), |
||
| 14 | 'network_add_new_users' => array( 'Jetpack', 'network_add_new_users' ), |
||
| 15 | 'network_site_upload_space' => array( 'Jetpack', 'network_site_upload_space' ), |
||
| 16 | 'network_upload_file_types' => array( 'Jetpack', 'network_upload_file_types' ), |
||
| 17 | 'network_enable_administration_menus' => array( 'Jetpack', 'network_enable_administration_menus' ), |
||
| 18 | ); |
||
| 19 | |||
| 20 | static $sync = array(); |
||
|
0 ignored issues
–
show
|
|||
| 21 | |||
| 22 | static function init() { |
||
| 23 | if ( is_multisite() ) { |
||
| 24 | self::$functions = array_merge( self::$functions, self::$multi_site_functions ); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | static function sync() { |
||
| 29 | return self::values( self::get_function_to_sync() ); |
||
| 30 | } |
||
| 31 | |||
| 32 | static function register( $key, $function ) { |
||
| 33 | self::$functions[ $key ] = $function; |
||
| 34 | } |
||
| 35 | |||
| 36 | static function trigger_sync( $key ) { |
||
| 37 | self::$sync[] = $key; |
||
| 38 | } |
||
| 39 | |||
| 40 | View Code Duplication | static function sync_sometimes() { |
|
| 41 | // Since there are option in the sync we know that things have changed. |
||
| 42 | if ( ! empty ( self::$sync ) ) { |
||
| 43 | return self::sync_all(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $values = self::values( self::$functions ); |
||
| 47 | $check_sum = self::get_check_sum( $values ); |
||
| 48 | |||
| 49 | if ( Jetpack_Options::get_option( 'function_check_sum' ) !== $check_sum ) { |
||
| 50 | return self::sync_all( $values, $check_sum ); |
||
| 51 | } |
||
| 52 | |||
| 53 | return array(); |
||
| 54 | } |
||
| 55 | |||
| 56 | View Code Duplication | static function sync_all( $values = null, $check_sum = null ) { |
|
| 57 | if ( is_null( $values ) ) { |
||
| 58 | $values = self::values( array_keys( self::$functions ) ); |
||
| 59 | } |
||
| 60 | if ( is_null( $check_sum ) ) { |
||
| 61 | $check_sum = self::get_check_sum( $values ); |
||
| 62 | } |
||
| 63 | Jetpack_Options::update_option( 'function_check_sum', $check_sum ); |
||
| 64 | |||
| 65 | return $values; |
||
| 66 | } |
||
| 67 | |||
| 68 | static function get_check_sum( $values = null ) { |
||
| 69 | if ( is_null( $values ) ) { |
||
| 70 | $values = self::values(); |
||
| 71 | } |
||
| 72 | |||
| 73 | return crc32( self::get_query_string( $values ) ); |
||
| 74 | } |
||
| 75 | |||
| 76 | static function get_query_string( $values ) { |
||
| 77 | return build_query( $values ); |
||
| 78 | } |
||
| 79 | |||
| 80 | static function values( $sync = array() ) { |
||
| 81 | $values = array(); |
||
| 82 | if ( ! empty( $sync ) ) { |
||
| 83 | foreach ( $sync as $key ) { |
||
| 84 | $value = self::get( $key ); |
||
| 85 | if( ! is_null( $value ) ) { |
||
| 86 | $values[ $key ] = $value; |
||
| 87 | } |
||
| 88 | |||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | return $values; |
||
| 93 | } |
||
| 94 | |||
| 95 | static function get_function_to_sync() { |
||
| 96 | return array_unique( self::$sync ); |
||
| 97 | } |
||
| 98 | |||
| 99 | static function get( $key ) { |
||
| 100 | |||
| 101 | if ( is_callable( self::$functions[ $key ] ) ) { |
||
| 102 | return call_user_func( self::$functions[ $key ] ); |
||
| 103 | } |
||
| 104 | |||
| 105 | return null; |
||
| 106 | |||
| 107 | } |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.