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

PHP Fatal error: Uncaught Error / Transformer #818

Closed
cybeardjm opened this issue Jul 23, 2024 · 3 comments
Closed

PHP Fatal error: Uncaught Error / Transformer #818

cybeardjm opened this issue Jul 23, 2024 · 3 comments
Labels
Needs triage [Type] Bug Something isn't working

Comments

@cybeardjm
Copy link

Quick summary

PHP Fatal error: Uncaught Error: Call to undefined function Activitypub\Transformer\get_sample_permalink() in /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-post.php:104
Stack trace:
#0 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-post.php(91): Activitypub\Transformer\Post->get_url()
#1 [internal function]: Activitypub\Transformer\Post->get_id()
#2 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-base.php(63): call_user_func()
#3 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-base.php(82): Activitypub\Transformer\Base->transform_object_properties()
#4 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-post.php(56): Activitypub\Transformer\Base->to_object()
#5 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-base.php(95): Activitypub\Transformer\Post->to_object()
#6 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/class-activity-dispatcher.php(83): Activitypub\Transformer\Base->to_activity()
#7 /srv/data/web/vhosts//htdocs/wp-includes/class-wp-hook.php(324): Activitypub\Activity_Dispatcher::send_activity()
#8 /srv/data/web/vhosts//htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#9 /srv/data/web/vhosts//htdocs/wp-includes/plugin.php(517): WP_Hook->do_action()
#10 /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/class-activity-dispatcher.php(204): do_action()
#11 /srv/data/web/vhosts//htdocs/wp-includes/class-wp-hook.php(324): Activitypub\Activity_Dispatcher::send_post()
#12 /srv/data/web/vhosts//htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#13 /srv/data/web/vhosts//htdocs/wp-includes/plugin.php(565): WP_Hook->do_action()
#14 /srv/data/web/vhosts//htdocs/wp-cron.php(191): do_action_ref_array()
#15 {main}
thrown in /srv/data/web/vhosts//htdocs/wp-content/plugins/activitypub/includes/transformer/class-post.php on line 104

Steps to reproduce

N/A

What you expected to happen

N/A

What actually happened

Found this error in my PHP errorlog. It's the only one so far...

Impact

One

Available workarounds?

No but the platform is still usable

Logs or notes

No response

@cybeardjm cybeardjm added [Type] Bug Something isn't working Needs triage labels Jul 23, 2024
@janboddez
Copy link
Contributor

janboddez commented Aug 1, 2024

I still see this issue even in the latest version.

As for the fix: adding the leading backslash doesn't really do much; if a function does not exist in the current namespace, PHP will automatically look for a global function (i.e., one defined by, in our case, WP core).

The problem is that the global function \get_sample_permalink() also doesn't exist. (The error message again including the namespace does not change that fact. The error always includes the namespace; I agree it's confusing.)

The reason, I think, is that core's wp-admin/includes/post.php (where said function is defined) is not always loaded. (It's really part of WP-Admin. I'm guessing the "Activity Dispatcher" is called by WP-Cron, which may load fewer files by default?)

Similar to https://github.com/WordPress/wordpress-develop/blob/d0566719b39b1ccc88eac525e936b1e29fef5860/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L228-L230, we should require_once the file containing the missing function:

if ( ! function_exists( 'get_sample_permalink' ) ) {
	require_once ABSPATH . 'wp-admin/includes/post.php';
}

Before calling it.

That is, I didn't actually test this :-D but I'm fairly sure it'd solve the issue?

@cybeardjm
Copy link
Author

Thx @janboddez - Indeed I saw it appear again, but wasn't sure when I updated, so didn't add to my original comment here.

@janboddez
Copy link
Contributor

Oh, it's already fixed in the latest master (?) branch. #832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage [Type] Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants