*/ public static function defaults() { return array( 'package_lookup' => '', 'beside' => false, 'onboarded' => false, 'keep_data' => true, ); } /** * All settings, with defaults filled in. * * @return array */ public static function all() { $saved = get_option( self::OPTION, array() ); $out = self::defaults(); if ( is_array( $saved ) ) { if ( isset( $saved['package_lookup'] ) && in_array( $saved['package_lookup'], array( 'yes', 'no' ), true ) ) { $out['package_lookup'] = $saved['package_lookup']; } $out['onboarded'] = ! empty( $saved['onboarded'] ); $out['keep_data'] = array_key_exists( 'keep_data', $saved ) ? ! empty( $saved['keep_data'] ) : true; // Settings saved by an older release have "intercept" but no "beside": they keep the buttons beside Install Now. $out['beside'] = array_key_exists( 'beside', $saved ) ? ! empty( $saved['beside'] ) : ( array_key_exists( 'intercept', $saved ) ? true : $out['beside'] ); // "Review every install" (intercept) replaced Install Now. It was retired in 1.0.1: those sites get the button beside it. $out['beside'] = $out['beside'] || ! empty( $saved['intercept'] ); } return $out; } /** * One setting. * * @param string $key Setting name. * @return mixed */ public static function get( $key ) { $all = self::all(); return $all[ $key ] ?? null; } /** * Change settings. Unknown keys and invalid values are ignored. * * @param array $changes Values to set. */ public static function update( array $changes ) { $now = self::all(); if ( isset( $changes['package_lookup'] ) && in_array( $changes['package_lookup'], array( 'yes', 'no' ), true ) ) { $now['package_lookup'] = $changes['package_lookup']; } if ( array_key_exists( 'beside', $changes ) ) { $now['beside'] = (bool) $changes['beside']; } if ( array_key_exists( 'keep_data', $changes ) ) { $now['keep_data'] = (bool) $changes['keep_data']; } if ( array_key_exists( 'onboarded', $changes ) ) { $now['onboarded'] = (bool) $changes['onboarded']; } update_option( self::OPTION, $now, false ); } /** * A review control (beside Install Now, on the upload form, on updates) is on only after * the administrator has finished the first-run choices. The defaults alone never add it. * * @param string $key beside. * @return bool */ public static function active( $key ) { return (bool) self::get( 'onboarded' ) && (bool) self::get( $key ); } }