Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP Warnings on accessing $coauthor instance #975

Closed
cobianzo opened this issue Aug 2, 2023 · 2 comments · Fixed by #976
Closed

Fix PHP Warnings on accessing $coauthor instance #975

cobianzo opened this issue Aug 2, 2023 · 2 comments · Fixed by #976

Comments

@cobianzo
Copy link
Contributor

cobianzo commented Aug 2, 2023

at https://github.com/Automattic/Co-Authors-Plus/blob/master/template-tags.php#L75 we are continously getting PHP warnings for accessnig to inexisting properties user_login and linked_account.
This could be improved with a simple isset verificationi before accessing the values.

if ( ( isset( $coauthor->user_login ) && $user == $coauthor->user_login ) || 
		( isset( $coauthor->linked_account ) && $user == $coauthor->linked_account ) ) {
			return true;
		}
@GaryJones
Copy link
Contributor

Thanks @cobianzo - are you able to determine why $coauthors ends up being an array of items that are not the expected objects?

@cobianzo
Copy link
Contributor Author

cobianzo commented Aug 12, 2023

@GaryJones Hi I should investigate about it. We have quite a few of customized code which uses $coauthors instances every time we need to access to the author of a post.
I'll put some time aside to find out in what moment that happens.

I am not sure these items end up being an array as much as they are objects without the expected properties user_login and `linked_account'.

Here the PHP warning:

Warning: Undefined property: stdClass::$linked_account in /wp/wp-content/plugins/co-authors-plus/co-authors-plus.php on line 1122 [inews61.vipdev.lndo.site/wp-json/wp/v2/posts/2376374?_embed=true&access_token=Uo9HQbCl76rL] [wp-includes/class-wp-hook.php:310 CoAuthors_Plus->filter_count_user_posts(), wp-includes/plugin.php:205 WP_Hook->apply_filters(), wp-includes/user.php:573 apply_filters('get_usernumposts'), wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:445 count_user_posts(), wp-includes/rest-api.php:821 WP_REST_Users_Controller->get_item_permissions_check(), wp-includes/class-wp-hook.php:308 rest_send_allow_header(), wp-includes/plugin.php:205 WP_Hook->apply_filters(), wp-includes/rest-api/class-wp-rest-server.php:731 apply_filters('rest_post_dispatch'), wp-includes/rest-api/class-wp-rest-server.php:584 WP_REST_Server->embed_links(), wp-includes/rest-api/class-wp-rest-server.php:503 WP_REST_Server->response_to_data(), wp-includes/rest-api.php:410 WP_REST_Server->serve_request(), wp-includes/class-wp-hook.php:308 rest_api_loaded(), wp-includes/class-wp-hook.php:332 WP_Hook->apply_filters(), wp-includes/plugin.php:565 WP_Hook->do_action(), wp-includes/class-wp.php:399 do_action_ref_array(), wp-includes/class-wp.php:780 WP->parse_request(), wp-includes/functions.php:1332 WP->main(), wp-blog-header.php:16 wp(), index.php:17 require('wp-blog-header.php')]

@GaryJones GaryJones linked a pull request Aug 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants