PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
← All changes | includes/permalink-rewrite.php +42 -0 2.7.72.13.0 View file →
@@ -1,0 +1,42 @@
1 +<?php
2 +namespace ABlocks;
3 +
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
8 +class PermalinkRewrite {
9 + public static function init() {
10 + $self = new self();
11 + add_filter( 'query_vars', array( $self, 'register_query_vars' ) );
12 + add_action( 'generate_rewrite_rules', array( $self, 'add_rewrite_rules' ) );
13 + }
14 + public function register_query_vars( $query_vars ) {
15 + $query_vars[] = 'ablocks_dashboard_page';
16 + $query_vars[] = 'ablocks_dashboard_sub_page';
17 + return $query_vars;
18 + }
19 + public function add_rewrite_rules( $wp_rewrite ) {
20 + // Frontend Dashboard
21 + $dashboard_page_id = (int) Helper::get_settings( 'frontend_dashboard_page' );
22 + if ( ! $dashboard_page_id ) {
23 + return;
24 + }
25 + $dashboard_page_slug = get_post_field( 'post_name', $dashboard_page_id );
26 + $dashboard_pages = json_decode( get_option( ABLOCKS_FRONTEND_DASHBOARD_SUB_PAGES_SETTINGS_NAME, '{}' ), true );
27 + foreach ( $dashboard_pages as $dashboard_page ) {
28 + $dashboard_key = $dashboard_page['slug'];
29 + $new_rules[ "({$dashboard_page_slug})/{$dashboard_key}/?$" ] = 'index.php?pagename=' . $wp_rewrite->preg_index( 1 ) . '&ablocks_dashboard_page=' . $dashboard_key;
30 + $new_rules[ "({$dashboard_page_slug})/{$dashboard_key}/(.+?)/?$" ] = 'index.php?pagename=' . $wp_rewrite->preg_index( 1 ) . '&ablocks_dashboard_page=' . $dashboard_key . '&ablocks_dashboard_sub_page=' . $wp_rewrite->preg_index( 2 );
31 + // Child Items
32 + if ( isset( $dashboard_page['child_items'] ) && is_array( $dashboard_page['child_items'] ) ) {
33 + foreach ( $dashboard_page['child_items'] as $child_key => $child_page ) {
34 + $new_rules[ "({$dashboard_page_slug})/{$dashboard_key}/{$child_key}/?$" ] = 'index.php?pagename=' . $wp_rewrite->preg_index( 1 ) . '&ablocks_dashboard_page=' . $dashboard_key;
35 + $new_rules[ "({$dashboard_page_slug})/{$dashboard_key}/{$child_key}/(.+?)/?$" ] = 'index.php?pagename=' . $wp_rewrite->preg_index( 1 ) . '&ablocks_dashboard_page=' . $dashboard_key . '&ablocks_dashboard_sub_page=' . $child_key;
36 + }
37 + }
38 + }
39 +
40 + $wp_rewrite->rules = ( $new_rules ?? [] ) + $wp_rewrite->rules;
41 + }
42 +}