Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/vendor
composer.lock
/composer.lock
/*.sublime-project
/*.sublime-workspace
/.phpcs.xml
/phpcs.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ After cloning this repository, run `composer install` in the root directory of t

### From Packaged Releases on WordPress.org

Packaged releases on WordPress.org will automatically include the required autoloaders.
Packaged releases on WordPress.org will automatically include the required autoloaders.
19 changes: 19 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Mindsize\WP_Plugin_Base;

define('WP_PLUGIN_BASE_VERSION', '1.0.0');
define('WP_PLUGIN_BASE_SLUG', 'wp-plugin-base');
define('WP_PLUGIN_BASE_FILE', __FILE__);
define('WP_PLUGIN_BASE_DIR', plugin_dir_path(WP_PLUGIN_BASE_FILE));
define('WP_PLUGIN_BASE_URL', plugin_dir_url(WP_PLUGIN_BASE_FILE));

function wp_plugin_base()
{
return PluginFactory::create();
}

function load_plugin()
{
$instance = wp_plugin_base();
$instance->init();
}
15 changes: 3 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
"type": "wordpress-plugin",
"license": "GPL-2.0",
"require": {
"composer/installers": "^1.4",
"xrstf/composer-php52": "^1.0",
"gamajo/template-loader": "^1.3"
},
"autoload": {
"classmap": [
"includes"
]
},
"scripts": {
"post-install-cmd": [
"xrstf\\Composer52\\Generator::onPostInstallCmd"
],
"post-update-cmd": [
"xrstf\\Composer52\\Generator::onPostInstallCmd"
],
"post-autoload-dump": [
"xrstf\\Composer52\\Generator::onPostInstallCmd"
]
"require-dev": {
"phpro/grumphp": "^0.14.1",
"squizlabs/php_codesniffer": "^3.3"
}
}
6 changes: 6 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
hide_circumvention_tip: true
ignore_unstaged_changes: true
tasks:
phpcs:
standard: null
16 changes: 6 additions & 10 deletions includes/class-cli.php → includes/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
use WP_CLI_Command;
use WP_CLI;

if ( ! class_exists( 'WP_CLI_Command' ) ) {
return;
}

/**
* CLI access to the sample plugin.
*
Expand All @@ -25,10 +21,10 @@
* $ wp wp-plugin-base ping
* pong
*/
class CLI extends WP_CLI_Command {

public function ping() {
WP_CLI::line( 'pong' );
}

class CLI extends WP_CLI_Command
{
public function ping()
{
WP_CLI::line('pong');
}
}
43 changes: 43 additions & 0 deletions includes/Core.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Mindsize\WP_Plugin_Base;

use WP_CLI;

/**
* WP Plugin Base main class file.
*
* This class file is the base of this WordPress sample plugin, someday it will do great things.
*
* @since 1.0.0
* @author Mindsize <info@mindsize.me>
* @copyright Copyright (c) 2017 Mindsize <info@mindsize.me>
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0
*/
class Core
{

/**
* Container for template loader instance.
*/
protected $template_loader;

/**
* Constructor.
*/
public function init()
{
if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI_Command')) {
WP_CLI::add_command(WP_PLUGIN_BASE_SLUG, __NAMESPACE__ . '\\CLI');
}

$this->template_loader = new TemplateLoader();
}

/**
* Template loader
*/
public function templateLoader()
{
return $this->template_loader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
* @copyright Copyright (c) 2017 Mindsize <info@mindsize.me>
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0
*/
class WP_Plugin_Factory {
public static function create() {
static $plugin = null;
class PluginFactory
{
public static function create()
{
static $plugin = null;

if ( null === $plugin ) {
$plugin = new Core();
}
if (null === $plugin) {
$plugin = new Core();
}

return $plugin;
}
return $plugin;
}
}
58 changes: 58 additions & 0 deletions includes/TemplateLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Mindsize\WP_Plugin_Base;

use Gamajo_Template_Loader;

/**
* Template loader which allows for WordPress template files that can even be overridden from the theme.
*
* @since 1.0.0
* @author Mindsize <info@mindsize.me>
* @copyright Copyright (c) 2017 Mindsize <info@mindsize.me>
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0
*/
class TemplateLoader extends Gamajo_Template_Loader
{

/**
* Prefix for filter names.
*
* @since 1.0.0
*
* @var string
*/
protected $filter_prefix = WP_PLUGIN_BASE_SLUG;

/**
* Directory name where custom templates for this plugin should be found in the theme.
*
* @since 1.0.0
*
* @var string
*/
protected $theme_template_directory = WP_PLUGIN_BASE_SLUG;

/**
* Reference to the root directory path of this plugin.
*
* Can either be a defined constant, or a relative reference from where the subclass lives.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_directory = WP_PLUGIN_BASE_DIR;

/**
* Directory name where templates are found in this plugin.
*
* Can either be a defined constant, or a relative reference from where the subclass lives.
*
* e.g. 'templates' or 'includes/templates', etc.
*
* @since 1.1.0
*
* @var string
*/
protected $plugin_template_directory = 'templates';
}
40 changes: 0 additions & 40 deletions includes/class-core.php

This file was deleted.

57 changes: 0 additions & 57 deletions includes/class-template-loader.php

This file was deleted.

6 changes: 6 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="PSR2">
<description>Override to always use PSR2 for this project.</description>

<rule ref="PSR2"/>
</ruleset>
32 changes: 6 additions & 26 deletions wp-plugin-base.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
<?php
namespace Mindsize\WP_Plugin_Base;

/**
* Plugin Name: WordPress Plugin Base
* Description: This is a sample plugin that was created with mindsize/wp-plugin-base
* Plugin Name: WP Plugin Base
* Description: Base plugin on which a composerised modern plugin can be implemented.
* Author: Mindsize
* Author URI: http://mindsize.me
* Version: 1.0.0
* Requires at least: 4.4
* Tested up to: 4.8
*/

define( 'WP_PLUGIN_BASE_VERSION', '1.0.0' );
define( 'WP_PLUGIN_BASE_SLUG', 'wp-plugin-base' );
define( 'WP_PLUGIN_BASE_FILE', __FILE__ );
define( 'WP_PLUGIN_BASE_DIR', plugin_dir_path( WP_PLUGIN_BASE_FILE ) );
define( 'WP_PLUGIN_BASE_URL', plugin_dir_url( WP_PLUGIN_BASE_FILE ) );

if ( file_exists( WP_PLUGIN_BASE_DIR . 'vendor/autoload_52.php' ) ) {
require_once WP_PLUGIN_BASE_DIR . 'vendor/autoload_52.php';
}

function wp_plugin_base() {
if ( ! class_exists( __NAMESPACE__ . '\\WP_Plugin_Factory' ) ) {
throw new \Exception( __NAMESPACE__ . '\\WP_Plugin_Factory class cannot be found.' );
}

return WP_Plugin_Factory::create();
}
namespace Mindsize\WP_Plugin_Base;

function load_plugin() {
$instance = wp_plugin_base();
$instance->init();
}
require_once 'vendor/autoload.php';
require_once 'bootstrap.php';

add_action( 'plugins_loaded', __NAMESPACE__ . '\\load_plugin' );
add_action('plugins_loaded', __NAMESPACE__ . '\\load_plugin');