Support has been upgraded!
The Support Forum is closed. Not to worry! Providing the top quality support you expect and we're known for will continue! We're not ending support, just changing where you submit requests. This will provide you with the best experience possible.
Premium Support
Have you purchased an addon for Connections such as one of our premium templates or extensions with a valid license and you need help?
Please open a Support Ticket in your user account.
Free Support
Are you using the free Connections plugin? Don't worry, you are still very important to us! We are still providing you with the same high quality support that we're known for.
Please open a new support topic in the WordPress support forums for Connections.
Tagged: 8.5.1, error, php, plugin conflict, theme conflict
- This topic has 24 replies, 2 voices, and was last updated 10 years, 9 months ago by
Steven Zahm.
-
AuthorPosts
-
10/21/2015 at 11:55 pm #351308
SnailsFromJupiter
GuestHi again
I went back to Twenty Fifteen theme with all the plugins deactivated. I have also done diffs for the plugins with the master versions and found no differences.
All I can think of is that Wordfence Security of Simple Firewall have made changes to system files (outside of plugins and the theme) to improve security but to break Connections. i.e. if those plugins are deactivated I’m assuming they can still make changes in other places? I’m not sure. I just can’t think of what else it could be.
I feel the only way forward now is to create a blank WordPress installation on the same host, and slowly add everything back in, one step at a time. i.e. install a plugin. Copy one setting across at a time, while testing for the issue. Then put each page and post back one at a time. It is hugely laborious but I don’t see another way to track this down. I can eventually then do a recursive diff between all the files to see if it was a file issue, if all the files are functionally the same then it would mean the database had become corrupted somehow.
Thanks.
10/22/2015 at 9:09 am #351395SnailsFromJupiter
GuestHi again
Adding this to the top of your
filterPostTitle()function also fixes the issue.if ( is_404() ) return $title;wp_query->post is not being set when a 404 occurs (we knew this anyway but this is definitely confirmed by that line of code). Is it normal for wp_query->post to not be set during a 404?
I have a custom 404 filter set up in my child theme which I have disabled, however the issue still occurs (I went back to Twenty Fifteen previously anyway so my 404 could not have been called in that case).
10/22/2015 at 9:20 am #351396SnailsFromJupiter
GuestI know this isn’t exactly the same issue, however the response below is maybe a clue. The person says that the OP’s query might not have returned a WP_Post object. So even though your filter callback gets called at the correct times, maybe $wp_query contains a query that didn’t return any results OR it doesn’t contain the WP_Post object as we’ve already said.
$wp_query->queried_object->IDhas several potential points of failure:Your query may not be dealing with a WP_Post object. The queried_object can also reference a taxonomy in some circumstances.
Your query may not have actually identified any results. Your queried_object could be null, and thus you’re asking for a property on an nonexistent object.
You could be using$wp_queryin code that does not have a reference to that global. If you determine that$wp_queryitself is null, you should addglobal $wp_query;
… somewhere above your code.========================
p.s. if I try and italicise a variable like $with_underscore in these posts I get $with_underscore and not $nounderscore.
10/22/2015 at 9:22 am #351397SnailsFromJupiter
GuestThe issue I described with the italics. Trying to italicise a variable with an underscore shows up as the variable but with an asterisk either side. i.e. the shortcode isn’t working. This only happens in the preview window. It seems to work once it’s posted.
10/22/2015 at 9:47 am #351398Steven Zahm
KeymasterSnailsFromJupiter I do not think using
get_queried_object_id()would be correct since the returned object is not necessarily a post. Curious, add this to the file and visit a know page and a 404 page. I’d be SnailsFromJupiterI do not think using
get_queried_object_id()would not be correct since the returned object is not necessarily a post.Curious, add this to the file and visit a know page and a 404 page. I’d be interested to the the results:
var_dump( $wp_query->post ); var_dump( $post );I find this whole thing odd because the global
$postobject should not be set on a 404 anyway (I think) so the filter should bail right there and then. Stranger still the global$postcomes from$wp_query->posthttps://github.com/WordPress/WordPress/blob/4.3.1/wp-includes/class-wp.php#L518
Anyway, like I said, I’d like to see the output of the dumps. Also… do this in Chrome with the dev tools open. Watch the Network tab. Does a 301 redirect happen when you hit a 404?interested to the the results: var_dump( $wp_query->post ); var_dump( $post ); I find this whole thing odd because the global
$postobject should not be set on a 404 anyway (I think) so the filter should bail right there and then. Stranger still the global$postcomes from$wp_query->posthttps://github.com/WordPress/WordPress/blob/4.3.1/wp-includes/class-wp.php#L518 Anyway, like I said, I’d like to see the output of the dumps. Also… do this in Chrome with the dev tools open. Watch the Network tab. Does a 301 redirect happen when you hit a 404?10/22/2015 at 1:55 pm #351430SnailsFromJupiter
GuestHi Steven
I’m feel I’m getting closer to the issue. I think the is_404() fix is the best one (and the other defensive programming is also useful that you said you have put in for the next release). I’m not convinced that this is a bug outside your plugin. I’m starting to wonder if in some rarer instances your filter callback is legitimately called with $wp_query->post being not set. In which case your callback should handle that case (by returning $title).
See the first answer to my question on StackOverflow: https://stackoverflow.com/questions/33283211/why-is-wp-query-post-unset-during-404
It’s not that $wp_query->post is unset during a 404…but rather that it’s never set at all. In fact, $wp_query->post is unset for all new instances of WP_Query, when it is initialized.
10/22/2015 at 3:24 pm #351448SnailsFromJupiter
GuestThe 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;10/22/2015 at 5:40 pm #351455Steven Zahm
Keymaster@ SnailsFromJupiter
re: It’s not that $wp_query->post is unset during a 404…but rather that it’s never set at all. In fact, $wp_query->post is unset for all new instances of WP_Query, when it is initialized.
Yep, that’s what I said in this reply; “I find this whole thing odd because the global $post object should not be set on a 404 anyway (I think)“.
I came to that conclusion based on the same code was pointed out in SO.
This is why I wanted to see the var_dumps I asked for in this reply. It should be NULL on 404’s and therefore not pass the comparison and simply return the title without further processing. But since it is passing the comparison, they must not be NULL… I’m still very interested in seeing the results of the var_dump if you’re willing to share.
I definitely agree API/s should be used at all times and leave the globals alone.
I have to deal with other devs directly modding the globals directly all too frequently which breaks things unexpectedly. This is why my immediate thought was that the theme or plugins was the cause.
I ended up with the solution I did after several revisions because of it not working in x-scenario for different users. So far reading the globals directly has been the most reliable.
I see no harm in adding the is_404() check, I probably add it. This is the change I went with 2 days ago.
Since I can not replicate the issue, can you give it a test?
I’m not sure I want to use
get_queried_object_id()because the ID returned is contextual. For a post or page it comes from the$wp_query->post->IDanyway, see this.10/22/2015 at 7:34 pm #351480SnailsFromJupiter
GuestThanks for your patience so far Steven. I can see your point about working with many developers. I also feel WordPress development is messy… it is a fantastic platform but it feels like it’s been hacked form early version of code rather than designed from the ground up. I guess we have to work with what we have… a great platform… that’s a bit hacky at times. As developers it makes it hard to do things the ‘right way’. Your compromises are sound.
Apologies for missing your var_dump() comment. That was a good call.
Here are the results of the var_dumps() you requested:
404
- $page (undefined causing an error)
- $wp_query->post = NULL
Known page [not a Connections page – let me know if you want that]
- $page (undefined causing an error)
- $wp_query->post = [SEE BELOW]
object(WP_Post)#2773 (24) { ["ID"]=> int(225) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2015-09-25 15:56:23" ["post_date_gmt"]=> string(19) "2015-09-25 14:56:23" ["post_content"]=> string(1939) "Contents of page were here " ["post_title"]=> string(31) "Find Rented Property" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(31) "find-rented-property" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-10-05 20:46:48" ["post_modified_gmt"]=> string(19) "2015-10-05 19:46:48" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(44) "http://www.example.com/?page_id=225" ["menu_order"]=> int(0) ["post_type"]=> string(4) "page" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }10/22/2015 at 7:42 pm #351481SnailsFromJupiter
GuestI made a mistake. Here are the correct var_dumps for $post. The var_dumps() for $wp_query->post were correct.
404
- $post =
object(WP_Post)#3009 (24) { ["ID"]=> int(110) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2015-09-20 03:11:02" ["post_date_gmt"]=> string(19) "2015-09-20 02:11:02" ["post_content"]=> string(3390) "Contents of page were here" ["post_title"]=> string(25) "Declutter Before You Move" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(25) "declutter-before-you-move" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-09-20 03:43:45" ["post_modified_gmt"]=> string(19) "2015-09-20 02:43:45" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(38) "http://www.example.com/?p=110" ["menu_order"]=> int(0) ["post_type"]=> string(4) "post" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }Known Page (Not a Connections page)
- $post =
object(WP_Post)#3016 (24) { ["ID"]=> int(110) ["post_author"]=> string(1) "2" ["post_date"]=> string(19) "2015-09-20 03:11:02" ["post_date_gmt"]=> string(19) "2015-09-20 02:11:02" ["post_content"]=> string(3390) "Contents of page were here" ["post_title"]=> string(25) "Declutter Before You Move" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(25) "declutter-before-you-move" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-09-20 03:43:45" ["post_modified_gmt"]=> string(19) "2015-09-20 02:43:45" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(38) "http://www.example.com/?p=110" ["menu_order"]=> int(0) ["post_type"]=> string(4) "post" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" } -
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.
