Page Links To - Version 2.5

Version Description

  • Allow all show_ui post types to use the meta box.
  • Introduce a filter so a plugin can remove a post type from the list.
  • Target filtering for WordPress nav menus.
  • Silence some PHP notices. Props Ross McKay, Bill Erickson.
Download this release

Release Info

Developer markjaquith
Plugin Icon wp plugin Page Links To
Version 2.5
Comparing to
See all releases

Code changes from version 2.4.1 to 2.5

Files changed (2) hide show
  1. page-links-to.php +30 -14
  2. readme.txt +12 -5
page-links-to.php CHANGED
@@ -3,12 +3,12 @@
3
  Plugin Name: Page Links To
4
  Plugin URI: http://txfx.net/wordpress-plugins/page-links-to/
5
  Description: Allows you to point WordPress pages or posts to a URL of your choosing. Good for setting up navigational links to non-WP sections of your site or to off-site resources.
6
- Version: 2.4.1
7
  Author: Mark Jaquith
8
  Author URI: http://coveredwebservices.com/
9
  */
10
 
11
- /* Copyright 2005-2010 Mark Jaquith (email: mark.gpl@txfx.net)
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
@@ -51,7 +51,7 @@ class CWS_PageLinksTo {
51
  * PHP 5 constructor
52
  */
53
  function __construct() {
54
- add_action( 'init', array( &$this, 'init' ) );
55
  }
56
 
57
  /**
@@ -59,12 +59,13 @@ class CWS_PageLinksTo {
59
  */
60
  function init() {
61
  $this->maybe_upgrade();
62
- add_filter( 'wp_list_pages', array( &$this, 'wp_list_pages' ) );
63
- add_action( 'template_redirect', array( &$this, 'template_redirect' ) );
64
- add_filter( 'page_link', array( &$this, 'link' ), 20, 2 );
65
- add_filter( 'post_link', array( &$this, 'link' ), 20, 2 );
66
- add_action( 'do_meta_boxes', array( &$this, 'do_meta_boxes' ), 20, 2 );
67
- add_action( 'save_post', array( &$this, 'save_post' ) );
 
68
  }
69
 
70
  /**
@@ -142,8 +143,11 @@ class CWS_PageLinksTo {
142
  * @param string $context the current context
143
  */
144
  function do_meta_boxes( $page, $context ) {
145
- if ( ( 'page' === $page || 'post' === $page ) && 'advanced' === $context )
146
- add_meta_box( 'page-links-to', 'Page Links To', array( &$this, 'meta_box' ), $page, 'advanced', 'low' );
 
 
 
147
  }
148
 
