10/22/2015 at 3:24 pm
#351448
Guest
The following is an improved version of the function. Using global variables is bad practise in any coding environment. WordPress is poorly designed as it seems to encourage the use of global variables. I have removed two global variables below and used member function calls instead. This gets rid of the bug and makes the code more robust. I have tested Connections, regular pages and posts, and also 404’s. Everything works.
/**
* Add the the current Connections directory location/query to the page title.
*
* NOTE: $id really isn't optional, some plugins fail to use the `the_title` filter correctly,
* ie. "Display Posts Shortcode", causes Connections to crash an burn if not supplied.
*
* @access private
* @since 0.7.8
* @static
*
* @uses get_query_var()
*
* @param string $title The browser tab/window title.
* @param int $id The page/post ID.
*
* @return string
*/
public static function filterPostTitle( $title, $id = 0 ) {
global /*$wp_query, $post,*/ $connections;
// Added by MY on 22nd October 2015.
// Return the existing title if the current page is not found.
if ( is_404() ) return $title;
// Whether or not to filter the page title with the current directory location.
if ( ! cnSettingsAPI::get( 'connections', 'connections_seo', 'page_title' ) ) return $title;
// Added by MY on 22nd October 2015.
// Get the post ID.
$post_id = get_queried_object_id();
//if ( ! is_object( $post ) || $wp_query->post->ID != $id || ! self::$filterPermalink ) return $title;
if ( $post_id != $id || ! self::$filterPermalink ) return $title;
