-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtootpress_url.php
97 lines (76 loc) · 1.57 KB
/
tootpress_url.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* URL
*
* @package TootPress
* @since 0.1
*/
// Security: Stops code execution if WordPress is not loaded
if (!defined('ABSPATH')) { exit; }
/**
* Add TootPress to WordPress Query Vars
*
* Query Variable "tootpress" is used for Paging
*
* @since 0.1
*/
function tootpress_urlvars( $qvars )
{
$qvars[] = 'tootpress';
return $qvars;
}
add_filter('query_vars', 'tootpress_urlvars' );
/**
* Reads the Query Var from URL
*
* Used for Paging
*
* @since 0.1
*
* @return bool Yes or No
*/
function tootpress_get_query_var() {
// Get Query from URL
$qvar=get_query_var( 'tootpress');
// If Query Var is not set
if ($qvar=="") {$qvar="1";}
return $qvar;
}
/**
* Adds Rewrite Rule to Wordpress
*
* For Query Variable "tootpress"
*
* Example:
* https://domain/slug/3 > https://domain/index.php?pagename=slug&tootpress=3
*
* @since 0.1
*
* @return array Rewrite Rules
*/
function tootpress_insert_rewrite( $rules ) {
// Get the Page for Toots
$pageid=get_option('tootpress_page_id');
// Get the Slug for the toot page
$slug = get_post_field( 'post_name', $pageid );
// Create Rewrite Rules
// () > Terms
// \d+ > Integer
// / > Seperator
// $ > Both terms must exist
$newrules = array();
$newrules['('.$slug.')/(\d+)$'] = 'index.php?pagename=$matches[1]&tootpress=$matches[2]';
return $newrules + $rules;
}
add_filter( 'rewrite_rules_array','tootpress_insert_rewrite' );
/**
* Get TootPress Blog URL
*
* @since 0.1
*
* @return string URL
*/
function tootpress_blog_url() {
return get_page_link();
}
?>