Custom Permalinks - Version 1.2.18

Version Description

  • April 05, 2018 =

    • Enhancement
    • Merged custom-permalinks-main.php with custom-permalinks.php
    • Added uninstall.php
    • Bugs
    • Added feed redirect of default permalink
    • Provide proper feed of custom permalink
Download this release

Release Info

Developer sasiddiqui
Plugin Icon Custom Permalinks
Version 1.2.18
Comparing to
See all releases

Code changes from version 1.2.17 to 1.2.18

admin/class-custom-permalinks-about.php CHANGED
@@ -3,145 +3,149 @@
3
  * @package CustomPermalinks\Admin
4
  */
5
 
6
- class Custom_Permalinks_About {
7
-
8
- /**
9
- * Class constructor.
10
- */
11
- public function __construct() {
12
- $this->more_plugins();
13
- }
14
-
15
- /**
16
- * More Plugins HTML
17
- */
18
- private function more_plugins() {
19
- $plugin_url = plugins_url( '/admin', CUSTOM_PERMALINKS_FILE );
20
- $img_src = $plugin_url . '/images';
21
- wp_enqueue_style( 'style', $plugin_url . '/css/about-plugins.min.css' );
22
- $plugin_name = __( 'Custom Permalinks', 'custom-permalinks' );
23
- $button_text = __( 'Check it out', 'custom-permalinks' );
24
- $five_star = '<span class="star">
25
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
26
- <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
27
- 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
28
- </svg>
29
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
30
- <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
31
- 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
32
- </svg>
33
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
34
- <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
35
- 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
36
- </svg>
37
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
38
- <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
39
- 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
40
- </svg>
41
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
42
- <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
43
- 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
44
- </svg>
45
- </span>';
46
- ?>
47
-
48
- <div class="wrap">
49
- <div class="float">
50
- <h1><?php echo $plugin_name . ' ' . CUSTOM_PERMALINKS_PLUGIN_VERSION; ?></h1>
51
- <div class="tagline">
52
- <p><?php _e('Thank you for choosing Custom Permalinks! We hope that your experience with our plugin for updating permalinks is quick and easy. We are trying to make it more feasible for you and provide capabilities in it.', 'custom-permalinks' ); ?></p>
53
- <p><?php printf( __( 'To support future development and help to make it even better just leaving us a <a href="%s" title="Custom Permalinks Rating" target="_blank">%s</a> rating with a nice message to me :)', 'custom-permalinks' ), 'https://wordpress.org/support/plugin/custom-permalinks/reviews/?rate=5#new-post', $five_star ); ?></p>
54
- </div>
55
- </div>
56
-
57
- <div class="float">
58
- <object type="image/svg+xml" data="<?php echo $img_src;?>/custom-permalinks.svg" width="128" height="128"></object>
59
- </div>
60
-
61
- <div class="product">
62
- <h2><?php _e( 'More from Sami Ahmed Siddiqui', 'custom-permalinks' ); ?></h2>
63
- <span><?php _e('Our List of Plugins provides the services which helps you to manage your site URLs(Permalinks), Prevent your site from XSS Attacks, Brute force attacks, increase your site visitors by adding Structured JSON Markup and so on.', 'custom-permalinks' ); ?></span>
64
- <div class="box recommended">
65
- <div class="img">
66
- <img src= "<?php echo $img_src; ?>/prevent-xss-vulnerability.png" style="transform:scale(1.5)" />
67
- </div>
68
-
69
- <h3><?php _e( 'Prevent XSS Vulnerability', 'custom-permalinks' ); ?></h3>
70
- <p><?php _e( 'Secure your site from the <strong>XSS Attacks</strong> so, your users won\'t lose any kind of information or not redirected to any other site by visiting to your site with the <strong>malicious code</strong> in the URL or so. In this way, users can open your site URLs without any hesitation.', 'custom-permalinks' ); ?></p>
71
- <a href="https://wordpress.org/plugins/prevent-xss-vulnerability/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
72
- </div>
73
-
74
- <div class="box">
75
- <div class="img">
76
- <img src= "<?php echo $img_src; ?>/permalinks-customizer.svg" />
77
- </div>
78
-
79
- <h3><?php _e( 'Permalinks Customizer', 'custom-permalinks' ); ?></h3>
80
- <p><?php _e( 'Allows you to either define different Permalink Structure or define same Permalink Structure for default and Custom PostTypes, Taxonomies. Plugin automatically creates the user-friendly URLs as per your defined structured that can be edited from the single post/page.', 'custom-permalinks' ); ?></p>
81
- <a href="https://wordpress.org/plugins/permalinks-customizer/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
82
- </div>
83
-
84
- <div class="box recommended">
85
- <div class="img">
86
- <img src= "<?php echo $img_src; ?>/http-auth.svg" />
87
- </div>
88
-
89
- <h3><?php _e( 'Http Auth', 'schema-for-article' ); ?></h3>
90
- <p><?php _e( 'Allows you apply <strong>HTTP Auth</strong> on your site. You can apply Http Authentication all over the site or only the admin pages. It helps to stop cralwing on your site while on development or persist the <strong>Brute Attacks</strong> by locking the Admin Pages.', 'schema-for-article' ); ?></p>
91
- <a href="https://wordpress.org/plugins/http-auth/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
92
- </div>
93
-
94
- <div class="box">
95
- <div class="img">
96
- <img src= "<?php echo $img_src; ?>/schema-for-article.svg" />
97
- </div>
98
-
99
- <h3><?php _e( 'SCHEMA for Article', 'schema-for-article' ); ?></h3>
100
- <p><?php _e( 'Simply the easiest solution to add valid schema.org as a JSON script in the head of blog posts or articles. You can choose the schema either to show with the type of Article or NewsArticle from the settings page.', 'schema-for-article' ); ?></p>
101
- <a href="https://wordpress.org/plugins/schema-for-article/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
102
- </div>
103
-
104
- <div class="box">
105
- <div class="img">
106
- <img src= "<?php echo $img_src; ?>/make-paths-relative.svg" />
107
- </div>
108
-
109
- <h3><?php _e( 'Make Paths Relative', 'custom-permalinks' ); ?></h3>
110
- <p><?php _e( 'Convert the paths(URLs) to relative instead of absolute. You can make <strong>Post</strong>, <strong>Category</strong>, <strong>Archive</strong>, <strong>Image</strong> URLs and <strong>Script</strong> and <strong>Style</strong> src as per your requirement. You can choose which you want to be relative from the settings Page.', 'custom-permalinks' ); ?></p>
111
- <a href="https://wordpress.org/plugins/make-paths-relative/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
112
- </div>
113
-
114
- <div class="box">
115
- <div class="img">
116
- <img src= "<?php echo $img_src; ?>/json-structuring-markup.svg" />
117
- </div>
118
-
119
- <h3><?php _e( 'JSON Structuring Markup', 'custom-permalinks' ); ?></h3>
120
- <p><?php _e( 'Simply the easiest solution to add valid schema.org as a JSON script in the head of posts and pages. It provides you multiple <strong>SCHEMA</strong> types like Article, News Article, Organization and Website Schema.', 'custom-permalinks' ); ?></p>
121
- <a href="https://wordpress.org/plugins/json-structuring-markup/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
122
- </div>
123
-
124
- <div class="box">
125
- <div class="img">
126
- <img src= "<?php echo $img_src; ?>/remove-links-and-scripts.svg" />
127
- </div>
128
-
129
- <h3><?php _e( 'Remove Links and Scripts', 'custom-permalinks' ); ?></h3>
130
- <p><?php _e( 'It removes some meta data from the wordpress header so, your header keeps clean of useless information like <strong>shortlink</strong>, <strong>rsd_link</strong>, <strong>wlwmanifest_link</strong>, <strong>emoji_scripts</strong>, <strong>wp_embed</strong>, <strong>wp_json</strong>, <strong>emoji_styles</strong>, <strong>generator</strong> and so on.', 'custom-permalinks' ); ?></p>
131
- <a href="https://wordpress.org/plugins/remove-links-and-scripts/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
132
- </div>
133
-
134
- <div class="box">
135
- <div class="img">
136
- <img src= "<?php echo $img_src; ?>/media-post-permalink.png" style="transform:scale(1.5)" />
137
- </div>
138
-
139
- <h3><?php _e( 'Media Post Permalink', 'custom-permalinks' ); ?></h3>
140
- <p><?php _e( 'On uploading any image, let\'s say services.png, WordPress creates the <strong>attachment post</strong> with the permalink of <strong>/services/</strong> and doesn\'t allow you to use that permalink to point your page. In this case, we comes up with this great solution.', 'custom-permalinks' ); ?></p>
141
- <a href="https://wordpress.org/plugins/media-post-permalink/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
142
- </div>
143
- </div>
144
- </div>
145
- <?php
146
- }
 
 
 
 
147
  }
3
  * @package CustomPermalinks\Admin
4
  */
5
 
6
+ final class Custom_Permalinks_About {
7
+
8
+ /**
9
+ * Class constructor.
10
+ */
11
+ public function __construct() {
12
+ $this->more_plugins();
13
+ }
14
+
15
+ /**
16
+ * Print HTML for Custom Permalinks ABout Page
17
+ *
18
+ * @access private
19
+ * @since 1.2.11
20
+ * @return void
21
+ */
22
+ private function more_plugins() {
23
+ $plugin_url = plugins_url( '/admin', CUSTOM_PERMALINKS_FILE );
24
+ $img_src = $plugin_url . '/images';
25
+ wp_enqueue_style( 'style', $plugin_url . '/css/about-plugins.min.css' );
26
+ $plugin_name = __( 'Custom Permalinks', 'custom-permalinks' );
27
+ $button_text = __( 'Check it out', 'custom-permalinks' );
28
+ $five_star = '<span class="star">
29
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
30
+ <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
31
+ 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
32
+ </svg>
33
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
34
+ <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
35
+ 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
36
+ </svg>
37
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
38
+ <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
39
+ 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
40
+ </svg>
41
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
42
+ <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
43
+ 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
44
+ </svg>
45
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
46
+ <polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
47
+ 10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
48
+ </svg>
49
+ </span>';
50
+ ?>
51
+
52
+ <div class="wrap">
53
+ <div class="float">
54
+ <h1><?php echo $plugin_name . ' v' . CUSTOM_PERMALINKS_PLUGIN_VERSION; ?></h1>
55
+ <div class="tagline">
56
+ <p><?php _e('Thank you for choosing Custom Permalinks! We hope that your experience with our plugin for updating permalinks is quick and easy. We are trying to make it more feasible for you and provide capabilities in it.', 'custom-permalinks' ); ?></p>
57
+ <p><?php printf( __( 'To support future development and help to make it even better just leaving us a <a href="%s" title="Custom Permalinks Rating" target="_blank">%s</a> rating with a nice message to me :)', 'custom-permalinks' ), 'https://wordpress.org/support/plugin/custom-permalinks/reviews/?rate=5#new-post', $five_star ); ?></p>
58
+ </div>
59
+ </div>
60
+
61
+ <div class="float">
62
+ <object type="image/svg+xml" data="<?php echo $img_src;?>/custom-permalinks.svg" width="128" height="128"></object>
63
+ </div>
64
+
65
+ <div class="product">
66
+ <h2><?php _e( 'More from Sami Ahmed Siddiqui', 'custom-permalinks' ); ?></h2>
67
+ <span><?php _e('Our List of Plugins provides the services which helps you to manage your site URLs(Permalinks), Prevent your site from XSS Attacks, Brute force attacks, increase your site visitors by adding Structured JSON Markup and so on.', 'custom-permalinks' ); ?></span>
68
+ <div class="box recommended">
69
+ <div class="img">
70
+ <img src= "<?php echo $img_src; ?>/prevent-xss-vulnerability.png" style="transform:scale(1.5)" />
71
+ </div>
72
+
73
+ <h3><?php _e( 'Prevent XSS Vulnerability', 'custom-permalinks' ); ?></h3>
74
+ <p><?php _e( 'Secure your site from the <strong>XSS Attacks</strong> so, your users won\'t lose any kind of information or not redirected to any other site by visiting to your site with the <strong>malicious code</strong> in the URL or so. In this way, users can open your site URLs without any hesitation.', 'custom-permalinks' ); ?></p>
75
+ <a href="https://wordpress.org/plugins/prevent-xss-vulnerability/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
76
+ </div>
77
+
78
+ <div class="box">
79
+ <div class="img">
80
+ <img src= "<?php echo $img_src; ?>/permalinks-customizer.svg" />
81
+ </div>
82
+
83
+ <h3><?php _e( 'Permalinks Customizer', 'custom-permalinks' ); ?></h3>
84
+ <p><?php _e( 'Allows you to either define different Permalink Structure or define same Permalink Structure for default and Custom PostTypes, Taxonomies. Plugin automatically creates the user-friendly URLs as per your defined structured that can be edited from the single post/page.', 'custom-permalinks' ); ?></p>
85
+ <a href="https://wordpress.org/plugins/permalinks-customizer/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
86
+ </div>
87
+
88
+ <div class="box recommended">
89
+ <div class="img">
90
+ <img src= "<?php echo $img_src; ?>/http-auth.svg" />
91
+ </div>
92
+
93
+ <h3><?php _e( 'Http Auth', 'schema-for-article' ); ?></h3>
94
+ <p><?php _e( 'Allows you apply <strong>HTTP Auth</strong> on your site. You can apply Http Authentication all over the site or only the admin pages. It helps to stop cralwing on your site while on development or persist the <strong>Brute Attacks</strong> by locking the Admin Pages.', 'schema-for-article' ); ?></p>
95
+ <a href="https://wordpress.org/plugins/http-auth/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
96
+ </div>
97
+
98
+ <div class="box">
99
+ <div class="img">
100
+ <img src= "<?php echo $img_src; ?>/schema-for-article.svg" />
101
+ </div>
102
+
103
+ <h3><?php _e( 'SCHEMA for Article', 'schema-for-article' ); ?></h3>
104
+ <p><?php _e( 'Simply the easiest solution to add valid schema.org as a JSON script in the head of blog posts or articles. You can choose the schema either to show with the type of Article or NewsArticle from the settings page.', 'schema-for-article' ); ?></p>
105
+ <a href="https://wordpress.org/plugins/schema-for-article/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
106
+ </div>
107
+
108
+ <div class="box">
109
+ <div class="img">
110
+ <img src= "<?php echo $img_src; ?>/make-paths-relative.svg" />
111
+ </div>
112
+
113
+ <h3><?php _e( 'Make Paths Relative', 'custom-permalinks' ); ?></h3>
114
+ <p><?php _e( 'Convert the paths(URLs) to relative instead of absolute. You can make <strong>Post</strong>, <strong>Category</strong>, <strong>Archive</strong>, <strong>Image</strong> URLs and <strong>Script</strong> and <strong>Style</strong> src as per your requirement. You can choose which you want to be relative from the settings Page.', 'custom-permalinks' ); ?></p>
115
+ <a href="https://wordpress.org/plugins/make-paths-relative/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
116
+ </div>
117
+
118
+ <div class="box">
119
+ <div class="img">
120
+ <img src= "<?php echo $img_src; ?>/json-structuring-markup.svg" />
121
+ </div>
122
+
123
+ <h3><?php _e( 'JSON Structuring Markup', 'custom-permalinks' ); ?></h3>
124
+ <p><?php _e( 'Simply the easiest solution to add valid schema.org as a JSON script in the head of posts and pages. It provides you multiple <strong>SCHEMA</strong> types like Article, News Article, Organization and Website Schema.', 'custom-permalinks' ); ?></p>
125
+ <a href="https://wordpress.org/plugins/json-structuring-markup/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
126
+ </div>
127
+
128
+ <div class="box">
129
+ <div class="img">
130
+ <img src= "<?php echo $img_src; ?>/remove-links-and-scripts.svg" />
131
+ </div>
132
+
133
+ <h3><?php _e( 'Remove Links and Scripts', 'custom-permalinks' ); ?></h3>
134
+ <p><?php _e( 'It removes some meta data from the wordpress header so, your header keeps clean of useless information like <strong>shortlink</strong>, <strong>rsd_link</strong>, <strong>wlwmanifest_link</strong>, <strong>emoji_scripts</strong>, <strong>wp_embed</strong>, <strong>wp_json</strong>, <strong>emoji_styles</strong>, <strong>generator</strong> and so on.', 'custom-permalinks' ); ?></p>
135
+ <a href="https://wordpress.org/plugins/remove-links-and-scripts/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
136
+ </div>
137
+
138
+ <div class="box">
139
+ <div class="img">
140
+ <img src= "<?php echo $img_src; ?>/media-post-permalink.png" style="transform:scale(1.5)" />
141
+ </div>
142
+
143
+ <h3><?php _e( 'Media Post Permalink', 'custom-permalinks' ); ?></h3>
144
+ <p><?php _e( 'On uploading any image, let\'s say services.png, WordPress creates the <strong>attachment post</strong> with the permalink of <strong>/services/</strong> and doesn\'t allow you to use that permalink to point your page. In this case, we comes up with this great solution.', 'custom-permalinks' ); ?></p>
145
+ <a href="https://wordpress.org/plugins/media-post-permalink/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
146
+ </div>
147
+ </div>
148
+ </div>
149
+ <?php
150
+ }
151
  }
admin/class-custom-permalinks-admin.php CHANGED
@@ -3,509 +3,555 @@
3
  * @package CustomPermalinks\Admin
4
  */
5
 
