all() ); } array_walk( $redirects, [ $this, 'map_object_to_option' ] ); /** * Filter: 'Yoast\WP\SEO\save_redirects' - can be used to filter the redirects before saving. * * Note: This is a Premium plugin-only hook. * * @since 12.9.0 * * @param array $redirects */ $redirects = apply_filters( 'Yoast\WP\SEO\save_redirects', $redirects ); // Update the database option. update_option( self::OPTION, $redirects, false ); } /** * Setting the redirects property. * * @param string $option_name The target option name. * * @return array */ public function get_from_option( $option_name = self::OPTION ) { $redirects = get_option( $option_name ); /** * Filter: 'Yoast\WP\SEO\get_redirects' - can be used to filter the redirects on option retrieval. * * Note: This is a Premium plugin-only hook. * * @since 12.9.0 * * @param array $redirects */ $redirects = apply_filters( 'Yoast\WP\SEO\get_redirects', $redirects ); if ( ! is_array( $redirects ) ) { $redirects = []; } return $redirects; } /** * Runs the redirects modified hook with the altered redirect as input. * * @param WPSEO_Redirect $redirect The redirect that has been altered. * * @return void */ protected function run_redirects_modified_action( WPSEO_Redirect $redirect ) { /** * Filter: Yoast\WP\SEO\redirects_modified - Allow developers to run actions when the redirects are modified. * * Note: This is a Premium plugin-only hook. * * @since 12.9.0 * * @param string $origin The redirect origin. * @param string $target The redirect target. * @param int $type The redirect type (301, 404, 410, etc). */ do_action( 'Yoast\WP\SEO\redirects_modified', $redirect->get_origin(), $redirect->get_target(), $redirect->get_type() ); } /** * Maps the array values to a redirect object. * * @param array $redirect_values The data for the redirect option. * * @return void */ private function map_option_to_object( array &$redirect_values ) { $redirect_values = new WPSEO_Redirect( $redirect_values['origin'], $redirect_values['url'], $redirect_values['type'], $redirect_values['format'] ); } /** * Maps a redirect object to an array option. * * @param WPSEO_Redirect $redirect The redirect to map. * * @return void */ private function map_object_to_option( WPSEO_Redirect &$redirect ) { $redirect = [ 'origin' => $redirect->get_origin(), 'url' => $redirect->get_target(), 'type' => $redirect->get_type(), 'format' => $redirect->get_format(), ]; } }