Version Description
- Only rely on an internal cache for
wp_list_pages()processing, and time-limit the cache. - Work around some weird edge cases
Download this release
Release Info
| Developer | markjaquith |
| Plugin | |
| Version | 2.9.3 |
| Comparing to | |
| See all releases | |
Code changes from version 2.9.2 to 2.9.3
- page-links-to.php +30 -25
- readme.txt +6 -2
page-links-to.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 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.9.
|
| 7 |
Author: Mark Jaquith
|
| 8 |
Author URI: http://coveredwebservices.com/
|
| 9 |
Text Domain: page-links-to
|
|
@@ -130,6 +130,19 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 130 |
return $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $key ) );
|
| 131 |
}
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
/**
|
| 134 |
* Returns all links for the current site
|
| 135 |
*
|
|
@@ -144,7 +157,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 144 |
$links[ intval( $link->post_id ) ] = $link->meta_value;
|
| 145 |
}
|
| 146 |
}
|
| 147 |
-
set_transient( self::LINKS_CACHE_KEY, $links );
|
| 148 |
}
|
| 149 |
return $links;
|
| 150 |
}
|
|
@@ -156,11 +169,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 156 |
* @return mixed either a URL or false
|
| 157 |
*/
|
| 158 |
function get_link( $post_id ) {
|
| 159 |
-
|
| 160 |
-
if ( isset( $links[$post_id] ) )
|
| 161 |
-
return $links[$post_id];
|
| 162 |
-
else
|
| 163 |
-
return false;
|
| 164 |
}
|
| 165 |
|
| 166 |
/**
|
|
@@ -177,7 +186,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 177 |
$targets[ intval( $target->post_id ) ] = true;
|
| 178 |
}
|
| 179 |
}
|
| 180 |
-
set_transient( self::TARGETS_CACHE_KEY, $targets );
|
| 181 |
}
|
| 182 |
return $targets;
|
| 183 |
}
|
|
@@ -189,11 +198,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 189 |
* @return bool whether it should open in a new tab
|
| 190 |
*/
|
| 191 |
function get_target( $post_id ) {
|
| 192 |
-
|
| 193 |
-
if ( isset( $targets[$post_id] ) )
|
| 194 |
-
return true;
|
| 195 |
-
else
|
| 196 |
-
return false;
|
| 197 |
}
|
| 198 |
|
| 199 |
/**
|
|
@@ -220,7 +225,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 220 |
echo '<p>';
|
| 221 |
wp_nonce_field( 'cws_plt_' . $post->ID, '_cws_plt_nonce', false, true );
|
| 222 |
echo '</p>';
|
| 223 |
-
$url =
|
| 224 |
if ( ! $url ) {
|
| 225 |
$linked = false;
|
| 226 |
$url = 'http://';
|
|
@@ -233,7 +238,7 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 233 |
<p><label><input type="radio" id="cws-links-to-choose-custom" name="cws_links_to_choice" value="custom" <?php checked( $linked ); ?> /> <?php _e( 'A custom URL', 'page-links-to' ); ?></label></p>
|
| 234 |
<div style="webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin-left: 30px;" id="cws-links-to-custom-section" class="<?php echo ! $linked ? 'hide-if-js' : ''; ?>">
|
| 235 |
<p><input name="cws_links_to" type="text" style="width:75%" id="cws-links-to" value="<?php echo esc_attr( $url ); ?>" /></p>
|
| 236 |
-
<p><label for="cws-links-to-new-tab"><input type="checkbox" name="cws_links_to_new_tab" id="cws-links-to-new-tab" value="_blank" <?php checked(
|
| 237 |
</div>
|
| 238 |
<script src="<?php echo trailingslashit( plugin_dir_url( self::FILE ) ) . 'js/page-links-to.js?v=4'; ?>"></script>
|
| 239 |
<?php
|
|
@@ -438,29 +443,30 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 438 |
*/
|
| 439 |
function wp_list_pages( $pages ) {
|
| 440 |
$highlight = false;
|
|
|
|
|
|
|
| 441 |
$links = $this->get_links();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
if ( ! $links )
|
| 444 |
return $pages;
|
| 445 |
|
| 446 |
$this_url = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
| 447 |
-
$targets = array();
|
| 448 |
|
| 449 |
foreach ( (array) $links as $id => $page ) {
|
| 450 |
-
if ( $this->get_target( $id ) )
|
| 451 |
-
$targets[$page] = '_blank';
|
| 452 |
-
|
| 453 |
if ( str_replace( 'http://www.', 'http://', $this_url ) === str_replace( 'http://www.', 'http://', $page ) || ( is_home() && str_replace( 'http://www.', 'http://', trailingslashit( get_bloginfo( 'url' ) ) ) === str_replace( 'http://www.', 'http://', trailingslashit( $page ) ) ) ) {
|
| 454 |
$highlight = true;
|
| 455 |
$current_page = esc_url( $page );
|
| 456 |
}
|
| 457 |
}
|
| 458 |
|
| 459 |
-
if ( count( $
|
| 460 |
-
foreach ( $
|
| 461 |
$p = esc_url( $p );
|
| 462 |
-
$
|
| 463 |
-
$pages = str_replace( '<a href="' . $p . '"', '<a href="' . $p . '" target="' . $t . '"', $pages );
|
| 464 |
}
|
| 465 |
}
|
| 466 |
|
|
@@ -492,9 +498,8 @@ class CWS_PageLinksTo extends WP_Stack_Plugin {
|
|
| 492 |
*/
|
| 493 |
function load_post() {
|
| 494 |
if ( isset( $_GET['post'] ) ) {
|
| 495 |
-
if (
|
| 496 |
$this->hook( 'admin_notices', 'notify_of_external_link' );
|
| 497 |
-
}
|
| 498 |
}
|
| 499 |
}
|
| 500 |
|
| 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.9.3
|
| 7 |
Author: Mark Jaquith
|
| 8 |
Author URI: http://coveredwebservices.com/
|
| 9 |
Text Domain: page-links-to
|
| 130 |
return $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $key ) );
|
| 131 |
}
|
| 132 |
|
| 133 |
+
/**
|
| 134 |
+
* Returns a single piece of post meta
|
| 135 |
+
* @param integer $post_id a post ID
|
| 136 |
+
* @param string $key a post meta key
|
| 137 |
+
* @return string|false the post meta, or false, if it doesn't exist
|
| 138 |
+
*/
|
| 139 |
+
function get_post_meta( $post_id, $key ) {
|
| 140 |
+
$meta = get_post_meta( absint( $post_id ), $key, true );
|
| 141 |
+
if ( '' === $meta )
|
| 142 |
+
return false;
|
| 143 |
+
return $meta;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
/**
|
| 147 |
* Returns all links for the current site
|
| 148 |
*
|
| 157 |
$links[ intval( $link->post_id ) ] = $link->meta_value;
|
| 158 |
}
|
| 159 |
}
|
| 160 |
+
set_transient( self::LINKS_CACHE_KEY, $links, 10 * 60 );
|
| 161 |
}
|
| 162 |
return $links;
|
| 163 |
}
|
| 169 |
* @return mixed either a URL or false
|
| 170 |
*/
|
| 171 |
function get_link( $post_id ) {
|
| 172 |
+
return $this->get_post_meta( $post_id, self::LINK_META_KEY );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
|
| 175 |
/**
|
| 186 |
$targets[ intval( $target->post_id ) ] = true;
|
| 187 |
}
|
| 188 |
}
|
| 189 |
+
set_transient( self::TARGETS_CACHE_KEY, $targets, 10 * 60 );
|
| 190 |
}
|
| 191 |
return $targets;
|
| 192 |
}
|
| 198 |
* @return bool whether it should open in a new tab
|
| 199 |
*/
|
| 200 |
function get_target( $post_id ) {
|
| 201 |
+
return (bool) $this->get_post_meta( $post_id, self::TARGET_META_KEY );
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
}
|
| 203 |
|
| 204 |
/**
|
| 225 |
echo '<p>';
|
| 226 |
wp_nonce_field( 'cws_plt_' . $post->ID, '_cws_plt_nonce', false, true );
|
| 227 |
echo '</p>';
|
| 228 |
+
$url = $this->get_link( $post->ID );
|
| 229 |
if ( ! $url ) {
|
| 230 |
$linked = false;
|
| 231 |
$url = 'http://';
|
| 238 |
<p><label><input type="radio" id="cws-links-to-choose-custom" name="cws_links_to_choice" value="custom" <?php checked( $linked ); ?> /> <?php _e( 'A custom URL', 'page-links-to' ); ?></label></p>
|
| 239 |
<div style="webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin-left: 30px;" id="cws-links-to-custom-section" class="<?php echo ! $linked ? 'hide-if-js' : ''; ?>">
|
| 240 |
<p><input name="cws_links_to" type="text" style="width:75%" id="cws-links-to" value="<?php echo esc_attr( $url ); ?>" /></p>
|
| 241 |
+
<p><label for="cws-links-to-new-tab"><input type="checkbox" name="cws_links_to_new_tab" id="cws-links-to-new-tab" value="_blank" <?php checked( (bool) $this->get_target( $post->ID ) ); ?>> <?php _e( 'Open this link in a new tab', 'page-links-to' ); ?></label></p>
|
| 242 |
</div>
|
| 243 |
<script src="<?php echo trailingslashit( plugin_dir_url( self::FILE ) ) . 'js/page-links-to.js?v=4'; ?>"></script>
|
| 244 |
<?php
|
| 443 |
*/
|
| 444 |
function wp_list_pages( $pages ) {
|
| 445 |
$highlight = false;
|
| 446 |
+
|
| 447 |
+
// We use the "fetch all" versions here, because the pages might not be queried here
|
| 448 |
$links = $this->get_links();
|
| 449 |
+
$targets = $this->get_targets();
|
| 450 |
+
$targets_by_url = array();
|
| 451 |
+
foreach( array_keys( $targets ) as $targeted_id )
|
| 452 |
+
$targets_by_url[$links[$targeted_id]] = true;
|
| 453 |
|
| 454 |
if ( ! $links )
|
| 455 |
return $pages;
|
| 456 |
|
| 457 |
$this_url = ( is_ssl() ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|
|
|
| 458 |
|
| 459 |
foreach ( (array) $links as $id => $page ) {
|
|
|
|
|
|
|
|
|
|
| 460 |
if ( str_replace( 'http://www.', 'http://', $this_url ) === str_replace( 'http://www.', 'http://', $page ) || ( is_home() && str_replace( 'http://www.', 'http://', trailingslashit( get_bloginfo( 'url' ) ) ) === str_replace( 'http://www.', 'http://', trailingslashit( $page ) ) ) ) {
|
| 461 |
$highlight = true;
|
| 462 |
$current_page = esc_url( $page );
|
| 463 |
}
|
| 464 |
}
|
| 465 |
|
| 466 |
+
if ( count( $targets_by_url ) ) {
|
| 467 |
+
foreach ( array_keys( $targets_by_url ) as $p ) {
|
| 468 |
$p = esc_url( $p );
|
| 469 |
+
$pages = str_replace( '<a href="' . $p . '"', '<a href="' . $p . '" target="_blank"', $pages );
|
|
|
|
| 470 |
}
|
| 471 |
}
|
| 472 |
|
| 498 |
*/
|
| 499 |
function load_post() {
|
| 500 |
if ( isset( $_GET['post'] ) ) {
|
| 501 |
+
if ( $this->get_link( (int) $_GET['post'] ) )
|
| 502 |
$this->hook( 'admin_notices', 'notify_of_external_link' );
|
|
|
|
| 503 |
}
|
| 504 |
}
|
| 505 |
|
readme.txt
CHANGED
|
@@ -7,7 +7,7 @@ Donate link: http://txfx.net/wordpress-plugins/donate
|
|
| 7 |
Tags: page, redirect, link, external link, repoint
|
| 8 |
Requires at least: 3.4
|
| 9 |
Tested up to: 3.6
|
| 10 |
-
Stable tag: 2.9.
|
| 11 |
|
| 12 |
Lets you make a WordPress page (or other content type) link to an external URL of your choosing, instead of its WordPress URL.
|
| 13 |
|
|
@@ -59,7 +59,11 @@ Yes. Linking to `/my-photos.php` is a good idea, as it'll still work if you move
|
|
| 59 |
|
| 60 |
== Changelog ==
|
| 61 |
|
| 62 |
-
= 2.9.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
* Restore WordPress 3.4.x functionality.
|
| 64 |
|
| 65 |
= 2.9.1 =
|
| 7 |
Tags: page, redirect, link, external link, repoint
|
| 8 |
Requires at least: 3.4
|
| 9 |
Tested up to: 3.6
|
| 10 |
+
Stable tag: 2.9.3
|
| 11 |
|
| 12 |
Lets you make a WordPress page (or other content type) link to an external URL of your choosing, instead of its WordPress URL.
|
| 13 |
|
| 59 |
|
| 60 |
== Changelog ==
|
| 61 |
|
| 62 |
+
= 2.9.3 =
|
| 63 |
+
* Only rely on an internal cache for `wp_list_pages()` processing, and time-limit the cache.
|
| 64 |
+
* Work around some weird edge cases
|
| 65 |
+
|
| 66 |
+
= 2.9.2 =
|
| 67 |
* Restore WordPress 3.4.x functionality.
|
| 68 |
|
| 69 |
= 2.9.1 =
|
