Premmerce Permalink Manager for WooCommerce - Version 2.3.6

Version Description

(4th July 2022) =

  • Fix: Redirected URL now keeps the query strings from the original URL
  • Fix: Child category URLs now redirecting correctly after altering the category setting
  • Fix: Breadcrumbs URL now using the home URL instead of site URL
Download this release

Release Info

Developer premmerce
Plugin Icon 128x128 Premmerce Permalink Manager for WooCommerce
Version 2.3.6
Comparing to
See all releases

Code changes from version 2.3.5 to 2.3.6

premmerce-url-manager.php CHANGED
@@ -11,7 +11,7 @@ use Premmerce\UrlManager\UrlManagerPlugin;
11
  * Plugin Name: Premmerce Permalink Manager for WooCommerce
12
  * Plugin URI: https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/
13
  * Description: Premmerce Permalink Manager for WooCommerce allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
14
- * Version: 2.3.5
15
  *
16
  * Author: premmerce
17
  * Author URI: https://premmerce.com/
@@ -20,9 +20,9 @@ use Premmerce\UrlManager\UrlManagerPlugin;
20
  * Text Domain: premmerce-url-manager
21
  * Domain Path: /languages
22
  *
23
- * Tested up to: 5.9.1
24
  * WC requires at least: 3.6.0
25
- * WC tested up to: 6.2.1
26
  */
27
 
28
  // If this file is called directly, abort.
11
  * Plugin Name: Premmerce Permalink Manager for WooCommerce
12
  * Plugin URI: https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/
13
  * Description: Premmerce Permalink Manager for WooCommerce allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
14
+ * Version: 2.3.6
15
  *
16
  * Author: premmerce
17
  * Author URI: https://premmerce.com/
20
  * Text Domain: premmerce-url-manager
21
  * Domain Path: /languages
22
  *
23
+ * Tested up to: 6.0
24
  * WC requires at least: 3.6.0
25
+ * WC tested up to: 6.5.1
26
  */
27
 
28
  // If this file is called directly, abort.
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
 
2
  === Premmerce Permalink Manager for WooCommerce ===
3
 
4
- Contributors: premmerce
5
  Tags: woocommerce url, remove product, remove product_category, woocommerce permalink, woocommerce, woocommerce seo
6
  Requires at least: 4.8
7
  Tested up to: 6.0
8
- Stable tag: 2.3.5
9
  Requires PHP: 5.6
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -85,6 +85,12 @@ You can also install this plugin manually:
85
 
86
 
87
 
 
 
 
 
 
 
88
  = 2.3.5 =
89
 
90
  Release Date: Mar 3, 2022
1
 
2
  === Premmerce Permalink Manager for WooCommerce ===
3
 
4
+ Contributors: premmerce, freemius
5
  Tags: woocommerce url, remove product, remove product_category, woocommerce permalink, woocommerce, woocommerce seo
6
  Requires at least: 4.8
7
  Tested up to: 6.0
8
+ Stable tag: 2.3.6
9
  Requires PHP: 5.6
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
85
 
86
 
87
 
88
+ = 2.3.6 (4th July 2022) =
89
+
90
+ * Fix: Redirected URL now keeps the query strings from the original URL
91
+ * Fix: Child category URLs now redirecting correctly after altering the category setting
92
+ * Fix: Breadcrumbs URL now using the home URL instead of site URL
93
+
94
  = 2.3.5 =
95
 
96
  Release Date: Mar 3, 2022
src/Addons/AddonInterface.php CHANGED
@@ -1,14 +1,14 @@
1
  <?php namespace Premmerce\UrlManager\Addons;
2
 
3
- interface AddonInterface {
 
 
 
 
 
4
 
5
- /**
6
- * Check if addon is active
7
- */
8
- public function isActive();
9
-
10
- /**
11
- * Innit addon
12
- */
13
- public function init();
14
  }
1
  <?php namespace Premmerce\UrlManager\Addons;
2
 
3
+ interface AddonInterface
4
+ {
5
+ /**
6
+ * Check if addon is active
7
+ */
8
+ public function isActive();
9
 
10
+ /**
11
+ * Innit addon
12
+ */
13
+ public function init();
 
 
 
 
 
14
  }
src/Addons/AddonManager.php CHANGED
@@ -1,28 +1,30 @@
1
  <?php namespace Premmerce\UrlManager\Addons;
2
 
3
- class AddonManager {
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- /**
6
- * Get Addons
7
- *
8
- * @return string[]
9
- */
10
- public function getAddons() {
11
- return [
12
- BreadcrumbsAddon::class,
13
- YoastBreadcrumbsAddon::class
14
- ];
15
- }
16
-
17
- /**
18
- * Init Addons
19
- */
20
- public function initAddons() {
21
- foreach ( $this->getAddons() as $addon ) {
22
- $addon = new $addon();
23
- if ( $addon->isActive() ) {
24
- $addon->init();
25
- }
26
- }
27
- }
28
  }
1
  <?php namespace Premmerce\UrlManager\Addons;
2
 
3
+ class AddonManager
4
+ {
5
+ /**
6
+ * Get Addons
7
+ *
8
+ * @return string[]
9
+ */
10
+ public function getAddons()
11
+ {
12
+ return array(
13
+ BreadcrumbsAddon::class,
14
+ YoastBreadcrumbsAddon::class
15
+ );
16
+ }
17
 
18
+ /**
19
+ * Init Addons
20
+ */
21
+ public function initAddons()
22
+ {
23
+ foreach ($this->getAddons() as $addon) {
24
+ $addon = new $addon();
25
+ if ($addon->isActive()) {
26
+ $addon->init();
27
+ }
28
+ }
29
+ }
 
 
 
 
 
 
 
 
 
 
 
30
  }
src/Addons/BreadcrumbsAddon.php CHANGED
@@ -2,156 +2,159 @@
2
 
3
  use Premmerce\UrlManager\Admin\Settings;
4
 
5
- class BreadcrumbsAddon implements AddonInterface {
6
-
7
-
8
- /**
9
- * Breadcrumbs
10
- *
11
- * @var array
12
- */
13
- protected $breadcrumbs = [];
14
-
15
- /**
16
- * Options
17
- *
18
- * @var array
19
- */
20
- protected $options = [];
21
-
22
- /**
23
- * Constructor
24
- */
25
- public function __construct() {
26
- $options = get_option( Settings::OPTIONS );
27
- $this->options = $options;
28
- }
29
-
30
- /**
31
- * Is active
32
- *
33
- * @return boolean
34
- */
35
- public function isActive() {
36
- include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
37
- if ( ! empty( $this->options['breadcrumbs'] ) && is_plugin_active( 'woocommerce/woocommerce.php') ) {
38
- return true;
39
- }
40
-
41
- return false;
42
- }
43
-
44
- /**
45
- * Init reformat breadcrumbs
46
- */
47
- public function init() {
48
- add_filter( 'woocommerce_get_breadcrumb', [ $this, 'createBreadcrumbs' ], 999 );
49
- }
50
-
51
- /**
52
- * Init reformat breadcrumbs
53
- *
54
- * @param array $crumbs
55
- *
56
- * @return array|void
57
- */
58
- public function createBreadcrumbs( $crumbs ) {
59
- if ( ! is_product() && ! is_product_category() ) {
60
- return $crumbs;
61
- }
62
-
63
- $this->addCrumb( apply_filters( 'premmerce_permalink_home_breadcrumb_default', __( 'Home', 'premmerce-url-manager' ) ), get_site_url() );
64
-
65
- if ( empty( $this->options['br_remove_shop'] ) ) {
66
- $this->addCrumb( apply_filters( 'premmerce_permalink_shop_breadcrumb_default', __( 'Shop', 'premmerce-url-manager' ) ), get_permalink( wc_get_page_id( 'shop' ) ) );
67
- }
68
-
69
-
70
- if ( is_product() ) {
71
- if ( ! empty( $this->options['product'] ) ) {
72
- global $post;
73
-
74
- $terms = wc_get_product_terms(
75
- $post->ID,
76
- 'product_cat',
77
- array(
78
- 'orderby' => 'parent',
79
- 'order' => 'DESC',
80
- )
81
- );
82
-
83
- if ( $terms ) {
84
- $mainTerm = $terms[0];
85
- if ( 'category_slug' === $this->options['product'] ) {
86
- $this->addCrumb( $mainTerm->name, get_term_link( $mainTerm ) );
87
- } elseif ( 'hierarchical' === $this->options['product'] ) {
88
- $this->addCrumbAncestors( $mainTerm->term_id, 'product_cat' );
89
- $this->addCrumb( $mainTerm->name, get_term_link( $mainTerm ) );
90
- }
91
- }
92
-
93
- $this->addCrumb( get_the_title( $post ), get_permalink( $post ) );
94
- }
95
-
96
- } elseif ( is_product_category() ) {
97
-
98
- if ( ! empty( $this->options['category'] ) ) {
99
-
100
- $currentTerm = $GLOBALS['wp_query']->get_queried_object();
101
-
102
- if ( 'hierarchical' === $this->options['category'] ) {
103
- $this->addCrumbAncestors( $currentTerm->term_id, 'product_cat' );
104
- }
105
-
106
- $this->addCrumb( $currentTerm->name, get_term_link( $currentTerm, 'product_cat' ) );
107
- }
108
- }
109
-
110
- if ( ! empty( $this->breadcrumbs ) ) {
111
- return $this->getBreadcrumbs();
112
- }
113
-
114
- return $crumbs;
115
- }
116
-
117
- /**
118
- * Get breadcrumbs
119
- *
120
- * @return array
121
- */
122
- protected function getBreadcrumbs() {
123
- return $this->breadcrumbs;
124
- }
125
-
126
- /**
127
- * Add crumbs for a term
128
- *
129
- * @param int $termId Term ID
130
- * @param string $taxonomy Taxonomy
131
- */
132
- protected function addCrumbAncestors( $termId, $taxonomy ) {
133
- $ancestors = get_ancestors( $termId, $taxonomy );
134
- $ancestors = array_reverse( $ancestors );
135
-
136
- foreach ( $ancestors as $ancestor ) {
137
- $ancestor = get_term( $ancestor, $taxonomy );
138
-
139
- if ( ! is_wp_error( $ancestor ) && $ancestor ) {
140
- $this->addCrumb( $ancestor->name, get_term_link( $ancestor ) );
141
- }
142
- }
143
- }
144
-
145
- /**
146
- * Add a crumb
147
- *
148
- * @param string $name Name
149
- * @param string $link Link
150
- */
151
- protected function addCrumb( $name, $link = '' ) {
152
- $this->breadcrumbs[] = array(
153
- wp_strip_all_tags( $name ),
154
- $link,
155
- );
156
- }
 
 
 
157
  }
2
 
3
  use Premmerce\UrlManager\Admin\Settings;
4
 