6
- class Custom_Permalinks_Admin {
7
-
8
- /**
9
- * Initializes WordPress hooks
10
- */
11
- function __construct() {
12
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
13
- add_filter( 'plugin_action_links_' . CUSTOM_PERMALINKS_BASENAME,
14
- array( $this, 'settings_link' )
15
- );
16
- }
17
-
18
- /**
19
- * Added Pages in Menu for Settings
20
- */
21
- public function admin_menu() {
22
- add_menu_page( 'Custom Permalinks', 'Custom Permalinks', 'administrator',
23
- 'cp-post-permalinks', array( $this,'posttype_permalinks' ),
24
- 'dashicons-admin-links'
25
- );
26
- add_submenu_page( 'cp-post-permalinks', 'PostTypes Permalinks',
27
- 'PostTypes Permalinks', 'administrator', 'cp-post-permalinks',
28
- array( $this, 'posttype_permalinks' )
29
- );
30
- add_submenu_page( 'cp-post-permalinks', 'Category Permalinks',
31
- 'Category Permalinks', 'administrator', 'cp-category-permalinks',
32
- array( $this, 'category_permalinks' )
33
- );
34
- add_submenu_page( 'cp-post-permalinks', 'About Custom Permalinks',
35
- 'About CP', 'administrator', 'cp-about-plugins',
36
- array( $this, 'about_plugin' )
37
- );
38
- }
39
-
40
- /**
41
- * Shows all the Permalinks created by using this Plugin with Pager and
42
- * Search Functionality of Posts/Pages.
43
- */
44
- public function posttype_permalinks() {
45
- global $wpdb;
46
- $filter_options = '';
47
- $filter_permalink = '';
48
- $search_permalink = '';
49
- $html = '';
50
- $error = '';
51
-
52
- // Handle Bulk Operations
53
- if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
54
- || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
55
- && isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
56
- $post_ids = implode( ',', $_POST['permalink'] );
57
- if ( preg_match( '/^\d+(?:,\d+)*$/', $post_ids ) ) {
58
- $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids) AND meta_key = 'custom_permalink'" );
59
- } else {
60
- $error = '<div id="message" class="error">
61
- <p>' . __( 'There is some error to proceed your request. Please retry with your request or contact to the plugin author.', 'custom-permalinks' ) . '</p>
62
- </div>';
63
- }
64
- }
65
- $html .= '<div class="wrap">
66
- <h1 class="wp-heading-inline">' . __( 'PostTypes Permalinks', 'custom-permalinks' ) . '</h1>';
67
- $html .= $error;
68
-
69
- $search_value = '';
70
- if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
71
- $filter_permalink = 'AND pm.meta_value LIKE "%' . $_GET['s'] . '%"';
72
- $search_permalink = '&s=' . $_GET['s'] . '';
73
- $search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
74
- $html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
75
- }
76
- $page_limit = 'LIMIT 0, 20';
77
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
78
- && $_GET['paged'] > 1 ) {
79
- $pager = 20 * ( $_GET['paged'] - 1 );
80
- $page_limit = 'LIMIT ' . $pager . ', 20';
81
- }
82
- $sorting_by = 'ORDER By p.ID DESC';
83
- $order_by = 'asc';
84
- $order_by_class = 'desc';
85
- if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'title' ) {
86
- $filter_options .= '<input type="hidden" name="orderby" value="title" />';
87
- if ( isset( $_GET['order'] ) && $_GET['order'] == 'desc' ) {
88
- $sorting_by = 'ORDER By p.post_title DESC';
89
- $order_by = 'asc';
90
- $order_by_class = 'desc';
91
- $filter_options .= '<input type="hidden" name="order" value="desc" />';
92
- } else {
93
- $sorting_by = 'ORDER By p.post_title';
94
- $order_by = 'desc';
95
- $order_by_class = 'asc';
96
- $filter_options .= '<input type="hidden" name="order" value="asc" />';
97
- }
98
- }
99
- $count_query = "SELECT COUNT(p.ID) AS total_permalinks FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . "";
100
- $count_posts = $wpdb->get_row( $count_query );
101
-
102
- $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
103
- $html .= '<p class="search-box">';
104
- $html .= '<input type="hidden" name="page" value="cp-post-permalinks" />';
105
- $html .= $filter_options;
106
- $html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
107
- $html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
108
- $html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
109
- $html .= '</form>';
110
- $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
111
- $html .= '<div class="tablenav top">';
112
- $html .= '<div class="alignleft actions bulkactions">
113
- <label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
114
- <select name="action" id="bulk-action-selector-top">
115
- <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
116
- <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
117
- </select>
118
- <input type="submit" id="doaction" class="button action" value="Apply">
119
- </div>';
120
-
121
- $posts = 0;
122
- if ( isset( $count_posts->total_permalinks )
123
- && $count_posts->total_permalinks > 0 ) {
124
-
125
- $html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
126
-
127
- $query = "SELECT p.ID, p.post_title, p.post_type, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . " " . $sorting_by . " " . $page_limit . "";
128
- $posts = $wpdb->get_results( $query );
129
-
130
- $pagination_html = '';
131
- $total_pages = ceil( $count_posts->total_permalinks / 20 );
132
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
133
- && $_GET['paged'] > 0 ) {
134
- $pagination_html = $this->cp_pager(
135
- $count_posts->total_permalinks, $_GET['paged'], $total_pages
136
- );
137
- if ( $_GET['paged'] > $total_pages ) {
138
- $redirect_uri = explode(
139
- '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI']
140
- );
141
- header( 'Location: ' . $redirect_uri[0], 301 );
142
- exit();
143
- }
144
- } elseif ( ! isset( $_GET['paged'] ) ) {
145
- $pagination_html = $this->cp_pager(
146
- $count_posts->total_permalinks, 1, $total_pages
147
- );
148
- }
149
-
150
- $html .= $pagination_html;
151
- }
152
- $table_navigation = $this->tablenav_posts(
153
- $order_by_class, $order_by, $search_permalink
154
- );
155
-
156
- $html .= '</div>';
157
- $html .= '<table class="wp-list-table widefat fixed striped posts">
158
- <thead>' . $table_navigation . '</thead>
159
- <tbody>';
160
- if ( $posts != 0 && ! empty( $posts ) ) {
161
- foreach ( $posts as $post ) {
162
- $html .= '<tr valign="top">';
163
- $html .= '<th scope="row" class="check-column">
164
- <input type="checkbox" name="permalink[]" value="' . $post->ID . '" />
165
- </th>';
166
- $html .= '<td><strong>
167
- <a class="row-title" href="post.php?action=edit&post=' . $post->ID . '">' . $post->post_title . '</a>
168
- </strong></td>';
169
- $html .= '<td>' . ucwords( $post->post_type ) . '</td>';
170
- $html .= '<td>
171
- <a href="/' . $post->meta_value . '" target="_blank" title="' . __( "Visit " . $post->post_title, "custom-permalinks" ) . '">/' . urldecode( $post->meta_value ) . '</a>
172
- </td>';
173
- $html .= '</tr>';
174
- }
175
- } else {
176
- $html .= '<tr class="no-items">
177
- <td class="colspanchange" colspan="10">No permalinks found.</td>
178
- </tr>';
179
- }
180
- $html .= '</tbody>
181
- <tfoot>' . $table_navigation . '</tfoot>
182
- </table>';
183
-
184
- $html .= '<div class="tablenav bottom">
185
- <div class="alignleft actions bulkactions">
186
- <label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
187
- <select name="action2" id="bulk-action-selector-bottom">
188
- <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
189
- <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
190
- </select>
191
- <input type="submit" id="doaction2" class="button action" value="Apply">
192
- </div>
193
- ' . $pagination_html . '
194
- </div>';
195
- $html .= '</form></div>';
196
- echo $html;
197
-
198
- add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
199
- }
200
-
201
- /**
202
- * Return the Navigation row HTML same as Default Posts page for PostTypes
203
- */
204
- private function tablenav_posts( $order_by_class, $order_by, $search_permalink ) {
205
- $nav = '<tr>
206
- <td id="cb" class="manage-column column-cb check-column">
207
- <label class="screen-reader-text" for="cb-select-all-1">Select All</label>
208
- <input id="cb-select-all-1" type="checkbox">
209
- </td>
210
- <th scope="col" id="title" class="manage-column column-title column-primary sortable ' . $order_by_class . '">
211
- <a href="/wp-admin/admin.php?page=cp-post-permalinks&amp;orderby=title&amp;order=' . $order_by . $search_permalink . '"><span>' . __( "Title", "custom-permalinks" ) . '</span><span class="sorting-indicator"></span></a>
212
- </th>
213
- <th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
214
- <th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
215
- </tr>';
216
- return $nav;
217
- }
218
-
219
- /**
220
- * Shows all the Permalinks created by using this Plugin with Pager and Search Functionality of Category/Tags
221
- */
222
- public function category_permalinks() {
223
-
224
- $search_permalink = '';
225
- $html = '';
226
-
227
- // Handle Bulk Operations
228
- if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
229
- || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
230
- && isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
231
- $remove_perm = $_POST['permalink'];
232
- $data = get_option( 'custom_permalink_table' );
233
- if ( isset( $data ) && is_array( $data ) ) {
234
- $i = 0;
235
- foreach ( $data as $link => $info ) {
236
- if ( in_array( $info['id'], $remove_perm ) ) {
237
- unset( $data[$link] );
238
- unset( $remove_perm[$i] );
239
- if ( ! is_array( $remove_perm ) || empty( $remove_perm ) )
240
- break;
241
- }
242
- $i++;
243
- }
244
- }
245
- update_option( 'custom_permalink_table', $data );
246
- }
247
- $html .= '<div class="wrap">
248
- <h1 class="wp-heading-inline">' . __( 'Category/Tags Permalinks', 'custom-permalinks' ) . '</h1>';
249
-
250
- $search_value = '';
251
- if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
252
- $search_permalink = '&s=' . $_GET['s'] . '';
253
- $search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
254
- $html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
255
- }
256
- $pager_offset = '0';
257
- $page_limit = 20;
258
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
259
- $pager_offset = 20 * ( $_GET['paged'] - 1 );
260
- $page_limit = $pager_offset + 20;
261
- }
262
- $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
263
- $html .= '<p class="search-box">';
264
- $html .= '<input type="hidden" name="page" value="cp-category-permalinks" />';
265
- $html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
266
- $html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
267
- $html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
268
- $html .= '</form>';
269
- $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
270
- $html .= '<div class="tablenav top">';
271
- $html .= '<div class="alignleft actions bulkactions">
272
- <label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
273
- <select name="action" id="bulk-action-selector-top">
274
- <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
275
- <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
276
- </select>
277
- <input type="submit" id="doaction" class="button action" value="Apply">
278
- </div>';
279
-
280
- $posts = 0;
281
- $table = get_option( 'custom_permalink_table' );
282
- $count_tags = count( $table );
283
- $pagination_html = '';
284
- if ( isset( $table ) && is_array( $table ) && $count_tags > 0 ) {
285
-
286
- $filtered = array();
287
- if ( $search_value != '' ) {
288
- foreach ( $table as $key => $value ) {
289
- if ( preg_match( '/' . $search_value . '/', $key) ) {
290
- $filtered[$key] = $value;
291
- }
292
- }
293
- $table = $filtered;
294
- $count_tags = count( $table );
295
- }
296
-
297
- $html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
298
-
299
- $total_pages = ceil( $count_tags / 20 );
300
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
301
- && $_GET['paged'] > 0 ) {
302
- $pagination_html = $this->cp_pager(
303
- $count_tags, $_GET['paged'], $total_pages
304
- );
305
- if ( $_GET['paged'] > $total_pages ) {
306
- $redirect_uri = explode(
307
- '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI']
308
- );
309
- header( 'Location: ' . $redirect_uri[0], 301 );
310
- exit();
311
- }
312
- } elseif ( ! isset( $_GET['paged'] ) ) {
313
- $pagination_html = $this->cp_pager( $count_tags, 1, $total_pages );
314
- }
315
-
316
- $html .= $pagination_html;
317
- }
318
- $table_navigation = $this->tablenav_category( $search_permalink );
319
-
320
- $html .= '</div>';
321
- $html .= '<table class="wp-list-table widefat fixed striped posts">
322
- <thead>' . $table_navigation . '</thead>
323
- <tbody>';
324
-
325
- if ( $table && is_array( $table ) && $count_tags > 0 ) {
326
- uasort( $table, array( 'Custom_Permalinks_Admin', 'sort_array' ) );
327
- $i = -1;
328
- foreach ( $table as $permalink => $info ) {
329
- $i++;
330
- if ( $i < $pager_offset )
331
- continue;
332
-
333
- if ( $i >= $page_limit )
334
- break;
335
-
336
- $type = $info['kind'] == 'tag' ? 'post_tag' : 'category';
337
- $term = get_term( $info['id'], $type );
338
- $html .= '<tr valign="top">';
339
- $html .= '<th scope="row" class="check-column">
340
- <input type="checkbox" name="permalink[]" value="' . $info['id'] . '" />
341
- </th>';
342
- $html .= '<td><strong>
343
- <a class="row-title" href="edit-tags.php?action=edit&taxonomy=' . $type . '&tag_ID=' . $info['id'] . ' ">' . $term->name . '</a>
344
- </strong></td>';
345
- $html .= '<td>' . ucwords( $info['kind'] ) . '</td>';
346
- $html .= '<td>
347
- <a href="/' . $permalink . '" target="_blank" title="' . __( "Visit " . $term->name, "custom-permalinks" ) . '">/' . $permalink . '</a>
348
- </td>';
349
- $html .= '</tr>';
350
- }
351
- } else {
352
- $html .= '<tr class="no-items">
353
- <td class="colspanchange" colspan="10">No permalinks found.</td>
354
- </tr>';
355
- }
356
- $html .= '</tbody>
357
- <tfoot>' . $table_navigation . '</tfoot>
358
- </table>';
359
-
360
- $html .= '<div class="tablenav bottom">
361
- <div class="alignleft actions bulkactions">
362
- <label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
363
- <select name="action2" id="bulk-action-selector-bottom">
364
- <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
365
- <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
366
- </select>
367
- <input type="submit" id="doaction2" class="button action" value="Apply">
368
- </div>
369
- ' . $pagination_html . '
370
- </div>';
371
- $html .= '</form></div>';
372
- echo $html;
373
-
374
- add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
375
- }
376
-
377
- /**
378
- * Sort the terms array in desc order using term id
379
- */
380
- private function sort_array( $a, $b ) {
381
- return $b['id'] - $a['id'];
382
- }
383
-
384
- /**
385
- * Return the Navigation row HTML same as Default Posts page for Category
386
- */
387
- private function tablenav_category( $search_permalink ) {
388
- $nav = '<tr>
389
- <td id="cb" class="manage-column column-cb check-column">
390
- <label class="screen-reader-text" for="cb-select-all-1">Select All</label>
391
- <input id="cb-select-all-1" type="checkbox">
392
- </td>
393
- <th scope="col" id="title" class="manage-column column-title column-primary">' . __( "Title", "custom-permalinks" ) . '</th>
394
- <th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
395
- <th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
396
- </tr>';
397
- return $nav;
398
- }
399
-
400
- /**
401
- * Return the Pager HTML
402
- */
403
- private function cp_pager( $total_permalinks, $current_pager_value = 1, $total_pager = 0 ) {
404
-
405
- if ( $total_pager == 0 ) return;
406
-
407
- if ( $total_pager == 1 ) {
408
- $pagination_html = '<div class="tablenav-pages one-page">
409
- <span class="displaying-num">' . $total_permalinks . ' items</span>
410
- </div>';
411
- return $pagination_html;
412
- }
413
-
414
- $remove_pager_uri = explode(
415
- '&paged=' . $current_pager_value . '', $_SERVER['REQUEST_URI']
416
- );
417
- $pagination_html = '<div class="tablenav-pages">
418
- <span class="displaying-num">' . $total_permalinks . ' items</span>
419
- <span class="pagination-links">';
420
-
421
- if ( $current_pager_value == 1 ) {
422
- $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo; </span>
423
- <span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo; </span>';
424
- } else {
425
- $prev_page = $current_pager_value - 1;
426
- if ( $prev_page == 1 ) {
427
- $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
428
- } else {
429
- $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=1" title="First page" class="first-page">
430
- <span class="screen-reader-text">First page</span>
431
- <span aria-hidden="true">&laquo;</span>
432
- </a> ';
433
- }
434
- $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $prev_page . '" title="Previous page" class="prev-page">
435
- <span class="screen-reader-text">Previous page</span>
436
- <span aria-hidden="true">&lsaquo;</span>
437
- </a> ';
438
- }
439
-
440
- $pagination_html .= '<span class="paging-input">
441
- <label for="current-page-selector" class="screen-reader-text">Current Page</label>
442
- <input class="current-page" id="current-page-selector" type="text" name="paged" value="' . $current_pager_value . '" size="1" aria-describedby="table-paging" />
443
- <span class="tablenav-paging-text"> of <span class="total-pages">' . $total_pager . ' </span> </span>
444
- </span>';
445
-
446
- if ( $current_pager_value == $total_pager ) {
447
- $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo; </span>
448
- <span class="tablenav-pages-navspan" aria-hidden="true">&raquo; </span>';
449
- } else {
450
- $next_page = $current_pager_value + 1;
451
- $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $next_page . '" title="Next page" class="next-page">
452
- <span class="screen-reader-text">Next page</span>
453
- <span aria-hidden="true">&rsaquo;</span>
454
- </a> ';
455
- if ( $total_pager == $next_page) {
456
- $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
457
- } else {
458
- $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $total_pager . '" title="Last page" class="last-page">
459
- <span class="screen-reader-text">Last page</span>
460
- <span aria-hidden="true">&raquo;</span>
461
- </a> ';
462
- }
463
- }
464
- $pagination_html .= '</span></div>';
465
-
466
- return $pagination_html;
467
- }
468
-
469
- /**
470
- * Add About Plugins Page
471
- */
472
- public function about_plugin() {
473
- require_once(
474
- CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-about.php'
475
- );
476
- new Custom_Permalinks_About();
477
- add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
478
- }
479
-
480
- /**
481
- * Add Plugin Support and Follow Message in the footer of Admin Pages
482
- */
483
- public function admin_footer_text() {
484
- $footer_text = sprintf(
485
- __( 'Custom Permalinks version %s by <a href="%s" title="YAS Global Website" target="_blank">YAS Global</a> - <a href="%s" title="Support forums" target="_blank">Support forums</a> - Follow on Twitter: <a href="%s" title="Follow YAS Global on Twitter" target="_blank">YAS Global</a>', 'custom-permalinks' ),
486
- CUSTOM_PERMALINKS_PLUGIN_VERSION, 'https://www.yasglobal.com',
487
- 'https://wordpress.org/support/plugin/custom-permalinks',
488
- 'https://twitter.com/samisiddiqui91'
489
- );
490
- return $footer_text;
491
- }
492
-
493
- /**
494
- * Add About and Premium Settings Page Link on the Plugin Page
495
- * under the Plugin Name.
496
- */
497
- public function settings_link( $links ) {
498
- $about = sprintf(
499
- __( '<a href="%s" title="About">About</a>', 'custom-permalinks' ),
500
- 'admin.php?page=cp-about-plugins'
501
- );
502
- $premium_support = sprintf(
503
- __( '<a href="%s" title="Premium Support" target="_blank">Premium Support</a>', 'custom-permalinks' ),
504
- 'https://www.custompermalinks.com/#pricing-section'
505
- );
506
- array_unshift( $links, $premium_support );
507
- array_unshift( $links, $about );
508
-
509
- return $links;
510
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  }
3
  * @package CustomPermalinks\Admin
