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

Your plugin is causing PHP Warnings. #6

Closed
physixfan opened this issue Feb 15, 2017 · 23 comments
Closed

Your plugin is causing PHP Warnings. #6

physixfan opened this issue Feb 15, 2017 · 23 comments
Labels

Comments

@physixfan
Copy link

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/

@physixfan
Copy link
Author

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

@senlin senlin added the bug label Mar 3, 2017
@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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?

@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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.

@senlin senlin added the question label Mar 3, 2017
@physixfan
Copy link
Author

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.

@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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.

@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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

@physixfan
Copy link
Author

physixfan commented Mar 3, 2017

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...

@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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.

@physixfan
Copy link
Author

screen shot 2017-03-03 at 11 48 07

@physixfan
Copy link
Author

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

@physixfan
Copy link
Author

physixfan commented Mar 3, 2017

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.

@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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.

@senlin senlin added wontfix and removed question labels Mar 3, 2017
@physixfan
Copy link
Author

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...

@senlin
Copy link
Owner

senlin commented Mar 3, 2017

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.

@physixfan
Copy link
Author

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.

@senlin
Copy link
Owner

senlin commented Mar 4, 2017

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?

@physixfan
Copy link
Author

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

@senlin
Copy link
Owner

senlin commented Mar 4, 2017

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

@physixfan
Copy link
Author

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

@senlin
Copy link
Owner

senlin commented Mar 4, 2017

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 senlin closed this as completed Mar 4, 2017
@Chouby
Copy link

Chouby commented Mar 6, 2017

@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.

@senlin
Copy link
Owner

senlin commented Mar 15, 2017

@Chouby

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

@senlin senlin reopened this Mar 15, 2017
senlin pushed a commit that referenced this issue Mar 15, 2017
@senlin senlin closed this as completed Mar 15, 2017
@senlin
Copy link
Owner

senlin commented Mar 15, 2017

new version available https://github.com/senlin/so-pinyin-slugs/releases/tag/2.1.2 and at https://wordpress.org/plugins/so-pinyin-slugs

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

No branches or pull requests

3 participants