Premmerce Permalink Manager for WooCommerce - Version 1.0.1

Version Description

Release Date: Sep 26, 2017

  • Fixed a bug with wrong translation domain
  • Updated FileManager

=

Download this release

Release Info

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

Code changes from version 1.0 to 1.0.1

premmerce-url-manager.php CHANGED
@@ -6,16 +6,13 @@ use Premmerce\UrlManager\UrlManagerPlugin;
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+
6
  /**
7
  * WooCommerce Permalink Manager plugin
8
  *
 
 
 
9
  * @package Premmerce\UrlManager
10
  *
11
  * @wordpress-plugin
12
  * Plugin Name: WooCommerce Permalink Manager
13
  * Plugin URI: https://premmerce.com/woocommerce-permalink-manager-remove-shop-product-product-category-url/
14
  * Description: Premmerce WooCommerce Permalink Manager allows you to change WooCommerce permalink and remove product and product_category slugs from the URL.
15
+ * Version: 1.0.1
16
  * Author: premmerce
17
  * Author URI: https://premmerce.com/
18
  * License: GPL-2.0+
readme.txt CHANGED
@@ -2,8 +2,8 @@
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
@@ -16,7 +16,7 @@ This plugin allows you to configure URL generation strategy for your WooCommerce
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
@@ -33,7 +33,7 @@ Full documentation is available here: [WooCommerce Permalink Manager](https://pr
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
 
@@ -58,6 +58,13 @@ Release Date: July 24, 2017
58
 
59
  * Initial release
60
 
 
 
 
 
 
 
 
61
  == Translators ==
62
 
63
  = Available Languages =
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.2
6
+ Stable tag: 1.0.1
7
  Requires PHP: 7.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
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 “Premmerce url manager” =
20
 
21
  * Removing base from product category URL
22
  * Removing hierarchical slugs from product category URL
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 URL manager” from Plugins page
37
 
38
  == Frequently Asked Questions ==
39
 
58
 
59
  * Initial release
60
 
61
+ = 1.0.1 =
62
+
63
+ Release Date: Sep 26, 2017
64
+
65
+ * Fixed a bug with wrong translation domain
66
+ * Updated FileManager
67
+
68
  == Translators ==
69
 
70
  = Available Languages =
src/FileManager.php CHANGED
@@ -3,106 +3,122 @@
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
  }
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 string $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
+
109
+ /**
110
+ * @param string $template
111
+ * @param array $variables
112
+ *
113
+ * @return string
114
+ */
115
+ public function renderTemplate($template, array $variables = [])
116
+ {
117
+ ob_start();
118
+ $this->includeTemplate($template, $variables);
119
+ $content = ob_get_contents();
120
+ ob_end_clean();
121
+
122
+ return $content;
123
+ }
124
  }
src/UrlManagerPlugin.php CHANGED
@@ -8,109 +8,101 @@ use Premmerce\UrlManager\Frontend\Frontend;
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
  }
8
  *
9
  * @package Premmerce\UrlManager
10
  */
11
+ class UrlManagerPlugin {
12
+ const WOOCOMMERCE_PRODUCT = 'product';
13
+
14
+ const WOOCOMMERCE_CATEGORY = 'product_cat';
15
+
16
+ const DOMAIN = 'premmerce-url-manager';
17
+
18
+ const OPTION_URL = 'premmerce_url_manager_options';
19
+
20
+ const OPTION_DISABLED = 'premmerce_url_manager_disabled';
21
+
22
+ const OPTION_FLUSH = 'premmerce_url_manager_flush_rules';
23
+
24
+ /**
25
+ * @var FileManager
26
+ */
27
+ private $fileManager;
28
+
29
+ /**
30
+ * PluginManager constructor.
31
+ *
32
+ * @param FileManager $fileManager
33
+ */
34
+ public function __construct( FileManager $fileManager ) {
35
+ $this->fileManager = $fileManager;
36
+
37
+ add_action( 'init', [ $this, 'loadTextDomain' ] );
38
+
39
+ add_action( 'admin_init', [ $this, 'checkForWooCommerce' ] );
40
+ }
41
+
42
+ /**
43
+ * Run plugin part
44
+ */
45
+ public function run() {
46
+ if ( is_admin() ) {
47
+ new Admin( $this->fileManager );
48
+ } else {
49
+ new Frontend();
50
+ }
51
+ ( new PermalinkListener() )->registerFilters();
52
+ }
53
+
54
+ /**
55
+ * Fired when the plugin is activated
56
+ */
57
+ public function activate() {
58
+ if ( ! $this->checkForWooCommerce() ) {
59
+ $this->loadTextDomain();
60
+ $error_message = sprintf(
61
+ __( 'This plugin requires %s plugin to be active!', self::DOMAIN ),
62
+ '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>'
63
+ );
64
+ die( $error_message );
65
+ };
66
+
67
+ delete_option( self::OPTION_DISABLED );
68
+ flush_rewrite_rules();
69
+ }
70
+
71
+ /**
72
+ * Fired when the plugin is deactivated
73
+ */
74
+ public function deactivate() {
75
+ update_option( self::OPTION_DISABLED, true );
76
+ flush_rewrite_rules();
77
+ }
78
+
79
+ /**
80
+ * Fired during plugin uninstall
81
+ */
82
+ public static function uninstall() {
83
+ delete_option( self::OPTION_URL );
84
+ delete_option( self::OPTION_FLUSH );
85
+ delete_option( self::OPTION_DISABLED );
86
+ flush_rewrite_rules();
87
+ }
88
+
89
+ /**
90
+ * Load plugin translations
91
+ */
92
+ public function loadTextDomain() {
93
+ $name = $this->fileManager->getPluginName();
94
+ load_plugin_textdomain( self::DOMAIN, false, $name . '/languages/' );
95
+ }
96
+
97
+ /**
98
+ * Check if WooCommerce is active and deactivate plugin
99
+ */
100
+ public function checkForWooCommerce() {
101
+ $wooCommerceActive = is_plugin_active( 'woocommerce/woocommerce.php' );
102
+ if ( ! $wooCommerceActive ) {
103
+ deactivate_plugins( $this->fileManager->getMainFile() );
104
+ }
105
+
106
+ return $wooCommerceActive;
107
+ }
 
 
 
 
 
 
 
 
108
  }