karolispx
11/14/2016 - 12:27 PM

301

301

    /**
     * Add 301 redirects
     *
     * http://scottnelle.com/ simple 301 redirects plugin
     */
    public function redirects( $redirect_data )
    {
        if ( ! empty( $redirect_data ) && is_array( $redirect_data ) && class_exists( 'Simple301Redirects' ) ) {
            $redirects = array();

            // Existing redirects
            $existing_redirects = get_option('301_redirects');

            if ( ! empty( $existing_redirects ) ) {
                foreach ( $existing_redirects as $existing_redirect => $value ) {
                    $redirects[$existing_redirect] = $value;
                }
            }

            // New redirects
            foreach ( $redirect_data as $redirect ) {
                // Ensure this post's URL does not exist in redirects already
                $redirects[$redirect[0]] = $redirect[1];
            }

            update_option( '301_redirects', $redirects );
        }
    }