admin管理员组

文章数量:1289633

In WordPress we can easily extend a parent theme by creating a child theme. How can we create a child plugin from parent plugin?

I search a lot and people suggested to use actions and hooks but what if a plugin doesn't provide hooks and actions?

Actually I want to extend LearnDash plugin. I want to extend it's functionality in my child plugin. So that if any updates comes in plugin, it shouldn't conflict with our custom changes. But currently I have no idea how to extend it?

In WordPress we can easily extend a parent theme by creating a child theme. How can we create a child plugin from parent plugin?

I search a lot and people suggested to use actions and hooks but what if a plugin doesn't provide hooks and actions?

Actually I want to extend LearnDash plugin. I want to extend it's functionality in my child plugin. So that if any updates comes in plugin, it shouldn't conflict with our custom changes. But currently I have no idea how to extend it?

Share Improve this question edited Jun 7, 2020 at 17:47 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 7, 2020 at 15:33 Iftikhar uddinIftikhar uddin 1351 silver badge6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

There’s no standard method apart from hooks, and it’s up to the developer of the original plugin to add and support these. If the plugin is extendable they will have developer documentation (LearnDash’s is available here). The specifics will depend entirely on the plugin and how they’ve chosen to allow it.

No, you cannot. There is no such thing as child plugins. You need to use hooks/filters.

Child Plugins

In WordPress we can easily extend a parent theme by creating a child theme. How can we create a child plugin from parent plugin?

Extend is a.. generous term. A child theme lets you override templates of a parent theme, and load both their functions.php, but it's not an arbitrary file replacement mechanism. Look closer and you'll see that code in functions.php and loaded via include or require is not overridable via the child theme system. Those files are in the same situation as plugins.

Put simply, there is no such thing as a child plugin. The very concept makes no sense on a technical level.

What If There Are No Hooks?

I search a lot and people suggested to use actions and hooks but what if a plugin doesn't provide hooks and actions?

Then you have 3 options:

  • Fork the plugin and add them
  • Get the authors to add them and update the plugin
  • Accept that there are no hooks and filters in the plugin

Extending LearnDash

Actually I want to extend LearnDash plugin.

Then you should have contacted LearnDash support, WPSE doesn't offer support for 3rd party plugins.

I want to extend it's functionality in my child plugin.

You could create a second plugin that modifies LearnDash' behaviour by using hooks and filters, but it would not be a child plugin, it would just be a plugin.

Remember, plugins are just PHP files of code, they aren't sandboxed or separated. When the code is loaded, it's loaded. This means everything is all together at the same time, unseparated, and once it's loaded where it got loaded from is irrelevant.

This is why plugins in your theme work if you load them manually from functions.php, or why most of a themes functions.php loads if you move it to a plugin.

Handling Updates

So that if any updates comes in plugin, it shouldn't conflict with our custom changes. But currently I have no idea how to extend it?

Then your changes would be overwritten. Just like if I take your copy of "Toms memoirs v1" and replace it with a v2, your notes and scribbles will be gone when you open the new book up.

In Summary

So:

  • You could fork the plugin, be sure to rename it, but you'd have to manually integrate all the future updates. Big ongoing maintenance cost ( or if you prefer to leave it, big ongoing security hole )
  • Ask LearnDash to add the filters and hooks ( they might say no )
    • If learn dash can't or won't, then tough. You've reached the end of the road
  • Use a competitor or alternative
  • There is no such thing as parent or child plugins

Plugins aren't infinitely extendable, and some are better than others in differing ways

本文标签: How to extend a plugin like we do a theme