options_helper = $options_helper; } /** * Enables or disables the feature behind the given option and returns its new status. * * @param string $option_name The name of the boolean option that enables the feature. * @param array $input The input holding the desired `enabled` status. * * @return array|WP_Error The new status, or an error when the input is invalid or the status could not be saved. */ public function set_status( string $option_name, array $input ) { if ( ! isset( $input['enabled'] ) || ! \is_bool( $input['enabled'] ) ) { return new WP_Error( 'yoast_seo_feature_status_invalid_input', \__( 'The enabled status is required and must be a boolean.', 'wordpress-seo' ), [ 'status' => 400 ], ); } $enabled = $input['enabled']; if ( $this->options_helper->set( $option_name, $enabled ) !== true ) { return new WP_Error( 'yoast_seo_feature_status_not_saved', \__( 'The feature status could not be saved.', 'wordpress-seo' ), [ 'status' => 500 ], ); } return [ 'enabled' => $enabled ]; } }