Skip to content

Commit 144f756

Browse files
version 1.0.1
1 parent 7b9048d commit 144f756

17 files changed

+801
-96
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
composer.lock
22
.idea
3+
/vendor

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# WordPress Plugin Developer Boilerplate
2+
:us: - Starter package to start developing plugins with modern PHP.
3+
4+
:brazil: - Pacote inicial para começar a desenvolver plugins com PHP moderno.
5+
6+
### Support
7+
* PSR-4
8+
* PHP >= 7.4
9+
* WooCommerce Sniffs

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*** WooCommerce Extension Template Changelog ***
2+
3+
YYYY-MM-DD - version 1.0.0
4+
* Initial release

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"email": "heitorspedroso@gmail.com"
1212
}
1313
],
14-
"require": {},
1514
"autoload": {
1615
"psr-4": {
1716
"PluginDeveloperBoilerplate\\": "./src"
1817
}
18+
},
19+
"require-dev": {
20+
"woocommerce/woocommerce-sniffs": "^0.1.0"
1921
}
2022
}

phpcs.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WooCommerce Coding Standards">
3+
<description>My projects ruleset.</description>
4+
5+
<!-- Configs -->
6+
<config name="minimum_supported_wp_version" value="5.2" />
7+
<config name="testVersion" value="7.2-" />
8+
9+
<!-- Rules -->
10+
<rule ref="WooCommerce-Core" />
11+
12+
<rule ref="WordPress.WP.I18n">
13+
<properties>
14+
<property name="text_domain" type="array" value="pllugin-developer-boilerplate" />
15+
</properties>
16+
</rule>
17+
18+
<rule ref="WooCommerce.Functions.InternalInjectionMethod">
19+
<include-pattern>src/</include-pattern>
20+
<include-pattern>tests/php/src/</include-pattern>
21+
<properties>
22+
<property name="injectionMethod" value="init"/>
23+
</properties>
24+
</rule>
25+
26+
<rule ref="PHPCompatibility">
27+
<exclude-pattern>tests/</exclude-pattern>
28+
</rule>
29+
30+
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
31+
<exclude-pattern>tests/</exclude-pattern>
32+
<exclude-pattern>src/</exclude-pattern>
33+
<exclude-pattern>tests/php/src/</exclude-pattern>
34+
</rule>
35+
36+
<rule ref="Squiz.Classes.ClassFileName">
37+
<include-pattern>src/</include-pattern>
38+
<include-pattern>tests/php/src/</include-pattern>
39+
</rule>
40+
41+
<rule ref="Squiz.Classes.ValidClassName">
42+
<include-pattern>src/</include-pattern>
43+
<include-pattern>tests/php/src/</include-pattern>
44+
</rule>
45+
46+
<rule ref="Generic.Commenting">
47+
<exclude-pattern>tests/</exclude-pattern>
48+
</rule>
49+
50+
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
51+
<exclude-pattern>i18n/</exclude-pattern>
52+
<exclude-pattern>src/</exclude-pattern>
53+
<exclude-pattern>tests/php</exclude-pattern>
54+
<exclude-pattern>tests/Tools/</exclude-pattern>
55+
</rule>
56+
57+
<rule ref="Squiz.Commenting.FileComment.MissingPackageTag">
58+
<exclude-pattern>src/</exclude-pattern>
59+
<exclude-pattern>tests/php/</exclude-pattern>
60+
</rule>
61+
<rule ref="Squiz.Commenting.FileComment.Missing">
62+
<exclude-pattern>src/</exclude-pattern>
63+
<exclude-pattern>tests/php/</exclude-pattern>
64+
</rule>
65+
66+
<rule ref="Squiz.Commenting.FunctionCommentThrowTag.Missing">
67+
<exclude-pattern>tests/php/</exclude-pattern>
68+
</rule>
69+
70+
<rule ref="Squiz.Commenting.FileComment.Missing">
71+
<exclude-pattern>tests/php/</exclude-pattern>
72+
</rule>
73+
</ruleset>

