Skip to content

Commit

Permalink
Base WP plugin starter files.
Browse files Browse the repository at this point in the history
  • Loading branch information
xipasduarte committed Aug 6, 2017
1 parent 8503e36 commit 40b5e35
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
indent_size = 4
indent_style = space
trim_trailing_whitespace = false

[*.php]
indent_size = 4
indent_style = tab
35 changes: 35 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "[composer_vendor]/[composer_name]",
"description": "[plugin_description]",
"type": "wordpress-plugin",
"keywords": ["wordpress", "plugin"],
"homepage": "[plugin_url]",
"license": "GPL-2.0+",
"require": {
"composer/installers": "~1.0",
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "*@stable",
"10up/wp_mock": "@dev"
},
"authors": [],
"support": {
"issues": "",
"source": ""
},
"autoload": {
"psr-4": {
"[autoload_psr_4]": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"[autoload_tests_psr_4]": "tests/"
}
},
"minimum-stability": "stable",
"config": {
"sort-packages": true
}
}
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden.
Empty file added languages/wp-seed-plugin.pot
Empty file.
33 changes: 33 additions & 0 deletions lib/Activator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Fired during plugin activation
*
* @link [plugin_url]
*
* @package [vendor_name]
* @since [plugin_initial_version]
*/

namespace [namespace];

/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since [plugin_initial_version]
*/
class Activator {

/**
* Summary. (use period)
*
* Description. (use period)
*
* @since [plugin_initial_version]
*/
public static function activate() {

}
}
33 changes: 33 additions & 0 deletions lib/Deactivator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Fired during plugin deactivation
*
* @link [plugin_url]
*
* @package [vendor_name]
* @since [plugin_initial_version]
*/

namespace [namespace];

/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @since [plugin_initial_version]
*/
class Deactivator {

/**
* Summary. (use period)
*
* Description. (use period)
*
* @since [plugin_initial_version]
*/
public static function deactivate() {

}
}
59 changes: 59 additions & 0 deletions lib/I18n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link [plugin_url]
*
* @package [vendor_name]
* @since [plugin_initial_version]
*/

namespace [namespace];

/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since [plugin_initial_version]
*/
class I18n {

/**
* The domain specified for this plugin.
*
* @since [plugin_initial_version]
* @access private
* @var string $domain The domain identifier for this plugin.
*/
private $domain;

/**
* Load the plugin text domain for translation.
*
* @since [plugin_initial_version]
*/
public function load_plugin_textdomain() {
\load_plugin_textdomain(
$this->domain,
false,
dirname( dirname( \plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}

/**
* Set the domain equal to that of the specified domain.
*
* @since [plugin_initial_version]
*
* @param string $domain The domain that represents the locale of this plugin.
*/
public function set_domain( $domain ) {
$this->domain = $domain;
}
}
114 changes: 114 additions & 0 deletions lib/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both
* the public-facing side of the site and the dashboard.
*
* @link [plugin_url]
*
* @package [vendor_name]
* @since [plugin_initial_version]
*/

namespace [namespace];

/**
* The core plugin class.
*
* This is used to define internationalization, dashboard-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since [plugin_initial_version]
*/
class Plugin {

/**
* The unique identifier of this plugin.
*
* @since [plugin_initial_version]
* @access protected
* @var string $pluginname The string used to uniquely identify this
* plugin.
*/
protected $name;

/**
* The current version of the plugin.
*
* @since [plugin_initial_version]
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;

/**
* Define the core functionality of the plugin.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since [plugin_initial_version]
*
* @param string $name The plugin identifier.
* @param string $version Current version of the plugin.
*/
public function __construct( $name, $version ) {
$this->name = $name;
$this->version = $version;
}

/**
* Run the loader to execute all the hooks with WordPress.
*
* Load the dependencies, define the locale, and set the hooks for the
* Dashboard and the public-facing side of the site.
*
* @since [plugin_initial_version]
*/
public function run() {
$this->set_locale();
}

/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since [plugin_initial_version]
*
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->name;
}

/**
* Returns the version number of the plugin.
*
* @since [plugin_initial_version]
*
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}

/**
* Define the locale for this plugin for internationalization.
*
* Uses the I18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since [plugin_initial_version]
* @access private
*/
private function set_locale() {
$plugin_i18n = new I18n();
$plugin_i18n->set_domain( $this->get_plugin_name() );
$plugin_i18n->load_plugin_textdomain();
}
}
1 change: 1 addition & 0 deletions lib/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden.
23 changes: 23 additions & 0 deletions phpcs.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ruleset name="wp-seed-plugin">
<description>WP-Seed Plugin standards for WordPress.</description>

<exclude-pattern>*/phpunit.xml*</exclude-pattern>
<exclude-pattern>*/languages/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>

<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!-- Yoda conditions, we must ignore -->
<rule ref="WordPress.PHP.YodaConditions.NotYoda">
<severity>0</severity>
</rule>

<!-- Ignore lowercase filenames -->
<rule ref="Generic.Files.LowercasedFilename.NotFound">
<severity>0</severity>
</rule>

<rule ref="WordPress-Extra" />
</ruleset>
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<phpunit
bootstrap="test/phpunit/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite>
<directory suffix=".test.php">./test/phpunit/</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">./vendor/</directory>
</blacklist>
</filter>
</phpunit>
Loading

0 comments on commit 40b5e35

Please sign in to comment.