Safe Redirect Manager - Version 1.2

Version Description

  • safe-redirect-manager.php - manage_options capabilitiy required to use redirect manager, remove checkbox column, hide view switcher, fix search feature, hide privacy stuff for bulk edit
Download this release

Release Info

Developer tlovett1
Plugin Icon 128x128 Safe Redirect Manager
Version 1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.2

Files changed (4) hide show
  1. readme.txt +8 -0
  2. safe-redirect-manager.php +113 -5
  3. screenshot-1.png +0 -0
  4. screenshot-2.png +0 -0
readme.txt CHANGED
@@ -17,8 +17,16 @@ Safe Redirect Manager is a HTTP redirect manager for WordPress. An easy-to-use U
17
 
18
  Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
19
 
 
 
 
 
 
20
  == Changelog ==
21
 
 
 
 
22
  = 1.1 =
23
  * safe-redirect-manager.php - plugin_url() used properly, is_plugin_page function
24
 
17
 
18
  Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.
19
 
20
+ == Screenshots ==
21
+
22
+ 1. This view shows all your redirects. You can filter them by date or even search through them.
23
+ 2. This is the edit redirect page. Specify a "from" path, "to" path/URL, and a status code. You can schedule redirects for later dates just like posts.
24
+
25
  == Changelog ==
26
 
27
+ = 1.2 =
28
+ * safe-redirect-manager.php - manage_options capabilitiy required to use redirect manager, remove checkbox column, hide view switcher, fix search feature, hide privacy stuff for bulk edit
29
+
30
  = 1.1 =
31
  * safe-redirect-manager.php - plugin_url() used properly, is_plugin_page function
32
 
safe-redirect-manager.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Safe Redirect Manager
4
  Plugin URI: http://www.10up.com
5
  Description: Easily and safely manage HTTP redirects.
6
  Author: Taylor Lovett (10up LLC), VentureBeat
7
- Version: 1.1
8
  Author URI: http://www.10up.com
9
 
10
  GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