5
+ class BreadcrumbsAddon implements AddonInterface
6
+ {
7
+ /**
8
+ * Breadcrumbs
9
+ *
10
+ * @var array
11
+ */
12
+ protected $breadcrumbs = array();
13
+
14
+ /**
15
+ * Options
16
+ *
17
+ * @var array
18
+ */
19
+ protected $options = array();
20
+
21
+ /**
22
+ * Constructor
23
+ */
24
+ public function __construct()
25
+ {
26
+ $options = get_option(Settings::OPTIONS);
27
+ $this->options = $options;
28
+ }
29
+
30
+ /**
31
+ * Is active
32
+ *
33
+ * @return boolean
34
+ */
35
+ public function isActive()
36
+ {
37
+ include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
38
+ if (! empty($this->options['breadcrumbs']) && is_plugin_active('woocommerce/woocommerce.php')) {
39
+ return true;
40
+ }
41
+
42
+ return false;
43
+ }
44
+
45
+ /**
46
+ * Init reformat breadcrumbs
47
+ */
48
+ public function init()
49
+ {
50
+ add_filter('woocommerce_get_breadcrumb', array( $this, 'createBreadcrumbs' ), 999);
51
+ }
52
+
53
+ /**
54
+ * Init reformat breadcrumbs
55
+ *
56
+ * @param array $crumbs
57
+ *
58
+ * @return array|void
59
+ */
60
+ public function createBreadcrumbs($crumbs)
61
+ {
62
+ if (! is_product() && ! is_product_category()) {
63
+ return $crumbs;
64
+ }
65
+
66
+ $this->addCrumb(apply_filters('premmerce_permalink_home_breadcrumb_default', __('Home', 'premmerce-url-manager')), get_home_url());
67
+
68
+ if (empty($this->options['br_remove_shop'])) {
69
+ $this->addCrumb(apply_filters('premmerce_permalink_shop_breadcrumb_default', __('Shop', 'premmerce-url-manager')), get_permalink(wc_get_page_id('shop')));
70
+ }
71
+
72
+
73
+ if (is_product()) {
74
+ if (! empty($this->options['product'])) {
75
+ global $post;
76
+
77
+ $terms = wc_get_product_terms(
78
+ $post->ID,
79
+ 'product_cat',
80
+ array(
81
+ 'orderby' => 'parent',
82
+ 'order' => 'DESC',
83
+ )
84
+ );
85
+
86
+ if ($terms) {
87
+ $mainTerm = $terms[0];
88
+ if ('category_slug' === $this->options['product']) {
89
+ $this->addCrumb($mainTerm->name, get_term_link($mainTerm));
90
+ } elseif ('hierarchical' === $this->options['product']) {
91
+ $this->addCrumbAncestors($mainTerm->term_id, 'product_cat');
92
+ $this->addCrumb($mainTerm->name, get_term_link($mainTerm));
93
+ }
94
+ }
95
+
96
+ $this->addCrumb(get_the_title($post), get_permalink($post));
97
+ }
98
+ } elseif (is_product_category()) {
99
+ if (! empty($this->options['category'])) {
100
+ $currentTerm = $GLOBALS['wp_query']->get_queried_object();
101
+
102
+ if ('hierarchical' === $this->options['category']) {
103
+ $this->addCrumbAncestors($currentTerm->term_id, 'product_cat');
104
+ }
105
+
106
+ $this->addCrumb($currentTerm->name, get_term_link($currentTerm, 'product_cat'));
107
+ }
108
+ }
109
+
110
+ if (! empty($this->breadcrumbs)) {
111
+ return $this->getBreadcrumbs();
112
+ }
113
+
114
+ return $crumbs;
115
+ }
116
+
117
+ /**
118
+ * Get breadcrumbs
119
+ *
120
+ * @return array
121
+ */
122
+ protected function getBreadcrumbs()
123
+ {
124
+ return $this->breadcrumbs;
125
+ }
126
+
127
+ /**
128
+ * Add crumbs for a term
129
+ *
130
+ * @param int $termId Term ID
131
+ * @param string $taxonomy Taxonomy
132
+ */
133
+ protected function addCrumbAncestors($termId, $taxonomy)
134
+ {
135
+ $ancestors = get_ancestors($termId, $taxonomy);
136
+ $ancestors = array_reverse($ancestors);
137
+
138
+ foreach ($ancestors as $ancestor) {
139
+ $ancestor = get_term($ancestor, $taxonomy);
140
+
141
+ if (! is_wp_error($ancestor) && $ancestor) {
142
+ $this->addCrumb($ancestor->name, get_term_link($ancestor));
143
+ }
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Add a crumb
149
+ *
150
+ * @param string $name Name
151
+ * @param string $link Link
152
+ */
153
+ protected function addCrumb($name, $link = '')
154
+ {
155
+ $this->breadcrumbs[] = array(
156
+ wp_strip_all_tags($name),
157
+ $link,
158
+ );
159
+ }
160
  }
src/Addons/YoastBreadcrumbsAddon.php CHANGED
@@ -1,46 +1,50 @@
1
  <?php namespace Premmerce\UrlManager\Addons;
2
 
3
- class YoastBreadcrumbsAddon extends BreadcrumbsAddon {
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- /**
6
- * Is active
7
- *
8
- * @return boolean
9
- */
10
- public function isActive() {
11
- include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
12
- if ( ! empty( $this->options['breadcrumbs'] ) && is_plugin_active( 'wordpress-seo/wp-seo.php' ) ) {
13
- return true;
14
- }
15
 
16
- return false;
17
- }
 
 
 
 
 
18
 
19
- /**
20
- * Init reformat breadcrumbs
21
- */
22
- public function init() {
23
- add_filter( 'wpseo_breadcrumb_links', [ $this, 'createBreadcrumbs' ], 999 );
24
- }
 
 
 
25
 
26
- /**
27
- * Get breadcrumbs
28
- *
29
- * @return array
30
- */
31
- public function getBreadcrumbs() {
32
- return array_map( [ $this, 'reformatBreadcrumbs' ], $this->breadcrumbs );
33
- }
34
-
35
- /**
36
- * Reformat breadcrumbs
37
- *
38
- * @return array
39
- */
40
- protected function reformatBreadcrumbs( $arr ) {
41
- return [
42
- 'text' => $arr[0],
43
- 'url' => $arr[1],
44
- ];
45
- }
46
  }
1
  <?php namespace Premmerce\UrlManager\Addons;
2
 
3
+ class YoastBreadcrumbsAddon extends BreadcrumbsAddon
4
+ {
5
+ /**
6
+ * Is active
7
+ *
8
+ * @return boolean
9
+ */
10
+ public function isActive()
11
+ {
12
+ include_once ABSPATH . 'wp-admin/includes/plugin.php' ;
13
+ if (! empty($this->options['breadcrumbs']) && is_plugin_active('wordpress-seo/wp-seo.php')) {
14
+ return true;
15
+ }
16
 
17
+ return false;
18
+ }
 
 
 
 
 
 
 
 
19
 
20
+ /**
21
+ * Init reformat breadcrumbs
22
+ */
23
+ public function init()
24
+ {
25
+ add_filter('wpseo_breadcrumb_links', array( $this, 'createBreadcrumbs' ), 999);
26
+ }
27
 
28
+ /**
29
+ * Get breadcrumbs
30
+ *
31
+ * @return array
32
+ */
33
+ public function getBreadcrumbs()
34
+ {
35
+ return array_map(array( $this, 'reformatBreadcrumbs' ), $this->breadcrumbs);
36
+ }
37
 
38
+ /**
39
+ * Reformat breadcrumbs
40
+ *
41
+ * @return array
42
+ */
43
+ protected function reformatBreadcrumbs($arr)
44
+ {
45
+ return array(
46
+ 'text' => $arr[0],
47
+ 'url' => $arr[1],
48
+ );
49
+ }
 
 
 
 
 
 
 
 
50
  }
src/Admin/Admin.php CHANGED
@@ -1,356 +1,366 @@
1
  <?php namespace Premmerce\UrlManager\Admin;
2
 
3
- use Premmerce\UrlManager\Admin\Settings;
4
  use Premmerce\UrlManager\UrlManagerPlugin;
5
- use Premmerce\UrlManager\Admin\AffiliateTab;
6
  use Premmerce\SDK\V2\FileManager\FileManager;
7
- use Premmerce\UrlManager\Admin\BundleAndSave;
8
- use Premmerce\UrlManager\Admin\FieldsTypes\InputOptionTypeRadio;
9
- use Premmerce\UrlManager\Admin\FieldsTypes\InputOptionTypeCheckbox;
10
- use Premmerce\UrlManager\Admin\FieldsTypes\InputOptionTypeUrlSuffix;
11
 
12
  /**
13
  * Class Admin
14
  *
15
  * @package Premmerce\UrlManager
16
  */
17
- class Admin {
18
-
19
-
20
- /**
21
- * Settings Page
22
- *
23
- * @var string
24
- */
25
- private $settingsPage;
26
-
27
- /**
28
- * Settings Array
29
- *
30
- * @var arrat
31
- */
32
- private $settingsArray;
33
-
34
- /**
35
- * All Settings Field Names
36
- *
37
- * @var array
38
- */
39
- private $allFieldsName;
40
-
41
- /**
42
- * Settings Page
43
- *
44
- * @var string
45
- */
46
- private $parrentPageSlug;
47
-
48
- /**
49
- * FileManager
50
- *
51
- * @var FileManager
52
- */
53
- private $fileManager;
54
-
55
- /**
56
- * Settings
57
- *
58
- * @var Settings
59
- */
60
- private $settings;
61
-
62
- /**
63
- * Bundles and Save
64
- *
65
- * @var bundlesAndSave
66
- */
67
- private $bundlesAndSave;
68
-
69
- /**
70
- * Affiliate Tab
71
- *
72
- * @var affiliateTab
73
- */
74
- private $affiliate;
75
-
76
- const META_IGNORE_BANNER = 'premmerce_url_manager_ignore_banner';
77
-
78
- const WOO_TAB_NAME = 'woo_tab_premmerce_permalink';
79
-
80
- /**
81
- * Admin constructor.
82
- *
83
- * @param FileManager $fileManager
84
- */
85
- public function __construct( FileManager $fileManager) {
86
- $this->fileManager = $fileManager;
87
- $this->settings = new Settings($fileManager);
88
- $this->settingsPage = UrlManagerPlugin::DOMAIN . '-admin';
89
-
90
- $this->parrentPageSlug = 'premmerce';
91
- $this->bundlesAndSave = new BundleAndSave($fileManager);
92
- $this->affiliate = new AffiliateTab($fileManager);
93
- $this->registerActions();
94
- }
95
-
96
-
97
-
98
- private function registerActions() {
99
- $flushActions = [
100
- 'created_product_cat',
101
- 'edited_product_cat',
102
- 'delete_product_cat',
103
-
104
- 'created_product_tag',
105
- 'edited_product_tag',
106
- 'delete_product_tag',
107
-
108
- 'update_option_' . Settings::OPTIONS,
109
- ];
110
-
111
- foreach ($flushActions as $action) {
112
- add_action($action, [$this, 'triggerFlush']);
113
- }
114
-
115
- add_action('shutdown', [$this, 'flush']);
116
-
117
- add_action('admin_init', [$this->settings, 'register']);
118
-
119
- add_action('admin_enqueue_scripts', [$this, 'enqueueScripts']);
120
-
121
-
122
-
123
- add_action('admin_menu', [$this, 'addMenuPage'], 80);
124
- add_action('admin_menu', [$this, 'addFullPack'], 100);
125
- add_action('admin_notices', array($this, 'renderAdminBanner'));
126
- add_action('wp_ajax_premmerce_url_manager_ignore_banner', array($this, 'ignoreAdminBanner'));
127
- add_filter( 'plugin_action_links_' . plugin_basename( $this->fileManager->getMainFile() ), [$this, 'settingPageLink'], 10, 4 );
128
- add_filter('admin_footer_text', [$this, 'removeFooterAdmin']);
129
- }
130
-
131
- /**
132
- * Setting Page Link
133
- *
134
- * @param mixed $actions
135
- * @return void
136
- */
137
- public function settingPageLink( $actions) {
138
- $actions[] = '<a href="' . $this->getSettingLink() . '">' . __( 'Settings', 'premmerce-url-manager' ) . '</a>';
139
-
140
- return $actions;
141
- }
142
-
143
- /**
144
- * Get url to settings page
145
- *
146
- * @return string
147
- */
148
- public function getSettingLink() {
149
-
150
- $param = ['page' => 'premmerce-url-manager-admin' ];
151
- return esc_url( add_query_arg($param, get_admin_url() . 'admin.php' ) );
152
- }
153
-
154
- /**
155
- * Show Banner
156
- */
157
- public function renderAdminBanner() {
158
- if ($this->isBannerActive()) {
159
- $this->fileManager->includeTemplate('admin/banner.php', ['fm' => $this->fileManager]);
160
- }
161
- }
162
-
163
- /**
164
- * Hide Banner
165
- */
166
- public function ignoreAdminBanner() {
167
-
168
- $user = wp_get_current_user();
169
- $user_id = $user->ID;
170
-
171
- add_user_meta($user_id, self::META_IGNORE_BANNER, true, true);
172
-
173
- die;
174
- }
175
-
176
-
177
-
178
- /**
179
- * Add submenu to premmerce menu page
180
- */
181
- public function addMenuPage() {
182
- global $admin_page_hooks;
183
-
184
-
185
- $premmerceMenuExists = isset($admin_page_hooks['premmerce']);
186
-
187
- if ( ! $premmerceMenuExists) {
188
- $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>';
189
- $svg = 'data:image/svg+xml;base64,' . base64_encode($svg);
190
- add_menu_page(
191
- 'Premmerce',
192
- 'Premmerce',
193
- 'manage_options',
194
- 'premmerce',
195
- '',
196
- $svg
197
- );
198
- }
199
-
200
-
201
- add_submenu_page(
202
- $this->parrentPageSlug,
203
- __('Permalink Manager', 'premmerce-url-manager'),
204
- __('Permalink Manager', 'premmerce-url-manager'),
205
- 'manage_options',
206
- $this->settingsPage,
207
- [$this, 'options'],
208
- 10
209
- );
210
-
211
- if ( ! $premmerceMenuExists) {
212
- global $submenu;
213
- unset($submenu['premmerce'][0]);
214
- }
215
- }
216
-
217
- public function addFullPack() {
218
- if ( ! function_exists('get_plugins')) {
219
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
220
- }
221
-
222
- $plugins = get_plugins();
223
-
224
- $premmerceInstalled = array_key_exists('premmerce-premium/premmerce.php', $plugins)
225
- || array_key_exists('premmerce/premmerce.php', $plugins);
226
-
227
- if ( ! $premmerceInstalled) {
228
- add_submenu_page(
229
- 'premmerce',
230
- __('Get premmerce full pack', 'premmerce-url-manager'),
231
- __('Get premmerce full pack', 'premmerce-url-manager'),
232
- 'manage_options',
233
- admin_url('plugin-install.php?tab=plugin-information&plugin=premmerce')
234
- );
235
- }
236
- }
237
-
238
- /**
239
- * Options page
240
- */
241
- public function options() {
242
- $this->triggerFlush();
243
-
244
- $current = isset($_GET['tab']) ? wc_clean(wp_unslash($_GET['tab'])) : 'settings';
245
-
246
- $tabs['settings'] = __('Settings', 'premmerce-url-manager');
247
- $tabs['bundle_and_save'] = __('Bundle and Save', 'premmerce-url-manager');
248
- $tabs['affiliate'] = __('Affiliate', 'premmerce-url-manager');
249
-
250
- if (function_exists('premmerce_wpm_fs')) {
251
- if (premmerce_wpm_fs()->is_registered()) {
252
- $tabs['account'] = __('Account', 'premmerce-url-manager');
253
- }
254
- $tabs['contact'] = __('Contact Us', 'premmerce-url-manager');
255
- }
256
-
257
-
258
- $this->fileManager->includeTemplate('admin/main.php', [
259
- 'settings' => $this->settings,
260
- 'bundles' => $this->bundlesAndSave,
261
- 'affiliate' => $this->affiliate,
262
- 'tabs' => $tabs,
263
- 'current' => $current,
264
- ]);
265
- }
266
-
267
- /**
268
- * Enqueue Scripts
269
- *
270
- * @param string $hook
271
- */
272
- public function enqueueScripts( $hook) {
273
- //init input-mask
274
- wp_enqueue_script(
275
- 'input-mask.js',
276
- $this->fileManager->locateAsset( 'admin/js/input-mask.min.js' ),
277
- [ 'jquery' ],
278
- UrlManagerPlugin::getPluginVersion()
279
- );
280
- //add styles for Settings
281
- if (in_array($hook, ['premmerce_page_premmerce-url-manager-admin', 'woocommerce_page_wc-settings'])) {
282
- wp_enqueue_style('premmerce-permalink-style', $this->fileManager->locateAsset('admin/css/style.css'), [],
283
- UrlManagerPlugin::getPluginVersion());
284
- }
285
- //add scripts for settings
286
- wp_enqueue_script(
287
- 'premmerce-permalink-settings-script',
288
- $this->fileManager->locateAsset('admin/js/settings.js'),
289
- ['jquery'], UrlManagerPlugin::getPluginVersion()
290
- );
291
-
292
- if ($this->isBannerActive()) {
293
- wp_enqueue_script('premmerce-permalink-banner-script',
294
- $this->fileManager->locateAsset('admin/js/banner.js'),
295
- ['jquery'], UrlManagerPlugin::getPluginVersion());
296
- wp_enqueue_style('premmerce-permalink-banner-style',
297
- $this->fileManager->locateAsset('admin/css/banner.css'), [],
298
- UrlManagerPlugin::getPluginVersion());
299
- }
300
- }
301
-
302
-
303
- /**
304
- * Set flush trigger
305
- */
306
- public function triggerFlush() {
307
- update_option(Settings::OPTION_FLUSH, true);
308
- }
309
-
310
- /**
311
- * Flush rewrite rules
312
- */
313
- public function flush() {
314
- if (get_option(Settings::OPTION_FLUSH)) {
315
- flush_rewrite_rules();
316
- delete_option(Settings::OPTION_FLUSH);
317
- }
318
- }
319
-
320
- /**
321
- * Admin footer modification
322
- *
323
- * @param $text - default WordPress footer thankyou text
324
- */
325
- public function removeFooterAdmin( $text) {
326
- $screen = get_current_screen();
327
- $premmercePages = [
328
- 'premmerce_page_premmerce-url-manager-admin'
329
- ];
330
-
331
- if (in_array($screen->id, $premmercePages)) {
332
- $link = 'https://wordpress.org/support/plugin/woo-permalink-manager/reviews/?filter=5';
333
- $target = 'target="_blank"';
334
- $text = '<span id="footer-thankyou">';
335
- $text .= sprintf(
336
- /* translators: %%1$s: plugin link, %2$s target */
337
- __('Please rate our Premmerce Permalink Manager for WooCommerce on <a href="%1$s" %2$s>WordPress.org</a><br/>Thank you from the Premmerce team!', 'premmerce-filter'),
338
- $link,
339
- $target
340
- );
341
- $text .= '</span>';
342
- } else {
343
- $text = '<span id="footer-thankyou">' . $text . '</span>';
344
- }
345
-
346
- return $text;
347
- }
348
-
349
- public function isBannerActive() {
350
- $user = wp_get_current_user();
351
- $user_id = $user->ID;
352
-
353
- return ! get_user_meta($user_id, self::META_IGNORE_BANNER, true);
354
-
355
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  }
1
  <?php namespace Premmerce\UrlManager\Admin;
2
 
 
3
  use Premmerce\UrlManager\UrlManagerPlugin;
 
4
  use Premmerce\SDK\V2\FileManager\FileManager;
 
 
 
 
5
 
6
  /**
7
  * Class Admin
8
  *
9
  * @package Premmerce\UrlManager
10
  */
11
+ class Admin
12
+ {
13
+ /**
14
+ * Settings Page
15
+ *
16
+ * @var string
17
+ */
18
+ private $settingsPage;
19
+
20
+ /**
21
+ * Settings Array
22
+ *
23
+ * @var arrat
24
+ */
25
+ private $settingsArray;
26
+
27
+ /**
28
+ * All Settings Field Names
29
+ *
30
+ * @var array
31
+ */
32
+ private $allFieldsName;
33
+
34
+ /**
35
+ * Settings Page
36
+ *
37
+ * @var string
38
+ */
39
+ private $parrentPageSlug;
40
+
41
+ /**
42
+ * FileManager
43
+ *
44
+ * @var FileManager
45
+ */
46
+ private $fileManager;
47
+
48
+ /**
49
+ * Settings
50
+ *
51
+ * @var Settings
52
+ */
53
+ private $settings;
54
+
55
+ /**
56
+ * Bundles and Save
57
+ *
58
+ * @var bundlesAndSave
59
+ */
60
+ private $bundlesAndSave;
61
+
62
+ /**
63
+ * Affiliate Tab
64
+ *
65
+ * @var affiliateTab
66
+ */
67
+ private $affiliate;
68
+
69
+ const META_IGNORE_BANNER = 'premmerce_url_manager_ignore_banner';
70
+
71
+ const WOO_TAB_NAME = 'woo_tab_premmerce_permalink';
72
+
73
+ /**
74
+ * Admin constructor.
75
+ *
76
+ * @param FileManager $fileManager
77
+ */
78
+ public function __construct(FileManager $fileManager)
79
+ {
80
+ $this->fileManager = $fileManager;
81
+ $this->settings = new Settings($fileManager);
82
+ $this->settingsPage = UrlManagerPlugin::DOMAIN . '-admin';
83
+
84
+ $this->parrentPageSlug = 'premmerce';
85
+ $this->bundlesAndSave = new BundleAndSave($fileManager);
86
+ $this->affiliate = new AffiliateTab($fileManager);
87
+ $this->registerActions();
88
+ }
89
+
90
+ private function registerActions()
91
+ {
92
+ $flushActions = array(
93
+ 'created_product_cat',
94
+ 'edited_product_cat',
95
+ 'delete_product_cat',
96
+
97
+ 'created_product_tag',
98
+ 'edited_product_tag',
99
+ 'delete_product_tag',
100
+
101
+ 'update_option_' . Settings::OPTIONS,
102
+ );
103
+
104
+ foreach ($flushActions as $action) {
105
+ add_action($action, array($this, 'triggerFlush'));
106
+ }
107
+
108
+ add_action('shutdown', array($this, 'flush'));
109
+
110
+ add_action('admin_init', array($this->settings, 'register'));
111
+
112
+ add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'));
113
+
114
+
115
+
116
+ add_action('admin_menu', array($this, 'addMenuPage'), 80);
117
+ add_action('admin_menu', array($this, 'addFullPack'), 100);
118
+ add_action('admin_notices', array($this, 'renderAdminBanner'));
119
+ add_action('wp_ajax_premmerce_url_manager_ignore_banner', array($this, 'ignoreAdminBanner'));
120
+ add_filter('plugin_action_links_' . plugin_basename($this->fileManager->getMainFile()), array($this, 'settingPageLink'), 10, 4);
121
+ add_filter('admin_footer_text', array($this, 'removeFooterAdmin'));
122
+ }
123
+
124
+ /**
125
+ * Setting Page Link
126
+ *
127
+ * @param mixed $actions
128
+ * @return void
129
+ */
130
+ public function settingPageLink($actions)
131
+ {
132
+ $actions[] = '<a href="' . $this->getSettingLink() . '">' . __('Settings', 'premmerce-url-manager') . '</a>';
133
+
134
+ return $actions;
135
+ }
136
+
137
+ /**
138
+ * Get url to settings page
139
+ *
140
+ * @return string
141
+ */
142
+ public function getSettingLink()
143
+ {
144
+ $param = array('page' => 'premmerce-url-manager-admin' );
145
+ return esc_url(add_query_arg($param, get_admin_url() . 'admin.php'));
146
+ }
147
+
148
+ /**
149
+ * Show Banner
150
+ */
151
+ public function renderAdminBanner()
152
+ {
153
+ if ($this->isBannerActive()) {
154
+ $this->fileManager->includeTemplate('admin/banner.php', array('fm' => $this->fileManager));
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Hide Banner
160
+ */
161
+ public function ignoreAdminBanner()
162
+ {
163
+ $user = wp_get_current_user();
164
+ $user_id = $user->ID;
165
+
166
+ add_user_meta($user_id, self::META_IGNORE_BANNER, true, true);
167
+
168
+ die;
169
+ }
170
+
171
+ /**
172
+ * Add submenu to premmerce menu page
173
+ */
174
+ public function addMenuPage()
175
+ {
176
+ global $admin_page_hooks;
177
+
178
+
179
+ $premmerceMenuExists = isset($admin_page_hooks['premmerce']);
180
+
181
+ if (! $premmerceMenuExists) {
182
+ $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>';
183
+ $svg = 'data:image/svg+xml;base64,' . base64_encode($svg);
184
+ add_menu_page(
185
+ 'Premmerce',
186
+ 'Premmerce',
187
+ 'manage_options',
188
+ 'premmerce',
189
+ '',
190
+ $svg
191
+ );
192
+ }
193
+
194
+
195
+ add_submenu_page(
196
+ $this->parrentPageSlug,
197
+ __('Permalink Manager', 'premmerce-url-manager'),
198
+ __('Permalink Manager', 'premmerce-url-manager'),
199
+ 'manage_options',
200
+ $this->settingsPage,
201
+ array($this, 'options'),
202
+ 10
203
+ );
204
+
205
+ if (! $premmerceMenuExists) {
206
+ global $submenu;
207
+ unset($submenu['premmerce'][0]);
208
+ }
209
+ }
210
+
211
+ public function addFullPack()
212
+ {
213
+ if (! function_exists('get_plugins')) {
214
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
215
+ }
216
+
217
+ $plugins = get_plugins();
218
+
219
+ $premmerceInstalled = array_key_exists('premmerce-premium/premmerce.php', $plugins)
220
+ || array_key_exists('premmerce/premmerce.php', $plugins);
221
+
222
+ if (! $premmerceInstalled) {
223
+ add_submenu_page(
224
+ 'premmerce',
225
+ __('Get premmerce full pack', 'premmerce-url-manager'),
226
+ __('Get premmerce full pack', 'premmerce-url-manager'),
227
+ 'manage_options',
228
+ admin_url('plugin-install.php?tab=plugin-information&plugin=premmerce')
229
+ );
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Options page
235
+ */
236
+ public function options()
237
+ {
238
+ $this->triggerFlush();
239
+
240
+ $current = isset($_GET['tab']) ? wc_clean(wp_unslash($_GET['tab'])) : 'settings';
241
+
242
+ $tabs['settings'] = __('Settings', 'premmerce-url-manager');
243
+ $tabs['bundle_and_save'] = __('Bundle and Save', 'premmerce-url-manager');
244
+ $tabs['affiliate'] = __('Affiliate', 'premmerce-url-manager');
245
+
246
+ if (function_exists('premmerce_wpm_fs')) {
247
+ if (premmerce_wpm_fs()->is_registered()) {
248
+ $tabs['account'] = __('Account', 'premmerce-url-manager');
249
+ }
250
+ $tabs['contact'] = __('Contact Us', 'premmerce-url-manager');
251
+ }
252
+
253
+
254
+ $this->fileManager->includeTemplate('admin/main.php', array(
255
+ 'settings' => $this->settings,
256
+ 'bundles' => $this->bundlesAndSave,
257
+ 'affiliate' => $this->affiliate,
258
+ 'tabs' => $tabs,
259
+ 'current' => $current,
260
+ ));
261
+ }
262
+
263
+ /**
264
+ * Enqueue Scripts
265
+ *
266
+ * @param string $hook
267
+ */
268
+ public function enqueueScripts($hook)
269
+ {
270
+ //init input-mask
271
+ wp_enqueue_script(
272
+ 'input-mask.js',
273
+ $this->fileManager->locateAsset('admin/js/input-mask.min.js'),
274
+ array( 'jquery' ),
275
+ UrlManagerPlugin::getPluginVersion()
276
+ );
277
+ //add styles for Settings
278
+ if (in_array($hook, array('premmerce_page_premmerce-url-manager-admin', 'woocommerce_page_wc-settings'))) {
279
+ wp_enqueue_style(
280
+ 'premmerce-permalink-style',
281
+ $this->fileManager->locateAsset('admin/css/style.css'),
282
+ array(),
283
+ UrlManagerPlugin::getPluginVersion()
284
+ );
285
+ }
286
+ //add scripts for settings
287
+ wp_enqueue_script(
288
+ 'premmerce-permalink-settings-script',
289
+ $this->fileManager->locateAsset('admin/js/settings.js'),
290
+ array('jquery'),
291
+ UrlManagerPlugin::getPluginVersion()
292
+ );
293
+
294
+ if ($this->isBannerActive()) {
295
+ wp_enqueue_script(
296
+ 'premmerce-permalink-banner-script',
297
+ $this->fileManager->locateAsset('admin/js/banner.js'),
298
+ array('jquery'),
299
+ UrlManagerPlugin::getPluginVersion()
300
+ );
301
+ wp_enqueue_style(
302
+ 'premmerce-permalink-banner-style',
303
+ $this->fileManager->locateAsset('admin/css/banner.css'),
304
+ array(),
305
+ UrlManagerPlugin::getPluginVersion()
306
+ );
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Set flush trigger
312
+ */
313
+ public function triggerFlush()
314
+ {
315
+ update_option(Settings::OPTION_FLUSH, true);
316
+ }
317
+
318
+ /**
319
+ * Flush rewrite rules
320
+ */
321
+ public function flush()
322
+ {
323
+ if (get_option(Settings::OPTION_FLUSH)) {
324
+ flush_rewrite_rules();
325
+ delete_option(Settings::OPTION_FLUSH);
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Admin footer modification
331
+ *
332
+ * @param $text - default WordPress footer thankyou text
333
+ */
334
+ public function removeFooterAdmin($text)
335
+ {
336
+ $screen = get_current_screen();
337
+ $premmercePages = array(
338
+ 'premmerce_page_premmerce-url-manager-admin'
339
+ );
340
+
341
+ if (in_array($screen->id, $premmercePages)) {
342
+ $link = 'https://wordpress.org/support/plugin/woo-permalink-manager/reviews/?filter=5';
343
+ $target = 'target="_blank"';
344
+ $text = '<span id="footer-thankyou">';
345
+ $text .= sprintf(
346
+ /* translators: %%1$s: plugin link, %2$s target */
347
+ __('Please rate our Premmerce Permalink Manager for WooCommerce on <a href="%1$s" %2$s>WordPress.org</a><br/>Thank you from the Premmerce team!', 'premmerce-filter'),
348
+ $link,
349
+ $target
350
+ );
351
+ $text .= '</span>';
352
+ } else {
353
+ $text = '<span id="footer-thankyou">' . $text . '</span>';
354
+ }
355
+
356
+ return $text;
357
+ }
358
+
359
+ public function isBannerActive()
360
+ {
361
+ $user = wp_get_current_user();
362
+ $user_id = $user->ID;
363
+
364
+ return ! get_user_meta($user_id, self::META_IGNORE_BANNER, true);
365
+ }
366
  }
src/Admin/AffiliateTab.php CHANGED
@@ -3,36 +3,40 @@
3
  use Premmerce\SDK\V2\FileManager\FileManager;
4
  use Premmerce\UrlManager\Admin\Tabs\Base\TabInterface;
5
 
6
- class AffiliateTab implements TabInterface {
7
-
8
-
9
- /**
10
- * FileManager
11
- *
12
- * @var FileManager
13
- */
14
- private $fileManager;
15
-
16
- public function __construct( FileManager $fileManager) {
17
- $this->fileManager = $fileManager;
18
- }
19
-
20
- public function init() {
21
- }
22
-
23
- public function render() {
24
- }
25
-
26
-
27
- public function getLabel() {
28
- return __('Affiliate', 'premmerce-url-manager');
29
- }
30
-
31
- public function getName() {
32
- return 'affiliate';
33
- }
34
-
35
- public function valid() {
36
- return true;
37
- }
 
 
 
 
38
  }
3
  use Premmerce\SDK\V2\FileManager\FileManager;
4
  use Premmerce\UrlManager\Admin\Tabs\Base\TabInterface;
5
 
6
+ class AffiliateTab implements TabInterface
7
+ {
8
+ /**
9
+ * FileManager
10
+ *
11
+ * @var FileManager
12
+ */
13
+ private $fileManager;
14
+
15
+ public function __construct(FileManager $fileManager)
16
+ {
17
+ $this->fileManager = $fileManager;
18
+ }
19
+
20
+ public function init()
21
+ {
22
+ }
23
+
24
+ public function render()
25
+ {
26
+ }
27
+
28
+ public function getLabel()
29
+ {
30
+ return __('Affiliate', 'premmerce-url-manager');
31
+ }
32
+
33
+ public function getName()
34
+ {
35
+ return 'affiliate';
36
+ }
37
+
38
+ public function valid()
39
+ {
40
+ return true;
41
+ }
42
  }
src/Admin/BundleAndSave.php CHANGED
@@ -4,149 +4,156 @@ use Premmerce\UrlManager\UrlManagerPlugin;
4
  use Premmerce\SDK\V2\FileManager\FileManager;
5
  use Premmerce\UrlManager\Admin\Tabs\Base\TabInterface;
6
 
7
- class BundleAndSave implements TabInterface {
8
-
9
-
10
- /**
11
- * FileManager
12
- *
13
- * @var FileManager
14
- */
15
- private $fileManager;
16
-
17
- public function __construct( FileManager $fileManager) {
18
- $this->fileManager = $fileManager;
19
- $this->hooks();
20
- }
21
-
22
- public function init() {
23
-
24
- }
25
-
26
- public function hooks() {
27
- add_action( 'admin_enqueue_scripts', [$this, 'registerBundlesAssets'], 11 );
28
- }
29
-
30
- public function render() {
31
- $images = [
32
- 'header_img' => $this->fileManager->locateAsset('admin/img/premmerce_bundle.jpg'),
33
- 'premmerce_logo' => $this->fileManager->locateAsset('admin/img/premmerce.png'),
34
- 'permalink_img' => $this->fileManager->locateAsset('admin/img/permalink.png'),
35
- 'filter_img' => $this->fileManager->locateAsset('admin/img/filter.png'),
36
- 'variants_img' => $this->fileManager->locateAsset('admin/img/variants.png'),
37
- 'search_img' => $this->fileManager->locateAsset('admin/img/search.png'),
38
- 'riley_pearcy' => $this->fileManager->locateAsset('admin/img/riley_pearcy.jpg'),
39
- 'lian_perry' => $this->fileManager->locateAsset('admin/img/lian_perry.jpg'),
40
- 'rommie_mercer' => $this->fileManager->locateAsset('admin/img/rommie_mercer.jpg'),
41
- 'svg' => $this->fileManager->locateAsset('admin/img/svg.svg'),
42
- 'wp_logo' => $this->fileManager->locateAsset('admin/img/wp.png'),
43
- 'wp_rocket_logo' => $this->fileManager->locateAsset('admin/img/wp-rocket.jpg'),
44
- 'learnwoo_logo' => $this->fileManager->locateAsset('admin/img/learnwoo.png'),
45
- 'wp_lift_logo' => $this->fileManager->locateAsset('admin/img/wp-lift.png'),
46
- 'mayor_logo' => $this->fileManager->locateAsset('admin/img/mayor.png'),
47
- 'managewp_logo' => $this->fileManager->locateAsset('admin/img/managewp.png'),
48
- 'thanks_img' => $this->fileManager->locateAsset('admin/img/thanks.png'),
49
- ];
50
-
51
- //sections on Bundles tab
52
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/header.php', $images);
53
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/pricing.php', $images);
54
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/texts.php', $images);
55
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/testimonials.php', $images);
56
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/faq.php', $images);
57
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/featured-in.php', $images);
58
- $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/thanks.php', $images);
59
- }
60
-
61
- /**
62
- * Register css and js only for Bundles tab
63
- *
64
- * @param $page
65
- */
66
- public function registerBundlesAssets( $page) {
67
- if ('premmerce_page_premmerce-url-manager-admin' === $page) {
68
- //scripts and styles for bundle tab
69
- if (isset($_GET['tab']) && $_GET['tab'] === $this->getName()) {
70
- //css and js for bundle tab
71
- wp_enqueue_style(
72
- 'premmerce_url_manager_admin_premmerce_style',
73
- $this->fileManager->locateAsset('admin/css/premmerce.min.css'),
74
- [],
75
- UrlManagerPlugin::getPluginVersion()
76
- );
77
- wp_enqueue_script(
78
- 'premmerce_url_manager_admin_bundles_freemius_jquery_for_checkout_script',
79
- 'https://code.jquery.com/jquery-1.12.4.min.js',
80
- UrlManagerPlugin::getPluginVersion(),
81
- true
82
- );
83
- wp_enqueue_script(
84
- 'premmerce_url_manager_admin_bundles_freemius_checkout_script',
85
- 'https://checkout.freemius.com/checkout.min.js',
86
- UrlManagerPlugin::getPluginVersion(),
87
- true
88
- );
89
- wp_enqueue_script(
90
- 'premmerce_url_manager_admin_bundles_script',
91
- $this->fileManager->locateAsset('admin/js/bundles.js'),
92
- UrlManagerPlugin::getPluginVersion(),
93
- true
94
- );
95
- }
96
- }
97
- }
98
-
99
- /**
100
- * Get Label
101
- *
102
- * @return void
103
- */
104
- public function getLabel() {
105
- return __('Bundle & Save', 'premmerce-url-manager');
106
- }
107
-
108
- /**
109
- * Get Name
110
- *
111
- * @return void
112
- */
113
- public function getName() {
114
- return 'bundle_and_save';
115
- }
116
-
117
- /**
118
- * Valid
119
- *
120
- * @return void
121
- */
122
- public function valid() {
123
- return true;
124
- }
125
-
126
- /**
127
- * Get ico
128
- *
129
- * @param mixed $svg_url
130
- * @param mixed $name
131
- * @param mixed $echo
132
- * @return void
133
- */
134
- public static function premmerce_use_svg_symbol( $svg_url, $name, $echo = true) {
135
- $ico = '<use xlink:href="' . $svg_url . '#svg-icon__' . $name . '"></use>';
136
-
137
- $ksesDefaults = wp_kses_allowed_html( 'post' );
138
-
139
- $icoArgs = [
140
- 'use' => [
141
- 'href' => true,
142
- 'xlink:href' => true,
143
- ]
144
- ];
145
-
146
- if ($echo) {
147
- echo wp_kses( $ico, array_merge( $ksesDefaults, $icoArgs ) );
148
- } else {
149
- return $ico;
150
- }
151
- }
 
 
 
 
 
 
 
152
  }
4
  use Premmerce\SDK\V2\FileManager\FileManager;
5
  use Premmerce\UrlManager\Admin\Tabs\Base\TabInterface;
6
 
7
+ class BundleAndSave implements TabInterface
8
+ {
9
+ /**
10
+ * FileManager
11
+ *
12
+ * @var FileManager
13
+ */
14
+ private $fileManager;
15
+
16
+ public function __construct(FileManager $fileManager)
17
+ {
18
+ $this->fileManager = $fileManager;
19
+ $this->hooks();
20
+ }
21
+
22
+ public function init()
23
+ {
24
+ }
25
+
26
+ public function hooks()
27
+ {
28
+ add_action('admin_enqueue_scripts', array($this, 'registerBundlesAssets'), 11);
29
+ }
30
+
31
+ public function render()
32
+ {
33
+ $images = array(
34
+ 'header_img' => $this->fileManager->locateAsset('admin/img/premmerce_bundle.jpg'),
35
+ 'premmerce_logo' => $this->fileManager->locateAsset('admin/img/premmerce.png'),
36
+ 'permalink_img' => $this->fileManager->locateAsset('admin/img/permalink.png'),
37
+ 'filter_img' => $this->fileManager->locateAsset('admin/img/filter.png'),
38
+ 'variants_img' => $this->fileManager->locateAsset('admin/img/variants.png'),
39
+ 'search_img' => $this->fileManager->locateAsset('admin/img/search.png'),
40
+ 'riley_pearcy' => $this->fileManager->locateAsset('admin/img/riley_pearcy.jpg'),
41
+ 'lian_perry' => $this->fileManager->locateAsset('admin/img/lian_perry.jpg'),
42
+ 'rommie_mercer' => $this->fileManager->locateAsset('admin/img/rommie_mercer.jpg'),
43
+ 'svg' => $this->fileManager->locateAsset('admin/img/svg.svg'),
44
+ 'wp_logo' => $this->fileManager->locateAsset('admin/img/wp.png'),
45
+ 'wp_rocket_logo' => $this->fileManager->locateAsset('admin/img/wp-rocket.jpg'),
46
+ 'learnwoo_logo' => $this->fileManager->locateAsset('admin/img/learnwoo.png'),
47
+ 'wp_lift_logo' => $this->fileManager->locateAsset('admin/img/wp-lift.png'),
48
+ 'mayor_logo' => $this->fileManager->locateAsset('admin/img/mayor.png'),
49
+ 'managewp_logo' => $this->fileManager->locateAsset('admin/img/managewp.png'),
50
+ 'thanks_img' => $this->fileManager->locateAsset('admin/img/thanks.png'),
51
+ );
52
+
53
+ //sections on Bundles tab
54
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/header.php', $images);
55
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/pricing.php', $images);
56
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/texts.php', $images);
57
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/testimonials.php', $images);
58
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/faq.php', $images);
59
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/featured-in.php', $images);
60
+ $this->fileManager->includeTemplate('admin/tabs/bundle-and-save/thanks.php', $images);
61
+ }
62
+
63
+ /**
64
+ * Register css and js only for Bundles tab
65
+ *
66
+ * @param $page
67
+ */
68
+ public function registerBundlesAssets($page)
69
+ {
70
+ if ('premmerce_page_premmerce-url-manager-admin' === $page) {
71
+ //scripts and styles for bundle tab
72
+ if (isset($_GET['tab']) && $_GET['tab'] === $this->getName()) {
73
+ //css and js for bundle tab
74
+ wp_enqueue_style(
75
+ 'premmerce_url_manager_admin_premmerce_style',
76
+ $this->fileManager->locateAsset('admin/css/premmerce.min.css'),
77
+ array(),
78
+ UrlManagerPlugin::getPluginVersion()
79
+ );
80
+ wp_enqueue_script(
81
+ 'premmerce_url_manager_admin_bundles_freemius_jquery_for_checkout_script',
82
+ 'https://code.jquery.com/jquery-1.12.4.min.js',
83
+ UrlManagerPlugin::getPluginVersion(),
84
+ true
85
+ );
86
+ wp_enqueue_script(
87
+ 'premmerce_url_manager_admin_bundles_freemius_checkout_script',
88
+ 'https://checkout.freemius.com/checkout.min.js',
89
+ UrlManagerPlugin::getPluginVersion(),
90
+ true
91
+ );
92
+ wp_enqueue_script(
93
+ 'premmerce_url_manager_admin_bundles_script',
94
+ $this->fileManager->locateAsset('admin/js/bundles.js'),
95
+ UrlManagerPlugin::getPluginVersion(),
96
+ true
97
+ );
98
+ }
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Get Label
104
+ *
105
+ * @return void
106
+ */
107
+ public function getLabel()
108
+ {
109
+ return __('Bundle & Save', 'premmerce-url-manager');
110
+ }
111
+
112
+ /**
113
+ * Get Name
114
+ *
115
+ * @return void
116
+ */
117
+ public function getName()
118
+ {
119
+ return 'bundle_and_save';
120
+ }
121
+
122
+ /**
123
+ * Valid
124
+ *
125
+ * @return void
126
+ */
127
+ public function valid()
128
+ {
129
+ return true;
130
+ }
131
+
132
+ /**
133
+ * Get ico
134
+ *
135
+ * @param mixed $svg_url
136
+ * @param mixed $name
137
+ * @param mixed $echo
138
+ * @return void
139
+ */
140
+ public static function premmerce_use_svg_symbol($svg_url, $name, $echo = true)
141
+ {
142
+ $ico = '<use xlink:href="' . $svg_url . '#svg-icon__' . $name . '"></use>';
143
+
144
+ $ksesDefaults = wp_kses_allowed_html('post');
145
+
146
+ $icoArgs = array(
147
+ 'use' => array(
148
+ 'href' => true,
149
+ 'xlink:href' => true,
150
+ )
151
+ );
152
+
153
+ if ($echo) {
154
+ echo wp_kses($ico, array_merge($ksesDefaults, $icoArgs));
155
+ } else {
156
+ return $ico;
157
+ }
158
+ }
159
  }
src/Admin/Settings.php CHANGED
@@ -2,202 +2,211 @@
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 = '/product/%product_cat%/';
18
-
19
- const PERMALINK_WC_PRODUCT = 'product';
20
-
21
-
22
- /**
23
- * FileManager
24
- *
25
- * @var FileManager
26
- */
27
- private $fileManager;
28
-
29
- public function __construct( FileManager $fileManager ) {
30
- $this->fileManager = $fileManager;
31
- }
32
-
33
- public function register() {
34
- register_setting( self::OPTIONS, self::OPTIONS, [
35
- 'sanitize_callback' => [ $this, 'updateSettings' ],
36
- ] );
37
-
38
- add_settings_section( 'category_link', __( 'Categories', 'premmerce-url-manager' ), [
39
- $this,
40
- 'categorySection',
41
- ], self::SETTINGS_PAGE );
42
-
43
- add_settings_section( 'product_link', __( 'Products', 'premmerce-url-manager' ), [
44
- $this,
45
- 'productSection',
46
- ], self::SETTINGS_PAGE );
47
-
48
- add_settings_section('sku_link', __('SKU', 'premmerce-url-manager'), [
49
- $this,
50
- 'skuSection',
51
- ], self::SETTINGS_PAGE);
52
-
53
- add_settings_section( 'additional', __( 'Additional', 'premmerce-url-manager' ), [
54
- $this,
55
- 'canonicalSection',
56
- ], self::SETTINGS_PAGE );
57
-
58
- add_settings_section( 'suffix', __( 'URL\'s suffix', 'premmerce-url-manager' ), [
59
- $this,
60
- 'suffixSection',
61
- ], self::SETTINGS_PAGE );
62
- }
63
-
64
- /**
65
- * Get Main Settings Text
66
- *
67
- * @return void
68
- */
69
- public static function getMainSettingsText() {
70
- return __('WooCommerce Permalink Manager offers you the ability to create a custom URL structure for your permalinks. Custom URL structures can improve the aesthetics, usability, and forward-compatibility of your links. A number of settings are available, and here are some examples to get you started.', 'premmerce-url-manager');
71
- }
72
-
73
- public function show() {
74
- print( '<form action="' . esc_url(admin_url( 'options.php' )) . '" method="post">' );
75
-
76
- settings_errors();
77
-
78
- settings_fields( self::OPTIONS );
79
-
80
- do_settings_sections( self::SETTINGS_PAGE );
81
-
82
- submit_button();
83
- print( '</form>' );
84
- }
85
-
86
- /**
87
- * Get Product Path For Sku
88
- *
89
- * @return void
90
- */
91
- public function getProductPathForSku() {
92
- $product = $this->getOption( 'product' );
93
-
94
- switch ( $product ) {
95
- case 'category_slug':
96
- return '/category';
97
- case 'hierarchical':
98
- return 'parent-category/category';
99
- default:
100
- return '';
101
- }
102
- }
103
-
104
- public function categorySection() {
105
- $this->fileManager->includeTemplate( 'admin/section/category.php', [
106
- 'category' => $this->getOption( 'category' ),
107
- ] );
108
- }
109
-
110
- public function productSection() {
111
- $this->fileManager->includeTemplate( 'admin/section/product.php', [
112
- 'product' => $this->getOption( 'product' ),
113
- ] );
114
- }
115
-
116
- public function skuSection() {
117
- $this->fileManager->includeTemplate( 'admin/section/sku.php', [
118
- 'sku' => $this->getOption( 'sku' ),
119
- 'productPath' => $this->getProductPathForSku(),
120
- ] );
121
- }
122
-
123
- public function canonicalSection() {
124
- $this->fileManager->includeTemplate( 'admin/section/additional.php', [
125
- 'tag' => $this->getOption( 'tag' ),
126
- 'canonical' => $this->getOption( 'canonical' ),
127
- 'redirect' => $this->getOption( 'redirect' ),
128
- 'use_primary_category' => $this->getOption( 'use_primary_category' ),
129
- 'breadcrumbs' => $this->getOption( 'breadcrumbs' ),
130
- 'br_remove_shop' => $this->getOption( 'br_remove_shop' ),
131
- ] );
132
- }
133
-
134
- public function suffixSection() {
135
- $this->fileManager->includeTemplate( 'admin/section/suffix.php', [
136
- 'suffix' => $this->getOption( 'suffix', '' ),
137
- 'enable_suffix_products' => $this->getOption( 'enable_suffix_products', 'no' ),
138
- 'enable_suffix_categories' => $this->getOption( 'enable_suffix_categories', 'no' ),
139
- 'product' => $this->getOption( 'product' ),
140
- 'category' => $this->getOption( 'category' )
141
- ] );
142
- }
143
-
144
- /**
145
- * Update Settings
146
- *
147
- * @param mixed $settings
148
- * @return void
149
- */
150
- public function updateSettings( $settings ) {
151
- $this->fixWPWCSettings( $settings );
152
-
153
- if ( ! empty( $settings['suffix'] ) ) {
154
- esc_url_raw( $settings['suffix'] );
155
- }
156
-
157
- return $settings;
158
- }
159
-
160
- /**
161
- * Fix WP WC Settings
162
- *
163
- * @param mixed $options
164
- * @return void
165
- */
166
- private function fixWPWCSettings( $options ) {
167
-
168
- if ( isset($options['product']) && !empty($options['product']) || isset($options['category']) && !empty($options['category']) ) {
169
- if ( ! get_option( 'permalink_structure' ) ) {
170
- update_option( 'permalink_structure', self::PERMALINK_STRUCTURE );
171
- };
172
- }
173
-
174
- if ( isset($options['product']) && !empty($options['product']) ) {
175
-
176
- if ( 'slug' === $options['product']) {
177
- $wc['product_base'] = self::PERMALINK_WC_PRODUCT;
178
- }
179
- if ( in_array( $options['product'], [ 'category_slug', 'hierarchical' ] ) ) {
180
- $wc['product_base'] = self::PERMALINK_WC_PRODUCT_CAT;
181
- }
182
-
183
- update_option( 'woocommerce_permalinks', $wc );
184
- }
185
- }
186
-
187
- /**
188
- * Get Option
189
- *
190
- * @param string $key
191
- * @param mixed|null $default
192
- *
193
- * @return mixed|null
194
- */
195
- public function getOption( $key, $default = null ) {
196
-
197
- if ( ! isset( $this->options ) ) {
198
- $this->options = get_option( self::OPTIONS );
199
- }
200
-
201
- return isset( $this->options[ $key ] ) ? $this->options[ $key ] : $default;
202
- }
 
 
 
 
 
 
 
 
 
203
  }
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 = '/product/%product_cat%/';
18
+
19
+ const PERMALINK_WC_PRODUCT = 'product';
20
+
21
+ /**
22
+ * FileManager
23
+ *
24
+ * @var FileManager
25
+ */
26
+ private $fileManager;
27
+
28
+ public function __construct(FileManager $fileManager)
29
+ {
30
+ $this->fileManager = $fileManager;
31
+ }
32
+
33
+ public function register()
34
+ {
35
+ register_setting(self::OPTIONS, self::OPTIONS, array(
36
+ 'sanitize_callback' => array( $this, 'updateSettings' ),
37
+ ));
38
+
39
+ add_settings_section('category_link', __('Categories', 'premmerce-url-manager'), array(
40
+ $this,
41
+ 'categorySection',
42
+ ), self::SETTINGS_PAGE);
43
+
44
+ add_settings_section('product_link', __('Products', 'premmerce-url-manager'), array(
45
+ $this,
46
+ 'productSection',
47
+ ), self::SETTINGS_PAGE);
48
+
49
+ add_settings_section('sku_link', __('SKU', 'premmerce-url-manager'), array(
50
+ $this,
51
+ 'skuSection',
52
+ ), self::SETTINGS_PAGE);
53
+
54
+ add_settings_section('additional', __('Additional', 'premmerce-url-manager'), array(
55
+ $this,
56
+ 'canonicalSection',
57
+ ), self::SETTINGS_PAGE);
58
+
59
+ add_settings_section('suffix', __('URL\'s suffix', 'premmerce-url-manager'), array(
60
+ $this,
61
+ 'suffixSection',
62
+ ), self::SETTINGS_PAGE);
63
+ }
64
+
65
+ /**
66
+ * Get Main Settings Text
67
+ *
68
+ * @return void
69
+ */
70
+ public static function getMainSettingsText()
71
+ {
72
+ return __('WooCommerce Permalink Manager offers you the ability to create a custom URL structure for your permalinks. Custom URL structures can improve the aesthetics, usability, and forward-compatibility of your links. A number of settings are available, and here are some examples to get you started.', 'premmerce-url-manager');
73
+ }
74
+
75
+ public function show()
76
+ {
77
+ print('<form action="' . esc_url(admin_url('options.php')) . '" method="post">');
78
+
79
+ settings_errors();
80
+
81
+ settings_fields(self::OPTIONS);
82
+
83
+ do_settings_sections(self::SETTINGS_PAGE);
84
+
85
+ submit_button();
86
+ print('</form>');
87
+ }
88
+
89
+ /**
90
+ * Get Product Path For Sku
91
+ *
92
+ * @return void
93
+ */
94
+ public function getProductPathForSku()
95
+ {
96
+ $product = $this->getOption('product');
97
+
98
+ switch ($product) {
99
+ case 'category_slug':
100
+ return '/category';
101
+ case 'hierarchical':
102
+ return 'parent-category/category';
103
+ default:
104
+ return '';
105
+ }
106
+ }
107
+
108
+ public function categorySection()
109
+ {
110
+ $this->fileManager->includeTemplate('admin/section/category.php', array(
111
+ 'category' => $this->getOption('category'),
112
+ ));
113
+ }
114
+
115
+ public function productSection()
116
+ {
117
+ $this->fileManager->includeTemplate('admin/section/product.php', array(
118
+ 'product' => $this->getOption('product'),
119
+ ));
120
+ }
121
+
122
+ public function skuSection()
123
+ {
124
+ $this->fileManager->includeTemplate('admin/section/sku.php', array(
125
+ 'sku' => $this->getOption('sku'),
126
+ 'productPath' => $this->getProductPathForSku(),
127
+ ));
128
+ }
129
+
130
+ public function canonicalSection()
131
+ {
132
+ $this->fileManager->includeTemplate('admin/section/additional.php', array(
133
+ 'tag' => $this->getOption('tag'),
134
+ 'canonical' => $this->getOption('canonical'),
135
+ 'redirect' => $this->getOption('redirect'),
136
+ 'use_primary_category' => $this->getOption('use_primary_category'),
137
+ 'breadcrumbs' => $this->getOption('breadcrumbs'),
138
+ 'br_remove_shop' => $this->getOption('br_remove_shop'),
139
+ ));
140
+ }
141
+
142
+ public function suffixSection()
143
+ {
144
+ $this->fileManager->includeTemplate('admin/section/suffix.php', array(
145
+ 'suffix' => $this->getOption('suffix', ''),
146
+ 'enable_suffix_products' => $this->getOption('enable_suffix_products', 'no'),
147
+ 'enable_suffix_categories' => $this->getOption('enable_suffix_categories', 'no'),
148
+ 'product' => $this->getOption('product'),
149
+ 'category' => $this->getOption('category')
150
+ ));
151
+ }
152
+
153
+ /**
154
+ * Update Settings
155
+ *
156
+ * @param mixed $settings
157
+ * @return void
158
+ */
159
+ public function updateSettings($settings)
160
+ {
161
+ $this->fixWPWCSettings($settings);
162
+
163
+ if (! empty($settings['suffix'])) {
164
+ esc_url_raw($settings['suffix']);
165
+ }
166
+
167
+ return $settings;
168
+ }
169
+
170
+ /**
171
+ * Fix WP WC Settings
172
+ *
173
+ * @param mixed $options
174
+ * @return void
175
+ */
176
+ private function fixWPWCSettings($options)
177
+ {
178
+ if (isset($options['product']) && !empty($options['product']) || isset($options['category']) && !empty($options['category'])) {
179
+ if (! get_option('permalink_structure')) {
180
+ update_option('permalink_structure', self::PERMALINK_STRUCTURE);
181
+ };
182
+ }
183
+
184
+ if (isset($options['product']) && !empty($options['product'])) {
185
+ if ('slug' === $options['product']) {
186
+ $wc['product_base'] = self::PERMALINK_WC_PRODUCT;
187
+ }
188
+ if (in_array($options['product'], array( 'category_slug', 'hierarchical' ))) {
189
+ $wc['product_base'] = self::PERMALINK_WC_PRODUCT_CAT;
190
+ }
191
+
192
+ update_option('woocommerce_permalinks', $wc);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Get Option
198
+ *
199
+ * @param string $key
200
+ * @param mixed|null $default
201
+ *
202
+ * @return mixed|null
203
+ */
204
+ public function getOption($key, $default = null)
205
+ {
206
+ if (! isset($this->options)) {
207
+ $this->options = get_option(self::OPTIONS);
208
+ }
209
+
210
+ return isset($this->options[ $key ]) ? $this->options[ $key ] : $default;
211
+ }
212
  }
src/Admin/Tabs/Base/TabInterface.php CHANGED
@@ -1,34 +1,33 @@
1
  <?php namespace Premmerce\UrlManager\Admin\Tabs\Base;
2
 
3
- interface TabInterface {
 
 
 
 
 
4
 
 
 
 
 
5
 
6
- /**
7
- * Register hooks
8
- */
9
- public function init();
 
 
10
 
11
- /**
12
- * Render tab content
13
- */
14
- public function render();
15
 
16
- /**
17
- * Returns tab label
18
- *
19
- * @return string
20
- */
21
- public function getLabel();
22
-
23
- /**
24
- * Returns unique tab name
25
- */
26
- public function getName();
27
-
28
- /**
29
- * Is tab valid to render
30
- *
31
- * @return bool
32
- */
33
- public function valid();
34
  }
1
  <?php namespace Premmerce\UrlManager\Admin\Tabs\Base;
2
 
3
+ interface TabInterface
4
+ {
5
+ /**
6
+ * Register hooks
7
+ */
8
+ public function init();
9
 
10
+ /**
11
+ * Render tab content
12
+ */
13
+ public function render();
14
 
15
+ /**
16
+ * Returns tab label
17
+ *
18
+ * @return string
19
+ */
20
+ public function getLabel();
21
 
22
+ /**
23
+ * Returns unique tab name
24
+ */
25
+ public function getName();
26
 
27
+ /**
28
+ * Is tab valid to render
29
+ *
30
+ * @return bool
31
+ */
32
+ public function valid();
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
src/Frontend/Frontend.php CHANGED
@@ -28,14 +28,14 @@ class Frontend
28
  $options = get_option( Settings::OPTIONS );
29
  $this->options = $options;
30
  if ( !empty($options['product']) || !empty($options['sku']) ) {
31
- add_action( 'request', [ $this, 'replaceRequest' ], 11 );
32
  }
33
  if ( !empty($options['canonical']) ) {
34
- add_action( 'wp_head', [ $this, 'addCanonical' ] );
35
  }
36
  $isGetParamUrlFormat = apply_filters( 'wpml_setting', 0, 'language_negotiation_type' ) == '3';
37
  if ( class_exists( 'SitePress' ) && $isGetParamUrlFormat ) {
38
- add_filter( 'icl_ls_languages', [ $this, 'modifyWpmlLanguageSwitcher' ], 20 );
39
  }
40
  }
41
 
@@ -84,7 +84,7 @@ class Frontend
84
  if ( !empty($url) ) {
85
  $url = explode( '/', $url );
86
  $slug = array_pop( $url );
87
- $replace = [];
88
 
89
  if ( 'feed' === $slug ) {
90
  $replace['feed'] = $slug;
@@ -104,14 +104,18 @@ class Frontend
104
  $slug = array_pop( $url );
105
  }
106
 
107
- $num = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) as count_id FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s", [ $slug, self::WOO_PRODUCT ] ) ) );
108
 
109
  if ( $num > 0 ) {
110
  $replace['page'] = '';
111
  $replace['post_type'] = self::WOO_PRODUCT;
112
  $replace['product'] = $slug;
113
  $replace['name'] = $slug;
114
- return $replace;
 
 
 
 
115
  }
116
 
117
  }
@@ -184,7 +188,7 @@ class Frontend
184
  protected function findSlugBySku( $sku )
185
  {
186
  global $wpdb ;
187
- $skuId = $wpdb->get_row( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = %s AND meta_key = '_sku'", [ $sku ] ), ARRAY_A );
188
 
189
  if ( isset( $skuId['post_id'] ) ) {
190
  $postSlug = get_post_field( 'post_name', $skuId['post_id'] );
@@ -205,7 +209,7 @@ class Frontend
205
  */
206
  protected function checkIfWooCategoryExists( $request )
207
  {
208
- if ( !empty($this->options['category']) && in_array( $this->options['product'], [ 'category_slug', 'hierarchical' ] ) ) {
209
  if ( array_key_exists( self::WOO_CATEGORY, $request ) ) {
210
  return true;
211
  }
28
  $options = get_option( Settings::OPTIONS );
29
  $this->options = $options;
30
  if ( !empty($options['product']) || !empty($options['sku']) ) {
31
+ add_action( 'request', array( $this, 'replaceRequest' ), 11 );
32
  }
33
  if ( !empty($options['canonical']) ) {
34
+ add_action( 'wp_head', array( $this, 'addCanonical' ) );
35
  }
36
  $isGetParamUrlFormat = apply_filters( 'wpml_setting', 0, 'language_negotiation_type' ) == '3';
37
  if ( class_exists( 'SitePress' ) && $isGetParamUrlFormat ) {
38
+ add_filter( 'icl_ls_languages', array( $this, 'modifyWpmlLanguageSwitcher' ), 20 );
39
  }
40
  }
41
 
84
  if ( !empty($url) ) {
85
  $url = explode( '/', $url );
86
  $slug = array_pop( $url );
87
+ $replace = array();
88
 
89
  if ( 'feed' === $slug ) {
90
  $replace['feed'] = $slug;
104
  $slug = array_pop( $url );
105
  }
106
 
107
+ $num = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) as count_id FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s", array( $slug, self::WOO_PRODUCT ) ) ) );
108
 
109
  if ( $num > 0 ) {
110
  $replace['page'] = '';
111
  $replace['post_type'] = self::WOO_PRODUCT;
112
  $replace['product'] = $slug;
113
  $replace['name'] = $slug;
114
+ // Find other query vars
115
+ $old_request = $request;
116
+ unset( $old_request['pagename'] );
117
+ $extra = array_diff_key( $old_request, $replace );
118
+ return array_merge( $replace, $extra );
119
  }
120
 
121
  }
188
  protected function findSlugBySku( $sku )
189
  {
190
  global $wpdb ;
191
+ $skuId = $wpdb->get_row( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = %s AND meta_key = '_sku'", array( $sku ) ), ARRAY_A );
192
 
193
  if ( isset( $skuId['post_id'] ) ) {
194
  $postSlug = get_post_field( 'post_name', $skuId['post_id'] );
209
  */
210
  protected function checkIfWooCategoryExists( $request )
211
  {
212
+ if ( !empty($this->options['category']) && in_array( $this->options['product'], array( 'category_slug', 'hierarchical' ) ) ) {
213
  if ( array_key_exists( self::WOO_CATEGORY, $request ) ) {
214
  return true;
215
  }
src/PermalinkListener.php CHANGED
@@ -24,14 +24,14 @@ class PermalinkListener
24
  public function __construct()
25
  {
26
  $options = get_option( Settings::OPTIONS );
27
- $this->options = [
28
  'use_primary_category' => !empty($options['use_primary_category']),
29
  'product' => ( isset( $options['product'] ) ? $options['product'] : '' ),
30
  'suffix' => ( !empty($options['suffix']) ? $options['suffix'] : false ),
31
  'enable_suffix_categories' => ( isset( $options['enable_suffix_categories'] ) && !empty($options['enable_suffix_categories']) ? true : false ),
32
  'enable_suffix_products' => ( isset( $options['enable_suffix_products'] ) && !empty($options['enable_suffix_products']) ? true : false ),
33
  'sku' => ( isset( $options['sku'] ) ? $options['sku'] : '' ),
34
- ];
35
  $this->taxonomyOptions['product_cat'] = ( isset( $options['category'] ) ? $options['category'] : '' );
36
  }
37
 
@@ -42,17 +42,17 @@ class PermalinkListener
42
  {
43
  add_filter(
44
  'post_type_link',
45
- [ $this, 'replaceProductLink' ],
46
  1,
47
  2
48
  );
49
  add_filter(
50
  'term_link',
51
- [ $this, 'replaceTermLink' ],
52
  0,
53
  3
54
  );
55
- add_filter( 'rewrite_rules_array', [ $this, 'addRewriteRules' ], 99 );
56
  add_action( 'pll_init', function ( $polylang ) {
57
  $this->polyLang = $polylang;
58
  } );
@@ -123,7 +123,7 @@ class PermalinkListener
123
  wp_cache_flush();
124
  global $wp_rewrite ;
125
  $feed = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
126
- $customRules = [];
127
  /**
128
  * Remove WPML filters while getting terms, to get all languages
129
  */
@@ -138,10 +138,10 @@ class PermalinkListener
138
  foreach ( $this->taxonomyOptions as $taxonomy => $option ) {
139
 
140
  if ( !empty($option) ) {
141
- $terms = get_categories( [
142
  'taxonomy' => $taxonomy,
143
  'hide_empty' => false,
144
- ] );
145
  $hierarchical = $this->isHierarchical( $option );
146
  $suffix = false;
147
  foreach ( $terms as $term ) {
24
  public function __construct()
25
  {
26
  $options = get_option( Settings::OPTIONS );
27
+ $this->options = array(
28
  'use_primary_category' => !empty($options['use_primary_category']),
29
  'product' => ( isset( $options['product'] ) ? $options['product'] : '' ),
30
  'suffix' => ( !empty($options['suffix']) ? $options['suffix'] : false ),
31
  'enable_suffix_categories' => ( isset( $options['enable_suffix_categories'] ) && !empty($options['enable_suffix_categories']) ? true : false ),
32
  'enable_suffix_products' => ( isset( $options['enable_suffix_products'] ) && !empty($options['enable_suffix_products']) ? true : false ),
33
  'sku' => ( isset( $options['sku'] ) ? $options['sku'] : '' ),
34
+ );
35
  $this->taxonomyOptions['product_cat'] = ( isset( $options['category'] ) ? $options['category'] : '' );
36
  }
37
 
42
  {
43
  add_filter(
44
  'post_type_link',
45
+ array( $this, 'replaceProductLink' ),
46
  1,
47
  2
48
  );
49
  add_filter(
50
  'term_link',
51
+ array( $this, 'replaceTermLink' ),
52
  0,
53
  3
54
  );
55
+ add_filter( 'rewrite_rules_array', array( $this, 'addRewriteRules' ), 99 );
56
  add_action( 'pll_init', function ( $polylang ) {
57
  $this->polyLang = $polylang;
58
  } );
123
  wp_cache_flush();
124
  global $wp_rewrite ;
125
  $feed = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
126
+ $customRules = array();
127
  /**
128
  * Remove WPML filters while getting terms, to get all languages
129
  */
138
  foreach ( $this->taxonomyOptions as $taxonomy => $option ) {
139
 
140
  if ( !empty($option) ) {
141
+ $terms = get_categories( array(
142
  'taxonomy' => $taxonomy,
143
  'hide_empty' => false,
144
+ ) );
145
  $hierarchical = $this->isHierarchical( $option );
146
  $suffix = false;
147
  foreach ( $terms as $term ) {
src/Updater.php CHANGED
@@ -2,74 +2,75 @@
2
 
3
  use Premmerce\UrlManager\Admin\Settings;
4
 
5
- class Updater {
6
-
7
-
8
- const CURRENT_VERSION = '2.0';
9
-
10
- const DB_OPTION = 'premmerce_permalink_manager_db_version';
11
-
12
- public function checkForUpdates() {
13
- return $this->compare(self::CURRENT_VERSION);
14
- }
15
-
16
- private function compare( $version) {
17
- $dbVersion = get_option(self::DB_OPTION, 1.1);
18
-
19
- return version_compare($dbVersion, $version, '<');
20
- }
21
-
22
- public function update() {
23
- if ($this->checkForUpdates()) {
24
- foreach ($this->getUpdates() as $version => $callback) {
25
- if ($this->compare($version)) {
26
- call_user_func($callback);
27
- }
28
- }
29
-
30
- update_option(Settings::OPTION_FLUSH, true);
31
- }
32
- }
33
-
34
- public function getUpdates() {
35
- return [
36
- '2.0' => [$this, 'update2_0'],
37
- ];
38
- }
39
-
40
- public function update2_0() {
41
-
42
- $options = get_option('premmerce_url_manager_options', []);
43
- $options12 = [
44
- 'use_primary_category' => 'on',
45
- ];
46
-
47
- $wc = get_option('woocommerce_permalinks');
48
-
49
- $showProductCats = false;
50
- if ( ! empty($wc['product_base'])) {
51
- $showProductCats = strpos($wc['product_base'], '%product_cat%') !== false;
52
- }
53
-
54
-
55
- if ( ! empty($options['remove_product_base'])) {
56
- $options12['product'] = 'slug';
57
- if ($showProductCats) {
58
- $options12['product'] = 'hierarchical';
59
- }
60
- }
61
- if ( ! empty($options['remove_category_base'])) {
62
- $options12['category'] = 'hierarchical';
63
- if ( ! empty($options['remove_category_parent_slugs'])) {
64
- $options12['category'] = 'slug';
65
-
66
- }
67
- }
68
-
69
- update_option('premmerce_permalink_manager', $options12);
70
- delete_option('premmerce_url_manager_options');
71
- delete_option(Settings::OPTION_DISABLED);
72
- update_option(self::DB_OPTION, '2.0');
73
- }
74
-
 
75
  }
2
 
3
  use Premmerce\UrlManager\Admin\Settings;
4
 
5
+ class Updater
6
+ {
7
+ const CURRENT_VERSION = '2.0';
8
+
9
+ const DB_OPTION = 'premmerce_permalink_manager_db_version';
10
+
11
+ public function checkForUpdates()
12
+ {
13
+ return $this->compare(self::CURRENT_VERSION);
14
+ }
15
+
16
+ private function compare($version)
17
+ {
18
+ $dbVersion = get_option(self::DB_OPTION, 1.1);
19
+
20
+ return version_compare($dbVersion, $version, '<');
21
+ }
22
+
23
+ public function update()
24
+ {
25
+ if ($this->checkForUpdates()) {
26
+ foreach ($this->getUpdates() as $version => $callback) {
27
+ if ($this->compare($version)) {
28
+ call_user_func($callback);
29
+ }
30
+ }
31
+
32
+ update_option(Settings::OPTION_FLUSH, true);
33
+ }
34
+ }
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
+
71
+ update_option('premmerce_permalink_manager', $options12);
72
+ delete_option('premmerce_url_manager_options');
73
+ delete_option(Settings::OPTION_DISABLED);
74
+ update_option(self::DB_OPTION, '2.0');
75
+ }
76
  }
src/UrlManagerPlugin.php CHANGED
@@ -2,7 +2,6 @@
2
 
3
  use Premmerce\UrlManager\Admin\Admin;
4
  use Premmerce\UrlManager\Admin\Settings;
5
- use Premmerce\UrlManager\Admin\WooSettings;
6
  use Premmerce\UrlManager\Frontend\Frontend;
7
  use Premmerce\SDK\V2\FileManager\FileManager;
8
  use Premmerce\UrlManager\Addons\AddonManager;
@@ -13,167 +12,171 @@ use Premmerce\SDK\V2\Notifications\AdminNotifier;
13
  *
14
  * @package Premmerce\UrlManager
15
  */
16
- class UrlManagerPlugin {
 
 
17
 
18
- const DOMAIN = 'premmerce-url-manager';
19
 
20
-
21
-
22
- const VERSION = '2.3.5';
23
-
24
- /**
25
  * FileManager
26
- *
27
- * @var FileManager
28
- */
29
- private $fileManager;
30
-
31
- /**
32
- * Notifier
33
- *
34
- * @var AdminNotifier
35
- */
36
- private $notifier;
37
-
38
- /**
39
- * PluginManager constructor.
40
- *
41
- * @param $mainFile
42
- */
43
- public function __construct( $mainFile ) {
44
- $this->fileManager = new FileManager($mainFile);
45
- $this->notifier = new AdminNotifier();
46
-
47
- add_action('init', [$this, 'loadTextDomain']);
48
- add_action('admin_init', [$this, 'checkRequirePlugins']);
49
-
50
- premmerce_wpm_fs()->add_filter('freemius_pricing_js_path', [$this, 'cutomFreemiusPricingPage']);
51
- }
52
-
53
- /**
54
- * Get Plugin Version
55
- *
56
- * @return void
57
- */
58
- public static function getPluginVersion() {
59
-
60
- if (defined('self::VERSION')) {
61
- return self::VERSION;
62
- }
63
- return '1.0.0';
64
- }
65
-
66
- /**
67
- * Custom pricing page
68
- */
69
- public function cutomFreemiusPricingPage( $default_pricing_js_path) {
70
- $pluginDir = $this->fileManager->getPluginDirectory();
71
- $pricing_js_path = $pluginDir . '/assets/admin/js/pricing-page/freemius-pricing.js';
72
-
73
- return $pricing_js_path;
74
- }
75
-
76
- /**
77
- * Run plugin part
78
- */
79
- public function run() {
80
- $valid = count($this->validateRequiredPlugins()) === 0;
81
- ( new Updater() )->update();
82
-
83
- if (is_admin()) {
84
- new Admin($this->fileManager);
85
- }
86
-
87
- if ($valid) {
88
- if ( ! is_admin()) {
89
- new Frontend();
90
- }
91
- ( new PermalinkListener() )->registerFilters();
92
- ( new AddonManager() )->initAddons();
93
- }
94
- }
95
-
96
- /**
97
- * Fired when the plugin is activated
98
- */
99
- public function activate() {
100
- flush_rewrite_rules();
101
- }
102
-
103
- /**
104
- * Fired when the plugin is deactivated
105
- */
106
- public function deactivate() {
107
- $this->deleteUsersBannerMeta();
108
- flush_rewrite_rules();
109
- }
110
-
111
- /**
112
- * Fired during plugin uninstall
113
- */
114
- public static function uninstall() {
115
- delete_option(Updater::DB_OPTION);
116
- delete_option(Settings::OPTION_FLUSH);
117
- delete_option(Settings::OPTION_DISABLED);
118
- delete_option(Settings::OPTIONS);
119
-
120
- flush_rewrite_rules();
121
- }
122
-
123
-
124
-
125
- private function deleteUsersBannerMeta() {
126
- global $wpdb;
127
-
128
- $wpdb->delete($wpdb->usermeta, ['meta_key' => Admin::META_IGNORE_BANNER]);
129
- }
130
-
131
- /**
132
- * Load plugin translations
133
- */
134
- public function loadTextDomain() {
135
- $name = $this->fileManager->getPluginName();
136
- load_plugin_textdomain('premmerce-url-manager', false, $name . '/languages/');
137
- }
138
-
139
- /**
140
- * Check required plugins and push notifications
141
- */
142
- public function checkRequirePlugins() {
143
- /* translators: %%1$s: our plugin name, %2$s another plugin name */
144
- $message = __('The %1$s plugin requires %2$s plugin to be active!', 'premmerce-url-manager');
145
-
146
- $plugins = $this->validateRequiredPlugins();
147
-
148
- if (count($plugins)) {
149
- foreach ($plugins as $plugin) {
150
- $error = sprintf($message, 'WooCommerce Permalink Manager', $plugin);
151
- $this->notifier->push($error, AdminNotifier::ERROR, false);
152
- }
153
- }
154
-
155
- }
156
-
157
- /**
158
- * Validate required plugins
159
- *
160
- * @return array
161
- */
162
- private function validateRequiredPlugins() {
163
-
164
- $plugins = [];
165
-
166
- if ( ! function_exists('is_plugin_active')) {
167
- include_once ABSPATH . 'wp-admin/includes/plugin.php';
168
- }
169
-
170
- /**
171
- * Check if WooCommerce is active
172
- **/
173
- if ( ! ( is_plugin_active('woocommerce/woocommerce.php') || is_plugin_active_for_network('woocommerce/woocommerce.php') )) {
174
- $plugins[] = '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>';
175
- }
176
-
177
- return $plugins;
178
- }
 
 
 
 
 
 
179
  }
2
 
3
  use Premmerce\UrlManager\Admin\Admin;
4
  use Premmerce\UrlManager\Admin\Settings;
 
5
  use Premmerce\UrlManager\Frontend\Frontend;
6
  use Premmerce\SDK\V2\FileManager\FileManager;
7
  use Premmerce\UrlManager\Addons\AddonManager;
12
  *
13
  * @package Premmerce\UrlManager
14
  */
15
+ class UrlManagerPlugin
16
+ {
17
+ const DOMAIN = 'premmerce-url-manager';
18
 
19
+ const VERSION = '2.3.5';
20
 
21
+ /**
 
 
 
 
22
  * FileManager
23
+ *
24
+ * @var FileManager
25
+ */
26
+ private $fileManager;
27
+
28
+ /**
29
+ * Notifier
30
+ *
31
+ * @var AdminNotifier
32
+ */
33
+ private $notifier;
34
+
35
+ /**
36
+ * PluginManager constructor.
37
+ *
38
+ * @param $mainFile
39
+ */
40
+ public function __construct($mainFile)
41
+ {
42
+ $this->fileManager = new FileManager($mainFile);
43
+ $this->notifier = new AdminNotifier();
44
+
45
+ add_action('init', array($this, 'loadTextDomain'));
46
+ add_action('admin_init', array($this, 'checkRequirePlugins'));
47
+
48
+ premmerce_wpm_fs()->add_filter('freemius_pricing_js_path', array($this, 'cutomFreemiusPricingPage'));
49
+ }
50
+
51
+ /**
52
+ * Get Plugin Version
53
+ *
54
+ * @return void
55
+ */
56
+ public static function getPluginVersion()
57
+ {
58
+ if (defined('self::VERSION')) {
59
+ return self::VERSION;
60
+ }
61
+ return '1.0.0';
62
+ }
63
+
64
+ /**
65
+ * Custom pricing page
66
+ */
67
+ public function cutomFreemiusPricingPage($default_pricing_js_path)
68
+ {
69
+ $pluginDir = $this->fileManager->getPluginDirectory();
70
+ $pricing_js_path = $pluginDir . '/assets/admin/js/pricing-page/freemius-pricing.js';
71
+
72
+ return $pricing_js_path;
73
+ }
74
+
75
+ /**
76
+ * Run plugin part
77
+ */
78
+ public function run()
79
+ {
80
+ $valid = count($this->validateRequiredPlugins()) === 0;
81
+ ( new Updater() )->update();
82
+
83
+ if (is_admin()) {
84
+ new Admin($this->fileManager);
85
+ }
86
+
87
+ if ($valid) {
88
+ if (! is_admin()) {
89
+ new Frontend();
90
+ }
91
+ ( new PermalinkListener() )->registerFilters();
92
+ ( new AddonManager() )->initAddons();
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Fired when the plugin is activated
98
+ */
99
+ public function activate()
100
+ {
101
+ flush_rewrite_rules();
102
+ }
103
+
104
+ /**
105
+ * Fired when the plugin is deactivated
106
+ */
107
+ public function deactivate()
108
+ {
109
+ $this->deleteUsersBannerMeta();
110
+ flush_rewrite_rules();
111
+ }
112
+
113
+ /**
114
+ * Fired during plugin uninstall
115
+ */
116
+ public static function uninstall()
117
+ {
118
+ delete_option(Updater::DB_OPTION);
119
+ delete_option(Settings::OPTION_FLUSH);
120
+ delete_option(Settings::OPTION_DISABLED);
121
+ delete_option(Settings::OPTIONS);
122
+
123
+ flush_rewrite_rules();
124
+ }
125
+
126
+ private function deleteUsersBannerMeta()
127
+ {
128
+ global $wpdb;
129
+
130
+ $wpdb->delete($wpdb->usermeta, array('meta_key' => Admin::META_IGNORE_BANNER));
131
+ }
132
+
133
+ /**
134
+ * Load plugin translations
135
+ */
136
+ public function loadTextDomain()
137
+ {
138
+ $name = $this->fileManager->getPluginName();
139
+ load_plugin_textdomain('premmerce-url-manager', false, $name . '/languages/');
140
+ }
141
+
142
+ /**
143
+ * Check required plugins and push notifications
144
+ */
145
+ public function checkRequirePlugins()
146
+ {
147
+ /* translators: %%1$s: our plugin name, %2$s another plugin name */
148
+ $message = __('The %1$s plugin requires %2$s plugin to be active!', 'premmerce-url-manager');
149
+
150
+ $plugins = $this->validateRequiredPlugins();
151
+
152
+ if (count($plugins)) {
153
+ foreach ($plugins as $plugin) {
154
+ $error = sprintf($message, 'WooCommerce Permalink Manager', $plugin);
155
+ $this->notifier->push($error, AdminNotifier::ERROR, false);
156
+ }
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Validate required plugins
162
+ *
163
+ * @return array
164
+ */
165
+ private function validateRequiredPlugins()
166
+ {
167
+ $plugins = array();
168
+
169
+ if (! function_exists('is_plugin_active')) {
170
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
171
+ }
172
+
173
+ /**
174
+ * Check if WooCommerce is active
175
+ **/
176
+ if (! (is_plugin_active('woocommerce/woocommerce.php') || is_plugin_active_for_network('woocommerce/woocommerce.php'))) {
177
+ $plugins[] = '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>';
178
+ }
179
+
180
+ return $plugins;
181
+ }
182
  }
vendor/autoload.php CHANGED
@@ -2,6 +2,11 @@
2
 
3
  // autoload.php @generated by Composer
4
 
 
 
 
 
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInitd57565eb5812eae38d62a7da0f230b5f::getLoader();
2
 
3
  // autoload.php @generated by Composer
4
 
5
+ if (PHP_VERSION_ID < 50600) {
6
+ echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
7
+ exit(1);
8
+ }
9
+
10
  require_once __DIR__ . '/composer/autoload_real.php';
11
 
12
+ return ComposerAutoloaderInita6026d7805fa28dd437b7e92e52cc4a1::getLoader();
vendor/composer/ClassLoader.php CHANGED
@@ -149,7 +149,7 @@ class ClassLoader
149
 
150
  /**
151
  * @return string[] Array of classname => path
152
- * @psalm-var array<string, string>
153
  */
154
  public function getClassMap()
155
  {
149
 
150
  /**
151
  * @return string[] Array of classname => path
152
+ * @psalm-return array<string, string>
153
  */
154
  public function getClassMap()
155
  {
vendor/composer/InstalledVersions.php CHANGED
@@ -21,6 +21,8 @@ use Composer\Semver\VersionParser;
21
  * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
22
  *
23
  * To require its presence, you can require `composer-runtime-api ^2.0`
 
 
24
  */
25
  class InstalledVersions
26
  {
21
  * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
22
  *
23
  * To require its presence, you can require `composer-runtime-api ^2.0`
24
+ *
25
+ * @final
26
  */
27
  class InstalledVersions
28
  {
vendor/composer/autoload_classmap.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_classmap.php @generated by Composer
4
 
5
- $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
2
 
3
  // autoload_classmap.php @generated by Composer
4
 
5
+ $vendorDir = dirname(__DIR__);
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
vendor/composer/autoload_namespaces.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_namespaces.php @generated by Composer
4
 
5
- $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
2
 
3
  // autoload_namespaces.php @generated by Composer
4
 
5
+ $vendorDir = dirname(__DIR__);
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
vendor/composer/autoload_psr4.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_psr4.php @generated by Composer
4
 
5
- $vendorDir = dirname(dirname(__FILE__));
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
2
 
3
  // autoload_psr4.php @generated by Composer
4
 
5
+ $vendorDir = dirname(__DIR__);
6
  $baseDir = dirname($vendorDir);
7
 
8
  return array(
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitd57565eb5812eae38d62a7da0f230b5f
6
  {
7
  private static $loader;
8
 
@@ -22,31 +22,12 @@ class ComposerAutoloaderInitd57565eb5812eae38d62a7da0f230b5f
22
  return self::$loader;
23
  }
24
 
25
- spl_autoload_register(array('ComposerAutoloaderInitd57565eb5812eae38d62a7da0f230b5f', 'loadClassLoader'), true, true);
26
- self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
27
- spl_autoload_unregister(array('ComposerAutoloaderInitd57565eb5812eae38d62a7da0f230b5f', 'loadClassLoader'));
28
-
29
- $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
30
- if ($useStaticLoader) {
31
- require __DIR__ . '/autoload_static.php';
32
-
33
- call_user_func(\Composer\Autoload\ComposerStaticInitd57565eb5812eae38d62a7da0f230b5f::getInitializer($loader));
34
- } else {
35
- $map = require __DIR__ . '/autoload_namespaces.php';
36
- foreach ($map as $namespace => $path) {
37
- $loader->set($namespace, $path);
38
- }
39
-
40
- $map = require __DIR__ . '/autoload_psr4.php';
41
- foreach ($map as $namespace => $path) {
42
- $loader->setPsr4($namespace, $path);
43
- }
44
-
45
- $classMap = require __DIR__ . '/autoload_classmap.php';
46
- if ($classMap) {
47
- $loader->addClassMap($classMap);
48
- }
49
- }
50
 
51
  $loader->register(true);
52
 
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInita6026d7805fa28dd437b7e92e52cc4a1
6
  {
7
  private static $loader;
8
 
22
  return self::$loader;
23
  }
24
 
25
+ spl_autoload_register(array('ComposerAutoloaderInita6026d7805fa28dd437b7e92e52cc4a1', 'loadClassLoader'), true, true);
26
+ self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27
+ spl_autoload_unregister(array('ComposerAutoloaderInita6026d7805fa28dd437b7e92e52cc4a1', 'loadClassLoader'));
28
+
29
+ require __DIR__ . '/autoload_static.php';
30
+ call_user_func(\Composer\Autoload\ComposerStaticInita6026d7805fa28dd437b7e92e52cc4a1::getInitializer($loader));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  $loader->register(true);
33
 
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInitd57565eb5812eae38d62a7da0f230b5f
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'P' =>
@@ -32,9 +32,9 @@ class ComposerStaticInitd57565eb5812eae38d62a7da0f230b5f
32
  public static function getInitializer(ClassLoader $loader)
33
  {
34
  return \Closure::bind(function () use ($loader) {
35
- $loader->prefixLengthsPsr4 = ComposerStaticInitd57565eb5812eae38d62a7da0f230b5f::$prefixLengthsPsr4;
36
- $loader->prefixDirsPsr4 = ComposerStaticInitd57565eb5812eae38d62a7da0f230b5f::$prefixDirsPsr4;
37
- $loader->classMap = ComposerStaticInitd57565eb5812eae38d62a7da0f230b5f::$classMap;
38
 
39
  }, null, ClassLoader::class);
40
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInita6026d7805fa28dd437b7e92e52cc4a1
8
  {
9
  public static $prefixLengthsPsr4 = array (
10
  'P' =>
32
  public static function getInitializer(ClassLoader $loader)
33
  {
34
  return \Closure::bind(function () use ($loader) {
35
+ $loader->prefixLengthsPsr4 = ComposerStaticInita6026d7805fa28dd437b7e92e52cc4a1::$prefixLengthsPsr4;
36
+ $loader->prefixDirsPsr4 = ComposerStaticInita6026d7805fa28dd437b7e92e52cc4a1::$prefixDirsPsr4;
37
+ $loader->classMap = ComposerStaticInita6026d7805fa28dd437b7e92e52cc4a1::$classMap;
38
 
39
  }, null, ClassLoader::class);
40
  }
vendor/composer/installed.php CHANGED
@@ -1,22 +1,22 @@
1
  <?php return array(
2
  'root' => array(
3
- 'pretty_version' => 'dev-master',
4
- 'version' => 'dev-master',
5
  'type' => 'wordpress-plugin',
6
  'install_path' => __DIR__ . '/../../',
7
  'aliases' => array(),
8
- 'reference' => '0cacf3ffbcce738a59527f661a604355eebc055d',
9
  'name' => 'premmerce/woo-permalink-manager',
10
  'dev' => false,
11
  ),
12
  'versions' => array(
13
  'premmerce/woo-permalink-manager' => array(
14
- 'pretty_version' => 'dev-master',
15
- 'version' => 'dev-master',
16
  'type' => 'wordpress-plugin',
17
  'install_path' => __DIR__ . '/../../',
18
  'aliases' => array(),
19
- 'reference' => '0cacf3ffbcce738a59527f661a604355eebc055d',
20
  'dev_requirement' => false,
21
  ),
22
  'premmerce/wordpress-sdk' => array(
1
  <?php return array(
2
  'root' => array(
3
+ 'pretty_version' => 'dev-develop',
4
+ 'version' => 'dev-develop',
5
  'type' => 'wordpress-plugin',
6
  'install_path' => __DIR__ . '/../../',
7
  'aliases' => array(),
8
+ 'reference' => '9433134395b881ae7c40ef05b73a483a104bac6a',
9
  'name' => 'premmerce/woo-permalink-manager',
10
  'dev' => false,
11
  ),
12
  'versions' => array(
13
  'premmerce/woo-permalink-manager' => array(
14
+ 'pretty_version' => 'dev-develop',
15
+ 'version' => 'dev-develop',
16
  'type' => 'wordpress-plugin',
17
  'install_path' => __DIR__ . '/../../',
18
  'aliases' => array(),
19
+ 'reference' => '9433134395b881ae7c40ef05b73a483a104bac6a',
20
  'dev_requirement' => false,
21
  ),
22
  'premmerce/wordpress-sdk' => array(
woo-permalink-manager.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Premmerce Permalink Manager Slug fix
4
+ *
5
+ * This file is intended to fix a wrong plugin slug from an older version.
6
+ *
7
+ * @since 2.3.6
8
+ */
9
+
10
+ add_action(
11
+ 'plugins_loaded',
12
+ function() {
13
+ if ( ! function_exists( 'deactivate_plugins' ) ) {
14
+ include ABSPATH . 'wp-admin/includes/plugin.php';
15
+ }
16
+
17
+ // this file
18
+ $deactivate = plugin_basename( __FILE__ );
19
+
20
+ // correct file
21
+ $activate = dirname( $deactivate ) . '/premmerce-url-manager.php';
22
+
23
+ $network_wide = is_plugin_active_for_network( $deactivate );
24
+
25
+ // don't trigger (de)activation hooks
26
+ $silent = true;
27
+
28
+ deactivate_plugins( $deactivate, $silent, $network_wide );
29
+ activate_plugins( $activate, '', $network_wide, $silent );
30
+
31
+ }
32
+ );