*/ public static function schema() { return array( 'hide_unused' => array( 'type' => 'bool', 'default' => false, 'description' => 'Hide switched-off features from the settings screen nav. Same as the "Hide unused features" switch.', ), // Off by default: deleting the plugin keeps its data, so a delete done to reinstall or // by mistake loses nothing. uninstall.php reads this straight from the option, since // the plugin is not loaded when WordPress runs it. 'delete_data' => array( 'type' => 'bool', 'default' => false, 'panel' => true, 'description' => 'Delete all Adminkeep data (settings, CSS, code, the email log, redirects) when the plugin is deleted. Off keeps it.', ), ); } /** * Keys the Plugin settings panel shows and saves. * * @return string[] */ public static function panel_keys() { return array_keys( array_filter( self::schema(), static function ( $spec ) { return ! empty( $spec['panel'] ); } ) ); } /** * Every setting, resolved against its default. * * @return array */ public static function all() { $stored = Settings::get( self::KEY ); $values = array(); foreach ( self::schema() as $key => $spec ) { $values[ $key ] = array_key_exists( $key, $stored ) ? $stored[ $key ] : $spec['default']; } return $values; } /** * One setting. * * @param string $key Setting key. * @return mixed Its value, or null for an unknown key. */ public static function get( $key ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : null; } /** * Change one or more settings; everything not named is kept. The one writer for this key. * * Values are stored typed and only when they differ from the default, so an untouched * install carries no `_plugin` entry at all. * * @param array $changes Key => typed value. Unknown keys are ignored. * @return void */ public static function set( array $changes ) { $schema = self::schema(); $stored = Settings::get( self::KEY ); foreach ( $changes as $key => $value ) { if ( ! isset( $schema[ $key ] ) ) { continue; } if ( $value === $schema[ $key ]['default'] ) { unset( $stored[ $key ] ); } else { $stored[ $key ] = $value; } } Settings::update( self::KEY, $stored ); } }