@@ -66,11 +66,102 @@ class SRM_Safe_Redirect_Manager {
66
  add_action( 'admin_print_styles-edit.php', array( $this, 'action_print_logo_css' ), 10, 1 );
67
  add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
68
  add_action( 'admin_print_styles-post-new.php', array( $this, 'action_print_logo_css' ), 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
 
71
  /**
72
  * Swap tools logo for plugin logo
73
  *
 
74
  * @uses plugins_url
75
  * @return void
76
  */
@@ -82,7 +173,7 @@ class SRM_Safe_Redirect_Manager {
82
  background: url("<?php echo plugins_url( 'images/icon32x32.png', __FILE__ ); ?>") no-repeat top left !important;
83
  margin-right: 0;
84
  }
85
- #visibility {
86
  display: none;
87
  }
88
  </style>
@@ -93,6 +184,7 @@ class SRM_Safe_Redirect_Manager {
93
  /**
94
  * Removes bulk actions from post manager
95
  *
 
96
  * @return array
97
  */
98
  public function filter_bulk_actions() {
@@ -199,7 +291,7 @@ class SRM_Safe_Redirect_Manager {
199
  * @since 1.0
200
  * @param string $title
201
  * @param int $post_id
202
- * @uses is_admin
203
  * @return string
204
  */
205
  public function filter_admin_title( $title, $post_id ) {
@@ -297,9 +389,12 @@ class SRM_Safe_Redirect_Manager {
297
  $columns['title'] = __( 'Redirect From', 'safe-redirect-manager' );
298
 
299
  // Move date column to the back
300
- unset($columns['date']);
301
  $columns['date'] = __( 'Date', 'safe-redirect-manager' );
302
 
 
 
 
303
  return $columns;
304
  }
305
 
@@ -342,7 +437,7 @@ class SRM_Safe_Redirect_Manager {
342
  * Registers post types for plugin
343
  *
344
  * @since 1.0
345
- * @uses register_post_type, _x, plugins_url
346
  * @return void
347
  */
348
  public function action_register_post_types() {
@@ -361,6 +456,18 @@ class SRM_Safe_Redirect_Manager {
361
  'parent_item_colon' => '',
362
  'menu_name' => __( 'Safe Redirect Manager', 'safe-redirect-manager' )
363
  );
 
 
 
 
 
 
 
 
 
 
 
 
364
  $redirect_args = array(
365
  'labels' => $redirect_labels,
366
  'public' => false,
@@ -370,6 +477,7 @@ class SRM_Safe_Redirect_Manager {
370
  'query_var' => false,
371
  'rewrite' => false,
372
  'capability_type' => 'post',
 
373
  'has_archive' => false,
374
  'hierarchical' => false,
375
  'register_meta_box_cb' => array( $this, 'action_redirect_rule_metabox' ),
4
  Plugin URI: http://www.10up.com
5
  Description: Easily and safely manage HTTP redirects.
6
  Author: Taylor Lovett (10up LLC), VentureBeat
7
+ Version: 1.2
8
  Author URI: http://www.10up.com
9
 
10
  GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
66
  add_action( 'admin_print_styles-edit.php', array( $this, 'action_print_logo_css' ), 10, 1 );
67
  add_action( 'admin_print_styles-post.php', array( $this, 'action_print_logo_css' ), 10, 1 );
68
  add_action( 'admin_print_styles-post-new.php', array( $this, 'action_print_logo_css' ), 10, 1 );
69
+
70
+ // Search filters
71
+ add_filter( 'posts_join', array( $this, 'filter_search_join' ) );
72
+ add_filter( 'posts_where', array( $this, 'filter_search_where' ) );
73
+ add_filter( 'posts_distinct', array( $this, 'filter_search_distinct' ) );
74
+ }
75
+
76
+ /**
77
+ * Join posts table with postmeta table on search
78
+ *
79
+ * @since 1.2
80
+ * @param string $join
81
+ * @uses get_query_var
82
+ * @return string
83
+ */
84
+ public function filter_search_join( $join ) {
85
+ if ( $this->redirect_post_type != get_query_var( 'post_type' ) )
86
+ return $join;
87
+
88
+ global $wpdb;
89
+
90
+ $s = get_query_var( 's' );
91
+ if ( ! empty( $s ) ) {
92
+ $join .= " LEFT JOIN $wpdb->postmeta AS m ON ($wpdb->posts.ID = m.post_id) ";
93
+ }
94
+ return $join;
95
+ }
96
+
97
+ /**
98
+ * Return distinct search results
99
+ *
100
+ * @param string $distinct
101
+ * return string
102
+ */
103
+ public function filter_search_distinct( $distinct ) {
104
+ if ( $this->redirect_post_type != get_query_var( 'post_type' ) )
105
+ return $distinct;
106
+
107
+ return 'DISTINCT';
108
+ }
109
+
110
+ /**
111
+ * Join posts table with postmeta table on search
112
+ *
113
+ * @since 1.2
114
+ * @param string $where
115
+ * @uses is_search, get_query_var
116
+ * @return string
117
+ */
118
+ public function filter_search_where( $where ) {
119
+ if ( $this->redirect_post_type != get_query_var( 'post_type' ) || ! is_search() || empty( $where ) )
120
+ return $where;
121
+
122
+ $exact = get_query_var( 'exact' );
123
+ $n = ( ! empty( $exact ) ) ? '' : '%';
124
+
125
+ $search = '';
126
+ $seperator = '';
127
+ $terms = $this->get_search_terms();
128
+ $search .= '(';
129
+
130
+ // we check the meta values against each term in the search
131
+ foreach ( $terms as $term ) {
132
+ $search .= $seperator;
133
+ $search .= sprintf( "( ( m.meta_value LIKE '%s%s%s' AND m.meta_key = '%s') OR ( m.meta_value LIKE '%s%s%s' AND m.meta_key = '%s') )", $n, $term, $n, $this->meta_key_redirect_from, $n, $term, $n, $this->meta_key_redirect_to );
134
+ $seperator = ' OR ';
135
+ }
136
+
137
+ $search .= ')';
138
+
139
+ $where = preg_replace( '/\(\(\(.*?\)\)\)/is', '((' . $search . '))', $where );
140
+
141
+ return $where;
142
+ }
143
+
144
+ /**
145
+ * Get an array of search terms
146
+ *
147
+ * @since 1.2
148
+ * @uses get_query_var
149
+ * @return array
150
+ */
151
+ private function get_search_terms() {
152
+ $s = get_query_var( 's' );
153
+
154
+ if ( ! empty( $s ) ) {
155
+ preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', stripslashes( $s ), $matches );
156
+ $search_terms = array_map( create_function( '$a', 'return trim( $a, "\\"\'\\n\\r " );' ), $matches[0] );
157
+ }
158
+ return $search_terms;
159
  }
160
 
161
  /**
162
  * Swap tools logo for plugin logo
163
  *
164
+ * @since 1.1
165
  * @uses plugins_url
166
  * @return void
167
  */
173
  background: url("<?php echo plugins_url( 'images/icon32x32.png', __FILE__ ); ?>") no-repeat top left !important;
174
  margin-right: 0;
175
  }
176
+ #visibility, .view-switch, .posts .inline-edit-col-left .inline-edit-group {
177
  display: none;
178
  }
179
  </style>
184
  /**
185
  * Removes bulk actions from post manager
186
  *
187
+ * @since 1.0
188
  * @return array
189
  */
190
  public function filter_bulk_actions() {
291
  * @since 1.0
292
  * @param string $title
293
  * @param int $post_id
294
+ * @uses is_admin, get_post_meta
295
  * @return string
296
  */
297
  public function filter_admin_title( $title, $post_id ) {
389
  $columns['title'] = __( 'Redirect From', 'safe-redirect-manager' );
390
 
391
  // Move date column to the back
392
+ unset( $columns['date'] );
393
  $columns['date'] = __( 'Date', 'safe-redirect-manager' );
394
 
395
+ // get rid of checkboxes
396
+ unset( $columns['cb'] );
397
+
398
  return $columns;
399
  }
400
 
437
  * Registers post types for plugin
438
  *
439
  * @since 1.0
440
+ * @uses register_post_type, _x, plugins_url, apply_filters
441
  * @return void
442
  */
443
  public function action_register_post_types() {
456
  'parent_item_colon' => '',
457
  'menu_name' => __( 'Safe Redirect Manager', 'safe-redirect-manager' )
458
  );
459
+ $redirect_capability = 'manage_options';
460
+ $redirect_capability = apply_filters( 'srm_restrict_to_capability', $redirect_capability );
461
+ $capabilities = array(
462
+ 'edit_post' => $redirect_capability,
463
+ 'read_post' => $redirect_capability,
464
+ 'delete_post' => $redirect_capability,
465
+ 'edit_posts' => $redirect_capability,
466
+ 'edit_others_posts' => $redirect_capability,
467
+ 'publish_posts' => $redirect_capability,
468
+ 'read_private_posts' => $redirect_capability
469
+ );
470
+
471
  $redirect_args = array(
472
  'labels' => $redirect_labels,
473
  'public' => false,
477
  'query_var' => false,
478
  'rewrite' => false,
479
  'capability_type' => 'post',
480
+ 'capabilities' => $capabilities,
481
  'has_archive' => false,
482
  'hierarchical' => false,
483
  'register_meta_box_cb' => array( $this, 'action_redirect_rule_metabox' ),
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file