plugin-developer-boilerplate.php

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,62 @@
11
<?php
2-
/*
3-
* Plugin Name: Plugin Developer Boilerplate
4-
* Plugin URI: #
5-
* Description: Plugin Developer Boilerplate Description
6-
* Version: 1.0.0
7-
* Requires at least: 5.6.2
8-
* Requires PHP: 7.2
9-
* Author: Array é Vida
10-
* Author URI: https://arrayevida.com.br/
11-
* Developer: Heitor Sousa
12-
* Developer URI: https://arrayevida.com.br/
13-
* Domain Path: /languages
14-
* Text Domain: plugin-developer-boilerplate
15-
* *
16-
* Woo: 12345:12345
17-
* WC requires at least: 4.8.0
18-
* WC tested up to: 5.0.0
19-
*
20-
* License: GNU General Public License v3.0
21-
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
22-
*/
2+
/**
3+
*
4+
* Plugin Name: Plugin Developer Boilerplate
5+
* Plugin URI: #
6+
* Description: Plugin Developer Boilerplate Description
7+
* Version: 1.0.0
8+
* Requires at least: 5.6.2
9+
* Requires PHP: 7.2
10+
* Author: Array é Vida
11+
* Author URI: https://arrayevida.com.br/
12+
* Developer: Heitor Sousa
13+
* Developer URI: https://github.com/heitorspedroso
14+
* Domain Path: /languages
15+
* Text Domain: plugin-developer-boilerplate
16+
* *
17+
* Woo: 12345:12345
18+
* WC requires at least: 4.8.0
19+
* WC tested up to: 5.0.0
20+
*
21+
* License: GNU General Public License v3.0
22+
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
23+
*
24+
* @package 'plugin-developer-boilerplate'
25+
*/
2326

27+
use PluginDeveloperBoilerplate\Activate;
28+
use PluginDeveloperBoilerplate\Deactivate;
2429
use PluginDeveloperBoilerplate\PluginDeveloperBoilerplate;
2530

26-
if ( ! defined( 'ABSPATH' ) )
31+
if ( ! defined( 'ABSPATH' ) ) {
2732
exit;
33+
}
2834

29-
if (file_exists(dirname(__FILE__).'/vendor/autoload.php')){
30-
require_once dirname(__FILE__).'/vendor/autoload.php';
35+
if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
36+
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
3137
}
3238

33-
if ( ! class_exists( 'PluginDeveloperBoilerplate' ) ):
39+
if ( ! class_exists( 'Activate' ) ) :
40+
/**
41+
* Activate function.
42+
*/
43+
function activate() {
44+
Activate::activate();
45+
}
46+
register_activation_hook( __FILE__, 'activate' );
47+
endif;
48+
49+
50+
if ( ! class_exists( 'Deactivate' ) ) :
51+
/**
52+
* Deactivate function.
53+
*/
54+
function deactivate() {
55+
Deactivate::deactivate();
56+
}
57+
register_deactivation_hook( __FILE__, 'deactivate' );
58+
endif;
59+
60+
if ( ! class_exists( 'PluginDeveloperBoilerplate' ) ) :
3461
PluginDeveloperBoilerplate::instance();
3562
endif;

readme.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== Plugin Developer Boilerplate ===
2+
Contributors: Heitor Sousa
3+
Donate link: https://arrayevida.com.br
4+
Tags: plugin boilerplate
5+
Requires at least: 5.0.0
6+
Tested up to: 5.7.2
7+
Stable tag: 1.0.0
8+
License: GNU General Public License v3.0
9+
License URI: http://www.gnu.org/licenses/gpl-3.0.html
10+
11+
== Changelog ==
12+
13+
= 1.0.0 - YYYY-MM-DD =
14+
* First Version

src/Activate.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
<?php
2-
2+
/**
3+
* PluginDeveloperBoilerplate Activate
4+
*
5+
* @version 1.0.1
6+
* @package 'plugin-developer-boilerplate
7+
*/
38

49
namespace PluginDeveloperBoilerplate;
510

6-
if ( ! defined( 'ABSPATH' ) )
11+
if ( ! defined( 'ABSPATH' ) ) {
712
exit;
13+
}
814

