'wp_get_settings', 'title' => 'Get site settings', 'group' => 'settings', 'description' => 'Read general, reading, discussion, media and permalink settings.', 'read_only' => true, 'callback' => array( __CLASS__, 'get_settings' ), ) ); MCP100P_Tools::add( array( 'name' => 'wp_update_settings', 'title' => 'Update site settings', 'group' => 'settings', 'description' => 'Update site settings. Pass {"settings": {"option_name": value}}. Writable options: ' . implode( ', ', self::WRITABLE ) . '.', 'input' => array( 'settings' => array( 'type' => 'object', 'description' => 'Map of option name to new value.', ), ), 'required' => array( 'settings' ), 'idempotent' => true, 'callback' => array( __CLASS__, 'update_settings' ), ) ); } public static function get_settings() { if ( ! MCP100P_Server::owner_can( 'manage_options' ) ) { return MCP100P_Util::error( 'You are not allowed to view site settings.' ); } $out = array(); foreach ( self::READABLE as $name ) { $out[ $name ] = get_option( $name ); } return $out; } public static function update_settings( $args ) { if ( ! MCP100P_Server::owner_can( 'manage_options' ) ) { return MCP100P_Util::error( 'You are not allowed to change site settings.' ); } if ( ! is_array( $args['settings'] ) || ! $args['settings'] ) { return MCP100P_Util::error( 'settings must be a non-empty object.' ); } $updated = array(); $rejected = array(); foreach ( $args['settings'] as $name => $value ) { if ( ! in_array( $name, self::WRITABLE, true ) || ! is_scalar( $value ) ) { $rejected[] = $name; continue; } if ( 'timezone_string' === $name && '' !== $value && ! in_array( $value, timezone_identifiers_list(), true ) ) { $rejected[] = $name; continue; } update_option( $name, sanitize_option( $name, $value ) ); $updated[ $name ] = get_option( $name ); } return array( 'updated' => $updated ? $updated : new stdClass(), 'rejected' => $rejected, ); } }