FAQ's - octopus-digital-strategy/wp-barebones-plugin GitHub Wiki
#Frequently Asked Questions
Visit the Getting Started Guide to understand how to use this project.
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...
TBD