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

(PHP8.x) Attempt to read property "post_type" on int warning message #9728

Open
alexmangini opened this issue May 3, 2024 · 0 comments
Open
Labels
type-bug workflow-needs-replication workflow-pending-triage Items that need to be triaged and reviewed before they are worked on.

Comments

@alexmangini
Copy link

alexmangini commented May 3, 2024

Bug Report

When calling the_excerpt() within a single post that refers to a post (that no longer exists) on a Custom Post Type Archive page I get the following warning from includes/templates-functions.php line 462

Attempt to read property "post_type" on int wp-content/plugins/easy-digital-downloads/includes/template-functions.php:462 edd_after_download_content() wp-includes/class-wp-hook.php:324 apply_filters('the_content') wp-includes/formatting.php:3992

Information (if a specific version is affected):

PHP Version: 8.3.6

EDD Version (or branch): 3.2.12

WordPress Version: 6.5.2

Any other relevant information:

The edd_after_download_content() function calls global $post which usually returns an object, but it seems when the post is not found it returns an int of the post ID in reference which is causing the error on this check in the function:

if ( $post && $post->post_type == 'download' ...

I have patched this function on my installation to remove the global call and use get_ functions to get the post ID and post type check.

As far as I have tested, the purchase buttons still appear at the end of single downloads but I haven't tested further than that:

function edd_after_download_content( $content ) {
	if ( get_post_type() == 'download' && is_singular( 'download' ) && is_main_query() && !post_password_required() ) {
		ob_start();
		do_action( 'edd_after_download_content', get_the_ID() );
		$content .= ob_get_clean();
	}

	return $content;
}
@alexmangini alexmangini added type-bug workflow-needs-replication workflow-pending-triage Items that need to be triaged and reviewed before they are worked on. labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug workflow-needs-replication workflow-pending-triage Items that need to be triaged and reviewed before they are worked on.
Projects
None yet
Development

No branches or pull requests

1 participant