Skip to:
Content

BuddyPress.org

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#5241 closed defect (bug) (fixed)

Notices occur when BP_ENABLE_ROOT_PROFILES is enabled

Reported by: henrywright's profile henrywright Owned by: r-a-y's profile r-a-y
Milestone: 2.1 Priority: normal
Severity: minor Version: 1.7
Component: Core Keywords: needs-refresh has-patch
Cc: mpa4hu@…

Description

I am getting the same 3 PHP notices at various times when using BP with WordPress SEO:

  1. On successful avatar upload
  2. After clicking the submit button when searching private messages

The notices are:

Notice: Trying to get property of non-object in /htdocs/wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 548

Notice: Trying to get property of non-object in /htdocs/wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 840

Notice: Trying to get property of non-object in /htdocs/wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 843

After speaking with one of the plugin's contributors in the WP forum see the WP forum thread, they suggested I raise a BP ticket due to the notices being caused by BuddyPress doing something to the $post object which causes it to not be an object.

Attachments (1)

5241.01.patch (2.6 KB) - added by r-a-y 10 years ago.

Download all attachments as: .zip

Change History (25)

#1 @boonebgorges
11 years ago

  • Keywords reporter-feedback added

henrywright - What theme are you using? Is it using BP's theme compat?

I'm dubious that BP is wiping out the $post global - we use it in a number of important ways. I've just done a bit of testing using Twenty Twelve as a theme, and was not able to reproduce the notices. Are there any special settings I need to activate in WordPress SEO?

#2 @henrywright
11 years ago

I was using a child theme of bp-default.

Considering the attempts to get the $post property are all wrapped in a is_singular() check (see lines 548, 840 and 843 in class-frontend.php), should that particular piece of plugin code be running at all at the point of change-avatar or private message search? The change-avatar and private message pages are not any of is_single(), is_page() or is_attachment() are they?

UPDATE: I've been doing some investigation and can see an is_singular() check is being used around the code attempting to get the $post property. is_page() seems to return true for the change-avatar and private message pages (where there notices are displayed) but the $post variable seems to be null here. Could this be the reason why toys are being thrown out of the push buggy?

Last edited 11 years ago by henrywright (previous) (diff)

#3 @boonebgorges
11 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

: I've been doing some investigation and can see an is_singular() check is being used around the code attempting to get the $post property. is_page() seems to return true for the change-avatar and private message pages (where there notices are displayed) but the $post variable seems to be null here. Could this be the reason why toys are being thrown out of the push buggy?

Thanks for the additional investigation. This is related to the fact that you're using a bp-default descendant. In a nutshell: Because BP content is not WP content, it's not found by WP's initial parse_request() -> query chain. So there is a portion of the load process where WP thinks that requests for BP content are 404s. BP manually unsets this 404 before loading its template, and where/how this happens depends on whether you're using theme compat. The pre-theme-compat switch happens here http://buddypress.trac.wordpress.org/browser/tags/1.8.1/bp-core/bp-core-catchuri.php#L378. We manually flip is_page and is_singular to true, as well as turning off the 404. But we don't do anything to the $post global.

In contrast, theme compat fakes the entire content of a "dummy" post. See http://buddypress.trac.wordpress.org/browser/tags/1.8.1/bp-members/bp-members-screens.php#L407. So if you switch to a theme that utilizes theme compat, the notices should go away.