149
  function meta_box() {
@@ -167,7 +171,7 @@ class CWS_PageLinksTo {
167
  * @return int the post ID that was passed in
168
  */
169
  function save_post( $post_ID ) {
170
- if ( wp_verify_nonce( $_REQUEST['_txfx_pl2_nonce'], 'txfx_plt' ) ) {
171
  if ( isset( $_POST['txfx_links_to'] ) && strlen( $_POST['txfx_links_to'] ) > 0 && $_POST['txfx_links_to'] !== 'http://' ) {
172
  $link = stripslashes( $_POST['txfx_links_to'] );
173
  if ( 0 === strpos( $link, 'www.' ) )
@@ -195,14 +199,14 @@ class CWS_PageLinksTo {
195
  * @param string $link the URL for the post or page
196
  * @param int|object $post Either a post ID or a post object
197
  * @return string output URL
198
- */
199
  function link( $link, $post ) {
200
  $links = $this->get_links();
201
 
202
  // Really strange, but page_link gives us an ID and post_link gives us a post object
203
  $id = ( is_object( $post ) && $post->ID ) ? $post->ID : $post;
204
 
205
- if ( $links[$id] )
206
  $link = esc_url( $links[$id] );
207
 
208
  return $link;
@@ -234,6 +238,7 @@ class CWS_PageLinksTo {
234
  * @return string the modified HTML block
235
  */
236
  function wp_list_pages( $pages ) {
 
237
  $links = $this->get_links();
238
  $page_links_to_target_cache = $this->get_targets();
239
 
@@ -269,6 +274,17 @@ class CWS_PageLinksTo {
269
  return $pages;
270
  }
271
 
 
 
 
 
 
 
 
 
 
 
 
272
  }
273
 
274
  new CWS_PageLinksTo;
3
  Plugin Name: Page Links To
4
  Plugin URI: http://txfx.net/wordpress-plugins/page-links-to/
5
  Description: Allows you to point WordPress pages or posts to a URL of your choosing. Good for setting up navigational links to non-WP sections of your site or to off-site resources.
6
+ Version: 2.5
7
  Author: Mark Jaquith
8
  Author URI: http://coveredwebservices.com/
9
  */
10
 
11
+ /* Copyright 2005-2011 Mark Jaquith
12
 
13
  This program is free software; you can redistribute it and/or modify
14
  it under the terms of the GNU General Public License as published by
51
  * PHP 5 constructor
52
  */
53
  function __construct() {
54
+ add_action( 'init', array( $this, 'init' ) );
55
  }
56
 
57
  /**
59
  */
60
  function init() {
61
  $this->maybe_upgrade();
62
+ add_filter( 'wp_list_pages', array( $this, 'wp_list_pages' ) );
63
+ add_action( 'template_redirect', array( $this, 'template_redirect' ) );
64
+ add_filter( 'page_link', array( $this, 'link' ), 20, 2 );
65
+ add_filter( 'post_link', array( $this, 'link' ), 20, 2 );
66
+ add_action( 'do_meta_boxes', array( $this, 'do_meta_boxes' ), 20, 2 );
67
+ add_action( 'save_post', array( $this, 'save_post' ) );
68
+ add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ), 10, 2 );
69
  }
70
 
71
  /**
143
  * @param string $context the current context
144
  */
145
  function do_meta_boxes( $page, $context ) {
146
+ // Plugins that use custom post types can use this filter to hide the PLT UI in their post type.
147
+ $plt_post_types = apply_filters( 'page-links-to-post-types', array_keys( get_post_types( array('show_ui' => true ) ) ) );
148
+
149
+ if ( in_array( $page, $plt_post_types ) && 'advanced' === $context )
150
+ add_meta_box( 'page-links-to', 'Page Links To', array( $this, 'meta_box' ), $page, 'advanced', 'low' );
151
  }
152
 
153
  function meta_box() {
171
  * @return int the post ID that was passed in
172
  */
173
  function save_post( $post_ID ) {
174
+ if ( isset( $_REQUEST['_txfx_pl2_nonce'] ) && wp_verify_nonce( $_REQUEST['_txfx_pl2_nonce'], 'txfx_plt' ) ) {
175
  if ( isset( $_POST['txfx_links_to'] ) && strlen( $_POST['txfx_links_to'] ) > 0 && $_POST['txfx_links_to'] !== 'http://' ) {
176
  $link = stripslashes( $_POST['txfx_links_to'] );
177
  if ( 0 === strpos( $link, 'www.' ) )
199
  * @param string $link the URL for the post or page
200
  * @param int|object $post Either a post ID or a post object
201
  * @return string output URL
202
+ */
203
  function link( $link, $post ) {
204
  $links = $this->get_links();
205
 
206
  // Really strange, but page_link gives us an ID and post_link gives us a post object
207
  $id = ( is_object( $post ) && $post->ID ) ? $post->ID : $post;
208
 
209
+ if ( isset( $links[$id] ) && $links[$id] )
210
  $link = esc_url( $links[$id] );
211
 
212
  return $link;
238
  * @return string the modified HTML block
239
  */
240
  function wp_list_pages( $pages ) {
241
+ $highlight = false;
242
  $links = $this->get_links();
243
  $page_links_to_target_cache = $this->get_targets();
244
 
274
  return $pages;
275
  }
276
 
277
+ function wp_nav_menu_objects( $items, $args ) {
278
+ $page_links_to_target_cache = $this->get_targets();
279
+ $new_items = array();
280
+ foreach ( $items as $item ) {
281
+ if ( isset( $page_links_to_target_cache[$item->object_id] ) )
282
+ $item->target = $page_links_to_target_cache[$item->object_id];
283
+ $new_items[] = $item;
284
+ }
285
+ return $new_items;
286
+ }
287
+
288
  }
289
 
290
  new CWS_PageLinksTo;
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
- === Plugin Name ===
2
  Contributors: markjaquith
3
  Donate link: http://txfx.net/wordpress-plugins/donate
4
  Tags: page, redirect, link, external link, repoint
5
- Requires at least: 2.7
6
- Tested up to: 3.2
7
- Stable tag: 2.4.1
8
 
9
- Lets you make a WordPress page or post link to a URL of your choosing, instead of its WordPress post or page.
10
 
11
  == Description ==
12
 
@@ -56,8 +56,15 @@ Yes. Linking to `/my-photos.php` is a good idea, as it'll still work if you move
56
 
57
  == Changelog ==
58
 
 
 
 
 
 
 
59
  = 2.4.1 =
60
  * Fixed typo that was preventing 302 redirects from working. props Ryan Murphy.
 
61
 
62
  = 2.4 =
63
  * Rewrote using Singleton best practices
1
+ === Page Links To ===
2
  Contributors: markjaquith
3
  Donate link: http://txfx.net/wordpress-plugins/donate
4
  Tags: page, redirect, link, external link, repoint
5
+ Requires at least: 3.0
6
+ Tested up to: 3.3
7
+ Stable tag: 2.5
8
 
9
+ Lets you make a WordPress page (or other content type) link to an external URL of your choosing, instead of its WordPress URL.
10
 
11
  == Description ==
12
 
56
 
57
  == Changelog ==
58
 
59
+ = 2.5 =
60
+ * Allow all show_ui post types to use the meta box.
61
+ * Introduce a filter so a plugin can remove a post type from the list.
62
+ * Target filtering for WordPress nav menus.
63
+ * Silence some PHP notices. Props Ross McKay, Bill Erickson.
64
+
65
  = 2.4.1 =
66
  * Fixed typo that was preventing 302 redirects from working. props Ryan Murphy.
67
+ * Fixed a random PHP notice
68
 
69
  = 2.4 =
70
  * Rewrote using Singleton best practices