Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

The get_the_ID() function does not always return a post identifier #203

Closed
wants to merge 3 commits into from
Closed

Conversation

leopoiroux
Copy link

When calling the "wp_update_post" function, the context of a post is not always present. While this function runs a hook and goes through Members plugin. It cause a PHP Error.

content.js:3 E_NOTICE Trying to get property of non-object - /app/plugins/members/inc/template.php:95
#24 /app/plugins/members/inc/template.php:117 - members_can_user_view_post(0, false)
#23 /app/plugins/members/inc/functions-content-permissions.php:180 - members_can_current_user_view_post(false)
#22 /wp/wp-includes/class-wp-hook.php:286 - members_content_permissions_protect('')
#21 /wp/wp-includes/plugin.php:203 - WP_Hook->apply_filters('', Array[1])
#20 /app/plugins/wordpress-seo/admin/links/class-link-watcher.php:117 - apply_filters('the_content', '')
#19 /app/plugins/wordpress-seo/admin/links/class-link-watcher.php:64 - WPSEO_Link_Watcher->process(18204, '')
#18 /wp/wp-includes/class-wp-hook.php:288 - WPSEO_Link_Watcher->save_post(18204, WP_Post)
#17 /wp/wp-includes/class-wp-hook.php:310 - WP_Hook->apply_filters(18204, Array[3])
#16 /wp/wp-includes/plugin.php:453 - WP_Hook->do_action(Array[3])
#15 /wp/wp-includes/post.php:3673 - do_action('save_post', 18204, WP_Post, true)
#14 /wp/wp-includes/post.php:3746 - wp_insert_post(Array[30], false)
#13 /app/plugins/woody-plugin/src/Modules/Importer/Importer.php:143 - wp_update_post(Array[28])
#12 /app/plugins/woody-plugin/src/Modules/Importer/Importer.php:106 - Woody\Modules\Importer\Importer->flushSlugs(Array[6], false)
#11 /wp/wp-includes/rest-api/class-wp-rest-server.php:936 - Woody\Modules\Importer\Importer->chunkProceed(WP_REST_Request)
#10 /wp/wp-includes/rest-api/class-wp-rest-server.php:321 - WP_REST_Server->dispatch(WP_REST_Request)
#9 /wp/wp-includes/rest-api.php:266 - WP_REST_Server->serve_request('/woody_plugin_...')
#8 /wp/wp-includes/class-wp-hook.php:286 - rest_api_loaded(WP)
#7 /wp/wp-includes/class-wp-hook.php:310 - WP_Hook->apply_filters('', Array[1])
#6 /wp/wp-includes/plugin.php:515 - WP_Hook->do_action(Array[1])
#5 /wp/wp-includes/class-wp.php:373 - do_action_ref_array('parse_request', Array[1])
#4 /wp/wp-includes/class-wp.php:713 - WP->parse_request('')
#3 /wp/wp-includes/functions.php:960 - WP->main('')
#2 /wp/wp-blog-header.php:16 - wp()
#1 /index.php:5

When calling the "wp_update_post" function, the context of a post is not always present. While this function runs a hook and goes through Members plugin. It cause a PHP Error.

content.js:3  E_NOTICE  Trying to get property of non-object - /app/plugins/members/inc/template.php:95 
#24 /app/plugins/members/inc/template.php:117 - members_can_user_view_post(0, false)
#23 /app/plugins/members/inc/functions-content-permissions.php:180 - members_can_current_user_view_post(false)
#22 /wp/wp-includes/class-wp-hook.php:286 - members_content_permissions_protect('')
#21 /wp/wp-includes/plugin.php:203 - WP_Hook->apply_filters('', Array[1])
#20 /app/plugins/wordpress-seo/admin/links/class-link-watcher.php:117 - apply_filters('the_content', '')
#19 /app/plugins/wordpress-seo/admin/links/class-link-watcher.php:64 - WPSEO_Link_Watcher->process(18204, '')
#18 /wp/wp-includes/class-wp-hook.php:288 - WPSEO_Link_Watcher->save_post(18204, WP_Post)
#17 /wp/wp-includes/class-wp-hook.php:310 - WP_Hook->apply_filters(18204, Array[3])
#16 /wp/wp-includes/plugin.php:453 - WP_Hook->do_action(Array[3])
#15 /wp/wp-includes/post.php:3673 - do_action('save_post', 18204, WP_Post, true)
#14 /wp/wp-includes/post.php:3746 - wp_insert_post(Array[30], false)
#13 /app/plugins/woody-plugin/src/Modules/Importer/Importer.php:143 - wp_update_post(Array[28])
#12 /app/plugins/woody-plugin/src/Modules/Importer/Importer.php:106 - Woody\Modules\Importer\Importer->flushSlugs(Array[6], false)
#11 /wp/wp-includes/rest-api/class-wp-rest-server.php:936 - Woody\Modules\Importer\Importer->chunkProceed(WP_REST_Request)
#10 /wp/wp-includes/rest-api/class-wp-rest-server.php:321 - WP_REST_Server->dispatch(WP_REST_Request)
#9 /wp/wp-includes/rest-api.php:266 - WP_REST_Server->serve_request('/woody_plugin_...')
#8 /wp/wp-includes/class-wp-hook.php:286 - rest_api_loaded(WP)
#7 /wp/wp-includes/class-wp-hook.php:310 - WP_Hook->apply_filters('', Array[1])
#6 /wp/wp-includes/plugin.php:515 - WP_Hook->do_action(Array[1])
#5 /wp/wp-includes/class-wp.php:373 - do_action_ref_array('parse_request', Array[1])
#4 /wp/wp-includes/class-wp.php:713 - WP->parse_request('')
#3 /wp/wp-includes/functions.php:960 - WP->main('')
#2 /wp/wp-blog-header.php:16 - wp()
When calling the "wp_update_post" function, the context of a post is not always present. While this function runs a hook and goes through Members plugin. It cause a PHP Error.
@justintadlock
Copy link
Owner

I'm closing this specific PR because it doesn't follow the contributing guidelines

With that said, there really should be no need for the change. Most likely, there's another plugin that's inappropriately firing apply_filters( 'the_content' ), which should only ever be called in The Loop context with a valid global $post object.

@lkraav
Copy link

lkraav commented Nov 7, 2018

@leopoiroux you're actually hitting Yoast/wordpress-seo#11395, filed by yours truly a week ago, because of this very problem.

@leopoiroux
Copy link
Author

Thank you very much for this answer, indeed the Yoast plugin is more involved than you are.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants