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 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-defaults.php'; |
||
| 4 | |||
| 5 | class Jetpack_Sync_Settings { |
||
| 6 | const SETTINGS_OPTION_PREFIX = 'jetpack_sync_settings_'; |
||
| 7 | |||
| 8 | static $valid_settings = array( |
||
| 9 | 'dequeue_max_bytes' => true, |
||
| 10 | 'upload_max_bytes' => true, |
||
| 11 | 'upload_max_rows' => true, |
||
| 12 | 'sync_wait_time' => true, |
||
| 13 | 'sync_wait_threshold' => true, |
||
| 14 | 'max_queue_size' => true, |
||
| 15 | 'max_queue_lag' => true, |
||
| 16 | 'queue_max_writes_sec' => true, |
||
| 17 | 'post_types_blacklist' => true, |
||
| 18 | 'disable' => true, |
||
| 19 | 'render_filtered_content' => true, |
||
| 20 | 'post_meta_whitelist' => true, |
||
| 21 | 'comment_meta_whitelist' => true, |
||
| 22 | ); |
||
| 23 | |||
| 24 | static $is_importing; |
||
| 25 | static $is_doing_cron; |
||
| 26 | static $is_syncing; |
||
|
0 ignored issues
–
show
|
|||
| 27 | static $is_sending; |
||
|
0 ignored issues
–
show
The visibility should be declared for property
$is_sending.
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using class A {
var $property;
}
the property is implicitly global. To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2. Loading history...
|
|||
| 28 | |||
| 29 | static $settings_cache = array(); // some settings can be expensive to compute - let's cache them |
||
| 30 | |||
| 31 | static function get_settings() { |
||
| 32 | $settings = array(); |
||
| 33 | foreach ( array_keys( self::$valid_settings ) as $setting ) { |
||
| 34 | $settings[ $setting ] = self::get_setting( $setting ); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $settings; |
||
| 38 | } |
||
| 39 | |||
| 40 | // Fetches the setting. It saves it if the setting doesn't exist, so that it gets |
||
| 41 | // autoloaded on page load rather than re-queried every time. |
||
| 42 | static function get_setting( $setting ) { |
||
| 43 | if ( ! isset( self::$valid_settings[ $setting ] ) ) { |
||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | if ( isset( self::$settings_cache[ $setting ] ) ) { |
||
| 48 | return self::$settings_cache[ $setting ]; |
||
| 49 | } |
||
| 50 | |||
| 51 | $value = get_option( self::SETTINGS_OPTION_PREFIX . $setting ); |
||
| 52 | |||
| 53 | if ( false === $value ) { |
||
| 54 | $default_name = "default_$setting"; // e.g. default_dequeue_max_bytes |
||
| 55 | $value = Jetpack_Sync_Defaults::$$default_name; |
||
| 56 | update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true ); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ( is_numeric( $value ) ) { |
||
| 60 | $value = intval( $value ); |
||
| 61 | } |
||
| 62 | $default_array_value = null; |
||
| 63 | switch( $setting ) { |
||
| 64 | case 'post_types_blacklist': |
||
| 65 | $default_array_value = Jetpack_Sync_Defaults::$blacklisted_post_types; |
||
| 66 | break; |
||
| 67 | case 'post_meta_whitelist': |
||
| 68 | $default_array_value = Jetpack_Sync_Defaults::$post_meta_whitelist; |
||
|
0 ignored issues
–
show
The property
post_meta_whitelist cannot be accessed from this context as it is declared private in class Jetpack_Sync_Defaults.
This check looks for access to properties that are not accessible from the current context. If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class. Loading history...
|
|||
| 69 | break; |
||
| 70 | case 'comment_meta_whitelist': |
||
| 71 | $default_array_value = Jetpack_Sync_Defaults::$comment_meta_whitelist; |
||
|
0 ignored issues
–
show
The property
comment_meta_whitelist cannot be accessed from this context as it is declared private in class Jetpack_Sync_Defaults.
This check looks for access to properties that are not accessible from the current context. If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class. Loading history...
|
|||
| 72 | break; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ( $default_array_value ) { |
||
| 76 | if ( is_array( $value ) ) { |
||
| 77 | $value = array_unique( array_merge( $value, $default_array_value ) ); |
||
| 78 | } else { |
||
| 79 | $value = $default_array_value; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | self::$settings_cache[ $setting ] = $value; |
||
| 84 | |||
| 85 | return $value; |
||
| 86 | } |
||
| 87 | |||
| 88 | static function update_settings( $new_settings ) { |
||
| 89 | $validated_settings = array_intersect_key( $new_settings, self::$valid_settings ); |
||
| 90 | foreach ( $validated_settings as $setting => $value ) { |
||
| 91 | update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true ); |
||
| 92 | unset( self::$settings_cache[ $setting ] ); |
||
| 93 | |||
| 94 | // if we set the disabled option to true, clear the queues |
||
| 95 | if ( 'disable' === $setting && !! $value ) { |
||
| 96 | require_once dirname( __FILE__ ) . '/class.jetpack-sync-listener.php'; |
||
| 97 | $listener = Jetpack_Sync_Listener::get_instance(); |
||
| 98 | $listener->get_sync_queue()->reset(); |
||
| 99 | $listener->get_full_sync_queue()->reset(); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | // returns escapted SQL that can be injected into a WHERE clause |
||
| 105 | static function get_blacklisted_post_types_sql() { |
||
| 106 | return 'post_type NOT IN (\'' . join( '\', \'', array_map( 'esc_sql', self::get_setting( 'post_types_blacklist' ) ) ) . '\')'; |
||
| 107 | } |
||
| 108 | |||
| 109 | static function get_whitelisted_post_meta_sql() { |
||
| 110 | return 'meta_key IN (\'' . join( '\', \'', array_map( 'esc_sql', self::get_setting( 'post_meta_whitelist' ) ) ) . '\')'; |
||
| 111 | } |
||
| 112 | |||
| 113 | static function get_whitelisted_comment_meta_sql() { |
||
| 114 | return 'meta_key IN (\'' . join( '\', \'', array_map( 'esc_sql', self::get_setting( 'comment_meta_whitelist' ) ) ) . '\')'; |
||
| 115 | } |
||
| 116 | |||
| 117 | static function get_comments_filter_sql() { |
||
| 118 | return "comment_approved <> 'spam'"; |
||
| 119 | } |
||
| 120 | |||
| 121 | static function reset_data() { |
||
| 122 | $valid_settings = self::$valid_settings; |
||
| 123 | self::$settings_cache = array(); |
||
| 124 | foreach ( $valid_settings as $option => $value ) { |
||
| 125 | delete_option( self::SETTINGS_OPTION_PREFIX . $option ); |
||
| 126 | } |
||
| 127 | self::set_importing( null ); |
||
| 128 | self::set_doing_cron( null ); |
||
| 129 | self::set_is_syncing( null ); |
||
| 130 | self::set_is_sending( null ); |
||
| 131 | } |
||
| 132 | |||
| 133 | static function set_importing( $is_importing ) { |
||
| 134 | // set to NULL to revert to WP_IMPORTING, the standard behaviour |
||
| 135 | self::$is_importing = $is_importing; |
||
| 136 | } |
||
| 137 | |||
| 138 | static function is_importing() { |
||
| 139 | if ( ! is_null( self::$is_importing ) ) { |
||
| 140 | return self::$is_importing; |
||
| 141 | } |
||
| 142 | |||
| 143 | return defined( 'WP_IMPORTING' ) && WP_IMPORTING; |
||
| 144 | } |
||
| 145 | |||
| 146 | static function set_doing_cron( $is_doing_cron ) { |
||
| 147 | // set to NULL to revert to WP_IMPORTING, the standard behaviour |
||
| 148 | self::$is_doing_cron = $is_doing_cron; |
||
| 149 | } |
||
| 150 | |||
| 151 | static function is_doing_cron() { |
||
| 152 | if ( ! is_null( self::$is_doing_cron ) ) { |
||
| 153 | return self::$is_doing_cron; |
||
| 154 | } |
||
| 155 | |||
| 156 | return defined( 'DOING_CRON' ) && DOING_CRON; |
||
| 157 | } |
||
| 158 | |||
| 159 | static function is_syncing() { |
||
| 160 | return (bool) self::$is_syncing; |
||
| 161 | } |
||
| 162 | |||
| 163 | static function set_is_syncing( $is_syncing ) { |
||
| 164 | self::$is_syncing = $is_syncing; |
||
| 165 | } |
||
| 166 | |||
| 167 | static function is_sending() { |
||
| 168 | return (bool) self::$is_sending; |
||
| 169 | } |
||
| 170 | |||
| 171 | static function set_is_sending( $is_sending ) { |
||
| 172 | self::$is_sending = $is_sending; |
||
| 173 | } |
||
| 174 | } |
||
| 175 |
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.