DevinVinson / WordPress-Plugin-Boilerplate

[WordPress] A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.
http://wppb.io
7.62k stars 2.25k forks source link

Where to put my own code? #565

Open sintacs opened 3 years ago

sintacs commented 3 years ago

Hello,

I installed the plugin and want to start adding my own code (class exists). How do I start, where do I put the code?

Greetings Dirk

DevinVinson commented 3 years ago

You can edit your own plugin however you want to and put the code wherever you want. I have a walk through on writing a plugin using the boilerplate here if you wanted to see a simplified usage: https://devinvinson.com/simple-login-style-plugin/

sintacs commented 3 years ago

Thank you, but my plugin won't be this simple (simple in meaning including some js and/or css). Let me explain: I have a existing class that I want to include in the WPPB but don't know where to put existing it or the code of it. Should I copy the code into a existing file from the WPPB or include the class-file, but where and how do I initiate the class?

VoHoTv commented 2 years ago

@sintacs That depends on how the class is designed. But let's say it's a simple class with methods that should be added to a hook. Then either put it in the admin or public folder depending on what the functionality belongs to. And include it inside a method in class-plugin-name-public.php or even the load_dependencies method in class-plugin-name.php. Now all that's left to do is instantiate the class in the define_admin_hooks or define_public_hooks and hook it in.

But really, there are no good or bad ways to do it. This boilerplate is designed as a starting point for creating a plugin. And is not a framework with strict rules on what you should and shouldn't do. That is up to you :)

sintacs commented 2 years ago

@VoHoTv Thank you for your answer. I figured it out. :D

rolka commented 1 year ago

@DevinVinson Looks like you've got some broken image links on https://devinvinson.com/simple-login-style-plugin/