4
  */
5
 
6
+ final class Custom_Permalinks_Admin {
7
+
8
+ /**
9
+ * Initializes WordPress hooks
10
+ */
11
+ function __construct() {
12
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
13
+ add_filter( 'plugin_action_links_' . CUSTOM_PERMALINKS_BASENAME,
14
+ array( $this, 'settings_link' )
15
+ );
16
+ }
17
+
18
+ /**
19
+ * Added Pages in Menu for Settings
20
+ *
21
+ * @access public
22
+ * @since 1.2
23
+ * @return void
24
+ */
25
+ public function admin_menu() {
26
+ add_menu_page( 'Custom Permalinks', 'Custom Permalinks', 'administrator',
27
+ 'cp-post-permalinks', array( $this,'posttype_permalinks' ),
28
+ 'dashicons-admin-links'
29
+ );
30
+ add_submenu_page( 'cp-post-permalinks', 'PostTypes Permalinks',
31
+ 'PostTypes Permalinks', 'administrator', 'cp-post-permalinks',
32
+ array( $this, 'posttype_permalinks' )
33
+ );
34
+ add_submenu_page( 'cp-post-permalinks', 'Category Permalinks',
35
+ 'Category Permalinks', 'administrator', 'cp-category-permalinks',
36
+ array( $this, 'category_permalinks' )
37
+ );
38
+ add_submenu_page( 'cp-post-permalinks', 'About Custom Permalinks',
39
+ 'About CP', 'administrator', 'cp-about-plugins',
40
+ array( $this, 'about_plugin' )
41
+ );
42
+ }
43
+
44
+ /**
45
+ * Shows all the Permalinks created by using this Plugin with Pager and
46
+ * Search Functionality of Posts/Pages.
47
+ *
48
+ * @access public
49
+ * @since 1.2
50
+ * @return void
51
+ */
52
+ public function posttype_permalinks() {
53
+ global $wpdb;
54
+ $filter_options = '';
55
+ $filter_permalink = '';
56
+ $search_permalink = '';
57
+ $html = '';
58
+ $error = '';
59
+
60
+ // Handle Bulk Operations
61
+ if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
62
+ || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
63
+ && isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
64
+ $post_ids = implode( ',', $_POST['permalink'] );
65
+ if ( preg_match( '/^\d+(?:,\d+)*$/', $post_ids ) ) {
66
+ $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids) AND meta_key = 'custom_permalink'" );
67
+ } else {
68
+ $error = '<div id="message" class="error">
69
+ <p>' . __( 'There is some error to proceed your request. Please retry with your request or contact to the plugin author.', 'custom-permalinks' ) . '</p>
70
+ </div>';
71
+ }
72
+ }
73
+ $html .= '<div class="wrap">
74
+ <h1 class="wp-heading-inline">' . __( 'PostTypes Permalinks', 'custom-permalinks' ) . '</h1>';
75
+ $html .= $error;
76
+
77
+ $search_value = '';
78
+ if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
79
+ $filter_permalink = 'AND pm.meta_value LIKE "%' . $_GET['s'] . '%"';
80
+ $search_permalink = '&s=' . $_GET['s'] . '';
81
+ $search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
82
+ $html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
83
+ }
84
+ $page_limit = 'LIMIT 0, 20';
85
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
86
+ && $_GET['paged'] > 1 ) {
87
+ $pager = 20 * ( $_GET['paged'] - 1 );
88
+ $page_limit = 'LIMIT ' . $pager . ', 20';
89
+ }
90
+ $sorting_by = 'ORDER By p.ID DESC';
91
+ $order_by = 'asc';
92
+ $order_by_class = 'desc';
93
+ if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'title' ) {
94
+ $filter_options .= '<input type="hidden" name="orderby" value="title" />';
95
+ if ( isset( $_GET['order'] ) && $_GET['order'] == 'desc' ) {
96
+ $sorting_by = 'ORDER By p.post_title DESC';
97
+ $order_by = 'asc';
98
+ $order_by_class = 'desc';
99
+ $filter_options .= '<input type="hidden" name="order" value="desc" />';
100
+ } else {
101
+ $sorting_by = 'ORDER By p.post_title';
102
+ $order_by = 'desc';
103
+ $order_by_class = 'asc';
104
+ $filter_options .= '<input type="hidden" name="order" value="asc" />';
105
+ }
106
+ }
107
+ $count_query = "SELECT COUNT(p.ID) AS total_permalinks FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . "";
108
+ $count_posts = $wpdb->get_row( $count_query );
109
+
110
+ $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
111
+ $html .= '<p class="search-box">';
112
+ $html .= '<input type="hidden" name="page" value="cp-post-permalinks" />';
113
+ $html .= $filter_options;
114
+ $html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
115
+ $html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
116
+ $html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
117
+ $html .= '</form>';
118
+ $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
119
+ $html .= '<div class="tablenav top">';
120
+ $html .= '<div class="alignleft actions bulkactions">
121
+ <label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
122
+ <select name="action" id="bulk-action-selector-top">
123
+ <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
124
+ <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
125
+ </select>
126
+ <input type="submit" id="doaction" class="button action" value="Apply">
127
+ </div>';
128
+
129
+ $posts = 0;
130
+ if ( isset( $count_posts->total_permalinks )
131
+ && $count_posts->total_permalinks > 0 ) {
132
+
133
+ $html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
134
+
135
+ $query = "SELECT p.ID, p.post_title, p.post_type, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . " " . $sorting_by . " " . $page_limit . "";
136
+ $posts = $wpdb->get_results( $query );
137
+
138
+ $pagination_html = '';
139
+ $total_pages = ceil( $count_posts->total_permalinks / 20 );
140
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
141
+ && $_GET['paged'] > 0 ) {
142
+ $pagination_html = $this->cp_pager(
143
+ $count_posts->total_permalinks, $_GET['paged'], $total_pages
144
+ );
145
+ if ( $_GET['paged'] > $total_pages ) {
146
+ $redirect_uri = explode(
147
+ '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI']
148
+ );
149
+ header( 'Location: ' . $redirect_uri[0], 301 );
150
+ exit();
151
+ }
152
+ } elseif ( ! isset( $_GET['paged'] ) ) {
153
+ $pagination_html = $this->cp_pager(
154
+ $count_posts->total_permalinks, 1, $total_pages
155
+ );
156
+ }
157
+
158
+ $html .= $pagination_html;
159
+ }
160
+ $table_navigation = $this->tablenav_posts(
161
+ $order_by_class, $order_by, $search_permalink
162
+ );
163
+
164
+ $html .= '</div>';
165
+ $html .= '<table class="wp-list-table widefat fixed striped posts">
166
+ <thead>' . $table_navigation . '</thead>
167
+ <tbody>';
168
+ if ( $posts != 0 && ! empty( $posts ) ) {
169
+ foreach ( $posts as $post ) {
170
+ $html .= '<tr valign="top">';
171
+ $html .= '<th scope="row" class="check-column">
172
+ <input type="checkbox" name="permalink[]" value="' . $post->ID . '" />
173
+ </th>';
174
+ $html .= '<td><strong>
175
+ <a class="row-title" href="post.php?action=edit&post=' . $post->ID . '">' . $post->post_title . '</a>
176
+ </strong></td>';
177
+ $html .= '<td>' . ucwords( $post->post_type ) . '</td>';
178
+ $html .= '<td>
179
+ <a href="/' . $post->meta_value . '" target="_blank" title="' . __( "Visit " . $post->post_title, "custom-permalinks" ) . '">/' . urldecode( $post->meta_value ) . '</a>
180
+ </td>';
181
+ $html .= '</tr>';
182
+ }
183
+ } else {
184
+ $html .= '<tr class="no-items">
185
+ <td class="colspanchange" colspan="10">No permalinks found.</td>
186
+ </tr>';
187
+ }
188
+ $html .= '</tbody>
189
+ <tfoot>' . $table_navigation . '</tfoot>
190
+ </table>';
191
+
192
+ $html .= '<div class="tablenav bottom">
193
+ <div class="alignleft actions bulkactions">
194
+ <label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
195
+ <select name="action2" id="bulk-action-selector-bottom">
196
+ <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
197
+ <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
198
+ </select>
199
+ <input type="submit" id="doaction2" class="button action" value="Apply">
200
+ </div>
201
+ ' . $pagination_html . '
202
+ </div>';
203
+ $html .= '</form></div>';
204
+ echo $html;
205
+
206
+ add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
207
+ }
208
+
209
+ /**
210
+ * Return the Navigation row HTML same as Default Posts page for PostTypes
211
+ *
212
+ * @access private
213
+ * @since 1.2
214
+ * @return string
215
+ */
216
+ private function tablenav_posts( $order_by_class, $order_by, $search_permalink ) {
217
+ $nav = '<tr>
218
+ <td id="cb" class="manage-column column-cb check-column">
219
+ <label class="screen-reader-text" for="cb-select-all-1">Select All</label>
220
+ <input id="cb-select-all-1" type="checkbox">
221
+ </td>
222
+ <th scope="col" id="title" class="manage-column column-title column-primary sortable ' . $order_by_class . '">
223
+ <a href="/wp-admin/admin.php?page=cp-post-permalinks&amp;orderby=title&amp;order=' . $order_by . $search_permalink . '"><span>' . __( "Title", "custom-permalinks" ) . '</span><span class="sorting-indicator"></span></a>
224
+ </th>
225
+ <th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
226
+ <th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
227
+ </tr>';
228
+ return $nav;
229
+ }
230
+
231
+ /**
232
+ * Shows all the Permalinks created by using this Plugin with Pager and
233
+ * Search Functionality of Category/Tags
234
+ *
235
+ * @access public
236
+ * @since 1.2
237
+ * @return void
238
+ */
239
+ public function category_permalinks() {
240
+
241
+ $search_permalink = '';
242
+ $html = '';
243
+
244
+ // Handle Bulk Operations
245
+ if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
246
+ || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
247
+ && isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
248
+ $remove_perm = $_POST['permalink'];
249
+ $data = get_option( 'custom_permalink_table' );
250
+ if ( isset( $data ) && is_array( $data ) ) {
251
+ $i = 0;
252
+ foreach ( $data as $link => $info ) {
253
+ if ( in_array( $info['id'], $remove_perm ) ) {
254
+ unset( $data[$link] );
255
+ unset( $remove_perm[$i] );
256
+ if ( ! is_array( $remove_perm ) || empty( $remove_perm ) )
257
+ break;
258
+ }
259
+ $i++;
260
+ }
261
+ }
262
+ update_option( 'custom_permalink_table', $data );
263
+ }
264
+ $html .= '<div class="wrap">
265
+ <h1 class="wp-heading-inline">' . __( 'Category/Tags Permalinks', 'custom-permalinks' ) . '</h1>';
266
+
267
+ $search_value = '';
268
+ if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
269
+ $search_permalink = '&s=' . $_GET['s'] . '';
270
+ $search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
271
+ $html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
272
+ }
273
+ $pager_offset = '0';
274
+ $page_limit = 20;
275
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
276
+ $pager_offset = 20 * ( $_GET['paged'] - 1 );
277
+ $page_limit = $pager_offset + 20;
278
+ }
279
+ $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
280
+ $html .= '<p class="search-box">';
281
+ $html .= '<input type="hidden" name="page" value="cp-category-permalinks" />';
282
+ $html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
283
+ $html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
284
+ $html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
285
+ $html .= '</form>';
286
+ $html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
287
+ $html .= '<div class="tablenav top">';
288
+ $html .= '<div class="alignleft actions bulkactions">
289
+ <label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
290
+ <select name="action" id="bulk-action-selector-top">
291
+ <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
292
+ <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
293
+ </select>
294
+ <input type="submit" id="doaction" class="button action" value="Apply">
295
+ </div>';
296
+
297
+ $posts = 0;
298
+ $table = get_option( 'custom_permalink_table' );
299
+ $count_tags = count( $table );
300
+ $pagination_html = '';
301
+ if ( isset( $table ) && is_array( $table ) && $count_tags > 0 ) {
302
+
303
+ $filtered = array();
304
+ if ( $search_value != '' ) {
305
+ foreach ( $table as $key => $value ) {
306
+ if ( preg_match( '/' . $search_value . '/', $key) ) {
307
+ $filtered[$key] = $value;
308
+ }
309
+ }
310
+ $table = $filtered;
311
+ $count_tags = count( $table );
312
+ }
313
+
314
+ $html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
315
+
316
+ $total_pages = ceil( $count_tags / 20 );
317
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
318
+ && $_GET['paged'] > 0 ) {
319
+ $pagination_html = $this->cp_pager(
320
+ $count_tags, $_GET['paged'], $total_pages
321
+ );
322
+ if ( $_GET['paged'] > $total_pages ) {
323
+ $redirect_uri = explode(
324
+ '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI']
325
+ );
326
+ header( 'Location: ' . $redirect_uri[0], 301 );
327
+ exit();
328
+ }
329
+ } elseif ( ! isset( $_GET['paged'] ) ) {
330
+ $pagination_html = $this->cp_pager( $count_tags, 1, $total_pages );
331
+ }
332
+
333
+ $html .= $pagination_html;
334
+ }
335
+ $table_navigation = $this->tablenav_category( $search_permalink );
336
+
337
+ $html .= '</div>';
338
+ $html .= '<table class="wp-list-table widefat fixed striped posts">
339
+ <thead>' . $table_navigation . '</thead>
340
+ <tbody>';
341
+
342
+ if ( $table && is_array( $table ) && $count_tags > 0 ) {
343
+ uasort( $table, array( 'Custom_Permalinks_Admin', 'sort_array' ) );
344
+ $i = -1;
345
+ foreach ( $table as $permalink => $info ) {
346
+ $i++;
347
+ if ( $i < $pager_offset )
348
+ continue;
349
+
350
+ if ( $i >= $page_limit )
351
+ break;
352
+
353
+ $type = $info['kind'] == 'tag' ? 'post_tag' : 'category';
354
+ $term = get_term( $info['id'], $type );
355
+ $html .= '<tr valign="top">';
356
+ $html .= '<th scope="row" class="check-column">
357
+ <input type="checkbox" name="permalink[]" value="' . $info['id'] . '" />
358
+ </th>';
359
+ $html .= '<td><strong>
360
+ <a class="row-title" href="edit-tags.php?action=edit&taxonomy=' . $type . '&tag_ID=' . $info['id'] . ' ">' . $term->name . '</a>
361
+ </strong></td>';
362
+ $html .= '<td>' . ucwords( $info['kind'] ) . '</td>';
363
+ $html .= '<td>
364
+ <a href="/' . $permalink . '" target="_blank" title="' . __( "Visit " . $term->name, "custom-permalinks" ) . '">/' . $permalink . '</a>
365
+ </td>';
366
+ $html .= '</tr>';
367
+ }
368
+ } else {
369
+ $html .= '<tr class="no-items">
370
+ <td class="colspanchange" colspan="10">No permalinks found.</td>
371
+ </tr>';
372
+ }
373
+ $html .= '</tbody>
374
+ <tfoot>' . $table_navigation . '</tfoot>
375
+ </table>';
376
+
377
+ $html .= '<div class="tablenav bottom">
378
+ <div class="alignleft actions bulkactions">
379
+ <label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
380
+ <select name="action2" id="bulk-action-selector-bottom">
381
+ <option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
382
+ <option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
383
+ </select>
384
+ <input type="submit" id="doaction2" class="button action" value="Apply">
385
+ </div>
386
+ ' . $pagination_html . '
387
+ </div>';
388
+ $html .= '</form></div>';
389
+ echo $html;
390
+
391
+ add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
392
+ }
393
+
394
+ /**
395
+ * Sort the terms array in desc order using term id
396
+ *
397
+ * @access private
398
+ * @since 1.2
399
+ * @return integer
400
+ */
401
+ private function sort_array( $a, $b ) {
402
+ return $b['id'] - $a['id'];
403
+ }
404
+
405
+ /**
406
+ * Return the Navigation row HTML same as Default Posts page for Category
407
+ *
408
+ * @access private
409
+ * @since 1.2
410
+ * @return string
411
+ */
412
+ private function tablenav_category( $search_permalink ) {
413
+ $nav = '<tr>
414
+ <td id="cb" class="manage-column column-cb check-column">
415
+ <label class="screen-reader-text" for="cb-select-all-1">Select All</label>
416
+ <input id="cb-select-all-1" type="checkbox">
417
+ </td>
418
+ <th scope="col" id="title" class="manage-column column-title column-primary">' . __( "Title", "custom-permalinks" ) . '</th>
419
+ <th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
420
+ <th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
421
+ </tr>';
422
+ return $nav;
423
+ }
424
+
425
+ /**
426
+ * Return the Pager HTML
427
+ *
428
+ * @access private
429
+ * @since 1.2
430
+ * @return string
431
+ */
432
+ private function cp_pager( $total_permalinks, $current_pager_value = 1, $total_pager = 0 ) {
433
+
434
+ if ( $total_pager == 0 ) return;
435
+
436
+ if ( $total_pager == 1 ) {
437
+ $pagination_html = '<div class="tablenav-pages one-page">
438
+ <span class="displaying-num">' . $total_permalinks . ' items</span>
439
+ </div>';
440
+ return $pagination_html;
441
+ }
442
+
443
+ $remove_pager_uri = explode(
444
+ '&paged=' . $current_pager_value . '', $_SERVER['REQUEST_URI']
445
+ );
446
+ $pagination_html = '<div class="tablenav-pages">
447
+ <span class="displaying-num">' . $total_permalinks . ' items</span>
448
+ <span class="pagination-links">';
449
+
450
+ if ( $current_pager_value == 1 ) {
451
+ $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo; </span>
452
+ <span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo; </span>';
453
+ } else {
454
+ $prev_page = $current_pager_value - 1;
455
+ if ( $prev_page == 1 ) {
456
+ $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
457
+ } else {
458
+ $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=1" title="First page" class="first-page">
459
+ <span class="screen-reader-text">First page</span>
460
+ <span aria-hidden="true">&laquo;</span>
461
+ </a> ';
462
+ }
463
+ $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $prev_page . '" title="Previous page" class="prev-page">
464
+ <span class="screen-reader-text">Previous page</span>
465
+ <span aria-hidden="true">&lsaquo;</span>
466
+ </a> ';
467
+ }
468
+
469
+ $pagination_html .= '<span class="paging-input">
470
+ <label for="current-page-selector" class="screen-reader-text">Current Page</label>
471
+ <input class="current-page" id="current-page-selector" type="text" name="paged" value="' . $current_pager_value . '" size="1" aria-describedby="table-paging" />
472
+ <span class="tablenav-paging-text"> of <span class="total-pages">' . $total_pager . ' </span> </span>
473
+ </span>';
474
+
475
+ if ( $current_pager_value == $total_pager ) {
476
+ $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo; </span>
477
+ <span class="tablenav-pages-navspan" aria-hidden="true">&raquo; </span>';
478
+ } else {
479
+ $next_page = $current_pager_value + 1;
480
+ $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $next_page . '" title="Next page" class="next-page">
481
+ <span class="screen-reader-text">Next page</span>
482
+ <span aria-hidden="true">&rsaquo;</span>
483
+ </a> ';
484
+ if ( $total_pager == $next_page) {
485
+ $pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
486
+ } else {
487
+ $pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $total_pager . '" title="Last page" class="last-page">
488
+ <span class="screen-reader-text">Last page</span>
489
+ <span aria-hidden="true">&raquo;</span>
490
+ </a> ';
491
+ }
492
+ }
493
+ $pagination_html .= '</span></div>';
494
+
495
+ return $pagination_html;
496
+ }
497
+
498
+ /**
499
+ * Add About Plugins Page
500
+ *
501
+ * @access public
502
+ * @since 1.2.11
503
+ * @return void
504
+ */
505
+ public function about_plugin() {
506
+ require_once(
507
+ CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-about.php'
508
+ );
509
+ new Custom_Permalinks_About();
510
+ add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
511
+ }
512
+
513
+ /**
514
+ * Add Plugin Support and Follow Message in the footer of Admin Pages
515
+ *
516
+ * @access public
517
+ * @since 1.2.11
518
+ * @return string
519
+ */
520
+ public function admin_footer_text() {
521
+ $footer_text = sprintf(
522
+ __( 'Custom Permalinks version %s by <a href="%s" title="Sami Ahmed Siddiqui Company Website" target="_blank">Sami Ahmed Siddiqui</a> - <a href="%s" title="Support forums" target="_blank">Support forums</a> - Follow on Twitter: <a href="%s" title="Follow Sami Ahmed Siddiqui on Twitter" target="_blank">Sami Ahmed Siddiqui</a>', 'custom-permalinks' ),
523
+ CUSTOM_PERMALINKS_PLUGIN_VERSION, 'https://www.yasglobal.com/',
524
+ 'https://wordpress.org/support/plugin/custom-permalinks',
525
+ 'https://twitter.com/samisiddiqui91'
526
+ );
527
+ return $footer_text;
528
+ }
529
+
530
+ /**
531
+ * Add About and Premium Settings Page Link on the Plugin Page
532
+ * under the Plugin Name.
533
+ *
534
+ * @access public
535
+ * @since 1.2.11
536
+ * @return array
537
+ */
538
+ public function settings_link( $links ) {
539
+ $about = sprintf(
540
+ __( '<a href="%s" title="About">About</a>', 'custom-permalinks' ),
541
+ 'admin.php?page=cp-about-plugins'
542
+ );
543
+ $premium_support = sprintf(
544
+ __( '<a href="%s" title="Premium Support" target="_blank">Premium Support</a>', 'custom-permalinks' ),
545
+ 'https://www.custompermalinks.com/#pricing-section'
546
+ );
547
+ $contact = sprintf(
548
+ __( '<a href="%s" title="Contact" target="_blank">Contact</a>', 'custom-permalinks' ),
549
+ 'https://www.custompermalinks.com/contact-us/'
550
+ );
551
+ array_unshift( $links, $contact );
552
+ array_unshift( $links, $premium_support );
553
+ array_unshift( $links, $about );
554
+
555
+ return $links;
556
+ }
557
  }
