FAQ's - octopus-digital-strategy/wp-barebones-plugin GitHub Wiki

#Frequently Asked Questions

0. Is there a Quick Guide?

Visit the Getting Started Guide to understand how to use this project.

1. How do I add my own code to the plugin?

After you have completed all of the steps in the Getting Started Guide you should have an environment with your own custom namespace.

For the sake of this project we will use YOURPLUGIN as our namespace.

Remember we are using PSR-4, so lets add a class to the src/ directory named HelloShortCode.class.php

// Code for src/HelloShortCode.class.php

namespace YourPlugin;

class HelloShortCode
{
    public function __construct()
    {
       add_shortcode( 'my-own-shortcode', array( $this, 'Hello' ) );
    }

    public function Hello()
    {
        return '<span>Saying Hello</span>';
    }
}

###Edit SetupPlugin.class.php

One you code is complete you can instantiate the class from SetupPlugin.class.php constructor.

You have two options.

####With the use statement

use YourPlugin\HelloShortCode; // The use statement

class SetupPlugin
{

    public function __construct()
    {
        $this->registerStylesAndScripts();
        new HelloShortCode(); // 
    }

// The rest of the code...

####Without the use statement

class SetupPlugin
{

    public function __construct()
    {
        $this->registerStylesAndScripts();
        new YourPlugin\HelloShortCode(); // Namespace/Classname
    }

// The rest of the code...

2. Where do I add my own scripts or styles?

TBD

⚠️ **GitHub.com Fallback** ⚠️