Version Description
Release Date: July 24, 2017
- Initial release
=
Download this release
Release Info
Developer | premmerce |
Plugin | Premmerce Permalink Manager for WooCommerce |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- autoload.php +14 -0
- index.php +1 -0
- languages/premmerce-url-manager-ru_RU.mo +0 -0
- languages/premmerce-url-manager-ru_RU.po +92 -0
- languages/premmerce-url-manager-uk.mo +0 -0
- languages/premmerce-url-manager-uk.po +91 -0
- license.txt +339 -0
- premmerce-url-manager.php +44 -0
- readme.txt +71 -0
- src/Admin/Admin.php +135 -0
- src/FileManager.php +108 -0
- src/Frontend/Frontend.php +67 -0
- src/PermalinkListener.php +272 -0
- src/UrlManagerPlugin.php +116 -0
- views/admin/options.php +60 -0
autoload.php
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Register autoload callback
|
5 |
+
*/
|
6 |
+
spl_autoload_register(function ($class) {
|
7 |
+
$namespace = 'Premmerce\UrlManager\\';
|
8 |
+
$source = 'src\\';
|
9 |
+
$class = str_replace($namespace, $source, $class);
|
10 |
+
$file = plugin_dir_path(__FILE__) . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
|
11 |
+
if (file_exists($file)) {
|
12 |
+
require_once $file;
|
13 |
+
}
|
14 |
+
});
|
index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php // Silence is golden
|
languages/premmerce-url-manager-ru_RU.mo
ADDED
Binary file
|
languages/premmerce-url-manager-ru_RU.po
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: Premmerce url manager\n"
|
4 |
+
"POT-Creation-Date: 2017-08-30 10:35+0300\n"
|
5 |
+
"PO-Revision-Date: 2017-08-30 10:37+0300\n"
|
6 |
+
"Last-Translator: \n"
|
7 |
+
"Language-Team: \n"
|
8 |
+
"Language: ru\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.8.7.1\n"
|
13 |
+
"X-Poedit-Basepath: ..\n"
|
14 |
+
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
|
15 |
+
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
16 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
17 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
18 |
+
"X-Poedit-SearchPath-0: .\n"
|
19 |
+
|
20 |
+
#: src/UrlManagerPlugin.php:65
|
21 |
+
#, php-format
|
22 |
+
msgid "This plugin requires %s plugin to be active!"
|
23 |
+
msgstr "Для этого плагина необходим плагин %s!"
|
24 |
+
|
25 |
+
#: views/admin/options.php:11
|
26 |
+
msgid "Category"
|
27 |
+
msgstr "Категория"
|
28 |
+
|
29 |
+
#: views/admin/options.php:20 views/admin/options.php:48
|
30 |
+
msgid "Remove base"
|
31 |
+
msgstr "Не показывать префикс"
|
32 |
+
|
33 |
+
#: views/admin/options.php:23
|
34 |
+
msgid ""
|
35 |
+
"Remove prefix from category URL<br> default: /product-category/accessories/"
|
36 |
+
"action-figures/ - changed: /accessories/action-figures/"
|
37 |
+
msgstr ""
|
38 |
+
"Не показывать префикс в URL категории<br> по умолчанию: /product-category/"
|
39 |
+
"accessories/action-figures/ - изменено: /accessories/action-figures/"
|
40 |
+
|
41 |
+
#: views/admin/options.php:30
|
42 |
+
msgid "Remove parent slugs"
|
43 |
+
msgstr "Не показывать родительский URL"
|
44 |
+
|
45 |
+
#: views/admin/options.php:33
|
46 |
+
msgid ""
|
47 |
+
"Remove parent slugs from category URL<br> default: /product-category/"
|
48 |
+
"accessories/action-figures/ - changed: /product-category/action-figures/"
|
49 |
+
msgstr ""
|
50 |
+
"Не показывать родительский URL в категории<br> по умолчанию: /product-"
|
51 |
+
"category/accessories/action-figures/ - изменено: /product-category/action-"
|
52 |
+
"figures/"
|
53 |
+
|
54 |
+
#: views/admin/options.php:40
|
55 |
+
msgid "Product"
|
56 |
+
msgstr "Товар"
|
57 |
+
|
58 |
+
#: views/admin/options.php:51
|
59 |
+
msgid ""
|
60 |
+
"Remove prefix from product URL<br> default: /shop/accessories/action-figures/"
|
61 |
+
"acme/ - changed: /accessories/action-figures/acme/"
|
62 |
+
msgstr ""
|
63 |
+
"Не показывать префикс в URL товара<br> по умолчанию:/shop/accessories/action-"
|
64 |
+
"figures/acme/ - изменено: /accessories/action-figures/acme/"
|
65 |
+
|
66 |
+
#~ msgid ""
|
67 |
+
#~ "Remove prefix from product url<br> default: /shop/accessories/action-"
|
68 |
+
#~ "figures/acme/ - changed: /accessories/action-figures/acme/"
|
69 |
+
#~ msgstr ""
|
70 |
+
#~ "Не показывать префикс в url товара<br> по умолчанию:/shop/accessories/"
|
71 |
+
#~ "action-figures/acme/ - изменено: /accessories/action-figures/acme/"
|
72 |
+
|
73 |
+
#~ msgid ""
|
74 |
+
#~ "Remove parent slugs from category url<br> default: /product-category/"
|
75 |
+
#~ "accessories/action-figures/ - changed: /product-category/action-figures/"
|
76 |
+
#~ msgstr ""
|
77 |
+
#~ "Не показывать родительский url в категории<br> по умолчанию: /product-"
|
78 |
+
#~ "category/accessories/action-figures/ - изменено: /product-category/action-"
|
79 |
+
#~ "figures/"
|
80 |
+
|
81 |
+
#~ msgid "Url settings"
|
82 |
+
#~ msgstr "Настройки url"
|
83 |
+
|
84 |
+
#~ msgid ""
|
85 |
+
#~ "Remove prefix from category url<br> default: /product-category/"
|
86 |
+
#~ "accessories/action-figures/ - changed: /accessories/action-figures/"
|
87 |
+
#~ msgstr ""
|
88 |
+
#~ "Не показывать префикс в url категории<br> по умолчанию: /product-category/"
|
89 |
+
#~ "accessories/action-figures/ - изменено: /accessories/action-figures/"
|
90 |
+
|
91 |
+
#~ msgid "Remove category base"
|
92 |
+
#~ msgstr "Не показивать "
|
languages/premmerce-url-manager-uk.mo
ADDED
Binary file
|
languages/premmerce-url-manager-uk.po
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
msgid ""
|
2 |
+
msgstr ""
|
3 |
+
"Project-Id-Version: Premmerce url manager\n"
|
4 |
+
"POT-Creation-Date: 2017-08-30 10:34+0300\n"
|
5 |
+
"PO-Revision-Date: 2017-08-30 10:37+0300\n"
|
6 |
+
"Last-Translator: \n"
|
7 |
+
"Language-Team: \n"
|
8 |
+
"Language: uk\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.8.7.1\n"
|
13 |
+
"X-Poedit-Basepath: ..\n"
|
14 |
+
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
|
15 |
+
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
16 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
17 |
+
"X-Poedit-KeywordsList: __;_e\n"
|
18 |
+
"X-Poedit-SearchPath-0: .\n"
|
19 |
+
|
20 |
+
#: src/UrlManagerPlugin.php:65
|
21 |
+
#, php-format
|
22 |
+
msgid "This plugin requires %s plugin to be active!"
|
23 |
+
msgstr "Для цього плагіна необхідний плагін %s!"
|
24 |
+
|
25 |
+
#: views/admin/options.php:11
|
26 |
+
msgid "Category"
|
27 |
+
msgstr "Категорія"
|
28 |
+
|
29 |
+
#: views/admin/options.php:20 views/admin/options.php:48
|
30 |
+
msgid "Remove base"
|
31 |
+
msgstr "Не показувати префікс"
|
32 |
+
|
33 |
+
#: views/admin/options.php:23
|
34 |
+
msgid ""
|
35 |
+
"Remove prefix from category URL<br> default: /product-category/accessories/"
|
36 |
+
"action-figures/ - changed: /accessories/action-figures/"
|
37 |
+
msgstr ""
|
38 |
+
"Не відображати префікс в URL категорії<br> за замовчуванням: /product-"
|
39 |
+
"category/accessories/action-figures/ - змінено: /accessories/action-figures/"
|
40 |
+
|
41 |
+
#: views/admin/options.php:30
|
42 |
+
msgid "Remove parent slugs"
|
43 |
+
msgstr "Не показувати батьківський URL"
|
44 |
+
|
45 |
+
#: views/admin/options.php:33
|
46 |
+
msgid ""
|
47 |
+
"Remove parent slugs from category URL<br> default: /product-category/"
|
48 |
+
"accessories/action-figures/ - changed: /product-category/action-figures/"
|
49 |
+
msgstr ""
|
50 |
+
"Не відображати батьківський URL в категорії<br> за замовчуванням: /product-"
|
51 |
+
"category/accessories/action-figures/ - змінено: /product-category/action-"
|
52 |
+
"figures/"
|
53 |
+
|
54 |
+
#: views/admin/options.php:40
|
55 |
+
msgid "Product"
|
56 |
+
msgstr "Товар"
|
57 |
+
|
58 |
+
#: views/admin/options.php:51
|
59 |
+
msgid ""
|
60 |
+
"Remove prefix from product URL<br> default: /shop/accessories/action-figures/"
|
61 |
+
"acme/ - changed: /accessories/action-figures/acme/"
|
62 |
+
msgstr ""
|
63 |
+
"Не відображати префікс в URL товару<br> за замовчуванням: /shop/accessories/"
|
64 |
+
"action-figures/acme/ - змінено: /accessories/action-figures/acme/"
|
65 |
+
|
66 |
+
#~ msgid ""
|
67 |
+
#~ "Remove prefix from product url<br> default: /shop/accessories/action-"
|
68 |
+
#~ "figures/acme/ - changed: /accessories/action-figures/acme/"
|
69 |
+
#~ msgstr ""
|
70 |
+
#~ "Не відображати префікс в url товару<br> за замовчуванням: /shop/"
|
71 |
+
#~ "accessories/action-figures/acme/ - змінено: /accessories/action-figures/"
|
72 |
+
#~ "acme/"
|
73 |
+
|
74 |
+
#~ msgid ""
|
75 |
+
#~ "Remove parent slugs from category url<br> default: /product-category/"
|
76 |
+
#~ "accessories/action-figures/ - changed: /product-category/action-figures/"
|
77 |
+
#~ msgstr ""
|
78 |
+
#~ "Не відображати батьківський url в категорії<br> за замовчуванням: /"
|
79 |
+
#~ "product-category/accessories/action-figures/ - змінено: /product-category/"
|
80 |
+
#~ "action-figures/"
|
81 |
+
|
82 |
+
#~ msgid "Url settings"
|
83 |
+
#~ msgstr "Налаштування url"
|
84 |
+
|
85 |
+
#~ msgid ""
|
86 |
+
#~ "Remove prefix from category url<br> default: /product-category/"
|
87 |
+
#~ "accessories/action-figures/ - changed: /accessories/action-figures/"
|
88 |
+
#~ msgstr ""
|
89 |
+
#~ "Не відображати префікс в url категорії<br> за замовчуванням: /product-"
|
90 |
+
#~ "category/accessories/action-figures/ - змінено: /accessories/action-"
|
91 |
+
#~ "figures/"
|
license.txt
ADDED
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 2, June 1991
|
3 |
+
|
4 |
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
5 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6 |
+
Everyone is permitted to copy and distribute verbatim copies
|
7 |
+
of this license document, but changing it is not allowed.
|
8 |
+
|
9 |
+
Preamble
|
10 |
+
|
11 |
+
The licenses for most software are designed to take away your
|
12 |
+
freedom to share and change it. By contrast, the GNU General Public
|
13 |
+
License is intended to guarantee your freedom to share and change free
|
14 |
+
software--to make sure the software is free for all its users. This
|
15 |
+
General Public License applies to most of the Free Software
|
16 |
+
Foundation's software and to any other program whose authors commit to
|
17 |
+
using it. (Some other Free Software Foundation software is covered by
|
18 |
+
the GNU Lesser General Public License instead.) You can apply it to
|
19 |
+
your programs, too.
|
20 |
+
|
21 |
+
When we speak of free software, we are referring to freedom, not
|
22 |
+
price. Our General Public Licenses are designed to make sure that you
|
23 |
+
have the freedom to distribute copies of free software (and charge for
|
24 |
+
this service if you wish), that you receive source code or can get it
|
25 |
+
if you want it, that you can change the software or use pieces of it
|
26 |
+
in new free programs; and that you know you can do these things.
|
27 |
+
|
28 |
+
To protect your rights, we need to make restrictions that forbid
|
29 |
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30 |
+
These restrictions translate to certain responsibilities for you if you
|
31 |
+
distribute copies of the software, or if you modify it.
|
32 |
+
|
33 |
+
For example, if you distribute copies of such a program, whether
|
34 |
+
gratis or for a fee, you must give the recipients all the rights that
|
35 |
+
you have. You must make sure that they, too, receive or can get the
|
36 |
+
source code. And you must show them these terms so they know their
|
37 |
+
rights.
|
38 |
+
|
39 |
+
We protect your rights with two steps: (1) copyright the software, and
|
40 |
+
(2) offer you this license which gives you legal permission to copy,
|
41 |
+
distribute and/or modify the software.
|
42 |
+
|
43 |
+
Also, for each author's protection and ours, we want to make certain
|
44 |
+
that everyone understands that there is no warranty for this free
|
45 |
+
software. If the software is modified by someone else and passed on, we
|
46 |
+
want its recipients to know that what they have is not the original, so
|
47 |
+
that any problems introduced by others will not reflect on the original
|
48 |
+
authors' reputations.
|
49 |
+
|
50 |
+
Finally, any free program is threatened constantly by software
|
51 |
+
patents. We wish to avoid the danger that redistributors of a free
|
52 |
+
program will individually obtain patent licenses, in effect making the
|
53 |
+
program proprietary. To prevent this, we have made it clear that any
|
54 |
+
patent must be licensed for everyone's free use or not licensed at all.
|
55 |
+
|
56 |
+
The precise terms and conditions for copying, distribution and
|
57 |
+
modification follow.
|
58 |
+
|
59 |
+
GNU GENERAL PUBLIC LICENSE
|
60 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61 |
+
|
62 |
+
0. This License applies to any program or other work which contains
|
63 |
+
a notice placed by the copyright holder saying it may be distributed
|
64 |
+
under the terms of this General Public License. The "Program", below,
|
65 |
+
refers to any such program or work, and a "work based on the Program"
|
66 |
+
means either the Program or any derivative work under copyright law:
|
67 |
+
that is to say, a work containing the Program or a portion of it,
|
68 |
+
either verbatim or with modifications and/or translated into another
|
69 |
+
language. (Hereinafter, translation is included without limitation in
|
70 |
+
the term "modification".) Each licensee is addressed as "you".
|
71 |
+
|
72 |
+
Activities other than copying, distribution and modification are not
|
73 |
+
covered by this License; they are outside its scope. The act of
|
74 |
+
running the Program is not restricted, and the output from the Program
|
75 |
+
is covered only if its contents constitute a work based on the
|
76 |
+
Program (independent of having been made by running the Program).
|
77 |
+
Whether that is true depends on what the Program does.
|
78 |
+
|
79 |
+
1. You may copy and distribute verbatim copies of the Program's
|
80 |
+
source code as you receive it, in any medium, provided that you
|
81 |
+
conspicuously and appropriately publish on each copy an appropriate
|
82 |
+
copyright notice and disclaimer of warranty; keep intact all the
|
83 |
+
notices that refer to this License and to the absence of any warranty;
|
84 |
+
and give any other recipients of the Program a copy of this License
|
85 |
+
along with the Program.
|
86 |
+
|
87 |
+
You may charge a fee for the physical act of transferring a copy, and
|
88 |
+
you may at your option offer warranty protection in exchange for a fee.
|
89 |
+
|
90 |
+
2. You may modify your copy or copies of the Program or any portion
|
91 |
+
of it, thus forming a work based on the Program, and copy and
|
92 |
+
distribute such modifications or work under the terms of Section 1
|
93 |
+
above, provided that you also meet all of these conditions:
|
94 |
+
|
95 |
+
a) You must cause the modified files to carry prominent notices
|
96 |
+
stating that you changed the files and the date of any change.
|
97 |
+
|
98 |
+
b) You must cause any work that you distribute or publish, that in
|
99 |
+
whole or in part contains or is derived from the Program or any
|
100 |
+
part thereof, to be licensed as a whole at no charge to all third
|
101 |
+
parties under the terms of this License.
|
102 |
+
|
103 |
+
c) If the modified program normally reads commands interactively
|
104 |
+
when run, you must cause it, when started running for such
|
105 |
+
interactive use in the most ordinary way, to print or display an
|
106 |
+
announcement including an appropriate copyright notice and a
|
107 |
+
notice that there is no warranty (or else, saying that you provide
|
108 |
+
a warranty) and that users may redistribute the program under
|
109 |
+
these conditions, and telling the user how to view a copy of this
|
110 |
+
License. (Exception: if the Program itself is interactive but
|
111 |
+
does not normally print such an announcement, your work based on
|
112 |
+
the Program is not required to print an announcement.)
|
113 |
+
|
114 |
+
These requirements apply to the modified work as a whole. If
|
115 |
+
identifiable sections of that work are not derived from the Program,
|
116 |
+
and can be reasonably considered independent and separate works in
|
117 |
+
themselves, then this License, and its terms, do not apply to those
|
118 |
+
sections when you distribute them as separate works. But when you
|
119 |
+
distribute the same sections as part of a whole which is a work based
|
120 |
+
on the Program, the distribution of the whole must be on the terms of
|
121 |
+
this License, whose permissions for other licensees extend to the
|
122 |
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123 |
+
|
124 |
+
Thus, it is not the intent of this section to claim rights or contest
|
125 |
+
your rights to work written entirely by you; rather, the intent is to
|
126 |
+
exercise the right to control the distribution of derivative or
|
127 |
+
collective works based on the Program.
|
128 |
+
|
129 |
+
In addition, mere aggregation of another work not based on the Program
|
130 |
+
with the Program (or with a work based on the Program) on a volume of
|
131 |
+
a storage or distribution medium does not bring the other work under
|
132 |
+
the scope of this License.
|
133 |
+
|
134 |
+
3. You may copy and distribute the Program (or a work based on it,
|
135 |
+
under Section 2) in object code or executable form under the terms of
|
136 |
+
Sections 1 and 2 above provided that you also do one of the following:
|
137 |
+
|
138 |
+
a) Accompany it with the complete corresponding machine-readable
|
139 |
+
source code, which must be distributed under the terms of Sections
|
140 |
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141 |
+
|
142 |
+
b) Accompany it with a written offer, valid for at least three
|
143 |
+
years, to give any third party, for a charge no more than your
|
144 |
+
cost of physically performing source distribution, a complete
|
145 |
+
machine-readable copy of the corresponding source code, to be
|
146 |
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147 |
+
customarily used for software interchange; or,
|
148 |
+
|
149 |
+
c) Accompany it with the information you received as to the offer
|
150 |
+
to distribute corresponding source code. (This alternative is
|
151 |
+
allowed only for noncommercial distribution and only if you
|
152 |
+
received the program in object code or executable form with such
|
153 |
+
an offer, in accord with Subsection b above.)
|
154 |
+
|
155 |
+
The source code for a work means the preferred form of the work for
|
156 |
+
making modifications to it. For an executable work, complete source
|
157 |
+
code means all the source code for all modules it contains, plus any
|
158 |
+
associated interface definition files, plus the scripts used to
|
159 |
+
control compilation and installation of the executable. However, as a
|
160 |
+
special exception, the source code distributed need not include
|
161 |
+
anything that is normally distributed (in either source or binary
|
162 |
+
form) with the major components (compiler, kernel, and so on) of the
|
163 |
+
operating system on which the executable runs, unless that component
|
164 |
+
itself accompanies the executable.
|
165 |
+
|
166 |
+
If distribution of executable or object code is made by offering
|
167 |
+
access to copy from a designated place, then offering equivalent
|
168 |
+
access to copy the source code from the same place counts as
|
169 |
+
distribution of the source code, even though third parties are not
|
170 |
+
compelled to copy the source along with the object code.
|
171 |
+
|
172 |
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173 |
+
except as expressly provided under this License. Any attempt
|
174 |
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175 |
+
void, and will automatically terminate your rights under this License.
|
176 |
+
However, parties who have received copies, or rights, from you under
|
177 |
+
this License will not have their licenses terminated so long as such
|
178 |
+
parties remain in full compliance.
|
179 |
+
|
180 |
+
5. You are not required to accept this License, since you have not
|
181 |
+
signed it. However, nothing else grants you permission to modify or
|
182 |
+
distribute the Program or its derivative works. These actions are
|
183 |
+
prohibited by law if you do not accept this License. Therefore, by
|
184 |
+
modifying or distributing the Program (or any work based on the
|
185 |
+
Program), you indicate your acceptance of this License to do so, and
|
186 |
+
all its terms and conditions for copying, distributing or modifying
|
187 |
+
the Program or works based on it.
|
188 |
+
|
189 |
+
6. Each time you redistribute the Program (or any work based on the
|
190 |
+
Program), the recipient automatically receives a license from the
|
191 |
+
original licensor to copy, distribute or modify the Program subject to
|
192 |
+
these terms and conditions. You may not impose any further
|
193 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
194 |
+
You are not responsible for enforcing compliance by third parties to
|
195 |
+
this License.
|
196 |
+
|
197 |
+
7. If, as a consequence of a court judgment or allegation of patent
|
198 |
+
infringement or for any other reason (not limited to patent issues),
|
199 |
+
conditions are imposed on you (whether by court order, agreement or
|
200 |
+
otherwise) that contradict the conditions of this License, they do not
|
201 |
+
excuse you from the conditions of this License. If you cannot
|
202 |
+
distribute so as to satisfy simultaneously your obligations under this
|
203 |
+
License and any other pertinent obligations, then as a consequence you
|
204 |
+
may not distribute the Program at all. For example, if a patent
|
205 |
+
license would not permit royalty-free redistribution of the Program by
|
206 |
+
all those who receive copies directly or indirectly through you, then
|
207 |
+
the only way you could satisfy both it and this License would be to
|
208 |
+
refrain entirely from distribution of the Program.
|
209 |
+
|
210 |
+
If any portion of this section is held invalid or unenforceable under
|
211 |
+
any particular circumstance, the balance of the section is intended to
|
212 |
+
apply and the section as a whole is intended to apply in other
|
213 |
+
circumstances.
|
214 |
+
|
215 |
+
It is not the purpose of this section to induce you to infringe any
|
216 |
+
patents or other property right claims or to contest validity of any
|
217 |
+
such claims; this section has the sole purpose of protecting the
|
218 |
+
integrity of the free software distribution system, which is
|
219 |
+
implemented by public license practices. Many people have made
|
220 |
+
generous contributions to the wide range of software distributed
|
221 |
+
through that system in reliance on consistent application of that
|
222 |
+
system; it is up to the author/donor to decide if he or she is willing
|
223 |
+
to distribute software through any other system and a licensee cannot
|
224 |
+
impose that choice.
|
225 |
+
|
226 |
+
This section is intended to make thoroughly clear what is believed to
|
227 |
+
be a consequence of the rest of this License.
|
228 |
+
|
229 |
+
8. If the distribution and/or use of the Program is restricted in
|
230 |
+
certain countries either by patents or by copyrighted interfaces, the
|
231 |
+
original copyright holder who places the Program under this License
|
232 |
+
may add an explicit geographical distribution limitation excluding
|
233 |
+
those countries, so that distribution is permitted only in or among
|
234 |
+
countries not thus excluded. In such case, this License incorporates
|
235 |
+
the limitation as if written in the body of this License.
|
236 |
+
|
237 |
+
9. The Free Software Foundation may publish revised and/or new versions
|
238 |
+
of the General Public License from time to time. Such new versions will
|
239 |
+
be similar in spirit to the present version, but may differ in detail to
|
240 |
+
address new problems or concerns.
|
241 |
+
|
242 |
+
Each version is given a distinguishing version number. If the Program
|
243 |
+
specifies a version number of this License which applies to it and "any
|
244 |
+
later version", you have the option of following the terms and conditions
|
245 |
+
either of that version or of any later version published by the Free
|
246 |
+
Software Foundation. If the Program does not specify a version number of
|
247 |
+
this License, you may choose any version ever published by the Free Software
|
248 |
+
Foundation.
|
249 |
+
|
250 |
+
10. If you wish to incorporate parts of the Program into other free
|
251 |
+
programs whose distribution conditions are different, write to the author
|
252 |
+
to ask for permission. For software which is copyrighted by the Free
|
253 |
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254 |
+
make exceptions for this. Our decision will be guided by the two goals
|
255 |
+
of preserving the free status of all derivatives of our free software and
|
256 |
+
of promoting the sharing and reuse of software generally.
|
257 |
+
|
258 |
+
NO WARRANTY
|
259 |
+
|
260 |
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261 |
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262 |
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263 |
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264 |
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265 |
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266 |
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267 |
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268 |
+
REPAIR OR CORRECTION.
|
269 |
+
|
270 |
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272 |
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273 |
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274 |
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275 |
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276 |
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277 |
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278 |
+
POSSIBILITY OF SUCH DAMAGES.
|
279 |
+
|
280 |
+
END OF TERMS AND CONDITIONS
|
281 |
+
|
282 |
+
How to Apply These Terms to Your New Programs
|
283 |
+
|
284 |
+
If you develop a new program, and you want it to be of the greatest
|
285 |
+
possible use to the public, the best way to achieve this is to make it
|
286 |
+
free software which everyone can redistribute and change under these terms.
|
287 |
+
|
288 |
+
To do so, attach the following notices to the program. It is safest
|
289 |
+
to attach them to the start of each source file to most effectively
|
290 |
+
convey the exclusion of warranty; and each file should have at least
|
291 |
+
the "copyright" line and a pointer to where the full notice is found.
|
292 |
+
|
293 |
+
<one line to give the program's name and a brief idea of what it does.>
|
294 |
+
Copyright (C) <year> <name of author>
|
295 |
+
|
296 |
+
This program is free software; you can redistribute it and/or modify
|
297 |
+
it under the terms of the GNU General Public License as published by
|
298 |
+
the Free Software Foundation; either version 2 of the License, or
|
299 |
+
(at your option) any later version.
|
300 |
+
|
301 |
+
This program is distributed in the hope that it will be useful,
|
302 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304 |
+
GNU General Public License for more details.
|
305 |
+
|
306 |
+
You should have received a copy of the GNU General Public License along
|
307 |
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
308 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
309 |
+
|
310 |
+
Also add information on how to contact you by electronic and paper mail.
|
311 |
+
|
312 |
+
If the program is interactive, make it output a short notice like this
|
313 |
+
when it starts in an interactive mode:
|
314 |
+
|
315 |
+
Gnomovision version 69, Copyright (C) year name of author
|
316 |
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
317 |
+
This is free software, and you are welcome to redistribute it
|
318 |
+
under certain conditions; type `show c' for details.
|
319 |
+
|
320 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
321 |
+
parts of the General Public License. Of course, the commands you use may
|
322 |
+
be called something other than `show w' and `show c'; they could even be
|
323 |
+
mouse-clicks or menu items--whatever suits your program.
|
324 |
+
|
325 |
+
You should also get your employer (if you work as a programmer) or your
|
326 |
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
327 |
+
necessary. Here is a sample; alter the names:
|
328 |
+
|
329 |
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
330 |
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
331 |
+
|
332 |
+
<signature of Ty Coon>, 1 April 1989
|
333 |
+
Ty Coon, President of Vice
|
334 |
+
|
335 |
+
This General Public License does not permit incorporating your program into
|
336 |
+
proprietary programs. If your program is a subroutine library, you may
|
337 |
+
consider it more useful to permit linking proprietary applications with the
|
338 |
+
library. If this is what you want to do, use the GNU Lesser General
|
339 |
+
Public License instead of this License.
|
premmerce-url-manager.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
use Premmerce\UrlManager\FileManager;
|
4 |
+
use Premmerce\UrlManager\UrlManagerPlugin;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* WooCommerce Permalink Manager plugin
|
8 |
+
*
|
9 |
+
*
|
10 |
+
* @link http://premmerce.com
|
11 |
+
* @since 1.0
|
12 |
+
* @package Premmerce\UrlManager
|
13 |
+
*
|
14 |
+
* @wordpress-plugin
|
15 |
+
* Plugin Name: WooCommerce Permalink Manager
|
16 |
+
* Plugin URI: https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/
|
17 |
+
* Description: Premmerce WooCommerce Permalink Manager allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
|
18 |
+
* Version: 1.0
|
19 |
+
* Author: premmerce
|
20 |
+
* Author URI: https://premmerce.com/
|
21 |
+
* License: GPL-2.0+
|
22 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
23 |
+
* Text Domain: premmerce-url-manager
|
24 |
+
* Domain Path: /languages
|
25 |
+
*/
|
26 |
+
|
27 |
+
// If this file is called directly, abort.
|
28 |
+
if (! defined('WPINC')) {
|
29 |
+
die;
|
30 |
+
}
|
31 |
+
|
32 |
+
call_user_func(function () {
|
33 |
+
require_once plugin_dir_path(__FILE__) . 'autoload.php';
|
34 |
+
|
35 |
+
$main = new UrlManagerPlugin(new FileManager(__FILE__));
|
36 |
+
|
37 |
+
register_activation_hook(__FILE__, [ $main, 'activate' ]);
|
38 |
+
|
39 |
+
register_deactivation_hook(__FILE__, [ $main, 'deactivate' ]);
|
40 |
+
|
41 |
+
register_uninstall_hook(__FILE__, [ UrlManagerPlugin::class, 'uninstall' ]);
|
42 |
+
|
43 |
+
$main->run();
|
44 |
+
});
|
readme.txt
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.8
|
6 |
+
Stable tag: 1.0
|
7 |
+
Requires PHP: 7.0
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Premmerce WooCommerce Permalink Manager allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
This plugin allows you to configure URL generation strategy for your WooCommerce based store. This is one of the must-have plugins for online store SEO according to [WooCommerce SEO Audit](https://premmerce.com/complete-woocommerce-seo-guide-tips/)
|
16 |
+
|
17 |
+
Full documentation is available here: [WooCommerce Permalink Manager](https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/)
|
18 |
+
|
19 |
+
= Major features in “WooCommerce Permalink Manager” =
|
20 |
+
|
21 |
+
* Removing base from product category URL
|
22 |
+
* Removing hierarchical slugs from product category URL
|
23 |
+
* Removing base from product URL
|
24 |
+
* Using “Yoast SEO” permanent category url for products with multiple categories
|
25 |
+
|
26 |
+
= Compatibility with other Plugins =
|
27 |
+
|
28 |
+
* WooCommerce
|
29 |
+
* Yoast SEO
|
30 |
+
* WooCommerce Multilingual
|
31 |
+
|
32 |
+
= Installation =
|
33 |
+
|
34 |
+
1. Unzip the downloaded zip file.
|
35 |
+
1. Upload the plugin folder into the “wp-content/plugins/” directory of your WordPress site.
|
36 |
+
1. Activate “WooCommerce Permalink Manager” from Plugins page
|
37 |
+
|
38 |
+
== Frequently Asked Questions ==
|
39 |
+
|
40 |
+
= Does the plugin affect the overall response rate of an online store? =
|
41 |
+
We have tested how the plugin works with the basic WooCommerce kit and the standard storefront theme and haven’t noticed any influence on the response rate of the store.
|
42 |
+
|
43 |
+
= Does the plugin create link duplicates? Does it affect SEO? =
|
44 |
+
The plugin works perfectly with the Yoast SEO plugin installed. No link duplicates are generated. All similar URLs are automatically tagged as canonical in accordance with the search engines’ recommendations.
|
45 |
+
|
46 |
+
== Screenshots ==
|
47 |
+
|
48 |
+
1. The plugin settings
|
49 |
+
2. Category page with changed url
|
50 |
+
3. Product page with changed url
|
51 |
+
|
52 |
+
|
53 |
+
== Changelog ==
|
54 |
+
|
55 |
+
= 1.0 =
|
56 |
+
|
57 |
+
Release Date: July 24, 2017
|
58 |
+
|
59 |
+
* Initial release
|
60 |
+
|
61 |
+
== Translators ==
|
62 |
+
|
63 |
+
= Available Languages =
|
64 |
+
|
65 |
+
* English (Default)
|
66 |
+
* Russian
|
67 |
+
* Ukrainian
|
68 |
+
|
69 |
+
== Documentation ==
|
70 |
+
|
71 |
+
Full documentation is available here: [WooCommerce permalink manager](https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/)
|
src/Admin/Admin.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php namespace Premmerce\UrlManager\Admin;
|
2 |
+
|
3 |
+
use Premmerce\UrlManager\FileManager;
|
4 |
+
use Premmerce\UrlManager\UrlManagerPlugin;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Class Admin
|
8 |
+
*
|
9 |
+
* @package Premmerce\UrlManager
|
10 |
+
*/
|
11 |
+
class Admin
|
12 |
+
{
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
private $settingsPage;
|
18 |
+
/**
|
19 |
+
* @var FileManager
|
20 |
+
*/
|
21 |
+
private $fileManager;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Admin constructor.
|
25 |
+
*
|
26 |
+
* @param FileManager $fileManager
|
27 |
+
*/
|
28 |
+
public function __construct(FileManager $fileManager)
|
29 |
+
{
|
30 |
+
$this->fileManager = $fileManager;
|
31 |
+
$this->settingsPage = UrlManagerPlugin::DOMAIN . '-admin';
|
32 |
+
$this->registerActions();
|
33 |
+
}
|
34 |
+
|
35 |
+
private function registerActions()
|
36 |
+
{
|
37 |
+
$flushActions = [
|
38 |
+
'created_product_cat',
|
39 |
+
'edited_product_cat',
|
40 |
+
'delete_product_cat',
|
41 |
+
'update_option_' . UrlManagerPlugin::OPTION_URL,
|
42 |
+
];
|
43 |
+
|
44 |
+
foreach ($flushActions as $action) {
|
45 |
+
add_action($action, [ $this, 'triggerFlush' ]);
|
46 |
+
}
|
47 |
+
|
48 |
+
add_action('admin_menu', [ $this, 'addMenuPage' ]);
|
49 |
+
|
50 |
+
add_action('admin_init', [ $this, 'registerSettings' ]);
|
51 |
+
|
52 |
+
add_action('init', [ $this, 'flush' ], 999);
|
53 |
+
}
|
54 |
+
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Add submenu to premmerce menu page
|
58 |
+
*/
|
59 |
+
public function addMenuPage()
|
60 |
+
{
|
61 |
+
global $admin_page_hooks;
|
62 |
+
|
63 |
+
$premmerceMenuExists = isset($admin_page_hooks['premmerce']);
|
64 |
+
|
65 |
+
if (! $premmerceMenuExists) {
|
66 |
+
add_menu_page(
|
67 |
+
'Premmerce',
|
68 |
+
'Premmerce',
|
69 |
+
'manage_options',
|
70 |
+
'premmerce'
|
71 |
+
);
|
72 |
+
}
|
73 |
+
|
74 |
+
add_submenu_page(
|
75 |
+
'premmerce',
|
76 |
+
'Permalink Manager',
|
77 |
+
'Permalink Manager',
|
78 |
+
'manage_options',
|
79 |
+
$this->settingsPage,
|
80 |
+
[ $this, 'options' ]
|
81 |
+
);
|
82 |
+
|
83 |
+
if (! $premmerceMenuExists) {
|
84 |
+
global $submenu;
|
85 |
+
unset($submenu['premmerce'][0]);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Options page
|
92 |
+
*/
|
93 |
+
public function options()
|
94 |
+
{
|
95 |
+
$this->fileManager->includeTemplate(
|
96 |
+
'admin/options.php',
|
97 |
+
[
|
98 |
+
'options' => get_option(UrlManagerPlugin::OPTION_URL),
|
99 |
+
]
|
100 |
+
);
|
101 |
+
}
|
102 |
+
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Register settings group
|
106 |
+
*/
|
107 |
+
public function registerSettings()
|
108 |
+
{
|
109 |
+
register_setting(
|
110 |
+
UrlManagerPlugin::DOMAIN . '-group',
|
111 |
+
UrlManagerPlugin::OPTION_URL
|
112 |
+
);
|
113 |
+
}
|
114 |
+
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Set flush trigger
|
118 |
+
*/
|
119 |
+
public function triggerFlush()
|
120 |
+
{
|
121 |
+
update_option(UrlManagerPlugin::OPTION_FLUSH, true);
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Flush rewrite rules
|
126 |
+
*/
|
127 |
+
public function flush()
|
128 |
+
{
|
129 |
+
$option = UrlManagerPlugin::OPTION_FLUSH;
|
130 |
+
if (get_option($option)) {
|
131 |
+
add_action('shutdown', 'flush_rewrite_rules');
|
132 |
+
delete_option($option);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
src/FileManager.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php namespace Premmerce\UrlManager;
|
2 |
+
|
3 |
+
class FileManager
|
4 |
+
{
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @var string
|
8 |
+
*/
|
9 |
+
private $mainFile;
|
10 |
+
|
11 |
+
|
12 |
+
/**
|
13 |
+
* @var string
|
14 |
+
*/
|
15 |
+
private $pluginDirectory;
|
16 |
+
|
17 |
+
|
18 |
+
/**
|
19 |
+
* @var string
|
20 |
+
*/
|
21 |
+
private $pluginName;
|
22 |
+
|
23 |
+
|
24 |
+
/**
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
+
private $pluginUrl;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* PluginManager constructor.
|
31 |
+
*
|
32 |
+
* @param string $mainFile
|
33 |
+
*/
|
34 |
+
public function __construct($mainFile)
|
35 |
+
{
|
36 |
+
$this->mainFile = $mainFile;
|
37 |
+
$this->pluginDirectory = plugin_dir_path($this->mainFile);
|
38 |
+
$this->pluginName = basename($this->pluginDirectory);
|
39 |
+
$this->pluginUrl = plugin_dir_url($this->getMainFile());
|
40 |
+
}
|
41 |
+
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @return string
|
45 |
+
*/
|
46 |
+
public function getPluginDirectory()
|
47 |
+
{
|
48 |
+
return $this->pluginDirectory;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @return string
|
53 |
+
*/
|
54 |
+
public function getPluginName()
|
55 |
+
{
|
56 |
+
return $this->pluginName;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @return string
|
61 |
+
*/
|
62 |
+
public function getMainFile()
|
63 |
+
{
|
64 |
+
return $this->mainFile;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @param string $file
|
69 |
+
*
|
70 |
+
* @return string
|
71 |
+
*/
|
72 |
+
public function locateAsset($file)
|
73 |
+
{
|
74 |
+
return $this->pluginUrl . 'assets/' . $file;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* @param string $template
|
79 |
+
* @param array $variables
|
80 |
+
*/
|
81 |
+
public function includeTemplate($template, array $variables = [])
|
82 |
+
{
|
83 |
+
if ($templateFullPath = $this->locateTemplate($template)) {
|
84 |
+
extract($variables);
|
85 |
+
include $templateFullPath;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* @param $template
|
91 |
+
*
|
92 |
+
* @return string
|
93 |
+
*/
|
94 |
+
public function locateTemplate($template)
|
95 |
+
{
|
96 |
+
$frontendTemplate = $template;
|
97 |
+
|
98 |
+
if (strpos($template, 'frontend/') === 0) {
|
99 |
+
$frontendTemplate = str_replace('frontend/', '/', $template);
|
100 |
+
}
|
101 |
+
|
102 |
+
if ($file = locate_template($this->pluginName . '/' . $frontendTemplate)) {
|
103 |
+
return $file;
|
104 |
+
}
|
105 |
+
|
106 |
+
return $this->pluginDirectory . 'views/' . $template;
|
107 |
+
}
|
108 |
+
}
|
src/Frontend/Frontend.php
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php namespace Premmerce\UrlManager\Frontend;
|
2 |
+
|
3 |
+
use Premmerce\UrlManager\FileManager;
|
4 |
+
use Premmerce\UrlManager\UrlManagerPlugin;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Class Frontend
|
8 |
+
*
|
9 |
+
* @package Premmerce\UrlManager
|
10 |
+
*/
|
11 |
+
class Frontend
|
12 |
+
{
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Frontend constructor.
|
16 |
+
*/
|
17 |
+
public function __construct()
|
18 |
+
{
|
19 |
+
add_action('request', [ $this, 'replaceRequest' ]);
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Replace request if product found
|
25 |
+
*
|
26 |
+
*
|
27 |
+
* @param array $request
|
28 |
+
*
|
29 |
+
* @return array
|
30 |
+
*/
|
31 |
+
public function replaceRequest($request)
|
32 |
+
{
|
33 |
+
global $wp, $wpdb;
|
34 |
+
$url = $wp->request;
|
35 |
+
|
36 |
+
if (! empty($url)) {
|
37 |
+
$productRequest = [];
|
38 |
+
|
39 |
+
$url = explode('/', $url);
|
40 |
+
|
41 |
+
$slug = array_pop($url);
|
42 |
+
|
43 |
+
if ($slug === 'feed') {
|
44 |
+
$productRequest['feed'] = $slug;
|
45 |
+
$slug = array_pop($url);
|
46 |
+
}
|
47 |
+
|
48 |
+
$sql = "SELECT COUNT(ID) as count_id FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND post_status = %s";
|
49 |
+
|
50 |
+
$query = $wpdb->prepare($sql, [ $slug, UrlManagerPlugin::WOOCOMMERCE_PRODUCT, 'publish' ]);
|
51 |
+
|
52 |
+
$num = intval($wpdb->get_var($query));
|
53 |
+
|
54 |
+
if ($num > 0) {
|
55 |
+
$productRequest['post_type'] = UrlManagerPlugin::WOOCOMMERCE_PRODUCT;
|
56 |
+
|
57 |
+
$productRequest['product'] = $slug;
|
58 |
+
|
59 |
+
$productRequest['name'] = $slug;
|
60 |
+
|
61 |
+
return $productRequest;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
return $request;
|
66 |
+
}
|
67 |
+
}
|
src/PermalinkListener.php
ADDED
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php namespace Premmerce\UrlManager;
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class PermalinkListener
|
5 |
+
*
|
6 |
+
* The class is responsible for filtering of
|
7 |
+
* product and category links invoked by 'post_type_link' and 'term_link'
|
8 |
+
*
|
9 |
+
* @package Premmerce\UrlManager
|
10 |
+
*/
|
11 |
+
class PermalinkListener
|
12 |
+
{
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @var array
|
16 |
+
*/
|
17 |
+
private $categories;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Add post_type_link, term_link, rewrite_rules_array filters
|
21 |
+
*/
|
22 |
+
public function registerFilters()
|
23 |
+
{
|
24 |
+
add_filter('post_type_link', [ $this, 'replaceProductLink' ], 1, 2);
|
25 |
+
add_filter('term_link', [ $this, 'replaceCategoryLink' ], 1, 3);
|
26 |
+
add_filter('rewrite_rules_array', [ $this, 'addRewriteRules' ], 99);
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Replace category permalink according to settings
|
31 |
+
*
|
32 |
+
* @param string $link
|
33 |
+
* @param object $term
|
34 |
+
* @param string $taxonomy
|
35 |
+
*
|
36 |
+
* @return string
|
37 |
+
*/
|
38 |
+
public function replaceCategoryLink($link, $term, $taxonomy)
|
39 |
+
{
|
40 |
+
if ($taxonomy !== UrlManagerPlugin::WOOCOMMERCE_CATEGORY) {
|
41 |
+
return $link;
|
42 |
+
}
|
43 |
+
|
44 |
+
$permalinkStructure = wc_get_permalink_structure();
|
45 |
+
|
46 |
+
$category_base = trailingslashit($permalinkStructure['category_rewrite_slug']);
|
47 |
+
|
48 |
+
$urlOptions = get_option(UrlManagerPlugin::OPTION_URL);
|
49 |
+
|
50 |
+
$removeCategoryBase = isset($urlOptions['remove_category_base']);
|
51 |
+
$removeParentSlugs = isset($urlOptions['remove_category_parent_slugs']);
|
52 |
+
|
53 |
+
if ($removeCategoryBase) {
|
54 |
+
$link = str_replace($category_base, '', $link);
|
55 |
+
$category_base = '';
|
56 |
+
}
|
57 |
+
|
58 |
+
if ($removeParentSlugs) {
|
59 |
+
$link = home_url(trailingslashit($category_base . $term->slug));
|
60 |
+
}
|
61 |
+
|
62 |
+
|
63 |
+
return $link;
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Replace product permalink according to settings
|
69 |
+
*
|
70 |
+
*
|
71 |
+
* @param string $permalink
|
72 |
+
* @param object $post
|
73 |
+
*
|
74 |
+
* @return string
|
75 |
+
*/
|
76 |
+
public function replaceProductLink($permalink, $post)
|
77 |
+
{
|
78 |
+
if ($post->post_type !== UrlManagerPlugin::WOOCOMMERCE_PRODUCT) {
|
79 |
+
return $permalink;
|
80 |
+
}
|
81 |
+
|
82 |
+
$urlOptions = get_option(UrlManagerPlugin::OPTION_URL);
|
83 |
+
|
84 |
+
$permalinkStructure = wc_get_permalink_structure();
|
85 |
+
|
86 |
+
$product_base = $permalinkStructure['product_rewrite_slug'];
|
87 |
+
|
88 |
+
$removeProductBase = isset($urlOptions['remove_product_base']);
|
89 |
+
|
90 |
+
$product_base = explode('/', '/' . ltrim($product_base, '/'));
|
91 |
+
|
92 |
+
|
93 |
+
$remove = array_filter($product_base, function ($el) use ($removeProductBase) {
|
94 |
+
if ($el === '%product_cat%') {
|
95 |
+
return false;
|
96 |
+
}
|
97 |
+
if (mb_strlen($el) > 0) {
|
98 |
+
return $removeProductBase;
|
99 |
+
}
|
100 |
+
|
101 |
+
return true;
|
102 |
+
});
|
103 |
+
|
104 |
+
$remove = implode('/', $remove);
|
105 |
+
|
106 |
+
$link = str_replace($remove, '', $permalink);
|
107 |
+
|
108 |
+
$link = $this->setPrimaryCategoryLink($post, $link, $permalinkStructure);
|
109 |
+
|
110 |
+
return $link;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Replace %product_cat% variable with primary category link if seo plugin is enabled
|
115 |
+
*
|
116 |
+
* @param $post
|
117 |
+
* @param $link
|
118 |
+
* @param $permalinkStructure
|
119 |
+
*
|
120 |
+
* @return string
|
121 |
+
*/
|
122 |
+
protected function setPrimaryCategoryLink($post, $link, $permalinkStructure)
|
123 |
+
{
|
124 |
+
if ($this->checkSeoPlugin() && strpos($link, '%product_cat%') !== false) {
|
125 |
+
$category = new \WPSEO_Primary_Term(UrlManagerPlugin::WOOCOMMERCE_CATEGORY, $post->ID);
|
126 |
+
|
127 |
+
$primaryTerm = $category->get_primary_term();
|
128 |
+
|
129 |
+
$term = get_term($primaryTerm);
|
130 |
+
|
131 |
+
if ($term instanceof \WP_Error) {
|
132 |
+
return $link;
|
133 |
+
}
|
134 |
+
|
135 |
+
$termLink = get_term_link($term);
|
136 |
+
|
137 |
+
$search = [
|
138 |
+
home_url(),
|
139 |
+
trailingslashit($permalinkStructure['category_rewrite_slug']),
|
140 |
+
];
|
141 |
+
$termLink = trim(str_replace($search, '', $termLink), '/');
|
142 |
+
|
143 |
+
$link = str_replace('%product_cat%', $termLink, $link);
|
144 |
+
}
|
145 |
+
|
146 |
+
return $link;
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Check that seo plugin is enabled and available to use
|
151 |
+
*
|
152 |
+
* @return bool
|
153 |
+
*/
|
154 |
+
protected function checkSeoPlugin()
|
155 |
+
{
|
156 |
+
if (! function_exists('is_plugin_active')) {
|
157 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
158 |
+
}
|
159 |
+
|
160 |
+
$active = function_exists('is_plugin_active')
|
161 |
+
&& defined('WPSEO_BASENAME')
|
162 |
+
&& is_plugin_active(WPSEO_BASENAME)
|
163 |
+
&& class_exists(\WPSEO_Primary_Term::class);
|
164 |
+
|
165 |
+
return $active;
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Add rewrite rules for wp
|
170 |
+
*
|
171 |
+
* @param $rules
|
172 |
+
*
|
173 |
+
* @return array
|
174 |
+
*/
|
175 |
+
public function addRewriteRules($rules)
|
176 |
+
{
|
177 |
+
$premmerceOptions = get_option(UrlManagerPlugin::OPTION_URL);
|
178 |
+
|
179 |
+
if (! $premmerceOptions || get_option(UrlManagerPlugin::OPTION_DISABLED)) {
|
180 |
+
return $rules;
|
181 |
+
}
|
182 |
+
|
183 |
+
global $wp_rewrite;
|
184 |
+
|
185 |
+
wp_cache_flush();
|
186 |
+
|
187 |
+
$removeCategoryBase = isset($premmerceOptions['remove_category_base']);
|
188 |
+
$removeCategoryParentSlugs = isset($premmerceOptions['remove_category_parent_slugs']);
|
189 |
+
$removeProductBase = isset($premmerceOptions['remove_product_base']);
|
190 |
+
$permalinkStructure = wc_get_permalink_structure();
|
191 |
+
|
192 |
+
$useParentCategorySlug = strpos($permalinkStructure['product_rewrite_slug'], '%product_cat%') !== false;
|
193 |
+
|
194 |
+
$categoryBase = $removeCategoryBase ? '' : $permalinkStructure['category_rewrite_slug'];
|
195 |
+
|
196 |
+
|
197 |
+
$categoryRules = [];
|
198 |
+
$productRules = [];
|
199 |
+
|
200 |
+
$categories = $this->getCategories();
|
201 |
+
|
202 |
+
|
203 |
+
foreach ($categories as $category) {
|
204 |
+
$categorySlug = $category['slug'];
|
205 |
+
|
206 |
+
|
207 |
+
if (! $removeCategoryParentSlugs) {
|
208 |
+
$categorySlug = $this->getCategoryFullPath($category);
|
209 |
+
}
|
210 |
+
|
211 |
+
$categoryRules[ $categoryBase . $categorySlug . '/?$' ] = 'index.php?product_cat=' . $category['slug'];
|
212 |
+
$categoryRules[ $categoryBase . $categorySlug . '/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?product_cat=' . $category['slug'] . '&feed=$matches[1]';
|
213 |
+
$categoryRules[ $categoryBase . $categorySlug . '/' . $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$' ] = 'index.php?product_cat=' . $category['slug'] . '&paged=$matches[1]';
|
214 |
+
|
215 |
+
if ($removeProductBase && $useParentCategorySlug) {
|
216 |
+
$productRules[ $categorySlug . '/([^/]+)/?$' ] = 'index.php?product=$matches[1]';
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
$rules = empty($rules) ? [] : $rules;
|
221 |
+
|
222 |
+
return $categoryRules + $productRules + $rules;
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Returns categories array:
|
227 |
+
* ['category id' => ['slug' => 'category slug', 'parent' => 'parent category id']]
|
228 |
+
*
|
229 |
+
* @return array
|
230 |
+
*/
|
231 |
+
private function getCategories()
|
232 |
+
{
|
233 |
+
if (is_null($this->categories)) {
|
234 |
+
$categories = get_categories([
|
235 |
+
'taxonomy' => UrlManagerPlugin::WOOCOMMERCE_CATEGORY,
|
236 |
+
'hide_empty' => false,
|
237 |
+
]);
|
238 |
+
|
239 |
+
$slugs = [];
|
240 |
+
foreach ($categories as $category) {
|
241 |
+
$slugs[ $category->term_id ] = [
|
242 |
+
'parent' => $category->parent,
|
243 |
+
'slug' => $category->slug,
|
244 |
+
];
|
245 |
+
}
|
246 |
+
|
247 |
+
$this->categories = $slugs;
|
248 |
+
}
|
249 |
+
|
250 |
+
return $this->categories;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Recursively builds category full path
|
255 |
+
*
|
256 |
+
* @param $category
|
257 |
+
*
|
258 |
+
* @return string
|
259 |
+
*/
|
260 |
+
public function getCategoryFullPath($category)
|
261 |
+
{
|
262 |
+
$categories = $this->getCategories();
|
263 |
+
|
264 |
+
$parent = $category['parent'];
|
265 |
+
|
266 |
+
if ($parent > 0 && array_key_exists($parent, $categories)) {
|
267 |
+
return $this->getCategoryFullPath($categories[ $parent ]) . '/' . $category['slug'];
|
268 |
+
}
|
269 |
+
|
270 |
+
return $category['slug'];
|
271 |
+
}
|
272 |
+
}
|
src/UrlManagerPlugin.php
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php namespace Premmerce\UrlManager;
|
2 |
+
|
3 |
+
use Premmerce\UrlManager\Admin\Admin;
|
4 |
+
use Premmerce\UrlManager\Frontend\Frontend;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Class UrlManagerPlugin
|
8 |
+
*
|
9 |
+
* @package Premmerce\UrlManager
|
10 |
+
*/
|
11 |
+
class UrlManagerPlugin
|
12 |
+
{
|
13 |
+
const WOOCOMMERCE_PRODUCT = 'product';
|
14 |
+
|
15 |
+
const WOOCOMMERCE_CATEGORY = 'product_cat';
|
16 |
+
|
17 |
+
const DOMAIN = 'premmerce-url-manager';
|
18 |
+
|
19 |
+
const OPTION_URL = 'premmerce_url_manager_options';
|
20 |
+
|
21 |
+
const OPTION_DISABLED = 'premmerce_url_manager_disabled';
|
22 |
+
|
23 |
+
const OPTION_FLUSH = 'premmerce_url_manager_flush_rules';
|
24 |
+
|
25 |
+
/**
|
26 |
+
* @var FileManager
|
27 |
+
*/
|
28 |
+
private $fileManager;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* PluginManager constructor.
|
32 |
+
*
|
33 |
+
* @param FileManager $fileManager
|
34 |
+
*/
|
35 |
+
public function __construct(FileManager $fileManager)
|
36 |
+
{
|
37 |
+
$this->fileManager = $fileManager;
|
38 |
+
|
39 |
+
add_action('init', [ $this, 'loadTextDomain' ]);
|
40 |
+
|
41 |
+
add_action('admin_init', [ $this, 'checkForWooCommerce' ]);
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Run plugin part
|
46 |
+
*/
|
47 |
+
public function run()
|
48 |
+
{
|
49 |
+
if (is_admin()) {
|
50 |
+
new Admin($this->fileManager);
|
51 |
+
} else {
|
52 |
+
new Frontend();
|
53 |
+
}
|
54 |
+
( new PermalinkListener() )->registerFilters();
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Fired when the plugin is activated
|
59 |
+
*/
|
60 |
+
public function activate()
|
61 |
+
{
|
62 |
+
if (! $this->checkForWooCommerce()) {
|
63 |
+
$this->loadTextDomain();
|
64 |
+
$error_message = sprintf(
|
65 |
+
__('This plugin requires %s plugin to be active!', self::DOMAIN),
|
66 |
+
'<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>'
|
67 |
+
);
|
68 |
+
die($error_message);
|
69 |
+
};
|
70 |
+
|
71 |
+
delete_option(self::OPTION_DISABLED);
|
72 |
+
flush_rewrite_rules();
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Fired when the plugin is deactivated
|
77 |
+
*/
|
78 |
+
public function deactivate()
|
79 |
+
{
|
80 |
+
update_option(self::OPTION_DISABLED, true);
|
81 |
+
flush_rewrite_rules();
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Fired during plugin uninstall
|
86 |
+
*/
|
87 |
+
public static function uninstall()
|
88 |
+
{
|
89 |
+
delete_option(self::OPTION_URL);
|
90 |
+
delete_option(self::OPTION_FLUSH);
|
91 |
+
delete_option(self::OPTION_DISABLED);
|
92 |
+
flush_rewrite_rules();
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Load plugin translations
|
97 |
+
*/
|
98 |
+
public function loadTextDomain()
|
99 |
+
{
|
100 |
+
$name = $this->fileManager->getPluginName();
|
101 |
+
load_plugin_textdomain($name, false, $name . '/languages/');
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Check if WooCommerce is active and deactivate plugin
|
106 |
+
*/
|
107 |
+
public function checkForWooCommerce()
|
108 |
+
{
|
109 |
+
$wooCommerceActive = is_plugin_active('woocommerce/woocommerce.php');
|
110 |
+
if (! $wooCommerceActive) {
|
111 |
+
deactivate_plugins($this->fileManager->getMainFile());
|
112 |
+
}
|
113 |
+
|
114 |
+
return $wooCommerceActive;
|
115 |
+
}
|
116 |
+
}
|
views/admin/options.php
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php use Premmerce\UrlManager\UrlManagerPlugin;
|
2 |
+
|
3 |
+
?>
|
4 |
+
<div class="wrap">
|
5 |
+
<h1>WooCommerce Permalink Manager</h1>
|
6 |
+
<form method="post" action="options.php">
|
7 |
+
<?php settings_fields('premmerce-url-manager-group'); ?>
|
8 |
+
<table class="form-table">
|
9 |
+
<tbody>
|
10 |
+
<tr>
|
11 |
+
<th><?php _e('Category', UrlManagerPlugin::DOMAIN) ?></th>
|
12 |
+
<?php $checked = isset($options['remove_category_base']) ? 'checked' : '' ?>
|
13 |
+
<td>
|
14 |
+
<fieldset>
|
15 |
+
|
16 |
+
<label for="">
|
17 |
+
|
18 |
+
<input type="checkbox"
|
19 |
+
name="<?php echo UrlManagerPlugin::OPTION_URL ?>[remove_category_base]" <?php echo $checked ?>>
|
20 |
+
<?php _e('Remove base', UrlManagerPlugin::DOMAIN) ?>
|
21 |
+
</label>
|
22 |
+
<p class="description">
|
23 |
+
<?php _e('Remove prefix from category URL<br> default: /product-category/accessories/action-figures/ - changed: /accessories/action-figures/', UrlManagerPlugin::DOMAIN) ?>
|
24 |
+
</p>
|
25 |
+
<br>
|
26 |
+
<label for="">
|
27 |
+
<?php $checked = isset($options['remove_category_parent_slugs']) ? 'checked' : '' ?>
|
28 |
+
<input type="checkbox"
|
29 |
+
name="<?php echo UrlManagerPlugin::OPTION_URL ?>[remove_category_parent_slugs]" <?php echo $checked ?>>
|
30 |
+
<?php _e('Remove parent slugs', UrlManagerPlugin::DOMAIN); ?>
|
31 |
+
</label>
|
32 |
+
<p class="description">
|
33 |
+
<?php _e('Remove parent slugs from category URL<br> default: /product-category/accessories/action-figures/ - changed: /product-category/action-figures/', UrlManagerPlugin::DOMAIN) ?>
|
34 |
+
</p>
|
35 |
+
</fieldset>
|
36 |
+
</td>
|
37 |
+
</tr>
|
38 |
+
<tr>
|
39 |
+
<th>
|
40 |
+
<?php _e('Product', UrlManagerPlugin::DOMAIN) ?>
|
41 |
+
</th>
|
42 |
+
<td>
|
43 |
+
<fieldset>
|
44 |
+
<label for="">
|
45 |
+
<?php $checked = isset($options['remove_product_base']) ? 'checked' : '' ?>
|
46 |
+
<input type="checkbox"
|
47 |
+
name="premmerce_url_manager_options[remove_product_base]" <?php echo $checked ?>>
|
48 |
+
<?php _e('Remove base', UrlManagerPlugin::DOMAIN) ?>
|
49 |
+
</label>
|
50 |
+
<p class="description">
|
51 |
+
<?php _e('Remove prefix from product URL<br> default: /shop/accessories/action-figures/acme/ - changed: /accessories/action-figures/acme/', UrlManagerPlugin::DOMAIN) ?>
|
52 |
+
</p>
|
53 |
+
</fieldset>
|
54 |
+
</td>
|
55 |
+
</tr>
|
56 |
+
</tbody>
|
57 |
+
</table>
|
58 |
+
<?php submit_button(); ?>
|
59 |
+
</form>
|
60 |
+
</div>
|