Version Description
- Proper linking for custom post types (insead of just a 301).
- Fixed a bug that prevented links from opening in a new window.
- Notifies people when they are editing content that uses this plugin.
- Removed the option to set redirection type. Always 301, now.
- Removed some PHP4 and WP 2.8 back compat stuff.
Download this release
Release Info
Developer | markjaquith |
Plugin | Page Links To |
Version | 2.6 |
Comparing to | |
See all releases |
Code changes from version 2.5 to 2.6
- page-links-to.php +22 -34
- readme.txt +11 -4
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.
|
7 |
Author: Mark Jaquith
|
8 |
Author URI: http://coveredwebservices.com/
|
9 |
*/
|
10 |
|
11 |
-
/* Copyright 2005-
|
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
|
@@ -25,32 +25,13 @@ Author URI: http://coveredwebservices.com/
|
|
25 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26 |
*/
|
27 |
|
28 |
-
// Compat functions for WP < 2.8
|
29 |
-
if ( !function_exists( 'esc_attr' ) ) {
|
30 |
-
function esc_attr( $attr ) {
|
31 |
-
return attribute_escape( $attr );
|
32 |
-
}
|
33 |
-
|
34 |
-
function esc_url( $url ) {
|
35 |
-
return clean_url( $url );
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
class CWS_PageLinksTo {
|
|
|
40 |
var $targets;
|
41 |
var $links;
|
42 |
|
43 |
-
/**
|
44 |
-
* PHP 4 constructor
|
45 |
-
*/
|
46 |
-
function CWS_PageLinksTo() {
|
47 |
-
return $this->__construct();
|
48 |
-
}
|
49 |
-
|
50 |
-
/**
|
51 |
-
* PHP 5 constructor
|
52 |
-
*/
|
53 |
function __construct() {
|
|
|
54 |
add_action( 'init', array( $this, 'init' ) );
|
55 |
}
|
56 |
|
@@ -63,9 +44,11 @@ class CWS_PageLinksTo {
|
|
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 |
/**
|
@@ -81,6 +64,7 @@ class CWS_PageLinksTo {
|
|
81 |
update_option( 'txfx_plt_schema_version', 3 );
|
82 |
}
|
83 |
}
|
|
|
84 |
/**
|
85 |
* Returns post ids and meta values that have a given key
|
86 |
* @param string $key post meta key
|
@@ -161,7 +145,6 @@ class CWS_PageLinksTo {
|
|
161 |
?>
|
162 |
<p>Point to this URL: <input name="txfx_links_to" type="text" style="width:75%" id="txfx_links_to" value="<?php echo esc_attr( $url ); ?>" /></p>
|
163 |
<p><label for="txfx_links_to_new_window"><input type="checkbox" name="txfx_links_to_new_window" id="txfx_links_to_new_window" value="_blank" <?php checked( '_blank', get_post_meta( $post->ID, '_links_to_target', true ) ); ?>> Open this link in a new window</label></p>
|
164 |
-
<p><label for="txfx_links_to_302"><input type="checkbox" name="txfx_links_to_302" id="txfx_links_to_302" value="302" <?php checked( '302', get_post_meta( $post->ID, '_links_to_type', true ) ); ?>> Use a temporary <code>302</code> redirect (default is a permanent <code>301</code> redirect)</label></p>
|
165 |
<?php
|
166 |
}
|
167 |
|
@@ -181,10 +164,6 @@ class CWS_PageLinksTo {
|
|
181 |
update_post_meta( $post_ID, '_links_to_target', '_blank' );
|
182 |
else
|
183 |
delete_post_meta( $post_ID, '_links_to_target' );
|
184 |
-
if ( isset( $_POST['txfx_links_to_302'] ) )
|
185 |
-
update_post_meta( $post_ID, '_links_to_type', '302' );
|
186 |
-
else
|
187 |
-
delete_post_meta( $post_ID, '_links_to_type' );
|
188 |
} else {
|
189 |
delete_post_meta( $post_ID, '_links_to' );
|
190 |
delete_post_meta( $post_ID, '_links_to_target' );
|
@@ -226,9 +205,7 @@ class CWS_PageLinksTo {
|
|
226 |
if ( !$link )
|
227 |
return;
|
228 |
|
229 |
-
|
230 |
-
$redirect_type = ( '302' == $redirect_type ) ? '302' : '301';
|
231 |
-
wp_redirect( $link, $redirect_type );
|
232 |
exit;
|
233 |
}
|
234 |
|
@@ -245,7 +222,7 @@ class CWS_PageLinksTo {
|
|
245 |
if ( !$links && !$page_links_to_target_cache )
|
246 |
return $pages;
|
247 |
|
248 |
-
$this_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
249 |
$targets = array();
|
250 |
|
251 |
foreach ( (array) $links as $id => $page ) {
|
@@ -262,7 +239,7 @@ class CWS_PageLinksTo {
|
|
262 |
foreach ( $targets as $p => $t ) {
|
263 |
$p = esc_url( $p );
|
264 |
$t = esc_attr( $t );
|
265 |
-
$pages = str_replace( '<a href="' . $p . '"
|
266 |
}
|
267 |
}
|
268 |
|
@@ -270,7 +247,6 @@ class CWS_PageLinksTo {
|
|
270 |
$pages = preg_replace( '| class="([^"]+)current_page_item"|', ' class="$1"', $pages ); // Kill default highlighting
|
271 |
$pages = preg_replace( '|<li class="([^"]+)"><a href="' . preg_quote( $current_page ) . '"|', '<li class="$1 current_page_item"><a href="' . $current_page . '"', $pages );
|
272 |
}
|
273 |
-
|
274 |
return $pages;
|
275 |
}
|
276 |
|
@@ -285,6 +261,18 @@ class CWS_PageLinksTo {
|
|
285 |
return $new_items;
|
286 |
}
|
287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
}
|
289 |
|
290 |
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.6
|
7 |
Author: Mark Jaquith
|
8 |
Author URI: http://coveredwebservices.com/
|
9 |
*/
|
10 |
|
11 |
+
/* Copyright 2005-2012 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
|
25 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26 |
*/
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
class CWS_PageLinksTo {
|
29 |
+
static $instance;
|
30 |
var $targets;
|
31 |
var $links;
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
function __construct() {
|
34 |
+
self::$instance = $this;
|
35 |
add_action( 'init', array( $this, 'init' ) );
|
36 |
}
|
37 |
|
44 |
add_action( 'template_redirect', array( $this, 'template_redirect' ) );
|
45 |
add_filter( 'page_link', array( $this, 'link' ), 20, 2 );
|
46 |
add_filter( 'post_link', array( $this, 'link' ), 20, 2 );
|
47 |
+
add_filter( 'post_type_link', array( $this, 'link', ), 20, 2 );
|
48 |
add_action( 'do_meta_boxes', array( $this, 'do_meta_boxes' ), 20, 2 );
|
49 |
add_action( 'save_post', array( $this, 'save_post' ) );
|
50 |
add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ), 10, 2 );
|
51 |
+
add_action( 'load-post.php', array( $this, 'load_post' ) );
|
52 |
}
|
53 |
|
54 |
/**
|
64 |
update_option( 'txfx_plt_schema_version', 3 );
|
65 |
}
|
66 |
}
|
67 |
+
|
68 |
/**
|
69 |
* Returns post ids and meta values that have a given key
|
70 |
* @param string $key post meta key
|
145 |
?>
|
146 |
<p>Point to this URL: <input name="txfx_links_to" type="text" style="width:75%" id="txfx_links_to" value="<?php echo esc_attr( $url ); ?>" /></p>
|
147 |
<p><label for="txfx_links_to_new_window"><input type="checkbox" name="txfx_links_to_new_window" id="txfx_links_to_new_window" value="_blank" <?php checked( '_blank', get_post_meta( $post->ID, '_links_to_target', true ) ); ?>> Open this link in a new window</label></p>
|
|
|
148 |
<?php
|
149 |
}
|
150 |
|
164 |
update_post_meta( $post_ID, '_links_to_target', '_blank' );
|
165 |
else
|
166 |
delete_post_meta( $post_ID, '_links_to_target' );
|
|
|
|
|
|
|
|
|
167 |
} else {
|
168 |
delete_post_meta( $post_ID, '_links_to' );
|
169 |
delete_post_meta( $post_ID, '_links_to_target' );
|
205 |
if ( !$link )
|
206 |
return;
|
207 |
|
208 |
+
wp_redirect( $link, 301 );
|
|
|
|
|
209 |
exit;
|
210 |
}
|
211 |
|
222 |
if ( !$links && !$page_links_to_target_cache )
|
223 |
return $pages;
|
224 |
|
225 |
+
$this_url = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
226 |
$targets = array();
|
227 |
|
228 |
foreach ( (array) $links as $id => $page ) {
|
239 |
foreach ( $targets as $p => $t ) {
|
240 |
$p = esc_url( $p );
|
241 |
$t = esc_attr( $t );
|
242 |
+
$pages = str_replace( '<a href="' . $p . '"', '<a href="' . $p . '" target="' . $t . '"', $pages );
|
243 |
}
|
244 |
}
|
245 |
|
247 |
$pages = preg_replace( '| class="([^"]+)current_page_item"|', ' class="$1"', $pages ); // Kill default highlighting
|
248 |
$pages = preg_replace( '|<li class="([^"]+)"><a href="' . preg_quote( $current_page ) . '"|', '<li class="$1 current_page_item"><a href="' . $current_page . '"', $pages );
|
249 |
}
|
|
|
250 |
return $pages;
|
251 |
}
|
252 |
|
261 |
return $new_items;
|
262 |
}
|
263 |
|
264 |
+
function load_post() {
|
265 |
+
if ( isset( $_GET['post'] ) ) {
|
266 |
+
if ( $url = get_post_meta( absint( $_GET['post'] ), '_links_to', true ) ) {
|
267 |
+
add_action( 'admin_notices', array( $this, 'notify_of_external_link' ) );
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
|
272 |
+
function notify_of_external_link() {
|
273 |
+
?><div class="updated"><p><?php _e( '<strong>Note</strong>: This content is pointing to an alternate URL. Use the “Page Links To” box to change this behavior.', 'page-links-to' ); ?></p></div><?php
|
274 |
+
}
|
275 |
+
|
276 |
}
|
277 |
|
278 |
new CWS_PageLinksTo;
|
readme.txt
CHANGED
@@ -3,14 +3,14 @@ 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.
|
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 |
|
13 |
-
This plugin allows you to make a WordPress page or post link to a URL of your choosing, instead of its WordPress page or post URL. It also will redirect people who go to the old (or "normal") URL to the new one you've chosen
|
14 |
|
15 |
This functionality is useful for setting up navigational links to non-WordPress sections of your site or to off-site resources.
|
16 |
|
@@ -44,7 +44,7 @@ Just use "#" at the link. That won't go anywhere.
|
|
44 |
|
45 |
= Can this be used to repoint categories to an arbitrary URL? =
|
46 |
|
47 |
-
|
48 |
|
49 |
= My links are sending me to http://myblog.com/www.site-i-wanted-to-link-to.com ... why? =
|
50 |
|
@@ -56,6 +56,13 @@ Yes. Linking to `/my-photos.php` is a good idea, as it'll still work if you move
|
|
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.
|
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.1
|
7 |
+
Stable tag: 2.6
|
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 |
|
13 |
+
This plugin allows you to make a WordPress page or post link to a URL of your choosing, instead of its WordPress page or post URL. It also will redirect people who go to the old (or "normal") URL to the new one you've chosen.
|
14 |
|
15 |
This functionality is useful for setting up navigational links to non-WordPress sections of your site or to off-site resources.
|
16 |
|
44 |
|
45 |
= Can this be used to repoint categories to an arbitrary URL? =
|
46 |
|
47 |
+
No.
|
48 |
|
49 |
= My links are sending me to http://myblog.com/www.site-i-wanted-to-link-to.com ... why? =
|
50 |
|
56 |
|
57 |
== Changelog ==
|
58 |
|
59 |
+
= 2.6 =
|
60 |
+
* Proper linking for custom post types (insead of just a 301).
|
61 |
+
* Fixed a bug that prevented links from opening in a new window.
|
62 |
+
* Notifies people when they are editing content that uses this plugin.
|
63 |
+
* Removed the option to set redirection type. Always 301, now.
|
64 |
+
* Removed some PHP4 and WP 2.8 back compat stuff.
|
65 |
+
|
66 |
= 2.5 =
|
67 |
* Allow all show_ui post types to use the meta box.
|
68 |
* Introduce a filter so a plugin can remove a post type from the list.
|