changelog.txt CHANGED
@@ -2,27 +2,27 @@
2
 
3
  This file contains only old changelog. See readme.txt for newer versions.
4
 
5
- = 1.2.5 =
6
 
7
  * Fixed Category/Tag Update Issue + Typo on Admin Page
8
 
9
- = 1.2.4 =
10
 
11
  * Fixed Slug issue with Yoast SEO
12
 
13
- = 1.2.3 =
14
 
15
  * Fixed PHP Notice on Edit Post Page
16
 
17
- = 1.2.2 =
18
 
19
  * Fixed Typo of Class Object for term on Admin Page
20
 
21
- = 1.2.1 =
22
 
23
  * Fixed Class Typo
24
 
25
- = 1.2 =
26
 
27
  * Enhancements
28
  * Added Filter to Exclude/Ignore URL to be processed
@@ -32,7 +32,7 @@ This file contains only old changelog. See readme.txt for newer versions.
32
  * Bugs
33
  * Fixed Vulnerability Issues
34
 
35
- = 1.1 =
36
 
37
  * Enhancements
38
  * Added PostTypes Permalinks Page
@@ -49,51 +49,51 @@ This file contains only old changelog. See readme.txt for newer versions.
49
  * 404 Issues
50
  * Child pages bug
51
 
52
- = 1.0.2 =
53
 
54
  * Fixed Notice and some URL Issues
55
 
56
- = 1.0.1 =
57
 
58
  * Fixed issue with AMP Pages
59
 
60
- = 1.0 =
61
 
62
  * Updated Query on the `custom_permalinks_request` Function
63
 
64
- = 0.9.3 =
65
 
66
  * Fixed PolyLang Conflicts
67
 
68
- = 0.9.2 =
69
 
70
  * Fixed WPML Conflicts
71
 
72
- = 0.9.1 =
73
 
74
  * Fixed issues of Filters and Actions (Replaces 'edit_files' with 10)
75
 
76
- = 0.9 =
77
 
78
  * Resolved the conflict with PolyLang Plugin
79
 
80
- = 0.8 =
81
 
82
  * Fixed (Draft preview issue for custom post types + some PHP Warnings)
83
 
84
- = 0.7.28 =
85
 
86
  * Fixed draft preview issue(posts + pages)
87
 
88
- = 0.7.27 =
89
 
90
  * Fixed Loop Redirecting issue
91
 
92
- = 0.7.26 =
93
 
94
  * Fixed PHP Notice issue
95
 
96
- = 0.7.25 =
97
 
98
  * Fixed draft preview issue
99
 
2
 
3
  This file contains only old changelog. See readme.txt for newer versions.
4
 
5
+ = 1.2.5 - Oct 17, 2017 =
6
 
7
  * Fixed Category/Tag Update Issue + Typo on Admin Page
8
 
9
+ = 1.2.4 - Oct 07, 2017 =
10
 
11
  * Fixed Slug issue with Yoast SEO
12
 
13
+ = 1.2.3 - Sept 27, 2017 =
14
 
15
  * Fixed PHP Notice on Edit Post Page
16
 
17
+ = 1.2.2 - Sept 26, 2017 =
18
 
19
  * Fixed Typo of Class Object for term on Admin Page
20
 
21
+ = 1.2.1 - Sept 25, 2017 =
22
 
23
  * Fixed Class Typo
24
 
25
+ = 1.2 - Sept 25, 2017 =
26
 
27
  * Enhancements
28
  * Added Filter to Exclude/Ignore URL to be processed
32
  * Bugs
33
  * Fixed Vulnerability Issues
34
 
35
+ = 1.1 - Sept 25, 2017 =
36
 
37
  * Enhancements
38
  * Added PostTypes Permalinks Page
49
  * 404 Issues
50
  * Child pages bug
51
 
52
+ = 1.0.2 - Aug 15, 2017 =
53
 
54
  * Fixed Notice and some URL Issues
55
 
56
+ = 1.0.1 - Aug 12, 2017 =
57
 
58
  * Fixed issue with AMP Pages
59
 
60
+ = 1.0 - Aug 11, 2017 =
61
 
62
  * Updated Query on the `custom_permalinks_request` Function
63
 
64
+ = 0.9.3 - July 21, 2017 =
65
 
66
  * Fixed PolyLang Conflicts
67
 
68
+ = 0.9.2 - July 16, 2017 =
69
 
70
  * Fixed WPML Conflicts
71
 
72
+ = 0.9.1 - July 16, 2017 =
73
 
74
  * Fixed issues of Filters and Actions (Replaces 'edit_files' with 10)
75
 
76
+ = 0.9 - July 16, 2017 =
77
 
78
  * Resolved the conflict with PolyLang Plugin
79
 
80
+ = 0.8 - Aug 19, 2016 =
81
 
82
  * Fixed (Draft preview issue for custom post types + some PHP Warnings)
83
 
84
+ = 0.7.28 - July 28, 2016 =
85
 
86
  * Fixed draft preview issue(posts + pages)
87
 
88
+ = 0.7.27 - July 21, 2016 =
89
 
90
  * Fixed Loop Redirecting issue
91
 
92
+ = 0.7.26 - July 20, 2016 =
93
 
94
  * Fixed PHP Notice issue
95
 
96
+ = 0.7.25 - June 06, 2016 =
97
 
98
  * Fixed draft preview issue
99
 
