Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify wordpress plugin functions without editing the plugin?

I'm working with wordpress and I search to modify plugin functions without editing the plugin for not break function after update.

But I didn't find solution yet. Can you help me ?

Thanks in advance

like image 539
Samuel SEILLER Avatar asked Nov 13 '22 17:11

Samuel SEILLER


1 Answers

I have encountered this issue many times. As others have said, you cannot modify PHP functions. Extending the class will not work because the plugin will instantiate the original class, not your extended version.

The best solution (has worked for me several times) is to add hooks to the existing plugin and submit back to the original author as follows:

  1. If the original plugin is on github, fork and clone it. Otherwise, put the original plugin under git control locally. You may need to do a diff or rollback later.
  2. Create a new plugin called WPML-extensions (or something)
  3. Search the original plugin code for actions or filters to use. If they are already available and do what you need, use them by hooking to them from the WPML-extensions plugin.
  4. If the correct hooks are not present in the WPML plugin, add them and then follow the step above. Try to use the latest version of the original plugin to maximize your chances of your changes being accepted.
  5. If you have modified the original plugin by adding actions or filters, do a git diff to save the patch so you can re-apply it later. Submit the patch to the original plugin author and hope for the best. If you stuck with just actions and filters, the author will most likely accept your changes immediately.
  6. If you update the original plugin later, you need to re-apply your changes until they are accepted. You can use that diff file. There may be a way to use git rebase to replay the changes you made after updating the plugin.
like image 109
Ben Allfree Avatar answered Jan 04 '23 03:01

Ben Allfree