Changeset 759230
- Timestamp:
- 08/20/2013 12:47:31 PM (13 years ago)
- Location:
- speedy-page-redirect/trunk
- Files:
-
- 6 edited
-
languages/speedy-page-redirect-nl_NL.mo (modified) (previous)
-
languages/speedy-page-redirect-nl_NL.po (modified) (1 diff)
-
languages/speedy-page-redirect.pot (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
-
speedy-page-redirect.php (modified) (13 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
speedy-page-redirect/trunk/languages/speedy-page-redirect-nl_NL.po
r382483 r759230 3 3 "Project-Id-Version: Page Redirect\n" 4 4 "Report-Msgid-Bugs-To: \n" 5 "POT-Creation-Date: 201 1-05-05 21:13+0100\n"5 "POT-Creation-Date: 2013-08-20 14:32+0100\n" 6 6 "PO-Revision-Date: \n" 7 "Last-Translator: Geert De Deckere <geert @idoe.be>\n"7 "Last-Translator: Geert De Deckere <geertdd@gmail.com>\n" 8 8 "Language-Team: Geert De Deckere\n" 9 "Language: en\n" 9 10 "MIME-Version: 1.0\n" 10 11 "Content-Type: text/plain; charset=UTF-8\n" 11 12 "Content-Transfer-Encoding: 8bit\n" 12 "X-Poedit- Language: English\n"13 " X-Poedit-KeywordsList: __;_e;esc_attr__;esc_attr_e\n"13 "X-Poedit-KeywordsList: __;_e;_ex;_n;_nx;_x;esc_attr__;esc_attr_e;esc_attr_x;" 14 "esc_html__;esc_html_e;esc_html_x\n" 14 15 "X-Poedit-Basepath: ../\n" 16 "X-Generator: Poedit 1.5.7\n" 15 17 "X-Poedit-SearchPath-0: .\n" 16 18 17 #: page-redirect.php:4619 #: speedy-page-redirect.php:119 18 20 msgid "Permanent" 19 21 msgstr "Permanent" 20 22 21 #: page-redirect.php:4723 #: speedy-page-redirect.php:120 22 24 msgid "Temporary" 23 25 msgstr "Tijdelijk" 24 26 25 #: page-redirect.php:9827 #: speedy-page-redirect.php:156 26 28 msgid "Page Redirect" 27 29 msgstr "Pagina Redirect" 28 30 29 #: page-redirect.php:11831 #: speedy-page-redirect.php:184 30 32 msgid "Destination URL:" 31 33 msgstr "Doorsturen naar:" 32 34 33 #: page-redirect.php:12635 #: speedy-page-redirect.php:191 34 36 msgid "Type of redirect:" 35 37 msgstr "Soort redirect:" 36 37 #: page-redirect.php:13038 #, php-format39 msgid "HTTP response status code: %s"40 msgstr "HTTP response status code: %s"41 -
speedy-page-redirect/trunk/languages/speedy-page-redirect.pot
r382483 r759230 3 3 "Project-Id-Version: Page Redirect\n" 4 4 "Report-Msgid-Bugs-To: \n" 5 "POT-Creation-Date: 201 1-05-05 21:12+0100\n"5 "POT-Creation-Date: 2013-08-20 14:35+0100\n" 6 6 "PO-Revision-Date: \n" 7 "Last-Translator: Geert De Deckere <geert @idoe.be>\n"7 "Last-Translator: Geert De Deckere <geertdd@gmail.com>\n" 8 8 "Language-Team: Geert De Deckere\n" 9 "Language: en\n" 9 10 "MIME-Version: 1.0\n" 10 11 "Content-Type: text/plain; charset=UTF-8\n" 11 12 "Content-Transfer-Encoding: 8bit\n" 12 "X-Poedit- Language: English\n"13 " X-Poedit-KeywordsList: __;_e;esc_attr__;esc_attr_e\n"13 "X-Poedit-KeywordsList: __;_e;_ex;_n;_nx;_x;esc_attr__;esc_attr_e;esc_attr_x;" 14 "esc_html__;esc_html_e;esc_html_x\n" 14 15 "X-Poedit-Basepath: ../\n" 16 "X-Generator: Poedit 1.5.7\n" 15 17 "X-Poedit-SearchPath-0: .\n" 16 18 17 #: page-redirect.php:4619 #: speedy-page-redirect.php:119 18 20 msgid "Permanent" 19 21 msgstr "" 20 22 21 #: page-redirect.php:4723 #: speedy-page-redirect.php:120 22 24 msgid "Temporary" 23 25 msgstr "" 24 26 25 #: page-redirect.php:9827 #: speedy-page-redirect.php:156 26 28 msgid "Page Redirect" 27 29 msgstr "" 28 30 29 #: page-redirect.php:11831 #: speedy-page-redirect.php:184 30 32 msgid "Destination URL:" 31 33 msgstr "" 32 34 33 #: page-redirect.php:12635 #: speedy-page-redirect.php:191 34 36 msgid "Type of redirect:" 35 37 msgstr "" 36 37 #: page-redirect.php:13038 #, php-format39 msgid "HTTP response status code: %s"40 msgstr ""41 -
speedy-page-redirect/trunk/readme.txt
r484476 r759230 36 36 Example: 37 37 38 `add_filter('gdd_spr_post_types', 'gdd_spr_post_types'); 39 function gdd_spr_post_types($post_types) 40 { 38 `add_filter( 'gdd_spr_post_types', 'gdd_spr_post_types' ); 39 function gdd_spr_post_types( $post_types ) { 41 40 // Disable redirection for the "book" post type 42 unset( $post_types['book']);41 unset( $post_types['book'] ); 43 42 return $post_types; 44 43 }` … … 52 51 Example: 53 52 54 `add_filter('gdd_spr_statuses', 'gdd_spr_statuses'); 55 function gdd_spr_statuses($statuses) 56 { 53 `add_filter( 'gdd_spr_statuses', 'gdd_spr_statuses' ); 54 function gdd_spr_statuses( $statuses ) { 57 55 // Remove temporary redirection from the list 58 unset( $statuses[302]);56 unset( $statuses[302] ); 59 57 return $statuses; 60 58 }` … … 65 63 66 64 == Changelog == 65 66 = 0.4 = 67 * Improved loading of translation files. 68 * Using HTML5 "url" input type for the URL field. 69 * Made HTTP status code immediately visible in the redirection type dropdown. 70 * Applied WP coding standards. 67 71 68 72 = 0.3 = -
speedy-page-redirect/trunk/speedy-page-redirect.php
r759047 r759230 1 <?php defined( 'ABSPATH') or exit;1 <?php defined( 'ABSPATH' ) or exit; 2 2 /* 3 3 Plugin Name: Speedy Page Redirect 4 4 Plugin URI: http://wordpress.org/extend/plugins/speedy-page-redirect/ 5 5 Description: Redirect pages and posts to other locations. 6 Version: 0. 36 Version: 0.4 7 7 Author: Geert De Deckere 8 8 Author URI: http://geertdedeckere.be/ … … 36 36 * @const string 37 37 */ 38 const VERSION = '0. 3';38 const VERSION = '0.4'; 39 39 40 40 /** … … 66 66 * @return void 67 67 */ 68 public function __construct() 69 { 68 public function __construct() { 70 69 // Run update routine if needed, also upon activation 71 if (version_compare(self::VERSION, get_option('gdd_spr_version', 0), '>')) 72 { 70 if ( version_compare( self::VERSION, get_option( 'gdd_spr_version', 0 ), '>' ) ) { 73 71 $this->update(); 74 72 } 75 73 76 74 // This init action should happen after register_post_type calls: priority > 10 77 add_action( 'init', array($this, 'init'), 20);75 add_action( 'init', array( $this, 'init' ), 20 ); 78 76 } 79 77 … … 83 81 * @return void 84 82 */ 85 public function update() 86 { 83 public function update() { 87 84 // Store version of the installed plugin for future updates 88 update_option( 'gdd_spr_version', self::VERSION);85 update_option( 'gdd_spr_version', self::VERSION ); 89 86 } 90 87 … … 94 91 * @return void 95 92 */ 96 public function init() 97 { 98 // Load translated strings 99 load_plugin_textdomain('speedy-page-redirect', FALSE, dirname(plugin_basename(__FILE__)).'/languages/'); 93 public function init() { 94 // Load translations 95 $domain = 'speedy-page-redirect'; 96 $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 97 load_textdomain( $domain, WP_LANG_DIR . '/speedy-page-redirect/' . $domain . '-' . $locale . '.mo' ); 98 load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 100 99 101 100 // Automatically include all public custom post types 102 $this->post_types = array_merge(array('page' => 'page', 'post' => 'post'), get_post_types(array('_builtin' => FALSE))); 101 $this->post_types = array_merge( 102 array( 'page' => 'page', 'post' => 'post' ), 103 get_post_types( array( '_builtin' => false ) ) 104 ); 103 105 104 106 // Allow user to modify the post types 105 $this->post_types = apply_filters( 'gdd_spr_post_types', $this->post_types);107 $this->post_types = apply_filters( 'gdd_spr_post_types', $this->post_types ); 106 108 107 109 // Avoid needless work 108 if ( empty($this->post_types))110 if ( empty( $this->post_types ) ) 109 111 return; 110 112 111 113 // Mirror the post types array so we can do fast isset() checks on the keys 112 $this->post_types = array_combine( $this->post_types, $this->post_types);114 $this->post_types = array_combine( $this->post_types, $this->post_types ); 113 115 114 116 // Array with types of redirects: key = HTTP response status code, value = description 115 117 // Note: first element in the array will be selected by default 116 118 $this->statuses = array( 117 301 => sprintf( __('Permanent', 'speedy-page-redirect'), '301'),118 302 => sprintf( __('Temporary', 'speedy-page-redirect'), '302'),119 301 => sprintf( __( 'Permanent', 'speedy-page-redirect' ), '301' ), 120 302 => sprintf( __( 'Temporary', 'speedy-page-redirect' ), '302' ), 119 121 ); 120 122 121 123 // Allow user to modify the status list 122 $this->statuses = apply_filters( 'gdd_spr_statuses', $this->statuses);124 $this->statuses = apply_filters( 'gdd_spr_statuses', $this->statuses ); 123 125 124 126 // Add the link actions only for the applicable post types: pages, posts and/or custom post types 125 if (isset($this->post_types['page'])) 126 { 127 add_action('page_link', array($this, 'link'), 20, 2); 128 } 129 if (isset($this->post_types['post'])) 130 { 131 add_action('post_link', array($this, 'link'), 20, 2); 132 } 133 if (array_diff($this->post_types, array('page', 'post'))) 134 { 135 add_action('post_type_link', array($this, 'link'), 20, 2); 127 if ( isset( $this->post_types['page'] ) ) { 128 add_action( 'page_link', array( $this, 'link' ), 20, 2 ); 129 } 130 if ( isset( $this->post_types['post'] ) ) { 131 add_action( 'post_link', array( $this, 'link' ), 20, 2 ); 132 } 133 if ( array_diff( $this->post_types, array( 'page', 'post' ) ) ) { 134 add_action( 'post_type_link', array( $this, 'link' ), 20, 2 ); 136 135 } 137 136 138 137 // Action for the actual redirect 139 add_action( 'template_redirect', array($this, 'template_redirect'));138 add_action( 'template_redirect', array( $this, 'template_redirect' ) ); 140 139 141 140 // Stuff that's only required in the admin area 142 if (is_admin()) 143 { 141 if ( is_admin() ) { 144 142 // Meta box setup 145 add_action( 'add_meta_boxes', array($this, 'add_meta_boxes'));146 add_action( 'save_post', array($this, 'save_post'));143 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); 144 add_action( 'save_post', array( $this, 'save_post' ) ); 147 145 } 148 146 } … … 153 151 * @return void 154 152 */ 155 public function add_meta_boxes() 156 { 153 public function add_meta_boxes() { 157 154 // Add meta box for each post type 158 foreach ($this->post_types as $post_type) 159 { 160 add_meta_box('gdd_page_redirect', __('Page Redirect', 'speedy-page-redirect'), array($this, 'meta_box_show'), $post_type); 155 foreach ( $this->post_types as $post_type ) { 156 add_meta_box( 'gdd_page_redirect', __( 'Page Redirect', 'speedy-page-redirect' ), array( $this, 'meta_box_show' ), $post_type ); 161 157 } 162 158 } … … 168 164 * @return void 169 165 */ 170 public function meta_box_show($post) 171 { 166 public function meta_box_show( $post ) { 172 167 // Default data entered in the form 173 168 $default = array( 174 169 'url_raw' => 'http://', 175 'status' => 301,170 'status' => 301, 176 171 ); 177 172 178 173 // Load existing redirection data for this post if any 179 $data = (array) $this->get_post_data( $post->ID);174 $data = (array) $this->get_post_data( $post->ID ); 180 175 181 176 // Overwrite default values with existing ones 182 $values = array_merge( $default, $data);177 $values = array_merge( $default, $data ); 183 178 184 179 // Add a hidden nonce field for security 185 wp_nonce_field( 'gdd_spr_'.$post->ID, 'gdd_spr_nonce', FALSE);180 wp_nonce_field( 'gdd_spr_' . $post->ID, 'gdd_spr_nonce', false ); 186 181 187 182 // Output the URL field 188 183 echo '<p>'; 189 echo '<label for="gdd_spr_url">' .__('Destination URL:', 'speedy-page-redirect').'</label> ';190 echo '<input id="gdd_spr_url" name="gdd_spr_url" type=" text" value="'.esc_url($values['url_raw']).'" size="50" style="width:80%">';184 echo '<label for="gdd_spr_url">' . __( 'Destination URL:', 'speedy-page-redirect' ) . '</label> '; 185 echo '<input id="gdd_spr_url" name="gdd_spr_url" type="url" value="' . esc_url( $values['url_raw'] ) . '" size="50" style="width:80%">'; 191 186 echo '</p>'; 192 187 193 188 // Output the redirection type select list if needed 194 if (count($this->statuses) > 1) 195 { 189 if ( count( $this->statuses ) > 1 ) { 196 190 echo '<p>'; 197 echo '<label for="gdd_spr_status">' .__('Type of redirect:', 'speedy-page-redirect').'</label> ';191 echo '<label for="gdd_spr_status">' . __( 'Type of redirect:', 'speedy-page-redirect' ) . '</label> '; 198 192 echo '<select id="gdd_spr_status" name="gdd_spr_status">'; 199 foreach ($this->statuses as $status => $description) 200 { 201 echo '<option value="'.$status.'" '.selected($status, $values['status'], FALSE).' title="'.sprintf(esc_attr__('HTTP response status code: %s', 'speedy-page-redirect'), $status).'">'; 202 echo esc_html($description); 193 foreach ( $this->statuses as $status => $description ) { 194 echo '<option value="' . $status . '" ' .selected( $status, $values['status'], false ) . '>'; 195 echo esc_html( $description . ' – HTTP ' . $status ); 203 196 echo '</option>'; 204 197 } … … 214 207 * @return void 215 208 */ 216 public function save_post($post_id) 217 { 209 public function save_post( $post_id ) { 218 210 // Validate nonce 219 if ( ! isset( $_POST['gdd_spr_nonce']) || ! wp_verify_nonce($_POST['gdd_spr_nonce'], 'gdd_spr_'.$post_id))211 if ( ! isset( $_POST['gdd_spr_nonce'] ) || ! wp_verify_nonce( $_POST['gdd_spr_nonce'], 'gdd_spr_' . $post_id ) ) 220 212 return; 221 213 222 214 // Basic clean of the entered URL if any 223 $url = ( isset($_POST['gdd_spr_url'])) ? trim((string) $_POST['gdd_spr_url']) : '';215 $url = ( isset( $_POST['gdd_spr_url'] ) ) ? trim( (string) $_POST['gdd_spr_url'] ) : ''; 224 216 225 217 // A URL was entered (standalone protocols like "http://" are considered emtpy) 226 if ($url !== '' && ! preg_match('~^[-a-z0-9+.]++://$~i', $url)) 227 { 218 if ( '' !== $url && ! preg_match( '~^[-a-z0-9+.]++://$~i', $url ) ) { 228 219 // Prepare data array to store in the database 229 $data['url'] = esc_url_raw( $url);220 $data['url'] = esc_url_raw( $url ); 230 221 // Grab first status key from the list by default 231 $data['status'] = (int) key( $this->statuses);232 $data['status'] = ( ! empty( $data['status'])) ? $data['status'] : 301;222 $data['status'] = (int) key( $this->statuses ); 223 $data['status'] = ( ! empty( $data['status'] ) ) ? $data['status'] : 301; 233 224 234 225 // Overwrite the default status with the selected one if any 235 if (isset($_POST['gdd_spr_status']) && isset($this->statuses[(int) $_POST['gdd_spr_status']])) 236 { 226 if ( isset( $_POST['gdd_spr_status'] ) && isset( $this->statuses[ (int) $_POST['gdd_spr_status'] ] ) ) { 237 227 $data['status'] = (int) $_POST['gdd_spr_status']; 238 228 } 239 229 240 230 // Save the data in the postmeta table 241 update_post_meta( $post_id, '_gdd_speedy_page_redirect', $data);231 update_post_meta( $post_id, '_gdd_speedy_page_redirect', $data ); 242 232 } 243 233 // No URL entered 244 else 245 { 234 else { 246 235 // Delete any possible previous data stored for this post 247 delete_post_meta( $post_id, '_gdd_speedy_page_redirect');236 delete_post_meta( $post_id, '_gdd_speedy_page_redirect' ); 248 237 } 249 238 } … … 256 245 * @return string post URL 257 246 */ 258 public function link($url, $post) 259 { 247 public function link( $url, $post ) { 260 248 // Only continue if page redirection is enabled for this post type 261 if ( ! isset( $this->post_types[(string) get_post_type($post)]))249 if ( ! isset( $this->post_types[ (string) get_post_type( $post ) ] ) ) 262 250 return $url; 263 251 264 252 // page_link action returns ID, post_link action returns object 265 $post_id = ( isset($post->ID)) ? $post->ID : $post;253 $post_id = ( isset( $post->ID ) ) ? $post->ID : $post; 266 254 267 255 // No redirection data found 268 if ( ! $data = $this->get_post_data( $post_id))256 if ( ! $data = $this->get_post_data( $post_id ) ) 269 257 return $url; 270 258 271 259 // Only hard-code the destionation URL in case of a permanent redirect 272 if ( $data['status'] != 301)260 if ( 301 != $data['status'] ) 273 261 return $url; 274 262 … … 282 270 * @return void 283 271 */ 284 public function template_redirect() 285 { 272 public function template_redirect() { 286 273 global $post; 287 274 288 275 // Redirects only apply to pages or single posts 289 if ( ! is_page() && ! is_single() )276 if ( ! is_page() && ! is_single() ) 290 277 return; 291 278 292 279 // Only continue if page redirection is enabled for this post type 293 if ( ! isset( $this->post_types[(string) get_post_type($post)]))280 if ( ! isset( $this->post_types[ (string) get_post_type( $post ) ] ) ) 294 281 return; 295 282 296 283 // No redirection data found for this post 297 if ( ! $data = $this->get_post_data( $post->ID))284 if ( ! $data = $this->get_post_data( $post->ID ) ) 298 285 return; 299 286 300 287 // Finally do the redirect and quit 301 wp_redirect( $data['url'], $data['status']);288 wp_redirect( $data['url'], $data['status'] ); 302 289 exit; 303 290 } … … 308 295 * @param integer|object $post post ID or post object 309 296 * @param integer|object $blog blog ID or blog object 310 * @return array|NULL post redirection data for the post 311 */ 312 public function get_post_data($post, $blog = NULL) 313 { 297 * @return array|null post redirection data for the post 298 */ 299 public function get_post_data( $post, $blog = null ) { 314 300 // Clean post ID 315 $post_id = (int) ( (isset($post->ID)) ? $post->ID : $post);301 $post_id = (int) ( ( isset( $post->ID ) ) ? $post->ID : $post ); 316 302 317 303 // Clean blog ID 318 if ( ! $blog_id = (int) ((isset($blog->blog_id)) ? $blog->blog_id : $blog)) 319 { 304 if ( ! $blog_id = (int) ( ( isset( $blog->blog_id ) ) ? $blog->blog_id : $blog ) ) { 320 305 // Use current blog ID by default 321 306 global $blog_id; … … 323 308 324 309 // Load redirection data for this blog from the database 325 if ( ! isset($this->data[$blog_id])) 326 { 310 if ( ! isset( $this->data[ $blog_id ] ) ) { 327 311 // Load redirection data for all posts of this blog 328 312 global $wpdb; 329 $rows = $wpdb->get_results( 'SELECT post_id, meta_value FROM '.$wpdb->postmeta.' WHERE meta_key = "_gdd_speedy_page_redirect"');313 $rows = $wpdb->get_results( 'SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_gdd_speedy_page_redirect"' ); 330 314 331 315 // Initialize redirect data for the blog 332 $this->data[$blog_id] = array(); 333 334 foreach ($rows as $row) 335 { 316 $this->data[ $blog_id ] = array(); 317 318 foreach ( $rows as $row ) { 336 319 // Unserialize data 337 $data = unserialize( $row->meta_value);320 $data = unserialize( $row->meta_value ); 338 321 339 322 // Store the originally saved URL as raw_url … … 341 324 342 325 // Generate the full URL in case a relative URL is stored in the database 343 if (substr($data['url'], 0, 1) === '/') 344 { 345 $data['url'] = trailingslashit(get_bloginfo('url')).ltrim($data['url'], '/'); 326 if ( '/' === substr( $data['url'], 0, 1 ) ) { 327 $data['url'] = trailingslashit( get_bloginfo( 'url' ) ) . ltrim( $data['url'], '/' ); 346 328 } 347 329 348 330 // Cache redirection data in object property 349 $this->data[ $blog_id][(int) $row->post_id] = $data;331 $this->data[ $blog_id ][ (int) $row->post_id ] = $data; 350 332 } 351 333 } 352 334 353 335 // Return redirection data for post if any 354 return ( isset($this->data[$blog_id][$post_id])) ? $this->data[$blog_id][$post_id] : NULL;336 return ( isset( $this->data[ $blog_id ][ $post_id ] ) ) ? $this->data[ $blog_id ][ $post_id ] : null; 355 337 } 356 338 -
speedy-page-redirect/trunk/uninstall.php
r484476 r759230 1 <?php defined( 'WP_UNINSTALL_PLUGIN') or exit;1 <?php defined( 'WP_UNINSTALL_PLUGIN' ) or exit; 2 2 3 3 // Remove all plugin data from the database 4 4 global $wpdb; 5 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_gdd_speedy_page_redirect'");6 delete_option( 'gdd_spr_version');5 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_gdd_speedy_page_redirect'" ); 6 delete_option( 'gdd_spr_version' );
Note: See TracChangeset
for help on using the changeset viewer.