custom-permalinks-main.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
- /**
3
- * @package CustomPermalinks\Main
4
- */
5
-
6
- // Make sure we don't expose any info if called directly
7
- if ( ! defined( 'ABSPATH' ) ) {
8
- echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
9
- exit;
10
- }
11
-
12
- if ( ! function_exists( 'add_action' ) || ! function_exists( 'add_filter' ) ) {
13
- header( 'Status: 403 Forbidden' );
14
- header( 'HTTP/1.1 403 Forbidden' );
15
- exit();
16
- }
17
-
18
- define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.17' );
19
-
20
- if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
21
- define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( CUSTOM_PERMALINKS_FILE ) );
22
- }
23
-
24
- if ( ! defined( 'CUSTOM_PERMALINKS_BASENAME' ) ) {
25
- define( 'CUSTOM_PERMALINKS_BASENAME', plugin_basename( CUSTOM_PERMALINKS_FILE ) );
26
- }
27
-
28
- require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
29
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
30
- $custom_permalinks_frontend->init();
31
-
32
- require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
33
- $custom_permalinks_form = new Custom_Permalinks_Form();
34
- $custom_permalinks_form->init();
35
-
36
- if ( is_admin() ) {
37
- require_once( CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-admin.php' );
38
- new Custom_Permalinks_Admin();
39
- }
40
-
41
- /**
42
- * Add textdomain hook for translation
43
- */
44
- function custom_permalinks_translation_capability() {
45
- load_plugin_textdomain( 'custom-permalinks', FALSE,
46
- basename( dirname( CUSTOM_PERMALINKS_FILE ) ) . '/languages/'
47
- );
48
- }
49
- add_action( 'plugins_loaded', 'custom_permalinks_translation_capability' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
custom-permalinks.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Custom Permalinks
4
  * Plugin URI: https://wordpress.org/plugins/custom-permalinks/
5
  * Description: Set custom permalinks on a per-post basis
6
- * Version: 1.2.17
7
  * Author: Sami Ahmed Siddiqui
8
  * Author URI: https://www.custompermalinks.com/
9
  * Donate link: https://www.paypal.me/yasglobal
@@ -35,12 +35,87 @@
35
 
36
  // Make sure we don't expose any info if called directly
37
  if ( ! defined( 'ABSPATH' ) ) {
38
- echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
39
- exit;
40
  }
41
 
42
- if ( ! defined( 'CUSTOM_PERMALINKS_FILE' ) ) {
43
- define( 'CUSTOM_PERMALINKS_FILE', __FILE__ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
- require_once( dirname( CUSTOM_PERMALINKS_FILE ) . '/custom-permalinks-main.php' );
3
  * Plugin Name: Custom Permalinks
4
  * Plugin URI: https://wordpress.org/plugins/custom-permalinks/
5
  * Description: Set custom permalinks on a per-post basis
6
+ * Version: 1.2.18
7
  * Author: Sami Ahmed Siddiqui
8
  * Author URI: https://www.custompermalinks.com/
9
  * Donate link: https://www.paypal.me/yasglobal
35
 
36
  // Make sure we don't expose any info if called directly
37
  if ( ! defined( 'ABSPATH' ) ) {
38
+ echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
39
+ exit;
40
  }
41
 
42
+ final class Custom_Permalinks {
43
+
44
+ /**
45
+ * Class constructor.
46
+ */
47
+ public function __construct() {
48
+ $this->setup_constants();
49
+ $this->includes();
50
+
51
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
52
+ }
53
+
54
+ /**
55
+ * Setup plugin constants
56
+ *
57
+ * @access private
58
+ * @since 1.2.18
59
+ * @return void
60
+ */
61
+ private function setup_constants() {
62
+ if ( ! defined( 'CUSTOM_PERMALINKS_FILE' ) ) {
63
+ define( 'CUSTOM_PERMALINKS_FILE', __FILE__ );
64
+ }
65
+
66
+ if ( ! defined( 'CUSTOM_PERMALINKS_PLUGIN_VERSION' ) ) {
67
+ define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.18' );
68
+ }
69
+
70
+ if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
71
+ define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( CUSTOM_PERMALINKS_FILE ) );
72
+ }
73
+
74
+ if ( ! defined( 'CUSTOM_PERMALINKS_BASENAME' ) ) {
75
+ define( 'CUSTOM_PERMALINKS_BASENAME', plugin_basename( CUSTOM_PERMALINKS_FILE ) );
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Include required files
81
+ *
82
+ * @access private
83
+ * @since 1.2.18
84
+ * @return void
85
+ */
86
+ private function includes() {
87
+ require_once(
88
+ CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
89
+ );
90
+ $cp_frontend = new Custom_Permalinks_Frontend();
91
+ $cp_frontend->init();
92
+
93
+ require_once(
94
+ CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php'
95
+ );
96
+ $cp_form = new Custom_Permalinks_Form();
97
+ $cp_form->init();
98
+
99
+ if ( is_admin() ) {
100
+ require_once(
101
+ CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-admin.php'
102
+ );
103
+ new Custom_Permalinks_Admin();
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Loads the plugin language files
109
+ *
110
+ * @access public
111
+ * @since 1.2.18
112
+ * @return void
113
+ */
114
+ public function load_textdomain() {
115
+ load_plugin_textdomain( 'custom-permalinks', FALSE,
116
+ basename( dirname( CUSTOM_PERMALINKS_FILE ) ) . '/languages/'
117
+ );
118
+ }
119
  }
120
 
121
+ new Custom_Permalinks();
frontend/class-custom-permalinks-form.php CHANGED
@@ -3,382 +3,402 @@
3
  * @package CustomPermalinks\Frontend\Form
4
  */
5
 
6
- class Custom_Permalinks_Form {
7
-
8
- /**
9
- * Initialize WordPress Hooks
10
- */
11
- public function init() {
12
-
13
- add_filter( 'get_sample_permalink_html',
14
- array( $this, 'custom_permalinks_get_sample_permalink_html' ), 10, 4
15
- );
16
-
17
- add_action( 'save_post',
18
- array( $this, 'custom_permalinks_save_post' ), 10, 3
19
- );
20
- add_action( 'delete_post',
21
- array( $this, 'custom_permalinks_delete_permalink' ), 10
22
- );
23
-
24
- add_action( 'edit_tag_form',
25
- array( $this, 'custom_permalinks_term_options' )
26
- );
27
- add_action( 'add_tag_form',
28
- array( $this, 'custom_permalinks_term_options' )
29
- );
30
- add_action( 'edit_category_form',
31
- array( $this, 'custom_permalinks_term_options' )
32
- );
33
-
34
- add_action( 'edited_post_tag',
35
- array( $this, 'custom_permalinks_save_tag' )
36
- );
37
- add_action( 'edited_category',
38
- array( $this, 'custom_permalinks_save_category' )
39
- );
40
- add_action( 'create_post_tag',
41
- array( $this, 'custom_permalinks_save_tag' )
42
- );
43
- add_action( 'create_category',
44
- array( $this, 'custom_permalinks_save_category' )
45
- );
46
- add_action( 'delete_post_tag',
47
- array( $this, 'custom_permalinks_delete_term' )
48
- );
49
- add_action( 'delete_post_category',
50
- array( $this, 'custom_permalinks_delete_term' )
51
- );
52
- }
53
-
54
- /**
55
- * Save per-post options
56
- */
57
- public function custom_permalinks_save_post( $id ) {
58
- if ( ! isset( $_REQUEST['custom_permalinks_edit'] ) ) {
59
- return;
60
- }
61
-
62
- delete_post_meta( $id, 'custom_permalink' );
63
-
64
- require_once(
65
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
66
- );
67
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
68
- $original_link = $custom_permalinks_frontend->custom_permalinks_original_post_link( $id );
69
- $permalink_structure = get_option( 'permalink_structure' );
70
-
71
- if ( $_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link ) {
72
- add_post_meta( $id, 'custom_permalink',
73
- str_replace( '%2F', '/',
74
- urlencode( ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" ) )
75
- )
76
- );
77
- }
78
- }
79
-
80
- /**
81
- * Delete post
82
- */
83
- public function custom_permalinks_delete_permalink( $id ) {
84
- global $wpdb;
85
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'custom_permalink' AND post_id = %d", $id ) );
86
- }
87
-
88
- /**
89
- * Per-post/page options (Wordpress > 2.9)
90
- */
91
- public function custom_permalinks_get_sample_permalink_html( $html, $id, $new_title, $new_slug ) {
92
- $permalink = get_post_meta( $id, 'custom_permalink', true );
93
- $post = get_post( $id );
94
-
95
- if ( $post->post_type == 'attachment' || $post->ID == get_option( 'page_on_front' ) ) {
96
- return $html;
97
- }
98
-
99
- $exclude_post_types = $post->post_type;
100
- $excluded = apply_filters( 'custom_permalinks_exclude_post_type', $exclude_post_types );
101
- if ( '__true' === $excluded ) {
102
- return $html;
103
- }
104
-
105
- ob_start();
106
-
107
- require_once(
108
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
109
- );
110
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
111
- if ( $post->post_type == "page" ) {
112
- $original_page_url = $custom_permalinks_frontend->custom_permalinks_original_page_link( $id );
113
- $this->custom_permalinks_get_form( $permalink, $original_page_url, false, $post->post_name );
114
- } else {
115
- $original_post_url = $custom_permalinks_frontend->custom_permalinks_original_post_link( $id );
116
- $this->custom_permalinks_get_form( $permalink, $original_post_url, false, $post->post_name );
117
- }
118
-
119
- $content = ob_get_contents();
120
- ob_end_clean();
121
-
122
- if ( 'publish' == $post->post_status ) {
123
- $view_post = 'page' == $post->post_type ? __( 'View Page', 'custom-permalinks' ) : __( 'View Post', 'custom-permalinks' );
124
- }
125
-
126
- if ( preg_match( "@view-post-btn.*?href='([^']+)'@s", $html, $matches ) ) {
127
- $permalink = $matches[1];
128
- } else {
129
- list( $permalink, $post_name ) = get_sample_permalink( $post->ID, $new_title, $new_slug );
130
- if ( false !== strpos( $permalink, '%postname%' )
131
- || false !== strpos( $permalink, '%pagename%' ) ) {
132
- $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
133
- }
134
- }
135
-
136
- return '<strong>' . __( 'Permalink:', 'custom-permalinks' ) . "</strong>\n" . $content .
137
- ( isset( $view_post ) ? "<span id='view-post-btn'><a href='$permalink' class='button button-small' target='_blank'>$view_post</a></span>\n" : "" );
138
- }
139
-
140
- /**
141
- * Per-post options (Wordpress < 2.9)
142
- */
143
- public function custom_permalinks_post_options() {
144
- global $post;
145
- $post_id = $post;
146
- if ( is_object( $post_id ) ) {
147
- $post_id = $post_id->ID;
148
- }
149
-
150
- $permalink = get_post_meta( $post_id, 'custom_permalink', true );
151
- ?>
152
- <div class="postbox closed">
153
- <h3><?php _e( 'Custom Permalink', 'custom-permalinks' ) ?></h3>
154
- <div class="inside">
155
- <?php
156
- require_once(
157
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
158
- );
159
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
160
- $custom_permalinks_frontend->custom_permalinks_get_form( $permalink, $custom_permalinks_frontend->custom_permalinks_original_post_link( $post_id ) );
161
- ?>
162
- </div>
163
- </div>
164
- <?php
165
- }
166
-
167
- /**
168
- * Per-page options (Wordpress < 2.9)
169
- */
170
- public function custom_permalinks_page_options() {
171
- global $post;
172
- $post_id = $post;
173
- if (is_object( $post_id ) ) {
174
- $post_id = $post_id->ID;
175
- }
176
-
177
- $permalink = get_post_meta( $post_id, 'custom_permalink', true );
178
- ?>
179
- <div class="postbox closed">
180
- <h3><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></h3>
181
- <div class="inside">
182
- <?php
183
- require_once(
184
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
185
- );
186
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
187
- $page_permalink = $custom_permalinks_frontend->custom_permalinks_original_page_link( $post_id );
188
- $this->custom_permalinks_get_form( $permalink, $page_permalink );
189
- ?>
190
- </div>
191
- </div>
192
- <?php
193
- }
194
-
195
- /**
196
- * Per-category/tag options
197
- */
198
- public function custom_permalinks_term_options( $object ) {
199
- if ( is_object( $object ) && isset( $object->term_id ) ) {
200
- require_once(
201
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
202
- );
203
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
204
- $permalink = $custom_permalinks_frontend->custom_permalinks_permalink_for_term( $object->term_id );
205
-
206
- if ( $object->term_id ) {
207
- if ( $object->taxonomy == 'post_tag' ) {
208
- $originalPermalink = $custom_permalinks_frontend->custom_permalinks_original_tag_link( $object->term_id );
209
- } else {
210
- $originalPermalink = $custom_permalinks_frontend->custom_permalinks_original_category_link( $object->term_id );
211
- }
212
- }
213
-
214
- $this->custom_permalinks_get_form( $permalink, $originalPermalink );
215
- } else {
216
- $this->custom_permalinks_get_form( '' );
217
- }
218
-
219
- // Move the save button to above this form
220
- wp_enqueue_script( 'jquery' );
221
- ?>
222
- <script type="text/javascript">
223
- jQuery(document).ready(function() {
224
- var button = jQuery('#custom_permalink_form').parent().find('.submit');
225
- button.remove().insertAfter(jQuery('#custom_permalink_form'));
226
- });
227
- </script>
228
- <?php
229
- }
230
-
231
- /**
232
- * Helper function to render form
233
- */
234
- private function custom_permalinks_get_form( $permalink, $original = '', $renderContainers = true, $postname = '' ) {
235
- ?>
236
- <input value="true" type="hidden" name="custom_permalinks_edit" />
237
- <input value="<?php echo home_url(); ?>" type="hidden" name="custom_permalinks_home_url" id="custom_permalinks_home_url" />
238
- <input value="<?php echo htmlspecialchars( urldecode( $permalink ) ); ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
239
-
240
- <?php
241
- if ( $renderContainers ) :
242
- ?>
243
- <table class="form-table" id="custom_permalink_form">
244
- <tr>
245
- <th scope="row"><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></th>
246
- <td>
247
- <?php
248
- endif;
249
- if ( $permalink == '' ) {
250
- $original = $this->custom_permalinks_check_conflicts( $original );
251
- }
252
- $post_slug = htmlspecialchars( $permalink ? urldecode( $permalink ) : urldecode( $original ) );
253
- $original_encoded_url = htmlspecialchars( urldecode( $original ) );
254
- wp_enqueue_script( 'custom-permalinks-form', plugins_url( '/js/script-form.min.js', __FILE__ ), array(), false, true );
255
- $postname_html = '';
256
- if ( isset( $postname ) && $postname != '' ) {
257
- $postname_html = '<input type="hidden" id="new-post-slug" class="text" value="' . $postname . '" />';
258
- }
259
-
260
- echo home_url() . '/<span id="editable-post-name" title="Click to edit this part of the permalink">' . $postname_html;
261
-
262
- ?>
263
- <input type="text" id="custom-permalinks-post-slug" class="text" value="<?php echo $post_slug; ?>"
264
- style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd'; ?>"
265
- onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
266
- onblur="document.getElementById('custom_permalink').value = this.value; if ( this.value == '' || this.value == '<?php echo $original_encoded_url; ?>' ) { this.value = '<?php echo $original_encoded_url; ?>'; this.style.color = '#ddd'; }" />
267
- </span>
268
-
269
- <?php if ( $renderContainers ) : ?>
270
- <br />
271
- <small><?php _e( 'Leave blank to disable', 'custom-permalinks' ); ?></small>
272
- </td>
273
- </tr>
274
- </table>
275
- <?php
276
- endif;
277
- }
278
-
279
- /**
280
- * Save per-tag options
281
- */
282
- public function custom_permalinks_save_tag( $id ) {
283
- if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
284
- || isset( $_REQUEST['post_ID'] ) ) {
285
- return;
286
- }
287
- $newPermalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), '/' );
288
-
289
- require_once(
290
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
291
- );
292
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
293
- if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_tag_link( $id ) ) {
294
- return;
295
- }
296
-
297
- $term = get_term( $id, 'post_tag' );
298
- $this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
299
- }
300
-
301
- /**
302
- * Save per-category options
303
- */
304
- public function custom_permalinks_save_category( $id ) {
305
- if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
306
- || isset( $_REQUEST['post_ID'] ) ) {
307
- return;
308
- }
309
- $newPermalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), '/' );
310
-
311
- require_once(
312
- CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
313
- );
314
- $custom_permalinks_frontend = new Custom_Permalinks_Frontend();
315
- if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_category_link( $id ) ) {
316
- return;
317
- }
318
-
319
- $term = get_term( $id, 'category' );
320
- $this->custom_permalinks_save_term(
321
- $term, str_replace( '%2F', '/', urlencode( $newPermalink ) )
322
- );
323
- }
324
-
325
- /**
326
- * Save term (common to tags and categories)
327
- */
328
- public function custom_permalinks_save_term( $term, $permalink ) {
329
-
330
- $this->custom_permalinks_delete_term( $term->term_id );
331
- $table = get_option( 'custom_permalink_table' );
332
- if ( $permalink ) {
333
- $table[$permalink] = array(
334
- 'id' => $term->term_id,
335
- 'kind' => ( $term->taxonomy == 'category' ? 'category' : 'tag' ),
336
- 'slug' => $term->slug
337
- );
338
- }
339
-
340
- update_option( 'custom_permalink_table', $table );
341
- }
342
-
343
- /**
344
- * Delete term
345
- */
346
- public function custom_permalinks_delete_term( $id ) {
347
- $table = get_option( 'custom_permalink_table' );
348
- if ( $table ) {
349
- foreach ( $table as $link => $info ) {
350
- if ( $info['id'] == $id ) {
351
- unset( $table[$link] );
352
- break;
353
- }
354
- }
355
- }
356
- update_option( 'custom_permalink_table', $table );
357
- }
358
-
359
- /**
360
- * Check Conflicts and resolve it (e.g: Polylang)
361
- */
362
- public function custom_permalinks_check_conflicts( $requested_url = '' ) {
363
- if ( $requested_url == '' ) {
364
- return;
365
- }
366
-
367
- // Check if the Polylang Plugin is installed so, make changes in the URL
368
- if ( defined( 'POLYLANG_VERSION' ) ) {
369
- $polylang_config = get_option( 'polylang' );
370
- if ( $polylang_config['force_lang'] == 1 ) {
371
-
372
- if ( strpos( $requested_url, 'language/' ) !== false ) {
373
- $requested_url = str_replace( 'language/', '', $requested_url );
374
- }
375
-
376
- $remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
377
- if ( $remove_lang != '' ) {
378
- return $remove_lang;
379
- }
380
- }
381
- }
382
- return $requested_url;
383
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  }
3
  * @package CustomPermalinks\Frontend\Form
4
  */
5
 
