Permalink Manager Lite - Version 0.3.2

Version Description

  • Hotfix for front-end permalinks. The custom permastructures worked only in wp-admin.
Download this release

Release Info

Developer mbis
Plugin Icon 128x128 Permalink Manager Lite
Version 0.3.2
Comparing to
See all releases

Code changes from version 0.3.1 to 0.3.2

README.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: mbis
3
  Tags: urls, permalinks, slugs
4
  Requires at least: 4.0
5
- Tested up to: 4.5
6
- Stable tag: 0.3.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -70,10 +70,13 @@ After the plugin is installed you can access its dashboard from this page: `Tool
70
  1. Main dashboard.
71
  2. Find and replace section.
72
  3. Regenerate section.
73
- 4.
74
 
75
  == Changelog ==
76
 
 
 
 
77
  = 0.3.1 =
78
  * Hotfix for Posts & Pages permastructures
79
 
2
  Contributors: mbis
3
  Tags: urls, permalinks, slugs
4
  Requires at least: 4.0
5
+ Tested up to: 4.5.2
6
+ Stable tag: 0.3.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
70
  1. Main dashboard.
71
  2. Find and replace section.
72
  3. Regenerate section.
73
+ 4. Custom permastructures.
74
 
75
  == Changelog ==
76
 
77
+ = 0.3.2 =
78
+ * Hotfix for front-end permalinks. The custom permastructures worked only in wp-admin.
79
+
80
  = 0.3.1 =
81
  * Hotfix for Posts & Pages permastructures
82
 
inc/permalink-manager-wp-table.php DELETED
@@ -1,184 +0,0 @@
1
- <?php
2
- if( ! class_exists( 'WP_List_Table' ) ) {
3
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
- }
5
-
6
- /**
7
- * Create a new table class that will extend the WP_List_Table
8
- */
9
- class Permalink_Manager_Table extends WP_List_Table {
10
-
11
- public $screen_options_fields;
12
-
13
- function __construct() {
14
- global $status, $page;
15
-
16
- parent::__construct(array(
17
- 'singular' => 'slug',
18
- 'plural' => 'slugs',
19
- 'ajax' => true
20
- ));
21
-
22
- }
23
-
24
- /**
25
- * Override the parent columns method. Defines the columns to use in your listing table
26
- */
27
- public function get_columns() {
28
- $columns = array(
29
- //'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
30
- 'post_title' => __('Title', 'permalink-manager'),
31
- 'post_name' => __('Slug', 'permalink-manager'),
32
- 'post_date_gmt' => __('Date', 'permalink-manager'),
33
- 'post_permalink' => __('Permalink', 'permalink-manager'),
34
- 'post_status' => __('Post Status', 'permalink-manager'),
35
- 'post_type' => __('Post Type', 'permalink-manager')
36
- );
37
-
38
- return $columns;
39
- }
40
-
41
- /**
42
- * Hidden columns
43
- */
44
- public function get_hidden_columns() {
45
- return array('post_date_gmt');
46
- }
47
-
48
- /**
49
- * Sortable columns
50
- */
51
- public function get_sortable_columns() {
52
- return array(
53
- 'post_title' => array('post_title', false),
54
- 'post_name' => array('post_name', false),
55
- 'post_status' => array('post_status', false),
56
- 'post_type' => array('post_type', false),
57
- );
58
- }
59
-
60
- /**
61
- * Data inside the columns
62
- */
63
- public function column_default( $item, $column_name ) {
64
- switch( $column_name ) {
65
- case 'post_type':
66
- $post_type_obj = get_post_type_object( $item[ 'post_type' ] );
67
- return "{$post_type_obj->labels->singular_name}<br /><small>({$item[ $column_name ]})</small>";
68
-
69
- case 'post_status':
70
- $post_statuses_array = get_post_statuses();
71
- return "{$post_statuses_array[$item[ $column_name ]]}<br /><small>({$item[ $column_name ]})</small>";
72
-
73
- case 'post_permalink':
74
- return Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ], true) . ' <a href="' . Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ]) . '" target="_blank"><span class="dashicons dashicons-admin-links"></span></a>';
75
-
76
- case 'post_name':
77
- return '<input type="text" name="slug[' . $item[ 'ID' ] . ']" id="slug[' . $item[ 'ID' ] . ']" value="' . $item[ 'post_name' ] . '">';
78
-
79
- case 'post_title':
80
- $edit_post = $item[ 'post_title' ] . '<div class="row-actions">';
81
- $edit_post .= '<span class="edit"><a target="_blank" href="http://maciejbis.net/wp-admin/post.php?post=' . $item[ 'ID' ] . '&amp;action=edit" title="' . __('Edit', 'permalink-manager') . '">' . __('Edit', 'permalink-manager') . '</a> | </span>';
82
- $edit_post .= '<span class="view"><a target="_blank" href="' . Permalink_Manager_Helper_Functions::get_correct_permalink($item[ 'ID' ], $item[ 'post_name' ]) . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
83
- $edit_post .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
84
- $edit_post .= '</div>';
85
- return $edit_post;
86
-
87
- default:
88
- return $item[ $column_name ];
89
- }
90
- }
91
-
92
- /**
93
- * Sort the data
94
- */
95
- private function sort_data( $a, $b ) {
96
- // Set defaults
97
- $orderby = 'post_title';
98
- $order = 'asc';
99
-
100
- // If orderby is set, use this as the sort column
101
- if(!empty($_GET['orderby'])) {
102
- $orderby = $_GET['orderby'];
103
- }
104
-
105
- // If order is set use this as the order
106
- if(!empty($_GET['order'])) {
107
- $order = $_GET['order'];
108
- }
109
-
110
- $result = strnatcasecmp( $a[$orderby], $b[$orderby] );
111
-
112
- if($order === 'asc') {
113
- return $result;
114
- }
115
-
116
- return -$result;
117
- }
118
-
119
- /**
120
- * The button that allows to save updated slugs
121
- */
122
- function extra_tablenav( $which ) {
123
-
124
- $button_top = __( 'Update all slugs below', 'permalink-manager' );
125
- $button_bottom = __( 'Update all slugs above', 'permalink-manager' );
126
-
127
- echo '<div class="alignleft actions">';
128
- submit_button( ${"button_$which"}, 'primary', "update_all_slugs[{$which}]", false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
129
- echo '</div>';
130
- }
131
-
132
- /**
133
- * Prepare the items for the table to process
134
- */
135
- public function prepare_items($posts_table) {
136
- $columns = $this->get_columns();
137
- $hidden = $this->get_hidden_columns();
138
- $sortable = $this->get_sortable_columns();
139
- $currentPage = $this->get_pagenum();
140
-
141
- global $wpdb;
142
-
143
- // Load options and fields
144
- $saved_options = get_option('permalink-manager');
145
- $screen_options_fields = $this->screen_options_fields;
146
- $per_page = isset($saved_options['per_page']) ? $saved_options['per_page'] : $screen_options_fields['per_page']['default'];
147
- $post_types_array = isset($saved_options['post_types']) ? $saved_options['post_types'] : $screen_options_fields['post_types']['default'];
148
- $post_types = "'" . implode("', '", $post_types_array) . "'";
149
- $post_statuses_array = isset($saved_options['post_statuses']) ? $saved_options['post_statuses'] : $screen_options_fields['post_statuses']['default'];
150
- $post_statuses = "'" . implode("', '", $post_statuses_array) . "'";
151
-
152
- // Will be used in pagination settings
153
- $total_items = $wpdb->get_var("SELECT COUNT(id) FROM $posts_table WHERE post_status IN ($post_statuses) AND post_type IN ($post_types)");
154
-
155
- // SQL query parameters
156
- $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
157
- $orderby = (isset($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'ID';
158
- $offset = ($currentPage - 1) * $per_page;
159
-
160
- // Grab posts from database
161
- $sql_query = "SELECT * FROM $posts_table WHERE post_status IN ($post_statuses) AND post_type IN ($post_types) ORDER BY $orderby $order LIMIT $per_page OFFSET $offset";
162
- $data = $wpdb->get_results($sql_query, ARRAY_A);
163
-
164
- // Sort posts and count all posts
165
- usort( $data, array( &$this, 'sort_data' ) );
166
-
167
- $this->set_pagination_args( array(
168
- 'total_items' => $total_items,
169
- 'per_page' => $per_page
170
- ));
171
-
172
- $this->_column_headers = array($columns, $hidden, $sortable);
173
- $this->items = $data;
174
- }
175
-
176
- /**
177
- * This variable is assigned in permalink-manager.php before prepare_items() function is triggered, see permalinks_table_html() function
178
- */
179
- public function set_screen_option_fields($fields) {
180
- $this->screen_options_fields = $fields;
181
- }
182
-
183
- }
184
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
permalink-manager.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Permalink Manager
5
  * Plugin URI: http://maciejbis.net/
6
  * Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
7
- * Version: 0.3.1
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
@@ -20,7 +20,7 @@ if ( ! defined( 'WPINC' ) ) {
20
 
21
  // Define the directories used to load plugin files.
22
  define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
23
- define( 'PERMALINK_MANAGER_VERSION', '0.3.1' );
24
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
25
  define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
26
  define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
@@ -35,16 +35,21 @@ class Permalink_Manager_Class {
35
 
36
  $this->permalink_manager_options = get_option('permalink-manager');
37
 
38
- add_action( 'plugins_loaded', array($this, 'localize_me') );
39
- add_action( 'init', array($this, 'flush_rewrite_rules') );
40
- add_action( 'admin_init', array($this, 'bulk_actions') );
41
- add_action( 'admin_menu', array($this, 'add_menu_page') );
42
- add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugins_page_links') );
 
43
 
44
- add_filter( 'page_rewrite_rules', array($this, 'custom_page_rewrite_rules'), 999, 1);
45
- add_filter( 'post_rewrite_rules', array($this, 'custom_post_rewrite_rules'), 999, 1);
46
- add_filter( 'rewrite_rules_array', array($this, 'custom_cpt_rewrite_rules'), 999, 1);
 
 
 
47
  add_filter( '_get_page_link', array($this, 'custom_permalinks'), 999, 2);
 
48
  add_filter( 'post_link', array($this, 'custom_permalinks'), 999, 2);
49
  add_filter( 'post_type_link', array($this, 'custom_permalinks'), 999, 2);
50
 
@@ -647,15 +652,13 @@ class Permalink_Manager_Class {
647
  function run_permalink_manager() {
648
 
649
  // Load plugin files.
650
- if( is_admin() ) {
651
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-slug-editor.php';
652
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-base-editor.php';
653
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-screen-options.php';
654
- require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-helper-functions.php';
655
-
656
- $Permalink_Manager_Class = new Permalink_Manager_Class();
657
- $Permalink_Manager_Screen_Options = new Permalink_Manager_Screen_Options();
658
- }
659
 
660
  }
661
 
4
  * Plugin Name: Permalink Manager
5
  * Plugin URI: http://maciejbis.net/
6
  * Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
7
+ * Version: 0.3.2
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
20
 
21
  // Define the directories used to load plugin files.
22
  define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
23
+ define( 'PERMALINK_MANAGER_VERSION', '0.3.2' );
24
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
25
  define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
26
  define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
35
 
36
  $this->permalink_manager_options = get_option('permalink-manager');
37
 
38
+ if( is_admin() ) {
39
+ add_action( 'plugins_loaded', array($this, 'localize_me') );
40
+ add_action( 'init', array($this, 'flush_rewrite_rules') );
41
+ add_action( 'admin_init', array($this, 'bulk_actions') );
42
+ add_action( 'admin_menu', array($this, 'add_menu_page') );
43
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugins_page_links') );
44
 
45
+ add_filter( 'page_rewrite_rules', array($this, 'custom_page_rewrite_rules'), 999, 1);
46
+ add_filter( 'post_rewrite_rules', array($this, 'custom_post_rewrite_rules'), 999, 1);
47
+ add_filter( 'rewrite_rules_array', array($this, 'custom_cpt_rewrite_rules'), 999, 1);
48
+ }
49
+
50
+ // Public functions
51
  add_filter( '_get_page_link', array($this, 'custom_permalinks'), 999, 2);
52
+ add_filter( 'page_link', array($this, 'custom_permalinks'), 999, 2);
53
  add_filter( 'post_link', array($this, 'custom_permalinks'), 999, 2);
54
  add_filter( 'post_type_link', array($this, 'custom_permalinks'), 999, 2);
55
 
652
  function run_permalink_manager() {
653
 
654
  // Load plugin files.
655
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-slug-editor.php';
656
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-base-editor.php';
657
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-screen-options.php';
658
+ require_once PERMALINK_MANAGER_DIR . '/inc/permalink-manager-helper-functions.php';
659
+
660
+ $Permalink_Manager_Class = new Permalink_Manager_Class();
661
+ $Permalink_Manager_Screen_Options = new Permalink_Manager_Screen_Options();
 
 
662
 
663
  }
664