(FWIW, I switched to bp-default to test and I *still* didn't see the notices. So this is mostly an educated guess.)

Given that the old method is being abandoned, and given that the notices shouldn't actually cause any real problems (aside from some non-optimized robots/meta tags in wordpress-seo), I'm going to close this as wontfix. My apologies to the wordpress-seo devs for the inconvenience - this issue will disappear as people stop using the old BP themes.

#4 @henrywright
11 years ago

boonebgorges, thanks for the detailed explanation of what is happening, you've made sense out of a situation that was confusing me all morning. The guys at wordpress-seo suggested they can add some validation at their end - which will resolve the issue until people migrate away from bp-default.

#5 @henrywright
11 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Please feel free to re-close this ticket but I wanted to make you aware that notices have increased after upgrading to 1.9 beta 1. This is the set of notices displayed when visiting a member's profile page. Some notices seem to be displayed more than once:

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 548

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 638

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 840

Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 843

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3034

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3402

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3404

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3406

Last edited 11 years ago by henrywright (previous) (diff)

#6 @henrywright
11 years ago

I can see 3 of the notices that seem to be repeated lots are due to the use of the is_page() function (see lines 3402, 3404, 3406 in wp-includes/query.php).

Last edited 11 years ago by henrywright (previous) (diff)

#7 @r-a-y
11 years ago

henrywright: I can't duplicate this. Can you list the plugins that you are running?

Last edited 11 years ago by r-a-y (previous) (diff)

#8 @henrywright
11 years ago

r-a-y - Those notices came from a customised theme which had a few plugins activated. To make things less complicated, it might be worth looking at the PHP notices on http://jobtain.co.uk/henrywright/

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3276

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3651

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3653

Notice: Trying to get property of non-object in /wp-includes/query.php on line 3655

Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3276

The site has no plugins activated (aside from BP 1.9 beta 1). Uses Twenty Thirteen as it comes out of the box.

#9 @r-a-y
11 years ago

henrywright: I still can't duplicate this locally. Are you sure you're not running any additional plugins / code snippets anywhere?

I'm on WP 3.7.1, BP 1.9-bleeding. Tested with both Twenty Twelve and Twenty Thirteen.

Can you try reinstalling WordPress from the admin dashboard ("Dashboard > Updates") to see what happens?

#10 @r-a-y
11 years ago

Ahh, you're using root profiles!

Bug duplicated.

#11 @r-a-y
11 years ago

  • Component changed from Core to Rewrite Rules
  • Milestone set to 2.0
  • Severity changed from normal to minor
  • Summary changed from $post object doesn't seem to be an object to Notices occur when BP_ENABLE_ROOT_PROFILES is enabled
  • Version set to 1.7

This will hopefully resolve itself when rewrite rules are implemented in 2.0 (see #4954).

#12 @henrywright
11 years ago

Some more feedback on this since upgrading to 1.9. I'm now getting a huge number of debug notices when root profiles are enabled.

Steps:

a) Enable root profiles
b) visit the notifications page example.com/username/notifications

  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3675
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 552
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 642
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3671
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3673
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3675
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 848
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 851
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3671
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3673
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3675
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 154
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 159
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3671
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3673
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3675
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-frontend.php on line 642
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-opengraph.php on line 124
  1. Notice: Trying to get property of non-object in /wp-includes/general-template.php on line 1442
  1. Notice: Trying to get property of non-object in /wp-includes/general-template.php on line 1583
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3671
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3673
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3675
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-opengraph.php on line 327
  1. Notice: Trying to get property of non-object in /wp-includes/post-template.php on line 29
  1. Notice: Trying to get property of non-object in /wp-content/plugins/wordpress-seo/frontend/class-opengraph.php on line 332
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3671
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3673
  1. Notice: Trying to get property of non-object in /wp-includes/query.php on line 3675
  1. Notice: Trying to get property of non-object in /wp-includes/comment-template.php on line 939
  1. Notice: Trying to get property of non-object in /wp-includes/comment-template.php on line 964
  1. Notice: Trying to get property of non-object in /wp-includes/general-template.php on line 1704
  1. Notice: Undefined property: WP_Query::$post in /wp-includes/query.php on line 3296

These notices don't happen when root profiles are disabled.

@r-a-y
10 years ago

#13 @r-a-y
10 years ago

  • Component changed from Rewrite Rules to Core
  • Keywords has-patch added

While looking into another ticket, I came across this bug again.

Thought I might as well patch this since rewrite rules isn't going to be implemented until the next release cycle.

Attached patch:

  • Removes the query to look up the page based on the BP page offset. I don't think this is necessary. When we move to rewrite rules, we'll be using virtual pages anyway.
  • Resets the post with bp_theme_compat_reset_post() since it's a great function to add a dummy post
  • Sets the theme compat flag to false since bp_theme_compat_reset_post() sets that flag to true
  • Tweaks the locate_template() call so it is only run when bp_use_theme_compat_with_current_theme() is false. This should probably be moved to a separate commit altogether, but thought I'd throw it in here since I was touching bp_core_load_template()!

