senlin/pinyin-slugs

Your plugin is causing PHP Warnings.

Closed this issue · 23 comments

When your plugin is activated, I see a lot of PHP Warnings:

PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'getPinyinSlug' not found or invalid function name in ......./wp-includes/class-wp-hook.php on line 300, referer: https://www.mysite.com/wp-admin/

Hi

The author from plugin Polylang Pro have a suggestion of how to fix this problem:

You can move this line https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L217 here https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L131

Hi @physixfan sorry for late response, for some reason I have not been getting notified...

I'm not entirely sure why your suggestion would help, can you please link to where you received that suggestion?

Also, can you please show me a screenshot of the PHP Warning as I cannot replicate any PHP Warnings on a squeaky clean install even.

I use a paid version of Polylang, and the suggestion is via support ticket, not on a public forum. But I tested on my site, it really works. About the PHP Warnings, I use a plugin "Query Monitor" to see those PHP errors. Those PHP errors does not show on the screen without plugins.

Installed the Query Monitor plugin and still cannot see any PHP Warning, which by the way also would show when WP_DEBUG is set to true in the wp-config.php file, after all that's what it is for: debugging stuff.

Without being to replicate your issue and without being able to see an actual PHP Warning via a screenshot provided by you, there is not an awful lot I can do.

Furthermore I use this plugin myself on several live sites together with WPML and I have never experienced any issues.

I think the problem is the conflict with Polylang. Have you installed Polylang on your test site? Since I modified your code already, it takes some efforts to make a screenshot with these errors...

If you modified the code of the SO Pinyin Slugs plugin, then please understand that I cannot help you any further.

Also I don't think it is my responsibility to install the Polylang plugin as

  • a. I already have tried to reproduce the issue you have reported and
  • b. I am the one asking you for a screenshot of the PHP Warnings that you have reported
  • c. and lastly I don't even have access to the premium version of the Polylang plugin

Thanks for your understanding.

I am still investigating further. The screenshot is taken with the UNMODIFIED version of your plugin.

Now on my staging site, I disabled all the plugins except: SO pinyin slug, Polylang pro, and Query Monitor. And I changed my theme to twenty-seven. The php errors are still there. Interesting though, when I install those three plugins in a brand new site, there's no error.

Thank you.

As far as I can see the Component that is referred to is the Polylang Pro plugin and not the SO Pinyin Slugs plugin.

If the suggestion of the author of Polylang works for you, then I would like to suggest to implement that instead. I have no idea what the potential consequences are for implementing the suggested changes and unless something major happens, I don't expect any updates to this plugin, which means that you can use the mod-ed version for a long time to come.

PS PHP Warnings are not Errors. Errors would result in your site not working anymore.

OK I'll just use his suggestion then. If you release a new version in the future, it would be great if you can add this change...

As I said I will need further testing and it would be nice to know why the author of Polylang suggested to move the line up.

This is his full reply:

Frédéric replied
Feb 28, 9:29
Hi,

I fear that there is not much I can do. There is indeed a bug in this plugin. The author defines a filter before he defines the function hooked to this filter. Nothing wrong happens and you can just set WP_DEBUG to false in your wp-config.php and you would not see the warnings anymore.

Otherwise, you can move this line https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L217 here https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L131 but the fix will be removed at the next plugin update if the author does not fix the bug himself.

Okay... so please explain to me then. the filter is defined in the inc/functions.php file, which as a matter of fact is called on L126, which is still before L131, so how would moving the filter up to that line have any positive effect?

I don't know, as I am not an expert on PHP... But the change really makes the php warnings disappear...

The PHP Warnings that show only when the premium version of Polylang has been activated?

I just tested. Yes, you are correct, the warnings occur only when the Polylang pro is activated.

Okay, thanks for confirming that.

I then hope that you understand I will not "fix" this as long as this is an isolated case.

If (big if that is) there are more reports of PHP Warnings related to other plugins, then I might consider moving the line up.

Thanks for your understanding.

@senlin

I will explain the issue.

Here you add the filter as soon as the plugin is loaded: https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L217

The function getPinyinSlug() is defined in the file https://github.com/senlin/so-pinyin-slugs/blob/master/inc/functions.php

You include this file at this line https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L126 in the function SOPS_Load::includes()

This function is executed when the action plugins_loaded is executed https://github.com/senlin/so-pinyin-slugs/blob/master/so-pinyin-slugs.php#L66

So you add the filter as soon as the plugin is loaded but define the corresponding function only once the plugins_loaded has been fired.

If a plugin is calling sanitize_title() in between you get the warning reported by @physixfan.

My suggested fix is to add the filter only once you have included the file functions.php. You can do the opposite and include the file as soon as the plugin is loaded.

@Chouby

Thanks for your clarification, I will move it up in the next version.