9-
if ( ! class_exists( 'Activate' ) ):
15+
if ( ! class_exists( 'Activate' ) ) :
16+
/**
17+
* Class Activate
18+
*/
1019
final class Activate {
1120

12-
public static function activate(){
21+
/**
22+
* Activate
23+
*/
24+
public static function activate() {
25+
$log = new \WC_Logger();
26+
$log_entry = 'activate function';
27+
$log->add( 'plugin-developer-boilerplate', $log_entry );
1328
flush_rewrite_rules();
1429
}
1530

src/Deactivate.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
<?php
2-
2+
/**
3+
* PluginDeveloperBoilerplate Deactivate
4+
*
5+
* @version 1.0.1
6+
* @package 'plugin-developer-boilerplate
7+
*/
38

49
namespace PluginDeveloperBoilerplate;
510

6-
if ( ! defined( 'ABSPATH' ) )
11+
if ( ! defined( 'ABSPATH' ) ) {
712
exit;
13+
}
814

9-
if ( ! class_exists( 'Deactivate' ) ):
15+
if ( ! class_exists( 'Deactivate' ) ) :
16+
/**
17+
* Class Activate
18+
*/
1019
final class Deactivate {
1120

12-
public static function deactivate(){
21+
/**
22+
* Deactivate
23+
*/
24+
public static function deactivate() {
25+
$log = new \WC_Logger();
26+
$log_entry = 'deactivate function';
27+
$log->add( 'plugin-developer-boilerplate', $log_entry );
1328
flush_rewrite_rules();
1429
}
1530

src/PluginDeveloperBoilerplate.php

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
<?php
2+
/**
3+
* PluginDeveloperBoilerplate Init
4+
*
5+
* @version 1.0.1
6+
* @package 'plugin-developer-boilerplate
7+
*/
28

39
namespace PluginDeveloperBoilerplate;
410

5-
if ( ! defined( 'ABSPATH' ) )
11+
if ( ! defined( 'ABSPATH' ) ) {
612
exit;
13+
}
714

8-
if ( ! class_exists( 'PluginDeveloperBoilerplate' ) ):
15+
if ( ! class_exists( 'PluginDeveloperBoilerplate' ) ) :
916
/**
1017
* Class PluginDeveloperBoilerplate
11-
* @package PluginDeveloperBoilerplate
12-
* @author Heitor <heitorspedroso@gmail.com>
13-
* @version 1.0.0
1418
*/
1519
final class PluginDeveloperBoilerplate {
1620

1721
/**
22+
* Const PLUGIN_PATH
23+
*
1824
* @const PLUGIN_PATH
1925
*/
2026
public const PLUGIN_PATH = __FILE__;
2127

2228
/**
29+
* Instance of this class.
30+
*
2331
* @var $instance
2432
*/
2533
protected static $instance = null;
2634

2735
/**
36+
* Return an instance of this class.
37+
*
2838
* @return static::$instance
2939
*/
30-
final public static function instance() {
40+
public static function instance() {
3141
if ( null === static::$instance ) {
3242
static::$instance = new static();
3343
}
@@ -38,52 +48,29 @@ final public static function instance() {
3848
* PluginDeveloperBoilerplate constructor.
3949
*/
4050
public function __construct() {
41-
$this->registerHooks();
51+
$this->register_hooks();
52+
$this->register_classes();
4253
}
4354

4455
/**
45-
* registerHooks
56+
* Register_hooks function.
4657
*/
47-
private function registerHooks(){
48-
register_activation_hook( self::PLUGIN_PATH, [$this, 'activate'] );
49-
register_deactivation_hook ( self::PLUGIN_PATH, [$this, 'deactivate'] );
50-
51-
// Load plugin text domain.
52-
add_action( 'init', [$this, 'loadPluginTextDomain'] );
58+
private function register_hooks() {
59+
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
5360
}
5461

5562
/**
56-
* activate
63+
* Register_classes function.
5764
*/
58-
private function activate(){
59-
Activate::activate();
60-
}
65+
private function register_classes() {
6166

62-
/**
63-
* deactivate
64-
*/
65-
private function deactivate(){
66-
Deactivate::deactivate();
6767
}
6868

6969
/**
70-
* loadPluginTextDomain
70+
* Load_plugin_textdomain function
7171
*/
72-
public function loadPluginTextDomain() {
73-
load_plugin_textdomain( 'plugin-developer-boilerplate', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
74-
}
75-
76-
/**
77-
* Debug
78-
*/
79-
public function debugMe( $message ) {
80-
if ( WP_DEBUG === true ) {
81-
if ( is_array( $message ) || is_object( $message ) ) {
82-
error_log( print_r( $message, true ) );
83-
} else {
84-
error_log( $message );
85-
}
86-
}
72+
public function load_plugin_textdomain() {
73+
load_plugin_textdomain( 'plugin-developer-boilerplate', false, dirname( plugin_basename( self::PLUGIN_PATH ) ) . '/i18n/languages/' );
8774
}
8875
}
8976
endif;

0 commit comments

Comments
 (0)