false, 'skip_unchanged' => true, 'meta_allowlist' => [], ]; public function show(WP_REST_Request $request): WP_REST_Response { unset($request); $stored = get_option(self::OPTION, []); return $this->sendSuccess(self::visible(is_array($stored) ? $stored : [])); } public function update(WP_REST_Request $request): WP_REST_Response { $stored = get_option(self::OPTION, []); if (!is_array($stored)) { $stored = []; } if ($request->has_param('always_push_as_draft')) { $stored['always_push_as_draft'] = (bool) $request->get_param('always_push_as_draft'); } if ($request->has_param('skip_unchanged')) { $stored['skip_unchanged'] = (bool) $request->get_param('skip_unchanged'); } if ($request->has_param('meta_allowlist')) { $keys = MetaAllowlist::cleanKeys((array) $request->get_param('meta_allowlist')); if ($keys instanceof \WP_Error) { return $this->sendError($keys->get_error_message(), 400, $keys->get_error_code()); } $stored['meta_allowlist'] = $keys; } // allow_local is a wp-config constant only, so clear any stray stored value. unset($stored['allow_local']); update_option(self::OPTION, $stored, false); return $this->sendSuccess(self::visible($stored)); } /** * The settings as the screen edits them, with only the meta keys the rule still takes. * * @param array $stored * @return array */ private static function visible(array $stored): array { $settings = array_merge(self::DEFAULTS, $stored); $settings['meta_allowlist'] = MetaAllowlist::listed($settings); return $settings; } }