false, 'delete_data_on_uninstall' => false, 'block_rule_cap' => 'edit_posts', 'block_types' => 'all', ); } /** * All settings. * * @return array */ public static function all() { $raw = get_option( self::OPTION, array() ); $raw = is_array( $raw ) ? $raw : array(); return self::sanitize( array_merge( self::defaults(), $raw ) ); } /** * One setting. * * @param string $key Key. * @return mixed */ public static function get( $key ) { $all = self::all(); return isset( $all[ $key ] ) ? $all[ $key ] : null; } /** * Update some settings. * * @param array $changes Changes. */ public static function update( array $changes ) { $all = array_merge( self::all(), $changes ); update_option( self::OPTION, self::sanitize( $all ), true ); } /** * Sanitise. * * @param array $in Input. * @return array */ public static function sanitize( array $in ) { $d = self::defaults(); return array( 'main_query_fix' => ! empty( $in['main_query_fix'] ), 'delete_data_on_uninstall' => ! empty( $in['delete_data_on_uninstall'] ), 'block_rule_cap' => isset( $in['block_rule_cap'] ) && is_string( $in['block_rule_cap'] ) && preg_match( '/^[a-z_]+$/', $in['block_rule_cap'] ) ? $in['block_rule_cap'] : $d['block_rule_cap'], 'block_types' => isset( $in['block_types'] ) && ( 'all' === $in['block_types'] || is_array( $in['block_types'] ) ) ? $in['block_types'] : 'all', ); } }