add_permastruct example

$wp->add_query_var( $this->query_var );
        }

        if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
            if ( $this->hierarchical && $this->rewrite['hierarchical'] ) {
                $tag = '(.+?)';
            } else {
                $tag = '([^/]+)';
            }

            add_rewrite_tag( "%$this->name%", $tag$this->query_var ? "{$this->query_var}=" : "taxonomy=$this->name&term=" );
            add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $this->rewrite );
        }
    }

    /** * Removes any rewrite rules, permastructs, and rules for the taxonomy. * * @since 4.7.0 * * @global WP $wp Current WordPress environment instance. */
    public function remove_rewrite_rules() {
        
$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
                    add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
                    add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' );
                }
                if ( $this->rewrite['pages'] ) {
                    add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' );
                }
            }

            $permastruct_args         = $this->rewrite;
            $permastruct_args['feed'] = $permastruct_args['feeds'];
            add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args );
        }
    }

    /** * Registers the post type meta box if a custom callback was specified. * * @since 4.6.0 */
    public function register_meta_boxes() {
        if ( $this->register_meta_box_cb ) {
            add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 );
        }
global $wp_rewrite;

    // Back-compat for the old parameters: $with_front and $ep_mask.     if ( ! is_array( $args ) ) {
        $args = array( 'with_front' => $args );
    }

    if ( func_num_args() === 4 ) {
        $args['ep_mask'] = func_get_arg( 3 );
    }

    $wp_rewrite->add_permastruct( $name$struct$args );
}

/** * Removes a permalink structure. * * Can only be used to remove permastructs that were added using add_permastruct(). * Built-in permastructs cannot be removed. * * @since 4.5.0 * * @see WP_Rewrite::remove_permastruct() * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $name Name for permalink structure. */
Home | Imprint | This part of the site doesn't use cookies.