WordPress-Plugin-Boilerplate icon indicating copy to clipboard operation
WordPress-Plugin-Boilerplate copied to clipboard

Where to put my own code?

Open sintacs opened this issue 3 years ago • 5 comments

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

sintacs avatar Jul 08 '21 14:07 sintacs

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/

DevinVinson avatar Jul 08 '21 17:07 DevinVinson

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?

sintacs avatar Jul 09 '21 08:07 sintacs

@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 :)

VoHoTv avatar Sep 01 '21 09:09 VoHoTv

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

sintacs avatar Apr 11 '22 08:04 sintacs

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

rolka avatar Mar 31 '23 15:03 rolka