Version Description
Release Date: Aug 2, 2018
- Fixed upgrade page
Download this release
Release Info
Developer | premmerce |
Plugin | Premmerce Permalink Manager for WooCommerce |
Version | 2.1.2 |
Comparing to | |
See all releases |
Code changes from version 2.1.1 to 2.1.2
- freemius.php +0 -1
- premmerce-url-manager.php +1 -1
- readme.txt +7 -2
- src/Admin/Admin.php +41 -35
- src/Admin/Settings.php +125 -123
- src/Frontend/Frontend.php +4 -4
- src/PermalinkListener.php +8 -8
- src/Updater.php +11 -15
- src/UrlManagerPlugin.php +7 -11
freemius.php
CHANGED
@@ -24,7 +24,6 @@ function premmerce_wpm_fs()
|
|
24 |
'slug' => 'premmerce-url-manager-admin',
|
25 |
'override_exact' => true,
|
26 |
'support' => false,
|
27 |
-
'pricing' => false,
|
28 |
'contact' => false,
|
29 |
'account' => false,
|
30 |
'parent' => array(
|
24 |
'slug' => 'premmerce-url-manager-admin',
|
25 |
'override_exact' => true,
|
26 |
'support' => false,
|
|
|
27 |
'contact' => false,
|
28 |
'account' => false,
|
29 |
'parent' => array(
|
premmerce-url-manager.php
CHANGED
@@ -11,7 +11,7 @@ use Premmerce\UrlManager\UrlManagerPlugin;
|
|
11 |
* Plugin Name: WooCommerce Permalink Manager
|
12 |
* Plugin URI: https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/
|
13 |
* Description: Premmerce WooCommerce Permalink Manager allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
|
14 |
-
* Version: 2.1.
|
15 |
* Author: premmerce
|
16 |
* Author URI: https://premmerce.com/
|
17 |
* License: GPL-2.0+
|
11 |
* Plugin Name: WooCommerce Permalink Manager
|
12 |
* Plugin URI: https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/
|
13 |
* Description: Premmerce WooCommerce Permalink Manager allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
|
14 |
+
* Version: 2.1.2
|
15 |
* Author: premmerce
|
16 |
* Author URI: https://premmerce.com/
|
17 |
* License: GPL-2.0+
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== WooCommerce Permalink Manager ===
|
2 |
-
Contributors: premmerce
|
3 |
Tags: woocommerce url, remove product, remove product_category, woocommerce permalink, woocommerce, woocommerce seo
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 4.9.6
|
6 |
-
Stable tag: 2.1.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -179,6 +179,11 @@ Release Date: Jul 31, 2018
|
|
179 |
* Fixed AMP redirects
|
180 |
* Fixed tag permalinks updates
|
181 |
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
|
184 |
|
1 |
=== WooCommerce Permalink Manager ===
|
2 |
+
Contributors: premmerce, freemius
|
3 |
Tags: woocommerce url, remove product, remove product_category, woocommerce permalink, woocommerce, woocommerce seo
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 4.9.6
|
6 |
+
Stable tag: 2.1.2
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
179 |
* Fixed AMP redirects
|
180 |
* Fixed tag permalinks updates
|
181 |
|
182 |
+
= 2.1.2 =
|
183 |
+
|
184 |
+
Release Date: Aug 2, 2018
|
185 |
+
|
186 |
+
* Fixed upgrade page
|
187 |
|
188 |
|
189 |
|
src/Admin/Admin.php
CHANGED
@@ -10,11 +10,11 @@ use Premmerce\UrlManager\UrlManagerPlugin;
|
|
10 |
*/
|
11 |
class Admin
|
12 |
{
|
13 |
-
|
14 |
/**
|
15 |
* @var string
|
16 |
*/
|
17 |
private $settingsPage;
|
|
|
18 |
/**
|
19 |
* @var FileManager
|
20 |
*/
|
@@ -42,7 +42,7 @@ class Admin
|
|
42 |
|
43 |
private function registerActions()
|
44 |
{
|
45 |
-
$flushActions =
|
46 |
'created_product_cat',
|
47 |
'edited_product_cat',
|
48 |
'delete_product_cat',
|
@@ -52,29 +52,28 @@ class Admin
|
|
52 |
'delete_product_tag',
|
53 |
|
54 |
'update_option_' . Settings::OPTIONS,
|
55 |
-
|
56 |
|
57 |
foreach ($flushActions as $action) {
|
58 |
-
add_action($action,
|
59 |
}
|
60 |
|
61 |
-
add_action('shutdown',
|
62 |
|
63 |
|
64 |
-
add_action('admin_init',
|
65 |
|
66 |
-
add_action('admin_enqueue_scripts',
|
67 |
|
68 |
-
add_action('admin_menu',
|
69 |
|
70 |
#premmerce_clear
|
71 |
-
add_action('admin_menu',
|
72 |
add_action('admin_notices', array($this, 'renderAdminBanner'));
|
73 |
add_action('wp_ajax_premmerce_url_manager_ignore_banner', array($this, 'ignoreAdminBanner'));
|
74 |
#/premmerce_clear
|
75 |
-
|
76 |
-
|
77 |
}
|
|
|
78 |
#premmerce_clear
|
79 |
|
80 |
/**
|
@@ -83,9 +82,8 @@ class Admin
|
|
83 |
public function renderAdminBanner()
|
84 |
{
|
85 |
if ($this->isBannerActive()) {
|
86 |
-
$this->fileManager->includeTemplate('admin/banner.php',
|
87 |
}
|
88 |
-
|
89 |
}
|
90 |
|
91 |
/**
|
@@ -93,15 +91,14 @@ class Admin
|
|
93 |
*/
|
94 |
public function ignoreAdminBanner()
|
95 |
{
|
96 |
-
|
97 |
$user = wp_get_current_user();
|
98 |
$user_id = $user->ID;
|
99 |
|
100 |
add_user_meta($user_id, self::META_IGNORE_BANNER, true, true);
|
101 |
|
102 |
die;
|
103 |
-
|
104 |
}
|
|
|
105 |
#/premmerce_clear
|
106 |
|
107 |
/**
|
@@ -114,7 +111,7 @@ class Admin
|
|
114 |
$premmerceMenuExists = isset($admin_page_hooks['premmerce']);
|
115 |
|
116 |
|
117 |
-
if (
|
118 |
$svg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="16" style="fill:#82878c" viewBox="0 0 20 16"><g id="Rectangle_7"> <path d="M17.8,4l-0.5,1C15.8,7.3,14.4,8,14,8c0,0,0,0,0,0H8h0V4.3C8,4.1,8.1,4,8.3,4H17.8 M4,0H1C0.4,0,0,0.4,0,1c0,0.6,0.4,1,1,1 h1.7C2.9,2,3,2.1,3,2.3V12c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V1C5,0.4,4.6,0,4,0L4,0z M18,2H7.3C6.6,2,6,2.6,6,3.3V12 c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1v-1.7C8,10.1,8.1,10,8.3,10H14c1.1,0,3.2-1.1,5-4l0.7-1.4C20,4,20,3.2,19.5,2.6 C19.1,2.2,18.6,2,18,2L18,2z M14,11h-4c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1h4c0.6,0,1-0.4,1-1C15,11.4,14.6,11,14,11L14,11z M14,14 c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1C15,14.4,14.6,14,14,14L14,14z M4,14c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1 c0.6,0,1-0.4,1-1C5,14.4,4.6,14,4,14L4,14z"/></g></svg>';
|
119 |
$svg = 'data:image/svg+xml;base64,' . base64_encode($svg);
|
120 |
|
@@ -135,10 +132,10 @@ class Admin
|
|
135 |
__('Permalink Manager', 'premmerce-url-manager'),
|
136 |
'manage_options',
|
137 |
$this->settingsPage,
|
138 |
-
|
139 |
);
|
140 |
|
141 |
-
if (
|
142 |
global $submenu;
|
143 |
unset($submenu['premmerce'][0]);
|
144 |
}
|
@@ -149,7 +146,7 @@ class Admin
|
|
149 |
{
|
150 |
global $submenu;
|
151 |
|
152 |
-
if (
|
153 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
154 |
}
|
155 |
|
@@ -158,14 +155,15 @@ class Admin
|
|
158 |
$premmerceInstalled = array_key_exists('premmerce-premium/premmerce.php', $plugins)
|
159 |
|| array_key_exists('premmerce/premmerce.php', $plugins);
|
160 |
|
161 |
-
if (
|
162 |
-
$submenu['premmerce'][999] =
|
163 |
'Get premmerce full pack',
|
164 |
'manage_options',
|
165 |
admin_url('plugin-install.php?tab=plugin-information&plugin=premmerce'),
|
166 |
-
|
167 |
}
|
168 |
}
|
|
|
169 |
#/premmerce_clear
|
170 |
|
171 |
/**
|
@@ -185,16 +183,16 @@ class Admin
|
|
185 |
$tabs['account'] = __('Account', 'premmerce-url-manager');
|
186 |
}
|
187 |
$tabs['contact'] = __('Contact Us', 'premmerce-url-manager');
|
188 |
-
$tabs['pricing'] = __('Pricing', 'premmerce-url-manager');
|
189 |
}
|
190 |
#/premmerce_clear
|
191 |
|
192 |
|
193 |
-
$this->fileManager->includeTemplate('admin/main.php',
|
194 |
'settings' => $this->settings,
|
195 |
'tabs' => $tabs,
|
196 |
'current' => $current,
|
197 |
-
|
198 |
}
|
199 |
|
200 |
/**
|
@@ -203,23 +201,31 @@ class Admin
|
|
203 |
public function enqueueScripts($hook)
|
204 |
{
|
205 |
if ($hook == 'premmerce_page_premmerce-url-manager-admin') {
|
206 |
-
wp_enqueue_style(
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
209 |
}
|
210 |
#premmerce_clear
|
211 |
if ($this->isBannerActive()) {
|
212 |
-
wp_enqueue_script(
|
|
|
213 |
$this->fileManager->locateAsset('admin/js/banner.js'),
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
218 |
}
|
219 |
#/premmerce_clear
|
220 |
}
|
221 |
|
222 |
-
|
223 |
/**
|
224 |
* Set flush trigger
|
225 |
*/
|
@@ -246,7 +252,7 @@ class Admin
|
|
246 |
$user_id = $user->ID;
|
247 |
|
248 |
return ! get_user_meta($user_id, self::META_IGNORE_BANNER, true);
|
249 |
-
|
250 |
}
|
|
|
251 |
#/premmerce_clear
|
252 |
}
|
10 |
*/
|
11 |
class Admin
|
12 |
{
|
|
|
13 |
/**
|
14 |
* @var string
|
15 |
*/
|
16 |
private $settingsPage;
|
17 |
+
|
18 |
/**
|
19 |
* @var FileManager
|
20 |
*/
|
42 |
|
43 |
private function registerActions()
|
44 |
{
|
45 |
+
$flushActions = array(
|
46 |
'created_product_cat',
|
47 |
'edited_product_cat',
|
48 |
'delete_product_cat',
|
52 |
'delete_product_tag',
|
53 |
|
54 |
'update_option_' . Settings::OPTIONS,
|
55 |
+
);
|
56 |
|
57 |
foreach ($flushActions as $action) {
|
58 |
+
add_action($action, array($this, 'triggerFlush'));
|
59 |
}
|
60 |
|
61 |
+
add_action('shutdown', array($this, 'flush'));
|
62 |
|
63 |
|
64 |
+
add_action('admin_init', array($this->settings, 'register'));
|
65 |
|
66 |
+
add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'));
|
67 |
|
68 |
+
add_action('admin_menu', array($this, 'addMenuPage'));
|
69 |
|
70 |
#premmerce_clear
|
71 |
+
add_action('admin_menu', array($this, 'addFullPack'), 100);
|
72 |
add_action('admin_notices', array($this, 'renderAdminBanner'));
|
73 |
add_action('wp_ajax_premmerce_url_manager_ignore_banner', array($this, 'ignoreAdminBanner'));
|
74 |
#/premmerce_clear
|
|
|
|
|
75 |
}
|
76 |
+
|
77 |
#premmerce_clear
|
78 |
|
79 |
/**
|
82 |
public function renderAdminBanner()
|
83 |
{
|
84 |
if ($this->isBannerActive()) {
|
85 |
+
$this->fileManager->includeTemplate('admin/banner.php', array('fm' => $this->fileManager));
|
86 |
}
|
|
|
87 |
}
|
88 |
|
89 |
/**
|
91 |
*/
|
92 |
public function ignoreAdminBanner()
|
93 |
{
|
|
|
94 |
$user = wp_get_current_user();
|
95 |
$user_id = $user->ID;
|
96 |
|
97 |
add_user_meta($user_id, self::META_IGNORE_BANNER, true, true);
|
98 |
|
99 |
die;
|
|
|
100 |
}
|
101 |
+
|
102 |
#/premmerce_clear
|
103 |
|
104 |
/**
|
111 |
$premmerceMenuExists = isset($admin_page_hooks['premmerce']);
|
112 |
|
113 |
|
114 |
+
if (! $premmerceMenuExists) {
|
115 |
$svg = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="16" style="fill:#82878c" viewBox="0 0 20 16"><g id="Rectangle_7"> <path d="M17.8,4l-0.5,1C15.8,7.3,14.4,8,14,8c0,0,0,0,0,0H8h0V4.3C8,4.1,8.1,4,8.3,4H17.8 M4,0H1C0.4,0,0,0.4,0,1c0,0.6,0.4,1,1,1 h1.7C2.9,2,3,2.1,3,2.3V12c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1V1C5,0.4,4.6,0,4,0L4,0z M18,2H7.3C6.6,2,6,2.6,6,3.3V12 c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1v-1.7C8,10.1,8.1,10,8.3,10H14c1.1,0,3.2-1.1,5-4l0.7-1.4C20,4,20,3.2,19.5,2.6 C19.1,2.2,18.6,2,18,2L18,2z M14,11h-4c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1h4c0.6,0,1-0.4,1-1C15,11.4,14.6,11,14,11L14,11z M14,14 c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1c0.6,0,1-0.4,1-1C15,14.4,14.6,14,14,14L14,14z M4,14c-0.6,0-1,0.4-1,1c0,0.6,0.4,1,1,1 c0.6,0,1-0.4,1-1C5,14.4,4.6,14,4,14L4,14z"/></g></svg>';
|
116 |
$svg = 'data:image/svg+xml;base64,' . base64_encode($svg);
|
117 |
|
132 |
__('Permalink Manager', 'premmerce-url-manager'),
|
133 |
'manage_options',
|
134 |
$this->settingsPage,
|
135 |
+
array($this, 'options')
|
136 |
);
|
137 |
|
138 |
+
if (! $premmerceMenuExists) {
|
139 |
global $submenu;
|
140 |
unset($submenu['premmerce'][0]);
|
141 |
}
|
146 |
{
|
147 |
global $submenu;
|
148 |
|
149 |
+
if (! function_exists('get_plugins')) {
|
150 |
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
151 |
}
|
152 |
|
155 |
$premmerceInstalled = array_key_exists('premmerce-premium/premmerce.php', $plugins)
|
156 |
|| array_key_exists('premmerce/premmerce.php', $plugins);
|
157 |
|
158 |
+
if (! $premmerceInstalled) {
|
159 |
+
$submenu['premmerce'][999] = array(
|
160 |
'Get premmerce full pack',
|
161 |
'manage_options',
|
162 |
admin_url('plugin-install.php?tab=plugin-information&plugin=premmerce'),
|
163 |
+
);
|
164 |
}
|
165 |
}
|
166 |
+
|
167 |
#/premmerce_clear
|
168 |
|
169 |
/**
|
183 |
$tabs['account'] = __('Account', 'premmerce-url-manager');
|
184 |
}
|
185 |
$tabs['contact'] = __('Contact Us', 'premmerce-url-manager');
|
186 |
+
// $tabs['pricing'] = __('Pricing', 'premmerce-url-manager');
|
187 |
}
|
188 |
#/premmerce_clear
|
189 |
|
190 |
|
191 |
+
$this->fileManager->includeTemplate('admin/main.php', array(
|
192 |
'settings' => $this->settings,
|
193 |
'tabs' => $tabs,
|
194 |
'current' => $current,
|
195 |
+
));
|
196 |
}
|
197 |
|
198 |
/**
|
201 |
public function enqueueScripts($hook)
|
202 |
{
|
203 |
if ($hook == 'premmerce_page_premmerce-url-manager-admin') {
|
204 |
+
wp_enqueue_style(
|
205 |
+
'premmerce-permalink-style',
|
206 |
+
$this->fileManager->locateAsset('admin/css/style.css'),
|
207 |
+
array(),
|
208 |
+
UrlManagerPlugin::VERSION
|
209 |
+
);
|
210 |
}
|
211 |
#premmerce_clear
|
212 |
if ($this->isBannerActive()) {
|
213 |
+
wp_enqueue_script(
|
214 |
+
'premmerce-permalink-banner-script',
|
215 |
$this->fileManager->locateAsset('admin/js/banner.js'),
|
216 |
+
array('jquery'),
|
217 |
+
UrlManagerPlugin::VERSION
|
218 |
+
);
|
219 |
+
wp_enqueue_style(
|
220 |
+
'premmerce-permalink-banner-style',
|
221 |
+
$this->fileManager->locateAsset('admin/css/banner.css'),
|
222 |
+
array(),
|
223 |
+
UrlManagerPlugin::VERSION
|
224 |
+
);
|
225 |
}
|
226 |
#/premmerce_clear
|
227 |
}
|
228 |
|
|
|
229 |
/**
|
230 |
* Set flush trigger
|
231 |
*/
|
252 |
$user_id = $user->ID;
|
253 |
|
254 |
return ! get_user_meta($user_id, self::META_IGNORE_BANNER, true);
|
|
|
255 |
}
|
256 |
+
|
257 |
#/premmerce_clear
|
258 |
}
|
src/Admin/Settings.php
CHANGED
@@ -2,126 +2,128 @@
|
|
2 |
|
3 |
use Premmerce\SDK\V2\FileManager\FileManager;
|
4 |
|
5 |
-
class Settings
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
2 |
|
3 |
use Premmerce\SDK\V2\FileManager\FileManager;
|
4 |
|
5 |
+
class Settings
|
6 |
+
{
|
7 |
+
const OPTION_DISABLED = 'premmerce_url_manager_disabled';
|
8 |
+
|
9 |
+
const OPTION_FLUSH = 'premmerce_url_manager_flush_rules';
|
10 |
+
|
11 |
+
const OPTIONS = 'premmerce_permalink_manager';
|
12 |
+
|
13 |
+
const SETTINGS_PAGE = 'premmerce_permalink_manager_page';
|
14 |
+
|
15 |
+
const PERMALINK_STRUCTURE = '/%postname%/';
|
16 |
+
|
17 |
+
const PERMALINK_WC_PRODUCT_CAT = '/shop/%product_cat%/';
|
18 |
+
|
19 |
+
const PERMALINK_WC_PRODUCT = 'product';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* @var FileManager
|
23 |
+
*/
|
24 |
+
private $fileManager;
|
25 |
+
|
26 |
+
public function __construct(FileManager $fileManager)
|
27 |
+
{
|
28 |
+
$this->fileManager = $fileManager;
|
29 |
+
}
|
30 |
+
|
31 |
+
public function register()
|
32 |
+
{
|
33 |
+
register_setting(self::OPTIONS, self::OPTIONS, array(
|
34 |
+
'sanitize_callback' => array($this, 'updateSettings'),
|
35 |
+
));
|
36 |
+
|
37 |
+
add_settings_section('category_link', __('Categories', 'premmerce-url-manager'), array(
|
38 |
+
$this,
|
39 |
+
'categorySection',
|
40 |
+
), self::SETTINGS_PAGE);
|
41 |
+
add_settings_section('product_link', __('Products', 'premmerce-url-manager'), array(
|
42 |
+
$this,
|
43 |
+
'productSection',
|
44 |
+
), self::SETTINGS_PAGE);
|
45 |
+
add_settings_section('additional', __('Additional', 'premmerce-url-manager'), array(
|
46 |
+
$this,
|
47 |
+
'canonicalSection',
|
48 |
+
), self::SETTINGS_PAGE);
|
49 |
+
}
|
50 |
+
|
51 |
+
public function show()
|
52 |
+
{
|
53 |
+
print('<form action="' . admin_url('options.php') . '" method="post">');
|
54 |
+
|
55 |
+
settings_errors();
|
56 |
+
|
57 |
+
settings_fields(self::OPTIONS);
|
58 |
+
|
59 |
+
do_settings_sections(self::SETTINGS_PAGE);
|
60 |
+
|
61 |
+
submit_button();
|
62 |
+
print('</form>');
|
63 |
+
}
|
64 |
+
|
65 |
+
public function categorySection()
|
66 |
+
{
|
67 |
+
$this->fileManager->includeTemplate('admin/section/category.php', array(
|
68 |
+
'category' => $this->getOption('category'),
|
69 |
+
));
|
70 |
+
}
|
71 |
+
|
72 |
+
public function productSection()
|
73 |
+
{
|
74 |
+
$this->fileManager->includeTemplate('admin/section/product.php', array(
|
75 |
+
'product' => $this->getOption('product'),
|
76 |
+
));
|
77 |
+
}
|
78 |
+
|
79 |
+
public function canonicalSection()
|
80 |
+
{
|
81 |
+
$this->fileManager->includeTemplate('admin/section/additional.php', array(
|
82 |
+
'tag' => $this->getOption('tag'),
|
83 |
+
'canonical' => $this->getOption('canonical'),
|
84 |
+
'redirect' => $this->getOption('redirect'),
|
85 |
+
'use_primary_category' => $this->getOption('use_primary_category'),
|
86 |
+
));
|
87 |
+
}
|
88 |
+
|
89 |
+
public function updateSettings($settings)
|
90 |
+
{
|
91 |
+
$this->fixWPWCSettings($settings);
|
92 |
+
return $settings;
|
93 |
+
}
|
94 |
+
|
95 |
+
private function fixWPWCSettings($options)
|
96 |
+
{
|
97 |
+
if ($options['product'] || $options['category']) {
|
98 |
+
if (!get_option('permalink_structure')) {
|
99 |
+
update_option('permalink_structure', self::PERMALINK_STRUCTURE);
|
100 |
+
};
|
101 |
+
}
|
102 |
+
|
103 |
+
if ($options['product']) {
|
104 |
+
if ($options['product'] == 'slug') {
|
105 |
+
$wc['product_base'] = self::PERMALINK_WC_PRODUCT;
|
106 |
+
}
|
107 |
+
if (in_array($options['product'], array('category_slug', 'hierarchical'))) {
|
108 |
+
$wc['product_base'] = self::PERMALINK_WC_PRODUCT_CAT;
|
109 |
+
}
|
110 |
+
|
111 |
+
update_option('woocommerce_permalinks', $wc);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* @param string $key
|
117 |
+
* @param mixed|null $default
|
118 |
+
*
|
119 |
+
* @return mixed|null
|
120 |
+
*/
|
121 |
+
public function getOption($key, $default = null)
|
122 |
+
{
|
123 |
+
if (!isset($this->options)) {
|
124 |
+
$this->options = get_option(self::OPTIONS);
|
125 |
+
}
|
126 |
+
|
127 |
+
return isset($this->options[ $key ])? $this->options[ $key ] : $default;
|
128 |
+
}
|
129 |
+
}
|
src/Frontend/Frontend.php
CHANGED
@@ -20,10 +20,10 @@ class Frontend
|
|
20 |
{
|
21 |
$options = get_option( Settings::OPTIONS );
|
22 |
if ( !empty($options['product']) ) {
|
23 |
-
add_action( 'request',
|
24 |
}
|
25 |
if ( !empty($options['canonical']) ) {
|
26 |
-
add_action( 'wp_head',
|
27 |
}
|
28 |
#/premmerce_clear
|
29 |
}
|
@@ -43,7 +43,7 @@ class Frontend
|
|
43 |
if ( !empty($url) ) {
|
44 |
$url = explode( '/', $url );
|
45 |
$slug = array_pop( $url );
|
46 |
-
$replace =
|
47 |
|
48 |
if ( $slug === 'feed' ) {
|
49 |
$replace['feed'] = $slug;
|
@@ -64,7 +64,7 @@ class Frontend
|
|
64 |
}
|
65 |
|
66 |
$sql = "SELECT COUNT(ID) as count_id FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s";
|
67 |
-
$query = $wpdb->prepare( $sql,
|
68 |
$num = intval( $wpdb->get_var( $query ) );
|
69 |
|
70 |
if ( $num > 0 ) {
|
20 |
{
|
21 |
$options = get_option( Settings::OPTIONS );
|
22 |
if ( !empty($options['product']) ) {
|
23 |
+
add_action( 'request', array( $this, 'replaceRequest' ), 11 );
|
24 |
}
|
25 |
if ( !empty($options['canonical']) ) {
|
26 |
+
add_action( 'wp_head', array( $this, 'addCanonical' ) );
|
27 |
}
|
28 |
#/premmerce_clear
|
29 |
}
|
43 |
if ( !empty($url) ) {
|
44 |
$url = explode( '/', $url );
|
45 |
$slug = array_pop( $url );
|
46 |
+
$replace = array();
|
47 |
|
48 |
if ( $slug === 'feed' ) {
|
49 |
$replace['feed'] = $slug;
|
64 |
}
|
65 |
|
66 |
$sql = "SELECT COUNT(ID) as count_id FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s";
|
67 |
+
$query = $wpdb->prepare( $sql, array( $slug, self::WOO_PRODUCT ) );
|
68 |
$num = intval( $wpdb->get_var( $query ) );
|
69 |
|
70 |
if ( $num > 0 ) {
|
src/PermalinkListener.php
CHANGED
@@ -22,10 +22,10 @@ class PermalinkListener
|
|
22 |
public function __construct()
|
23 |
{
|
24 |
$options = get_option( Settings::OPTIONS );
|
25 |
-
$this->options =
|
26 |
'use_primary_category' => !empty($options['use_primary_category']),
|
27 |
'product' => ( isset( $options['product'] ) ? $options['product'] : '' ),
|
28 |
-
|
29 |
$this->taxonomyOptions['product_cat'] = ( isset( $options['category'] ) ? $options['category'] : '' );
|
30 |
#/premmerce_clear
|
31 |
}
|
@@ -37,17 +37,17 @@ class PermalinkListener
|
|
37 |
{
|
38 |
add_filter(
|
39 |
'post_type_link',
|
40 |
-
|
41 |
1,
|
42 |
2
|
43 |
);
|
44 |
add_filter(
|
45 |
'term_link',
|
46 |
-
|
47 |
0,
|
48 |
3
|
49 |
);
|
50 |
-
add_filter( 'rewrite_rules_array',
|
51 |
}
|
52 |
|
53 |
/**
|
@@ -113,14 +113,14 @@ class PermalinkListener
|
|
113 |
wp_cache_flush();
|
114 |
global $wp_rewrite ;
|
115 |
$feed = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
|
116 |
-
$customRules =
|
117 |
foreach ( $this->taxonomyOptions as $taxonomy => $option ) {
|
118 |
|
119 |
if ( !empty($option) ) {
|
120 |
-
$terms = get_categories(
|
121 |
'taxonomy' => $taxonomy,
|
122 |
'hide_empty' => false,
|
123 |
-
|
124 |
$hierarchical = $this->isHierarchical( $option );
|
125 |
foreach ( $terms as $term ) {
|
126 |
$slug = $this->buildTermPath( $term, $hierarchical );
|
22 |
public function __construct()
|
23 |
{
|
24 |
$options = get_option( Settings::OPTIONS );
|
25 |
+
$this->options = array(
|
26 |
'use_primary_category' => !empty($options['use_primary_category']),
|
27 |
'product' => ( isset( $options['product'] ) ? $options['product'] : '' ),
|
28 |
+
);
|
29 |
$this->taxonomyOptions['product_cat'] = ( isset( $options['category'] ) ? $options['category'] : '' );
|
30 |
#/premmerce_clear
|
31 |
}
|
37 |
{
|
38 |
add_filter(
|
39 |
'post_type_link',
|
40 |
+
array( $this, 'replaceProductLink' ),
|
41 |
1,
|
42 |
2
|
43 |
);
|
44 |
add_filter(
|
45 |
'term_link',
|
46 |
+
array( $this, 'replaceTermLink' ),
|
47 |
0,
|
48 |
3
|
49 |
);
|
50 |
+
add_filter( 'rewrite_rules_array', array( $this, 'addRewriteRules' ), 99 );
|
51 |
}
|
52 |
|
53 |
/**
|
113 |
wp_cache_flush();
|
114 |
global $wp_rewrite ;
|
115 |
$feed = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
|
116 |
+
$customRules = array();
|
117 |
foreach ( $this->taxonomyOptions as $taxonomy => $option ) {
|
118 |
|
119 |
if ( !empty($option) ) {
|
120 |
+
$terms = get_categories( array(
|
121 |
'taxonomy' => $taxonomy,
|
122 |
'hide_empty' => false,
|
123 |
+
) );
|
124 |
$hierarchical = $this->isHierarchical( $option );
|
125 |
foreach ( $terms as $term ) {
|
126 |
$slug = $this->buildTermPath( $term, $hierarchical );
|
src/Updater.php
CHANGED
@@ -4,7 +4,6 @@ use Premmerce\UrlManager\Admin\Settings;
|
|
4 |
|
5 |
class Updater
|
6 |
{
|
7 |
-
|
8 |
const CURRENT_VERSION = '2.1.1';
|
9 |
|
10 |
const DB_OPTION = 'premmerce_permalink_manager_db_version';
|
@@ -36,38 +35,36 @@ class Updater
|
|
36 |
|
37 |
public function getUpdates()
|
38 |
{
|
39 |
-
return
|
40 |
-
'2.0' =>
|
41 |
-
|
42 |
}
|
43 |
|
44 |
public function update2_0()
|
45 |
{
|
46 |
-
|
47 |
-
$
|
48 |
-
$options12 = [
|
49 |
'use_primary_category' => 'on',
|
50 |
-
|
51 |
|
52 |
$wc = get_option('woocommerce_permalinks');
|
53 |
|
54 |
$showProductCats = false;
|
55 |
-
if (
|
56 |
$showProductCats = strpos($wc['product_base'], '%product_cat%') !== false;
|
57 |
}
|
58 |
|
59 |
|
60 |
-
if (
|
61 |
$options12['product'] = 'slug';
|
62 |
if ($showProductCats) {
|
63 |
$options12['product'] = 'hierarchical';
|
64 |
}
|
65 |
}
|
66 |
-
if (
|
67 |
$options12['category'] = 'hierarchical';
|
68 |
-
if (
|
69 |
$options12['category'] = 'slug';
|
70 |
-
|
71 |
}
|
72 |
}
|
73 |
|
@@ -76,5 +73,4 @@ class Updater
|
|
76 |
delete_option(Settings::OPTION_DISABLED);
|
77 |
update_option(self::DB_OPTION, '2.0');
|
78 |
}
|
79 |
-
|
80 |
-
}
|
4 |
|
5 |
class Updater
|
6 |
{
|
|
|
7 |
const CURRENT_VERSION = '2.1.1';
|
8 |
|
9 |
const DB_OPTION = 'premmerce_permalink_manager_db_version';
|
35 |
|
36 |
public function getUpdates()
|
37 |
{
|
38 |
+
return array(
|
39 |
+
'2.0' => array($this, 'update2_0'),
|
40 |
+
);
|
41 |
}
|
42 |
|
43 |
public function update2_0()
|
44 |
{
|
45 |
+
$options = get_option('premmerce_url_manager_options', array());
|
46 |
+
$options12 = array(
|
|
|
47 |
'use_primary_category' => 'on',
|
48 |
+
);
|
49 |
|
50 |
$wc = get_option('woocommerce_permalinks');
|
51 |
|
52 |
$showProductCats = false;
|
53 |
+
if (! empty($wc['product_base'])) {
|
54 |
$showProductCats = strpos($wc['product_base'], '%product_cat%') !== false;
|
55 |
}
|
56 |
|
57 |
|
58 |
+
if (! empty($options['remove_product_base'])) {
|
59 |
$options12['product'] = 'slug';
|
60 |
if ($showProductCats) {
|
61 |
$options12['product'] = 'hierarchical';
|
62 |
}
|
63 |
}
|
64 |
+
if (! empty($options['remove_category_base'])) {
|
65 |
$options12['category'] = 'hierarchical';
|
66 |
+
if (! empty($options['remove_category_parent_slugs'])) {
|
67 |
$options12['category'] = 'slug';
|
|
|
68 |
}
|
69 |
}
|
70 |
|
73 |
delete_option(Settings::OPTION_DISABLED);
|
74 |
update_option(self::DB_OPTION, '2.0');
|
75 |
}
|
76 |
+
}
|
|
src/UrlManagerPlugin.php
CHANGED
@@ -13,7 +13,6 @@ use Premmerce\UrlManager\Frontend\Frontend;
|
|
13 |
*/
|
14 |
class UrlManagerPlugin
|
15 |
{
|
16 |
-
|
17 |
const DOMAIN = 'premmerce-url-manager';
|
18 |
|
19 |
const VERSION = '2.1.1';
|
@@ -39,9 +38,9 @@ class UrlManagerPlugin
|
|
39 |
$this->notifier = new AdminNotifier();
|
40 |
|
41 |
|
42 |
-
add_action('init',
|
43 |
|
44 |
-
add_action('admin_init',
|
45 |
}
|
46 |
|
47 |
/**
|
@@ -57,12 +56,11 @@ class UrlManagerPlugin
|
|
57 |
}
|
58 |
|
59 |
if ($valid) {
|
60 |
-
if (
|
61 |
new Frontend();
|
62 |
}
|
63 |
(new PermalinkListener())->registerFilters();
|
64 |
}
|
65 |
-
|
66 |
}
|
67 |
|
68 |
/**
|
@@ -98,7 +96,7 @@ class UrlManagerPlugin
|
|
98 |
{
|
99 |
global $wpdb;
|
100 |
|
101 |
-
$wpdb->delete($wpdb->usermeta,
|
102 |
}
|
103 |
|
104 |
/**
|
@@ -125,7 +123,6 @@ class UrlManagerPlugin
|
|
125 |
$this->notifier->push($error, AdminNotifier::ERROR, false);
|
126 |
}
|
127 |
}
|
128 |
-
|
129 |
}
|
130 |
|
131 |
/**
|
@@ -135,17 +132,16 @@ class UrlManagerPlugin
|
|
135 |
*/
|
136 |
private function validateRequiredPlugins()
|
137 |
{
|
|
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
if ( ! function_exists('is_plugin_active')) {
|
142 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
* Check if WooCommerce is active
|
147 |
**/
|
148 |
-
if (
|
149 |
$plugins[] = '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>';
|
150 |
}
|
151 |
|
13 |
*/
|
14 |
class UrlManagerPlugin
|
15 |
{
|
|
|
16 |
const DOMAIN = 'premmerce-url-manager';
|
17 |
|
18 |
const VERSION = '2.1.1';
|
38 |
$this->notifier = new AdminNotifier();
|
39 |
|
40 |
|
41 |
+
add_action('init', array($this, 'loadTextDomain'));
|
42 |
|
43 |
+
add_action('admin_init', array($this, 'checkRequirePlugins'));
|
44 |
}
|
45 |
|
46 |
/**
|
56 |
}
|
57 |
|
58 |
if ($valid) {
|
59 |
+
if (! is_admin()) {
|
60 |
new Frontend();
|
61 |
}
|
62 |
(new PermalinkListener())->registerFilters();
|
63 |
}
|
|
|
64 |
}
|
65 |
|
66 |
/**
|
96 |
{
|
97 |
global $wpdb;
|
98 |
|
99 |
+
$wpdb->delete($wpdb->usermeta, array('meta_key' => Admin::META_IGNORE_BANNER));
|
100 |
}
|
101 |
|
102 |
/**
|
123 |
$this->notifier->push($error, AdminNotifier::ERROR, false);
|
124 |
}
|
125 |
}
|
|
|
126 |
}
|
127 |
|
128 |
/**
|
132 |
*/
|
133 |
private function validateRequiredPlugins()
|
134 |
{
|
135 |
+
$plugins = array();
|
136 |
|
137 |
+
if (! function_exists('is_plugin_active')) {
|
|
|
|
|
138 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
139 |
}
|
140 |
|
141 |
/**
|
142 |
* Check if WooCommerce is active
|
143 |
**/
|
144 |
+
if (! (is_plugin_active('woocommerce/woocommerce.php') || is_plugin_active_for_network('woocommerce/woocommerce.php'))) {
|
145 |
$plugins[] = '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>';
|
146 |
}
|
147 |
|