Skip to content

Commit

Permalink
Fix permalink for future posts
Browse files Browse the repository at this point in the history
  • Loading branch information
misfist committed May 18, 2017
1 parent e854882 commit 810afd0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
47 changes: 47 additions & 0 deletions includes/content-filters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Tni Core Content Filters
*
* @package Tni_Core
* @subpackage Tni_Core\Includes
* @since 1.2.4
* @license GPL-2.0+
*/

/**
* Get Pretty Permalink for Future Posts
* When posts are scheduled (`post_status` = `future`), "pretty" permalinks aren't returned by `get_permalink()`
*
* @since 1.2.4
*
* @link https://github.com/thenewinquiry/tni-theme/issues/66
* @link https://core.trac.wordpress.org/ticket/30910
*
* @param string $permalink
* @param obj $post
* @param string $leavename
* @param boolean $sample
*
* @return string $permalink
*/
function tni_core_future_permalink( $permalink, $post, $leavename, $sample = false ) {
static $recursing = false;

/* If there is no post id or you're in the admin area */
if ( empty( $post->ID ) || is_admin() ) {
return $permalink;
}

if ( !$recursing ) {
if ( isset( $post->post_status ) && ( 'future' === $post->post_status ) ) {
$post->post_status = 'publish';
$recursing = true;
return get_permalink( $post, $leavename ) ;
}
}

$recursing = false;
return $permalink;
}
add_filter( 'post_link', 'tni_core_future_permalink', 10, 3 );
add_filter( 'post_type_link', 'tni_core_future_permalink', 10, 4 );
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: misfist
Tags: custom
Requires at least: 4.7
Tested up to: 4.7.4
Version: 1.2.3
Tested up to: 4.7.5
Version: 1.2.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -22,6 +22,9 @@ This section describes how to install the plugin and get it working.

== Changelog ==

= 1.2.4 May 18, 2017 =
* #66 {https://github.com/thenewinquiry/tni-theme/issues/66} - Fix permalink for `future` posts

= 1.2.3 May 10, 2017 =
* #23 - Added hide featured image checkbox field to blogs.

Expand Down
6 changes: 3 additions & 3 deletions tni-core-functionality.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Text Domain: tni-core
* Domain Path: /languages
*
* Version: 1.2.3
* Version: 1.2.4
*
* @package Tni_Core_Functionality
*/
Expand All @@ -26,6 +26,7 @@
define( 'TNI_CORE_DIR_URL', plugin_dir_url( __FILE__ ) );

require_once( 'includes/helpers.php' );
require_once( 'includes/content-filters.php' );
require_once( 'includes/template-tags.php' );

// Load plugin class files
Expand All @@ -42,7 +43,6 @@

// Load admin files
require_once( 'admin/class-tni-core-admin.php' );

require_once( 'includes/utilities.php' );

/**
Expand All @@ -52,7 +52,7 @@
* @return object Tni_Core
*/
function Tni_Core() {
$instance = Tni_Core::instance( __FILE__, '1.2.3' );
$instance = Tni_Core::instance( __FILE__, '1.2.4' );

return $instance;
}
Expand Down

0 comments on commit 810afd0

Please sign in to comment.