PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / extensions / albums / public / class-rewrite-rules.php
foogallery / extensions / albums / public Last commit date
class-foogallery-album-template-loader.php 2 months ago class-rewrite-rules.php 2 months ago class-shortcodes.php 2 months ago
class-rewrite-rules.php
47 lines
1 <?php
2 /**
3 * FooGallery Album Rewrite Rules
4 */
5 if (!class_exists('FooGallery_Album_Rewrite_Rules')) {
6
7 class FooGallery_Album_Rewrite_Rules {
8
9 function __construct() {
10 add_action( 'init', array( $this, 'add_gallery_endpoint' ) );
11 add_filter( 'redirect_canonical', array( $this, 'disable_canonical_redirect_for_front_page' ), 10, 2 );
12 add_action( 'update_option_page_on_front', array( $this, 'flush_rules' ) );
13 }
14
15 function add_gallery_endpoint() {
16 $gallery_slug = foogallery_album_gallery_url_slug();
17
18 // Ensures the $query_vars['item'] is available
19 add_rewrite_tag( "%{$gallery_slug}%", '([^&]+)' );
20
21 // Requires flushing endpoints whenever the front page is switched to a different page
22 $page_on_front = get_option( 'page_on_front' );
23
24 // Match the front page and pass item value as a query var.
25 add_rewrite_rule( "^{$gallery_slug}/([^/]*)/?", 'index.php?page_id='.$page_on_front.'&'.$gallery_slug.'=$matches[1]', 'top' );
26 // Match non-front page pages.
27 add_rewrite_rule( "^(.*)/{$gallery_slug}/([^/]*)/?", 'index.php?pagename=$matches[1]&static=true&'.$gallery_slug.'=$matches[2]', 'top' );
28 }
29
30 // http://wordpress.stackexchange.com/a/220484/52463
31 // In order to keep WordPress from forcing a redirect to the canonical
32 // home page, the redirect needs to be disabled.
33 function disable_canonical_redirect_for_front_page( $redirect_url, $requested_url ) {
34 if ( is_page() && $front_page = get_option( 'page_on_front' ) ) {
35 if ( is_page( $front_page ) ) {
36 $redirect_url = false;
37 }
38 }
39
40 return $redirect_url;
41 }
42
43 function flush_rules() {
44 flush_rewrite_rules();
45 }
46 }
47 }