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_Options_Sync { |
||
| 4 | |||
| 5 | static $options_to_sync = array(); |
||
|
0 ignored issues
–
show
|
|||
| 6 | |||
| 7 | static $sync = array(); |
||
| 8 | static $delete = array(); |
||
| 9 | |||
| 10 | static function init() { |
||
| 11 | |||
| 12 | foreach ( self::$options_to_sync as $option ) { |
||
| 13 | self::init_option( $option ); |
||
| 14 | } |
||
| 15 | } |
||
| 16 | |||
| 17 | static function init_option( $option ) { |
||
| 18 | add_action( "delete_option_{$option}", array( __CLASS__, 'delete_option' ) ); |
||
| 19 | add_action( "update_option_{$option}", array( __CLASS__, 'update_option' ) ); |
||
| 20 | add_action( "add_option_{$option}", array( __CLASS__, 'add_option' ) ); |
||
| 21 | } |
||
| 22 | |||
| 23 | static function init_mock_option( $option, $callback ) { |
||
| 24 | // The mock options get pre-fiexed with jetpack |
||
| 25 | self::init_option( 'jetpack_' . $option ); |
||
| 26 | |||
| 27 | add_filter( 'pre_option_jetpack_'. $option, $callback ); |
||
| 28 | // This shouldn't happen but if it does we return the same as before. |
||
| 29 | add_filter( 'option_jetpack_'. $option, $callback ); |
||
| 30 | } |
||
| 31 | |||
| 32 | static function delete_option( $option ) { |
||
| 33 | self::$delete[] = $option; |
||
| 34 | } |
||
| 35 | |||
| 36 | View Code Duplication | static function update_option() { |
|
| 37 | $option = current_filter(); |
||
| 38 | $prefix = 'update_option_'; |
||
| 39 | if ( 0 !== strpos( $option, $prefix ) ) { |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | $option = substr( $option, strlen( $prefix ) ); |
||
| 43 | self::$sync[] = $option; |
||
| 44 | } |
||
| 45 | |||
| 46 | static function add_option( $option ) { |
||
| 47 | self::$sync[] = $option; |
||
| 48 | } |
||
| 49 | |||
| 50 | static function options_to_delete() { |
||
| 51 | return array_unique( self::$delete ); |
||
| 52 | } |
||
| 53 | |||
| 54 | static function options_to_sync() { |
||
| 55 | return array_unique( self::$sync ); |
||
| 56 | } |
||
| 57 | } |
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.