Notices should disappear now when root profiles is enabled. I've tested this in various scenarios and it works. Also passes the existing root profile unit tests.

Feedback appreciated.

Last edited 10 years ago by r-a-y (previous) (diff)

#14 @boonebgorges
10 years ago

Is this going to cause problems for people doing checks like is_page( 'members' ), since we're switching from the bp_page to a dummy page?

#15 @boonebgorges
10 years ago

  • Milestone changed from 2.0 to 2.1

#16 @afercia
10 years ago

someway related:
in the "dummy" post the post ID is set to int 0, what about themes that in their pages may use functions like get_post_thumbnail_id() that expects a "real" ID? On failure, it will return false instead of an empty string (see the Codex) and I bet lots of themes are checking this against an empty string.

#17 @mpa4hu
10 years ago

  • Cc mpa4hu@… added

@r-a-y if I only have found this ticket earlier :)
I can confirm that patch works

The only thing that changed in my case (I use classes to determine current page) was that body classes on homepage now are

directory activity  buddypress page page-id-0 page-parent page-template-default logged-in no-js row

earlier it also had home-page but this is something I can work on, just reporting.

#18 @DJPaul
10 years ago

  • Keywords dev-feedback added

I think I would like to bump this to 2.2 because it sounds a pretty big change to make this late in the cycle, we might miss something subtle.

#19 follow-up: @r-a-y
10 years ago

in the "dummy" post the post ID is set to int 0, what about themes that in their pages may use functions like get_post_thumbnail_id() that expects a "real" ID?

get_post_thumbnail_id() doesn't work right now on BuddyPress pages because theme compatibility overrides the WP post anyway with or without this patch. It only works if you pass the correct post ID.

The only thing that changed in my case (I use classes to determine current page) was that body classes on homepage now

I can confirm this. It's missing the home-page class if you're using a BP page as the homepage and the page-id-X class is now always page-id-0. Once we move to rewrite rules, there will not be a page ID anyway.

I think I would like to bump this to 2.2

If I address the missing <body> home-page class, would it be doable for 2.1?

#20 in reply to: ↑ 19 @DJPaul
10 years ago

  • Keywords dev-feedback removed

If I address the missing <body> home-page class, would it be doable for 2.1?

Sure, as long as you're confident that the type of concern mentioned by Boone earlier isn't going to be a problem. 2.1's not scheduled to hit beta for almost 2 more weeks, so there's enough time. I bumped the ticket purely because it hadn't had any activity for about 3 months, and I wasn't sure if anyone wants going to finish up this last bit.

Replying to boonebgorges:

Is this going to cause problems for people doing checks like is_page( 'members' ), since we're switching from the bp_page to a dummy page?

#21 @DJPaul
10 years ago

  • Keywords needs-refresh added

#22 @DJPaul
10 years ago

R-a-y: did you get chance to finish this up for 2.1?

#23 @r-a-y
10 years ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from reopened to closed

In 8821:

In bp_core_load_template(), reset post globals if we're on a non-directory page.

If we're on a non-directory page, we are faking a WordPress page, so we
must reset the WordPress post globals to avoid notices from appearing. The
reset is done with the bp_theme_compat_reset_post() function and notably
fixes notices when the root profiles feature is toggled.

Commit also removes an unnecessary database query to determine whether
we're on a BuddyPress directory page. WordPress should have already made
this determination before BuddyPress has reached this point in
bp_core_load_template().

Fixes #5241.

#24 @djpaul
10 years ago

In 8932:

Fixes a regression in r8821 in rbp_core_load_template() which was preventing the correct parent page being highlighted in WP nav menus.

This change reinstates the page look up and post globals as before r8821. Overall, these changes are still a net benefit as an uncached SQL query has been removed. See #5241 for background.

Fixes #5810

Note: See TracTickets for help on using tickets.