Howdy
WordPress plugin starter. Based on "Service Provider" design pattern.
Environment setup
composer install
npm install
npm run dev
wp-config.php > define( HOWDY_DEV_MODE, true )
for loading unminified assets.
Plugin Backend Architecture
howdy.php |---- bootstrap.php
|
Service Provider |
| |
Controller |---- Helpers
| |
Views |
Debugging Tool/API
On development environment, two apis are available for better debugging experience.
dump($data); // debug data
dd($data); // debug data and die.
SingleTon
A trait for singleton is available. You can use it for creating single class instance. For example: check HowdyServiceProvider
we have used SingleTon
, then created class instance in howdy.php > HowdyServiceProvider::getInstance()
.
HTTP API
Set rest api base url, namespace, version in HowdyHttp
class
Request Example
/**
* GET request
*
* @param (string) $route
* @param (array) $arguments
* @return \Howdy\Helpers\Response
*/
$response = HowdyHttp::get( 'post',
[
'timeout' => 25
]
);
/**
* POST request
*
* @param (string) $route
* @param (array) $arguments
* @return \Howdy\Helpers\Response
*/
$response = HowdyHttp::post( 'authenticate',
[
'body' => [ 'token' => 'sdlfepoagdhwt3543sfes' ]
]
);
Response API
HTTP requests return \Howdy\Helpers\Response
object. This object has apis as below.
getBody() // json decoded body of the response
getBody(false) // json encoded body
getStatusCode() // status code of the response
getMessage() // response message
getHeaders() // get response headers
dump() // debug response
Response Example
$response = HowdyHttp::post( 'authenticate',
[
'body' => [ 'token' => 'sdlfepoagdhwt3543sfes' ]
]
);
if ( $response->getStatusCode() === 200 ) {
// Do something
}
$response->dump(); // debug response data
Deploy Automation
Deploy to WordPress org plugin repo by creating a tag and push it on Github. For doing so, just go to your plugin Github repo Settings > Secrets
and create tow variables as below. Then change SLUG
in .github/workflows/diploy.yml
, here add your plugin's WP ORG slug.
That's it, now whenever you push a tag on Github the plugin will be automatically deployed to WP ORG plugin repo. It remove all development files that are not required in production. If you want to change which development files to remove than just modife .distignore
WP_SVN_USER <your svn user>
WP_SVN_PASS <your svn password>