How to create Child Plugin for wordpress

独自空忆成欢 提交于 2021-01-26 21:46:16

问题


Actually I have changed some code in WordPress Store Locator. I want it to remain when plugin will update. So I want to create a child plugin for that. Any ideas on how I could manage it?


回答1:


This varies plugin to plugin, and it sometimes isn't even possible, other times plugins have documentation to extend them easily (such as WooCommerce and Gravity Forms). Some of them create Action Hooks with do_action() that let you extend the functionality easily. A common example is updating a post after a Gravity Form is submitted with their gform_after_submission hook.

Effectively, it depends on what you want to do, and how the plugin implements the functionality you want to change. If they add text with a Closure or Anonymous Function, it will be harder to modify said text, and you may have to look at something strange like doing a run-time find and replace using Output Buffering, typically on the template_redirect hook.

If you want to remove something a plugin does, you can often unhook it with remove_action. This can be a bit tricky depending on how the plugin is instantiated, sometimes its as simple as:

remove_action( 'some_hook', 'function_to_remove' );

Other times it's more complicated like:

global $plugin_class_var;
remove_action( 'some_hook', array($plugin_class_var, 'function_to_remove') );

Those are the basics of extending (or even 'shrinking'?) a plugin's functionality, and it's not always doable appropriately. Unfortunately the narrow answer to your question is outside of the scope of what we can provide from StackOverflow.

From here, you'll need to figure out exactly what you want to do with the plugin, and dig through the plugin's files to see if there's an appropriate hook or function you can use. If you're still stuck, you'll need to post a new question (don't update this one) with your exact desired result and anything you've tried, and the relevant code that goes along with it. "I want to change a plugin without editing core files" isn't nearly specific enough. "I want to replace an icon with a custom icon in this plugin, here's what I've tried" is specific enough to possibly answer.

Good luck!




回答2:


As per WordPress standard, it's called plugin's addon.

if the plugin has provided any action to update that functionality then you can use it with your addon (child plugin).

Here I am sending a link for reference. https://developer.wordpress.org/reference/functions/add_action/




回答3:


I just went through myself and I had so many changes that I couldn't just override the actions.

I created this tool that allows you to create a child plugin like a child theme. You can make updates to the plugin and still update it without losing your changes.

I'm posting this here because it relates and hopefully becomes useful to the next person who runs into this issue.

https://github.com/ThomasDepole/wordpress-child-plugin-tool



来源:https://stackoverflow.com/questions/50766761/how-to-create-child-plugin-for-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!