6
+ final class Custom_Permalinks_Form {
7
+
8
+ /**
9
+ * Initialize WordPress Hooks
10
+ *
11
+ * @access public
12
+ * @since 1.2
13
+ * @return void
14
+ */
15
+ public function init() {
16
+
17
+ add_filter( 'get_sample_permalink_html',
18
+ array( $this, 'custom_permalinks_get_sample_permalink_html' ), 10, 4
19
+ );
20
+
21
+ add_action( 'save_post',
22
+ array( $this, 'custom_permalinks_save_post' ), 10, 3
23
+ );
24
+ add_action( 'delete_post',
25
+ array( $this, 'custom_permalinks_delete_permalink' ), 10
26
+ );
27
+
28
+ add_action( 'edit_tag_form',
29
+ array( $this, 'custom_permalinks_term_options' )
30
+ );
31
+ add_action( 'add_tag_form',
32
+ array( $this, 'custom_permalinks_term_options' )
33
+ );
34
+ add_action( 'edit_category_form',
35
+ array( $this, 'custom_permalinks_term_options' )
36
+ );
37
+
38
+ add_action( 'edited_post_tag',
39
+ array( $this, 'custom_permalinks_save_tag' )
40
+ );
41
+ add_action( 'edited_category',
42
+ array( $this, 'custom_permalinks_save_category' )
43
+ );
44
+ add_action( 'create_post_tag',
45
+ array( $this, 'custom_permalinks_save_tag' )
46
+ );
47
+ add_action( 'create_category',
48
+ array( $this, 'custom_permalinks_save_category' )
49
+ );
50
+ add_action( 'delete_post_tag',
51
+ array( $this, 'custom_permalinks_delete_term' )
52
+ );
53
+ add_action( 'delete_post_category',
54
+ array( $this, 'custom_permalinks_delete_term' )
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Save per-post options
60
+ *
61
+ * @access public
62
+ * @return void
63
+ */
64
+ public function custom_permalinks_save_post( $id ) {
65
+ if ( ! isset( $_REQUEST['custom_permalinks_edit'] ) ) {
66
+ return;
67
+ }
68
+
69
+ delete_post_meta( $id, 'custom_permalink' );
70
+
71
+ $cp_frontend = new Custom_Permalinks_Frontend();
72
+ $original_link = $cp_frontend->custom_permalinks_original_post_link( $id );
73
+ $permalink_structure = get_option( 'permalink_structure' );
74
+
75
+ if ( $_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link ) {
76
+ add_post_meta( $id, 'custom_permalink',
77
+ str_replace( '%2F', '/',
78
+ urlencode( ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" ) )
79
+ )
80
+ );
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Delete Post Permalink
86
+ *
87
+ * @access public
88
+ * @return void
89
+ */
90
+ public function custom_permalinks_delete_permalink( $id ) {
91
+ global $wpdb;
92
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'custom_permalink' AND post_id = %d", $id ) );
93
+ }
94
+
95
+ /**
96
+ * Per-post/page options (Wordpress > 2.9)
97
+ *
98
+ * @access public
99
+ * @return string
100
+ */
101
+ public function custom_permalinks_get_sample_permalink_html( $html, $id, $new_title, $new_slug ) {
102
+ $permalink = get_post_meta( $id, 'custom_permalink', true );
103
+ $post = get_post( $id );
104
+
105
+ if ( 'attachment' == $post->post_type || $post->ID == get_option( 'page_on_front' ) ) {
106
+ return $html;
107
+ }
108
+
109
+ $exclude_post_types = $post->post_type;
110
+ $excluded = apply_filters( 'custom_permalinks_exclude_post_type', $exclude_post_types );
111
+ if ( '__true' === $excluded ) {
112
+ return $html;
113
+ }
114
+
115
+ ob_start();
116
+
117
+ $cp_frontend = new Custom_Permalinks_Frontend();
118
+ if ( 'page' == $post->post_type ) {
119
+ $original_page_url = $cp_frontend->custom_permalinks_original_page_link( $id );
120
+ $this->custom_permalinks_get_form( $permalink, $original_page_url, false, $post->post_name );
121
+ } else {
122
+ $original_post_url = $cp_frontend->custom_permalinks_original_post_link( $id );
123
+ $this->custom_permalinks_get_form( $permalink, $original_post_url, false, $post->post_name );
124
+ }
125
+
126
+ $content = ob_get_contents();
127
+ ob_end_clean();
128
+
129
+ if ( 'publish' == $post->post_status ) {
130
+ $view_post = 'page' == $post->post_type ? __( 'View Page', 'custom-permalinks' ) : __( 'View Post', 'custom-permalinks' );
131
+ }
132
+
133
+ if ( preg_match( "@view-post-btn.*?href='([^']+)'@s", $html, $matches ) ) {
134
+ $permalink = $matches[1];
135
+ } else {
136
+ list( $permalink, $post_name ) = get_sample_permalink( $post->ID, $new_title, $new_slug );
137
+ if ( false !== strpos( $permalink, '%postname%' )
138
+ || false !== strpos( $permalink, '%pagename%' ) ) {
139
+ $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
140
+ }
141
+ }
142
+
143
+ return '<strong>' . __( 'Permalink:', 'custom-permalinks' ) . "</strong>\n" . $content .
144
+ ( isset( $view_post ) ? "<span id='view-post-btn'><a href='$permalink' class='button button-small' target='_blank'>$view_post</a></span>\n" : "" );
145
+ }
146
+
147
+ /**
148
+ * Per-post options (Wordpress < 2.9)
149
+ *
150
+ * @access public
151
+ * @return void
152
+ */
153
+ public function custom_permalinks_post_options() {
154
+ global $post;
155
+ $post_id = $post;
156
+ if ( is_object( $post_id ) ) {
157
+ $post_id = $post_id->ID;
158
+ }
159
+
160
+ $permalink = get_post_meta( $post_id, 'custom_permalink', true );
161
+ ?>
162
+ <div class="postbox closed">
163
+ <h3><?php _e( 'Custom Permalink', 'custom-permalinks' ) ?></h3>
164
+ <div class="inside">
165
+ <?php
166
+ $cp_frontend = new Custom_Permalinks_Frontend();
167
+ $cp_frontend->custom_permalinks_get_form( $permalink, $cp_frontend->custom_permalinks_original_post_link( $post_id ) );
168
+ ?>
169
+ </div>
170
+ </div>
171
+ <?php
172
+ }
173
+
174
+ /**
175
+ * Per-page options (Wordpress < 2.9)
176
+ *
177
+ * @access public
178
+ * @return void
179
+ */
180
+ public function custom_permalinks_page_options() {
181
+ global $post;
182
+ $post_id = $post;
183
+ if (is_object( $post_id ) ) {
184
+ $post_id = $post_id->ID;
185
+ }
186
+
187
+ $permalink = get_post_meta( $post_id, 'custom_permalink', true );
188
+ ?>
189
+ <div class="postbox closed">
190
+ <h3><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></h3>
191
+ <div class="inside">
192
+ <?php
193
+ $cp_frontend = new Custom_Permalinks_Frontend();
194
+ $page_permalink = $cp_frontend->custom_permalinks_original_page_link( $post_id );
195
+ $this->custom_permalinks_get_form( $permalink, $page_permalink );
196
+ ?>
197
+ </div>
198
+ </div>
199
+ <?php
200
+ }
201
+
202
+ /**
203
+ * Per-category/tag options
204
+ *
205
+ * @access public
206
+ * @return void
207
+ */
208
+ public function custom_permalinks_term_options( $object ) {
209
+ if ( is_object( $object ) && isset( $object->term_id ) ) {
210
+ $cp_frontend = new Custom_Permalinks_Frontend();
211
+ $permalink = $cp_frontend->custom_permalinks_permalink_for_term( $object->term_id );
212
+
213
+ if ( $object->term_id ) {
214
+ if ( $object->taxonomy == 'post_tag' ) {
215
+ $originalPermalink = $cp_frontend->custom_permalinks_original_tag_link( $object->term_id );
216
+ } else {
217
+ $originalPermalink = $cp_frontend->custom_permalinks_original_category_link( $object->term_id );
218
+ }
219
+ }
220
+
221
+ $this->custom_permalinks_get_form( $permalink, $originalPermalink );
222
+ } else {
223
+ $this->custom_permalinks_get_form( '' );
224
+ }
225
+
226
+ // Move the save button to above this form
227
+ wp_enqueue_script( 'jquery' );
228
+ ?>
229
+ <script type="text/javascript">
230
+ jQuery(document).ready(function() {
231
+ var button = jQuery('#custom_permalink_form').parent().find('.submit');
232
+ button.remove().insertAfter(jQuery('#custom_permalink_form'));
233
+ });
234
+ </script>
235
+ <?php
236
+ }
237
+
238
+ /**
239
+ * Helper function to render form
240
+ *
241
+ * @access private
242
+ * @return void
243
+ */
244
+ private function custom_permalinks_get_form( $permalink, $original = '', $renderContainers = true, $postname = '' ) {
245
+ ?>
246
+ <input value="true" type="hidden" name="custom_permalinks_edit" />
247
+ <input value="<?php echo home_url(); ?>" type="hidden" name="custom_permalinks_home_url" id="custom_permalinks_home_url" />
248
+ <input value="<?php echo htmlspecialchars( urldecode( $permalink ) ); ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
249
+
250
+ <?php
251
+ if ( $renderContainers ) :
252
+ ?>
253
+ <table class="form-table" id="custom_permalink_form">
254
+ <tr>
255
+ <th scope="row"><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></th>
256
+ <td>
257
+ <?php
258
+ endif;
259
+ if ( $permalink == '' ) {
260
+ $original = $this->custom_permalinks_check_conflicts( $original );
261
+ }
262
+ $post_slug = htmlspecialchars( $permalink ? urldecode( $permalink ) : urldecode( $original ) );
263
+ $original_encoded_url = htmlspecialchars( urldecode( $original ) );
264
+ wp_enqueue_script( 'custom-permalinks-form', plugins_url( '/js/script-form.min.js', __FILE__ ), array(), false, true );
265
+ $postname_html = '';
266
+ if ( isset( $postname ) && $postname != '' ) {
267
+ $postname_html = '<input type="hidden" id="new-post-slug" class="text" value="' . $postname . '" />';
268
+ }
269
+
270
+ echo home_url() . '/<span id="editable-post-name" title="Click to edit this part of the permalink">' . $postname_html;
271
+
272
+ ?>
273
+ <input type="text" id="custom-permalinks-post-slug" class="text" value="<?php echo $post_slug; ?>"
274
+ style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd'; ?>"
275
+ onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
276
+ onblur="document.getElementById('custom_permalink').value = this.value; if ( this.value == '' || this.value == '<?php echo $original_encoded_url; ?>' ) { this.value = '<?php echo $original_encoded_url; ?>'; this.style.color = '#ddd'; }" />
277
+ </span>
278
+
279
+ <?php if ( $renderContainers ) : ?>
280
+ <br />
281
+ <small><?php _e( 'Leave blank to disable', 'custom-permalinks' ); ?></small>
282
+ </td>
283
+ </tr>
284
+ </table>
285
+ <?php
286
+ endif;
287
+ }
288
+
289
+ /**
290
+ * Save per-tag options
291
+ *
292
+ * @access public
293
+ * @return void
294
+ */
295
+ public function custom_permalinks_save_tag( $id ) {
296
+ if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
297
+ || isset( $_REQUEST['post_ID'] ) ) {
298
+ return;
299
+ }
300
+ $new_permalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), '/' );
301
+
302
+ $cp_frontend = new Custom_Permalinks_Frontend();
303
+ if ( $new_permalink == $cp_frontend->custom_permalinks_original_tag_link( $id ) ) {
304
+ return;
305
+ }
306
+
307
+ $term = get_term( $id, 'post_tag' );
308
+ $this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $new_permalink ) ) );
309
+ }
310
+
311
+ /**
312
+ * Save per-category options
313
+ *
314
+ * @access public
315
+ * @return void
316
+ */
317
+ public function custom_permalinks_save_category( $id ) {
318
+ if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
319
+ || isset( $_REQUEST['post_ID'] ) ) {
320
+ return;
321
+ }
322
+ $new_permalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), '/' );
323
+
324
+ $cp_frontend = new Custom_Permalinks_Frontend();
325
+ if ( $new_permalink == $cp_frontend->custom_permalinks_original_category_link( $id ) ) {
326
+ return;
327
+ }
328
+
329
+ $term = get_term( $id, 'category' );
330
+ $this->custom_permalinks_save_term(
331
+ $term, str_replace( '%2F', '/', urlencode( $new_permalink ) )
332
+ );
333
+ }
334
+
335
+ /**
336
+ * Save term (common to tags and categories)
337
+ *
338
+ * @access public
339
+ * @return void
340
+ */
341
+ public function custom_permalinks_save_term( $term, $permalink ) {
342
+
343
+ $this->custom_permalinks_delete_term( $term->term_id );
344
+ $table = get_option( 'custom_permalink_table' );
345
+ if ( $permalink ) {
346
+ $table[$permalink] = array(
347
+ 'id' => $term->term_id,
348
+ 'kind' => ( $term->taxonomy == 'category' ? 'category' : 'tag' ),
349
+ 'slug' => $term->slug
350
+ );
351
+ }
352
+
353
+ update_option( 'custom_permalink_table', $table );
354
+ }
355
+
356
+ /**
357
+ * Delete term
358
+ *
359
+ * @access public
360
+ * @return void
361
+ */
362
+ public function custom_permalinks_delete_term( $id ) {
363
+ $table = get_option( 'custom_permalink_table' );
364
+ if ( $table ) {
365
+ foreach ( $table as $link => $info ) {
366
+ if ( $info['id'] == $id ) {
367
+ unset( $table[$link] );
368
+ break;
369
+ }
370
+ }
371
+ }
372
+ update_option( 'custom_permalink_table', $table );
373
+ }
374
+
375
+ /**
376
+ * Check Conflicts and resolve it (e.g: Polylang)
377
+ *
378
+ * @access public
379
+ * @since 1.2
380
+ * @return string
381
+ */
382
+ public function custom_permalinks_check_conflicts( $requested_url = '' ) {
383
+ if ( '' == $requested_url ) {
384
+ return;
385
+ }
386
+
387
+ // Check if the Polylang Plugin is installed so, make changes in the URL
388
+ if ( defined( 'POLYLANG_VERSION' ) ) {
389
+ $polylang_config = get_option( 'polylang' );
390
+ if ( $polylang_config['force_lang'] == 1 ) {
391
+
392
+ if ( false !== strpos( $requested_url, 'language/' ) ) {
393
+ $requested_url = str_replace( 'language/', '', $requested_url );
394
+ }
395
+
396
+ $remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
397
+ if ( '' != $remove_lang ) {
398
+ return $remove_lang;
399
+ }
400
+ }
401
+ }
402
+ return $requested_url;
403
+ }
404
  }
frontend/class-custom-permalinks-frontend.php CHANGED
@@ -3,15 +3,19 @@
3
  * @package CustomPermalinks\Frontend
4
  */
5
 
6
- class Custom_Permalinks_Frontend {
7
-
8
- /**
9
- * Initialize WordPress Hooks
10
- */
 
 
 
 
11
  public function init() {
12
- add_filter( 'request', array( $this, 'custom_permalinks_request' ), 10, 1 );
13
 
14
- add_action( 'template_redirect', array( $this, 'custom_permalinks_redirect' ), 5 );
15
 
16
  add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
17
  add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
@@ -23,10 +27,13 @@ class Custom_Permalinks_Frontend {
23
  add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
24
  }
25
 
26
- /**
27
- * Filter to rewrite the query if we have a matching post
28
- */
29
- public function custom_permalinks_request( $query ) {
 
 
 
30
  global $wpdb;
31
  global $_CPRegisteredURL;
32
 
@@ -63,442 +70,496 @@ class Custom_Permalinks_Frontend {
63
  }
64
  $request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
65
 
66
- $remove_pager = '';
67
  if ( false !== strpos( $request_noslash, '/page/' ) ) {
68
- $check_pager = explode( '/', $request_noslash );
69
- $get_pager_no = count( $check_pager ) - 1;
70
- if ( is_numeric( $check_pager[$get_pager_no] ) ) {
71
- $remove_pager = '/page/' . $check_pager[$get_pager_no];
72
- $request_noslash = str_replace( $remove_pager, '', $request_noslash );
73
- }
74
- }
75
- if ( false !== strpos( $request_noslash, '/comment-page-' ) ) {
76
- $check_pager = explode( '/comment-page-', $request_noslash );
77
- $get_pager_no = count( $check_pager ) - 1;
78
- if ( is_numeric( $check_pager[$get_pager_no] ) ) {
79
- $remove_pager = '/comment-page-' . $check_pager[$get_pager_no];
80
- $request_noslash = str_replace( $remove_pager, '', $request_noslash );
81
- }
82
- }
 
 
 
 
 
 
 
83
 
84
  $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
85
- " FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
86
- " WHERE pm.meta_key = 'custom_permalink' " .
87
- " AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
88
- " AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
89
- " ORDER BY FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
90
- " FIELD(post_type,'post','page') LIMIT 1", $request_noslash, $request_noslash . "/" );
91
 
92
  $posts = $wpdb->get_results( $sql );
93
 
94
  if ( ! $posts ) {
95
- $def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
96
- if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
97
- || defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
98
- $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
99
- " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
100
- " meta_key = 'custom_permalink' AND meta_value != '' AND " .
101
- " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
102
- " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
103
- " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
104
- " ORDER BY LENGTH(meta_value) DESC, " .
105
- " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
106
- " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
107
- $request_noslash, $request_noslash . "/" );
108
-
109
- $posts = $wpdb->get_results( $sql );
110
- }
111
- }
112
-
113
- if ( $posts ) {
114
- // A post matches our request
115
- // Preserve this url for later if it's the same as the permalink (no extra stuff)
116
- if ( $request_noslash == trim( $posts[0]->meta_value, '/' ) ) {
117
- $_CPRegisteredURL = $request;
118
- }
119
-
120
- if ( $posts[0]->post_status == 'draft' ) {
121
- if ( $posts[0]->post_type == 'page' ) {
122
- $original_url = '?page_id=' . $posts[0]->ID;
123
- } else {
124
- $original_url = '?post_type=' . $posts[0]->post_type . '&p=' . $posts[0]->ID;
125
- }
126
- } else {
127
- $post_meta = trim( strtolower( $posts[0]->meta_value ), '/' );
128
- if ( $posts[0]->post_type == 'page' ) {
129
- $get_original_url = $this->custom_permalinks_original_page_link( $posts[0]->ID );
130
- $original_url = preg_replace( '@/+@', '/',
131
- str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
132
- );
133
- } else {
134
- $get_original_url = $this->custom_permalinks_original_post_link( $posts[0]->ID );
135
- $original_url = preg_replace( '@/+@', '/',
136
- str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
137
- );
138
- }
139
- if ( $remove_pager !== '' ) {
140
- $original_url = $original_url . $remove_pager;
141
- }
142
- }
143
- }
144
-
145
- if ( $original_url === NULL ) {
146
- // See if any terms have a matching permalink
147
- $table = get_option( 'custom_permalink_table' );
148
- if ( ! $table ) {
149
- return $query;
150
- }
151
-
152
- foreach ( array_keys( $table ) as $permalink ) {
153
- if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
154
- || $permalink == substr( $request_noslash . '/', 0, strlen( $permalink ) ) ) {
155
- $term = $table[$permalink];
156
-
157
- // Preserve this url for later if it's the same as the permalink (no extra stuff)
158
- if ( $request_noslash == trim( $permalink, '/' ) ) {
159
- $_CPRegisteredURL = $request;
160
- }
161
-
162
- if ( $term['kind'] == 'category' ) {
163
- $category_link = $this->custom_permalinks_original_category_link( $term['id'] );
164
- } else {
165
- $category_link = $this->custom_permalinks_original_tag_link( $term['id'] );
166
- }
167
-
168
- $original_url = str_replace(
169
- trim( $permalink, '/' ), $category_link, trim( $request, '/' )
170
- );
171
- }
172
- }
173
- }
174
-
175
- if ( $original_url !== NULL ) {
176
- $original_url = str_replace( '//', '/', $original_url );
177
-
178
- if ( ( $pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) !== false ) {
179
- $query_vars = substr( $_SERVER['REQUEST_URI'], $pos + 1);
180
- $original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars;
181
- }
182
-
183
- // Now we have the original URL, run this back through WP->parse_request, in order to
184
- // parse parameters properly. We set $_SERVER variables to fool the function.
185
- $old_request_uri = $_SERVER['REQUEST_URI'];
186
- $old_query_string = '';
187
- if ( isset( $_SERVER['QUERY_STRING'] ) ) {
188
- $old_query_string = $_SERVER['QUERY_STRING'];
189
- }
190
- $_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
191
- $path_info = apply_filters( 'custom_permalinks_path_info', '__false' );
192
- if ( '__false' !== $path_info ) {
193
- $_SERVER['PATH_INFO'] = '/' . ltrim( $original_url, '/' );
194
- }
195
- $_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' );
196
- parse_str( $_SERVER['QUERY_STRING'], $query_array );
197
- $old_values = array();
198
- if ( is_array( $query_array ) ) {
199
- foreach ( $query_array as $key => $value ) {
200
- $old_values[$key] = $_REQUEST[$key];
201
- $_REQUEST[$key] = $_GET[$key] = $value;
202
- }
203
- }
204
-
205
- // Re-run the filter, now with original environment in place
206
- remove_filter( 'request', array( $this, 'custom_permalinks_request' ), 10, 1 );
207
- global $wp;
208
- $wp->parse_request();
209
- $query = $wp->query_vars;
210
- add_filter( 'request', array( $this, 'custom_permalinks_request' ), 10, 1 );
211
-
212
- // Restore values
213
- $_SERVER['REQUEST_URI'] = $old_request_uri;
214
- $_SERVER['QUERY_STRING'] = $old_query_string;
215
- foreach ( $old_values as $key => $value ) {
216
- $_REQUEST[$key] = $value;
217
- }
218
- }
219
-
220
- return $query;
221
- }
222
-
223
- /**
224
- * Action to redirect to the custom permalink
225
- */
226
- public function custom_permalinks_redirect() {
227
- global $wpdb;
228
-
229
- $custom_permalink = '';
230
- $original_permalink = '';
231
-
232
- // Get request URI, strip parameters
233
- $url = parse_url( get_bloginfo( 'url' ) );
234
- $url = isset( $url['path'] ) ? $url['path'] : '';
235
- $request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
236
- $pos = strpos( $request, '?' );
237
- if ( $pos ) {
238
- $request = substr( $request, 0, $pos );
239
- }
240
-
241
- if ( defined( 'POLYLANG_VERSION' ) ) {
242
- require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
243
- $cp_form = new Custom_Permalinks_Form();
244
- $request = $cp_form->custom_permalinks_check_conflicts( $request );
245
  }
246
- $request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
247
 
248
- $remove_pager = '';
249
- if ( false !== strpos( $request_noslash, '/page/' ) ) {
250
- $check_pager = explode( '/', $request_noslash );
251
- $get_pager_no = count( $check_pager ) - 1;
252
- if ( is_numeric( $check_pager[$get_pager_no] ) ) {
253
- $remove_pager = '/page/' . $check_pager[$get_pager_no];
254
- $request_noslash = str_replace( $remove_pager, '', $request_noslash );
255
- }
 
 
 
 
256
  }
257
- if ( false !== strpos( $request_noslash, '/comment-page-' ) ) {
258
- $check_pager = explode( '/comment-page-', $request_noslash );
259
- $get_pager_no = count( $check_pager ) - 1;
260
- if ( is_numeric( $check_pager[$get_pager_no] ) ) {
261
- $remove_pager = '/comment-page-' . $check_pager[$get_pager_no];
262
- $request_noslash = str_replace( $remove_pager, '', $request_noslash );
263
- }
 
 
 
 
 
264
  }
265
-
266
- $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
267
- " FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
268
- " WHERE pm.meta_key = 'custom_permalink' " .
269
- " AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
270
- " AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
271
- " ORDER BY FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
272
- " FIELD(post_type,'post','page') LIMIT 1", $request_noslash, $request_noslash . "/" );
273
-
274
- $posts = $wpdb->get_results( $sql );
275
-
276
- if ( ! $posts ) {
277
- $def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
278
- if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
279
- || defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
280
- $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
281
- " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
282
- " meta_key = 'custom_permalink' AND meta_value != '' AND " .
283
- " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
284
- " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
285
- " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
286
- " ORDER BY LENGTH(meta_value) DESC, " .
287
- " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
288
- " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
289
- $request_noslash, $request_noslash . "/" );
290
-
291
- $posts = $wpdb->get_results( $sql );
292
- }
293
- }
294
-
295
- if ( ! isset( $posts[0]->ID ) || ! isset( $posts[0]->meta_value )
296
- || empty( $posts[0]->meta_value ) ) {
297
- global $wp_query;
298
-
299
- // If the post/tag/category we're on has a custom permalink, get it and check against the request
300
- if ( ( is_single() || is_page() ) && ! empty( $wp_query->post ) ) {
301
- $post = $wp_query->post;
302
- $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
303
- if ( $post->post_type == 'page' ) {
304
- $original_permalink = $this->custom_permalinks_original_page_link( $post->ID );
305
- } else {
306
- $original_permalink = $this->custom_permalinks_original_post_link( $post->ID );
307
- }
308
- } elseif ( is_tag() || is_category() ) {
309
- $theTerm = $wp_query->get_queried_object();
310
- $custom_permalink = $this->custom_permalinks_permalink_for_term( $theTerm->term_id );
311
- if ( is_tag() ) {
312
- $original_permalink = $this->custom_permalinks_original_tag_link( $theTerm->term_id );
313
- } else {
314
- $original_permalink = $this->custom_permalinks_original_category_link( $theTerm->term_id );
315
- }
316
- }
317
- } else {
318
- $custom_permalink = $posts[0]->meta_value;
319
- if ( $posts[0]->post_type == 'page' ) {
320
- $original_permalink = $this->custom_permalinks_original_page_link( $posts[0]->ID );
321
- } else {
322
- $original_permalink = $this->custom_permalinks_original_post_link( $posts[0]->ID );
323
- }
324
- }
325
-
326
- if ( $custom_permalink
327
- && ( substr( $request, 0, strlen( $custom_permalink ) ) != $custom_permalink
328
- || $request == $custom_permalink . '/' ) ) {
329
-
330
- // Request doesn't match permalink - redirect
331
- $url = $custom_permalink;
332
-
333
- if ( substr( $request, 0, strlen( $original_permalink ) ) == $original_permalink
334
- && trim( $request, '/' ) != trim( $original_permalink, '/' ) ) {
335
- // This is the original link; we can use this url to derive the new one
336
- $url = preg_replace( '@//*@', '/', str_replace( trim( $original_permalink, '/' ), trim( $custom_permalink, '/' ), $request ) );
337
- $url = preg_replace( '@([^?]*)&@', '\1?', $url );
338
- }
339
-
340
- // Append any query compenent
341
- $url .= strstr( $_SERVER['REQUEST_URI'], '?' );
342
-
343
- wp_redirect( home_url() . '/' . $url, 301 );
344
- exit();
345
- }
346
- }
347
-
348
- /**
349
- * Filter to replace the post permalink with the custom one
350
- */
351
- public function custom_permalinks_post_link( $permalink, $post ) {
352
- $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
353
- if ( $custom_permalink ) {
354
- $post_type = isset( $post->post_type ) ? $post->post_type : 'post';
355
- $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post->ID, 'element_type' => $post_type ) );
356
- if ( $language_code )
357
- return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
358
- else
359
- return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
360
- }
361
-
362
- return $permalink;
363
- }
364
-
365
- /**
366
- * Filter to replace the page permalink with the custom one
367
- */
368
- public function custom_permalinks_page_link( $permalink, $page ) {
369
- $custom_permalink = get_post_meta( $page, 'custom_permalink', true );
370
- if ( $custom_permalink ) {
371
- $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page' ) );
372
- if ( $language_code )
373
- return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
374
- else
375
- return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
376
- }
377
-
378
- return $permalink;
379
- }
380
-
381
- /**
382
- * Filter to replace the term permalink with the custom one
383
- */
384
- public function custom_permalinks_term_link( $permalink, $term ) {
385
- $table = get_option( 'custom_permalink_table' );
386
- if ( is_object( $term ) ) {
387
- $term = $term->term_id;
388
- }
389
-
390
- $custom_permalink = $this->custom_permalinks_permalink_for_term( $term );
391
- if ( $custom_permalink ) {
392
- $taxonomy = get_term( $term );
393
- if ( isset( $taxonomy ) && isset( $taxonomy->term_taxonomy_id ) ) {
394
- $term_type = isset( $taxonomy->taxonomy ) ? $taxonomy->taxonomy : 'category';
395
- $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $taxonomy->term_taxonomy_id, 'element_type' => $term_type ) );
396
- return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
397
- } else {
398
- return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
399
- }
400
- }
401
-
402
- return $permalink;
403
- }
404
-
405
- /**
406
- * Get original permalink for post
407
- */
408
- public function custom_permalinks_original_post_link( $post_id ) {
409
- remove_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
410
- remove_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
411
-
412
- require_once ABSPATH . '/wp-admin/includes/post.php';
413
- list( $permalink, $post_name ) = get_sample_permalink( $post_id );
414
- $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
415
- $permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
416
-
417
- add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
418
- add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
419
-
420
- return $permalink;
421
- }
422
-
423
- /**
424
- * Get original permalink for page
425
- */
426
- public function custom_permalinks_original_page_link( $post_id ) {
427
- remove_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
428
- remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
429
-
430
- require_once ABSPATH . '/wp-admin/includes/post.php';
431
- list( $permalink, $post_name ) = get_sample_permalink( $post_id );
432
- $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
433
- $permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
434
-
435
- add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
436
- add_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
437
- return $permalink;
438
- }
439
-
440
- /**
441
- * Get original permalink for tag
442
- */
443
- public function custom_permalinks_original_tag_link( $tag_id ) {
444
- remove_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
445
- remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
446
- $originalPermalink = ltrim( str_replace( home_url(), '', get_tag_link( $tag_id ) ), '/' );
447
- add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
448
- add_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
449
- return $originalPermalink;
450
- }
451
-
452
- /**
453
- * Get original permalink for category
454
- */
455
- public function custom_permalinks_original_category_link( $category_id ) {
456
- remove_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
457
- remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
458
- $originalPermalink = ltrim( str_replace( home_url(), '', get_category_link( $category_id ) ), '/' );
459
- add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
460
- add_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
461
- return $originalPermalink;
462
- }
463
-
464
- /**
465
- * Filter to handle trailing slashes correctly
466
- */
467
- public function custom_permalinks_trailingslash( $string, $type ) {
468
- global $_CPRegisteredURL;
469
-
470
- remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
471
- $url = parse_url( get_bloginfo( 'url' ) );
472
- $request = ltrim( isset( $url['path'] ) ? substr( $string, strlen( $url['path'] ) ) : $string, '/' );
473
- add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
474
-
475
- if ( ! trim( $request ) ) {
476
- return $string;
477
- }
478
-
479
- if ( trim( $_CPRegisteredURL, '/' ) == trim( $request, '/' ) ) {
480
- if ( isset( $url['path'] ) ) {
481
- return ( $string{0} == '/' ? '/' : '' ) . trailingslashit( $url['path'] ) . $_CPRegisteredURL;
482
- } else {
483
- return ( $string{0} == '/' ? '/' : '' ) . $_CPRegisteredURL;
484
- }
485
- }
486
- return $string;
487
- }
488
-
489
-
490
- /**
491
- * Get permalink for term
492
- */
493
- public function custom_permalinks_permalink_for_term( $id ) {
494
- $table = get_option( 'custom_permalink_table' );
495
- if ( $table ) {
496
- foreach ( $table as $link => $info ) {
497
- if ( $info['id'] == $id ) {
498
- return $link;
499
- }
500
- }
501
- }
502
- return false;
503
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  }
3
  * @package CustomPermalinks\Frontend
4
  */
5
 
6
+ final class Custom_Permalinks_Frontend {
7
+
8
+ /**
9
+ * Initialize WordPress Hooks
10
+ *
11
+ * @access public
12
+ * @since 1.2
13
+ * @return void
14
+ */
15
  public function init() {
16
+ add_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
17
 
18
+ add_action( 'template_redirect', array( $this, 'make_redirect' ), 5 );
19
 
20
  add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
21
  add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
27
  add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
28
  }
29
 
30
+ /**
31
+ * Filter to rewrite the query if we have a matching post
32
+ *
33
+ * @access public
34
+ * @return void
35
+ */
36
+ public function parse_request( $query ) {
37
  global $wpdb;
38
  global $_CPRegisteredURL;
39
 
70
  }
71
  $request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
72
 
73
+ $remove_pager = '';
74
  if ( false !== strpos( $request_noslash, '/page/' ) ) {
75
+ $check_pager = explode( '/', $request_noslash );
76
+ $get_pager_no = count( $check_pager ) - 1;
77
+ if ( is_numeric( $check_pager[$get_pager_no] ) ) {
78
+ $remove_pager = '/page/' . $check_pager[$get_pager_no];
79
+ $request_noslash = str_replace( $remove_pager, '', $request_noslash );
80
+ }
81
+ }
82
+
83
+ if ( false !== strpos( $request_noslash, '/comment-page-' ) ) {
84
+ $check_pager = explode( '/comment-page-', $request_noslash );
85
+ $get_pager_no = count( $check_pager ) - 1;
86
+ if ( is_numeric( $check_pager[$get_pager_no] ) ) {
87
+ $remove_pager = '/comment-page-' . $check_pager[$get_pager_no];
88
+ $request_noslash = str_replace( $remove_pager, '', $request_noslash );
89
+ }
90
+ }
91
+
92
+ $post_feed = 0;
93
+ if ( false !== strpos( $request_noslash, '/feed' ) ) {
94
+ $request_noslash = str_replace( '/feed', '', $request_noslash );
95
+ $post_feed = 1;
96
+ }
97
 
98
  $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
99
+ " FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
100
+ " WHERE pm.meta_key = 'custom_permalink' " .
101
+ " AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
102
+ " AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
103
+ " ORDER BY FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
104
+ " FIELD(post_type,'post','page') LIMIT 1", $request_noslash, $request_noslash . "/" );
105
 
106
  $posts = $wpdb->get_results( $sql );
107
 
108
  if ( ! $posts ) {
109
+ $def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
110
+ if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
111
+ || defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
112
+ $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
113
+ " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
114
+ " meta_key = 'custom_permalink' AND meta_value != '' AND " .
115
+ " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
116
+ " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
117
+ " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
118
+ " ORDER BY LENGTH(meta_value) DESC, " .
119
+ " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
120
+ " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
121
+ $request_noslash, $request_noslash . "/" );
122
+
123
+ $posts = $wpdb->get_results( $sql );
124
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  }
 
126
 
127
+ if ( $posts ) {
128
+ // A post matches our request
129
+ // Preserve this url for later if it's the same as the permalink (no extra stuff)
130
+ if ( $request_noslash == trim( $posts[0]->meta_value, '/' ) ) {
131
+ $_CPRegisteredURL = $request;
132
+ }
133
+
134
+ if ( 'draft' == $posts[0]->post_status ) {
135
+ if ( 'page' == $posts[0]->post_type ) {
136
+ $original_url = '?page_id=' . $posts[0]->ID;
137
+ } else {
138
+ $original_url = '?post_type=' . $posts[0]->post_type . '&p=' . $posts[0]->ID;
139
  }
140
+ } else {
141
+ $post_meta = trim( strtolower( $posts[0]->meta_value ), '/' );
142
+ if ( $posts[0]->post_type == 'page' ) {
143
+ $get_original_url = $this->custom_permalinks_original_page_link( $posts[0]->ID );
144
+ $original_url = preg_replace( '@/+@', '/',
145
+ str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
146
+ );
147
+ } else {
148
+ $get_original_url = $this->custom_permalinks_original_post_link( $posts[0]->ID );
149
+ $original_url = preg_replace( '@/+@', '/',
150
+ str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
151
+ );
152
  }
153
+ if ( 1 == $post_feed ) {
154
+ $original_url = $original_url . '/feed';
155
+ }
156
+ if ( '' !== $remove_pager ) {
157
+ $original_url = $original_url . $remove_pager;
158
+ }
159
+ }
160
+ }
161
+
162
+ if ( NULL === $original_url ) {
163
+ // See if any terms have a matching permalink
164
+ $table = get_option( 'custom_permalink_table' );
165
+ if ( ! $table ) {
166
+ return $query;
167
+ }
168
+
169
+ foreach ( array_keys( $table ) as $permalink ) {
170
+ if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
171
+ || $permalink == substr( $request_noslash . '/', 0, strlen( $permalink ) ) ) {
172
+ $term = $table[$permalink];
173
+
174
+ // Preserve this url for later if it's the same as the permalink (no extra stuff)
175
+ if ( $request_noslash == trim( $permalink, '/' ) ) {
176
+ $_CPRegisteredURL = $request;
177
+ }
178
+
179
+ if ( 'category' == $term['kind'] ) {
180
+ $category_link = $this->custom_permalinks_original_category_link( $term['id'] );
181
+ } else {
182
+ $category_link = $this->custom_permalinks_original_tag_link( $term['id'] );
183
+ }
184
+
185
+ $original_url = str_replace(
186
+ trim( $permalink, '/' ), $category_link, trim( $request, '/' )
187
+ );
188
+ }
189
+ }
190
+ }
191
+
192
+ if ( NULL !== $original_url ) {
193
+ $original_url = str_replace( '//', '/', $original_url );
194
+
195
+ $pos = strpos( $_SERVER['REQUEST_URI'], '?' );
196
+ if ( false !== $pos ) {
197
+ $query_vars = substr( $_SERVER['REQUEST_URI'], $pos + 1 );
198
+ $original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars;
199
+ }
200
+
201
+ // Now we have the original URL, run this back through WP->parse_request, in order to
202
+ // parse parameters properly. We set $_SERVER variables to fool the function.
203
+ $old_request_uri = $_SERVER['REQUEST_URI'];
204
+ $old_query_string = '';
205
+ if ( isset( $_SERVER['QUERY_STRING'] ) ) {
206
+ $old_query_string = $_SERVER['QUERY_STRING'];
207
+ }
208
+ $_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
209
+ $path_info = apply_filters( 'custom_permalinks_path_info', '__false' );
210
+ if ( '__false' !== $path_info ) {
211
+ $_SERVER['PATH_INFO'] = '/' . ltrim( $original_url, '/' );
212
+ }
213
+
214
+ $_SERVER['QUERY_STRING'] = '';
215
+ $pos = strpos( $original_url, '?' );
216
+ if ( false !== $pos ) {
217
+ $_SERVER['QUERY_STRING'] = substr( $original_url, $pos + 1 );
218
+ }
219
+
220
+ parse_str( $_SERVER['QUERY_STRING'], $query_array );
221
+ $old_values = array();
222
+ if ( is_array( $query_array ) ) {
223
+ foreach ( $query_array as $key => $value ) {
224
+ $old_values[$key] = $_REQUEST[$key];
225
+ $_REQUEST[$key] = $_GET[$key] = $value;
226
+ }
227
+ }
228
+
229
+ // Re-run the filter, now with original environment in place
230
+ remove_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
231
+ global $wp;
232
+ $wp->parse_request();
233
+ $query = $wp->query_vars;
234
+ add_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
235
+
236
+ // Restore values
237
+ $_SERVER['REQUEST_URI'] = $old_request_uri;
238
+ $_SERVER['QUERY_STRING'] = $old_query_string;
239
+ foreach ( $old_values as $key => $value ) {
240
+ $_REQUEST[$key] = $value;
241
+ }
242
+ }
243
+
244
+ return $query;
245
+ }
246
+
247
+ /**
248
+ * Action to redirect to the custom permalink
249
+ *
250
+ * @access public
251
+ * @return void
252
+ */
253
+ public function make_redirect() {
254
+ global $wpdb;
255
+
256
+ $custom_permalink = '';
257
+ $original_permalink = '';
258
+
259
+ // Get request URI, strip parameters
260
+ $url = parse_url( get_bloginfo( 'url' ) );
261
+ $url = isset( $url['path'] ) ? $url['path'] : '';
262
+ $request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
263
+ $pos = strpos( $request, '?' );
264
+ if ( $pos ) {
265
+ $request = substr( $request, 0, $pos );
266
+ }
267
+
268
+ if ( defined( 'POLYLANG_VERSION' ) ) {
269
+ require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
270
+ $cp_form = new Custom_Permalinks_Form();
271
+ $request = $cp_form->custom_permalinks_check_conflicts( $request );
272
+ }
273
+ $request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
274
+
275
+ $remove_pager = '';
276
+ if ( false !== strpos( $request_noslash, '/page/' ) ) {
277
+ $check_pager = explode( '/', $request_noslash );
278
+ $get_pager_no = count( $check_pager ) - 1;
279
+ if ( is_numeric( $check_pager[$get_pager_no] ) ) {
280
+ $remove_pager = '/page/' . $check_pager[$get_pager_no];
281
+ $request_noslash = str_replace( $remove_pager, '', $request_noslash );
282
+ }
283
+ }
284
+
285
+ if ( false !== strpos( $request_noslash, '/comment-page-' ) ) {
286
+ $check_pager = explode( '/comment-page-', $request_noslash );
287
+ $get_pager_no = count( $check_pager ) - 1;
288
+ if ( is_numeric( $check_pager[$get_pager_no] ) ) {
289
+ $remove_pager = '/comment-page-' . $check_pager[$get_pager_no];
290
+ $request_noslash = str_replace( $remove_pager, '', $request_noslash );
291
+ }
292
+ }
293
+
294
+ if ( false !== strpos( $request_noslash, '/feed' ) ) {
295
+ $request_noslash = str_replace( '/feed', '', $request_noslash );
296
+ }
297
+
298
+ $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
299
+ " FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
300
+ " WHERE pm.meta_key = 'custom_permalink' " .
301
+ " AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
302
+ " AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
303
+ " ORDER BY FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
304
+ " FIELD(post_type,'post','page') LIMIT 1", $request_noslash, $request_noslash . "/" );
305
+
306
+ $posts = $wpdb->get_results( $sql );
307
+
308
+ if ( ! $posts ) {
309
+ $def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
310
+ if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
311
+ || defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
312
+ $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
313
+ " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
314
+ " meta_key = 'custom_permalink' AND meta_value != '' AND " .
315
+ " ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
316
+ " LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
317
+ " AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
318
+ " ORDER BY LENGTH(meta_value) DESC, " .
319
+ " FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
320
+ " FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
321
+ $request_noslash, $request_noslash . "/" );
322
+
323
+ $posts = $wpdb->get_results( $sql );
324
+ }
325
+ }
326
+
327
+ if ( ! isset( $posts[0]->ID ) || ! isset( $posts[0]->meta_value )
328
+ || empty( $posts[0]->meta_value ) ) {
329
+ global $wp_query;
330
+
331
+ // If the post/tag/category we're on has a custom permalink, get it and check against the request
332
+ if ( ( is_single() || is_page() ) && ! empty( $wp_query->post ) ) {
333
+ $post = $wp_query->post;
334
+ $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
335
+ if ( $post->post_type == 'page' ) {
336
+ $original_permalink = $this->custom_permalinks_original_page_link( $post->ID );
337
+ } else {
338
+ $original_permalink = $this->custom_permalinks_original_post_link( $post->ID );
339
+ }
340
+ } elseif ( is_tag() || is_category() ) {
341
+ $theTerm = $wp_query->get_queried_object();
342
+ $custom_permalink = $this->custom_permalinks_permalink_for_term( $theTerm->term_id );
343
+ if ( is_tag() ) {
344
+ $original_permalink = $this->custom_permalinks_original_tag_link( $theTerm->term_id );
345
+ } else {
346
+ $original_permalink = $this->custom_permalinks_original_category_link( $theTerm->term_id );
347
+ }
348
+ }
349
+ } else {
350
+ $custom_permalink = $posts[0]->meta_value;
351
+ if ( 'page' == $posts[0]->post_type ) {
352
+ $original_permalink = $this->custom_permalinks_original_page_link( $posts[0]->ID );
353
+ } else {
354
+ $original_permalink = $this->custom_permalinks_original_post_link( $posts[0]->ID );
355
+ }
356
+ }
357
+
358
+ if ( $custom_permalink
359
+ && ( substr( $request, 0, strlen( $custom_permalink ) ) != $custom_permalink
360
+ || $request == $custom_permalink . '/' ) ) {
361
+
362
+ // Request doesn't match permalink - redirect
363
+ $url = $custom_permalink;
364
+
365
+ if ( substr( $request, 0, strlen( $original_permalink ) ) == $original_permalink
366
+ && trim( $request, '/' ) != trim( $original_permalink, '/' ) ) {
367
+ // This is the original link; we can use this url to derive the new one
368
+ $url = preg_replace( '@//*@', '/', str_replace( trim( $original_permalink, '/' ), trim( $custom_permalink, '/' ), $request ) );
369
+ $url = preg_replace( '@([^?]*)&@', '\1?', $url );
370
+ }
371
+
372
+ // Append any query compenent
373
+ $url .= strstr( $_SERVER['REQUEST_URI'], '?' );
374
+
375
+ wp_redirect( home_url() . '/' . $url, 301 );
376
+ exit();
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Filter to replace the post permalink with the custom one
382
+ *
383
+ * @access public
384
+ * @return string
385
+ */
386
+ public function custom_permalinks_post_link( $permalink, $post ) {
387
+ $custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
388
+ if ( $custom_permalink ) {
389
+ $post_type = isset( $post->post_type ) ? $post->post_type : 'post';
390
+ $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post->ID, 'element_type' => $post_type ) );
391
+ if ( $language_code )
392
+ return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
393
+ else
394
+ return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
395
+ }
396
+
397
+ return $permalink;
398
+ }
399
+
400
+ /**
401
+ * Filter to replace the page permalink with the custom one
402
+ *
403
+ * @access public
404
+ * @return string
405
+ */
406
+ public function custom_permalinks_page_link( $permalink, $page ) {
407
+ $custom_permalink = get_post_meta( $page, 'custom_permalink', true );
408
+ if ( $custom_permalink ) {
409
+ $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page' ) );
410
+ if ( $language_code )
411
+ return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
412
+ else
413
+ return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
414
+ }
415
+
416
+ return $permalink;
417
+ }
418
+
419
+ /**
420
+ * Filter to replace the term permalink with the custom one
421
+ *
422
+ * @access public
423
+ * @return string
424
+ */
425
+ public function custom_permalinks_term_link( $permalink, $term ) {
426
+ $table = get_option( 'custom_permalink_table' );
427
+ if ( is_object( $term ) ) {
428
+ $term = $term->term_id;
429
+ }
430
+
431
+ $custom_permalink = $this->custom_permalinks_permalink_for_term( $term );
432
+ if ( $custom_permalink ) {
433
+ $taxonomy = get_term( $term );
434
+ if ( isset( $taxonomy ) && isset( $taxonomy->term_taxonomy_id ) ) {
435
+ $term_type = 'category';
436
+ if ( isset( $taxonomy->taxonomy ) ) {
437
+ $term_type = $taxonomy->taxonomy;
438
+ }
439
+ $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $taxonomy->term_taxonomy_id, 'element_type' => $term_type ) );
440
+ return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
441
+ } else {
442
+ return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
443
+ }
444
+ }
445
+
446
+ return $permalink;
447
+ }
448
+
449
+ /**
450
+ * Get original permalink for post
451
+ *
452
+ * @access public
453
+ * @return string
454
+ */
455
+ public function custom_permalinks_original_post_link( $post_id ) {
456
+ remove_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
457
+ remove_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
458
+
459
+ require_once ABSPATH . '/wp-admin/includes/post.php';
460
+ list( $permalink, $post_name ) = get_sample_permalink( $post_id );
461
+ $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
462
+ $permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
463
+
464
+ add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
465
+ add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
466
+
467
+ return $permalink;
468
+ }
469
+
470
+ /**
471
+ * Get original permalink for page
472
+ *
473
+ * @access public
474
+ * @return string
475
+ */
476
+ public function custom_permalinks_original_page_link( $post_id ) {
477
+ remove_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
478
+ remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
479
+
480
+ require_once ABSPATH . '/wp-admin/includes/post.php';
481
+ list( $permalink, $post_name ) = get_sample_permalink( $post_id );
482
+ $permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
483
+ $permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
484
+
485
+ add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
486
+ add_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
487
+ return $permalink;
488
+ }
489
+
490
+ /**
491
+ * Get original permalink for tag
492
+ *
493
+ * @access public
494
+ * @return string
495
+ */
496
+ public function custom_permalinks_original_tag_link( $tag_id ) {
497
+ remove_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
498
+ remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
499
+ $originalPermalink = ltrim( str_replace( home_url(), '', get_tag_link( $tag_id ) ), '/' );
500
+ add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
501
+ add_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
502
+ return $originalPermalink;
503
+ }
504
+
505
+ /**
506
+ * Get original permalink for category
507
+ *
508
+ * @access public
509
+ * @return string
510
+ */
511
+ public function custom_permalinks_original_category_link( $category_id ) {
512
+ remove_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
513
+ remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
514
+ $originalPermalink = ltrim( str_replace( home_url(), '', get_category_link( $category_id ) ), '/' );
515
+ add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
516
+ add_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
517
+ return $originalPermalink;
518
+ }
519
+
520
+ /**
521
+ * Filter to handle trailing slashes correctly
522
+ *
523
+ * @access public
524
+ * @return string
525
+ */
526
+ public function custom_permalinks_trailingslash( $string, $type ) {
527
+ global $_CPRegisteredURL;
528
+
529
+ remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
530
+ $url = parse_url( get_bloginfo( 'url' ) );
531
+ $request = ltrim( isset( $url['path'] ) ? substr( $string, strlen( $url['path'] ) ) : $string, '/' );
532
+ add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
533
+
534
+ if ( ! trim( $request ) ) {
535
+ return $string;
536
+ }
537
+
538
+ if ( trim( $_CPRegisteredURL, '/' ) == trim( $request, '/' ) ) {
539
+ if ( isset( $url['path'] ) ) {
540
+ return ( $string{0} == '/' ? '/' : '' ) . trailingslashit( $url['path'] ) . $_CPRegisteredURL;
541
+ } else {
542
+ return ( $string{0} == '/' ? '/' : '' ) . $_CPRegisteredURL;
543
+ }
544
+ }
545
+ return $string;
546
+ }
547
+
548
+ /**
549
+ * Get permalink for term
550
+ *
551
+ * @access public
552
+ * @return boolean
553
+ */
554
+ public function custom_permalinks_permalink_for_term( $id ) {
555
+ $table = get_option( 'custom_permalink_table' );
556
+ if ( $table ) {
557
+ foreach ( $table as $link => $info ) {
558
+ if ( $info['id'] == $id ) {
559
+ return $link;
560
+ }
561
+ }
562
+ }
563
+ return false;
564
+ }
565
  }
languages/index.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
- /**
3
- * Silence is golden
4
  */
1
+ <?php
2
+ /**
3
+ * Silence is golden
4
  */
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/yasglobal
4
  Tags: permalink, url, link, address, custom, redirect, custom post type
5
  Requires at least: 2.6
6
  Tested up to: 4.9
7
- Stable tag: 1.2.17
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl.html
10
 
@@ -93,21 +93,30 @@ This process defines you the steps to follow either you are installing through W
93
 
94
  == Changelog ==
95
 
96
- = 1.2.17 =
 
 
 
 
 
 
 
 
 
 
97
 
98
  * Fixed Pagination Issue on Comments
99
  * Optimize Post Pager Query
100
 
101
-
102
- = 1.2.16 =
103
 
104
  * Added compatibility with Tasty Recipes Plugin
105
 
106
- = 1.2.15 =
107
 
108
  * Added filter which can be used to add PATH_INFO in $_SERVER Variable
109
 
110
- = 1.2.14 =
111
 
112
  * Enhancement
113
  * Added PATH_INFO in $_SERVER Variable
@@ -115,19 +124,19 @@ This process defines you the steps to follow either you are installing through W
115
  * Bugs
116
  * $this variable issue on static method
117
 
118
- = 1.2.12 =
119
 
120
  * Fixed translation path and pager content issue
121
 
122
- = 1.2.11 =
123
 
124
  * Fixed pager issue
125
 
126
- = 1.2.10 =
127
 
128
  * Fixed Redirect Issue of Child Pages
129
 
130
- = 1.2.9 =
131
 
132
  * Enhancements
133
  * Added Filter to enable the like query
@@ -136,15 +145,15 @@ This process defines you the steps to follow either you are installing through W
136
  * Removed LIKE Query in default. It only works if the site uses PolyLang,
137
  AMP Plugins or separately enabled using the provided filter.
138
 
139
- = 1.2.8 =
140
 
141
  * Add Order by in request query
142
 
143
- = 1.2.7 =
144
 
145
  * Fixed Parse Error
146
 
147
- = 1.2.6 =
148
 
149
  * Enhancements
150
  * Added Filter to Exclude Post types
4
  Tags: permalink, url, link, address, custom, redirect, custom post type
5
  Requires at least: 2.6
6
  Tested up to: 4.9
7
+ Stable tag: 1.2.18
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl.html
10
 
93
 
94
  == Changelog ==
95
 
96
+ = 1.2.18 - April 05, 2018 =
97
+
98
+ * Enhancement
99
+ * Merged custom-permalinks-main.php with custom-permalinks.php
100
+ * Added uninstall.php
101
+
102
+ * Bugs
103
+ * Added feed redirect of default permalink
104
+ * Provide proper feed of custom permalink
105
+
106
+ = 1.2.17 - Feb 13, 2018 =
107
 
108
  * Fixed Pagination Issue on Comments
109
  * Optimize Post Pager Query
110
 
111
+ = 1.2.16 - Feb 09, 2018 =
 
112
 
113
  * Added compatibility with Tasty Recipes Plugin
114
 
115
+ = 1.2.15 - Feb 08, 2018 =
116
 
117
  * Added filter which can be used to add PATH_INFO in $_SERVER Variable
118
 
119
+ = 1.2.14 - Feb 07, 2018 =
120
 
121
  * Enhancement
122
  * Added PATH_INFO in $_SERVER Variable
124
  * Bugs
125
  * $this variable issue on static method
126
 
127
+ = 1.2.12 - Jan 25, 2018 =
128
 
129
  * Fixed translation path and pager content issue
130
 
131
+ = 1.2.11 - Jan 24, 2018 =
132
 
133
  * Fixed pager issue
134
 
135
+ = 1.2.10 - Jan 17, 2018 =
136
 
137
  * Fixed Redirect Issue of Child Pages
138
 
139
+ = 1.2.9 - Jan 16, 2018 =
140
 
141
  * Enhancements
142
  * Added Filter to enable the like query
145
  * Removed LIKE Query in default. It only works if the site uses PolyLang,
146
  AMP Plugins or separately enabled using the provided filter.
147
 
148
+ = 1.2.8 - Nov 03, 2017 =
149
 
150
  * Add Order by in request query
151
 
152
+ = 1.2.7 - Oct 27, 2017 =
153
 
154
  * Fixed Parse Error
155
 
156
+ = 1.2.6 - Oct 27, 2017 =
157
 
158
  * Enhancements
159
  * Added Filter to Exclude Post types
uninstall.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * CustomPermalinks Uninstall
4
+ *
5
+ * Deletes Option and Post Permalinks on uninstalling the Plugin.
6
+ *
7
+ * @package CustomPermalinks/Uninstaller
8
+ * @since 1.2.18
9
+ */
10
+
11
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
12
+ exit;
13
+ }
14
+
15
+ delete_post_meta_by_key( 'custom_permalink' );
16
+ delete_option( 'custom_permalink_table' );
17
+
18
+ // Clear any cached data that has been removed
19
+ wp_cache_flush();