@sabbir1991/wpscaffold 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +326 -0
- package/bin/index.js +19 -0
- package/lib/generator.js +435 -0
- package/package.json +30 -0
- package/template/_editorconfig +19 -0
- package/template/_github/ISSUE_TEMPLATE/bug_report.yml +29 -0
- package/template/_github/ISSUE_TEMPLATE/config.yml +1 -0
- package/template/_github/ISSUE_TEMPLATE/feature_request.yml +18 -0
- package/template/_github/PULL_REQUEST_TEMPLATE.md +16 -0
- package/template/_github/workflows/lint.yml +31 -0
- package/template/_github/workflows/phpcs.yml +29 -0
- package/template/_github/workflows/phpunit.yml +34 -0
- package/template/_gitignore +34 -0
- package/template/_nvmrc +1 -0
- package/template/_stylelintignore +11 -0
- package/template/composer.json +35 -0
- package/template/eslint.config.js +8 -0
- package/template/includes/Admin/Menu.php +67 -0
- package/template/includes/Assets.php +140 -0
- package/template/includes/Blocks.php +53 -0
- package/template/includes/Plugin.php +59 -0
- package/template/includes/Traits/Singleton.php +46 -0
- package/template/languages/.gitkeep +0 -0
- package/template/lefthook.yml +13 -0
- package/template/phpcs.xml.dist +42 -0
- package/template/phpunit.xml.dist +19 -0
- package/template/plugin-skeleton.php +64 -0
- package/template/readme.txt +25 -0
- package/template/src/block/block.json +17 -0
- package/template/src/block/edit.js +17 -0
- package/template/src/block/index.js +13 -0
- package/template/src/block/render.php +13 -0
- package/template/src/block/style.scss +8 -0
- package/template/src/block/view.js +5 -0
- package/template/src/global/css/admin.scss +8 -0
- package/template/src/global/js/admin.js +5 -0
- package/template/tests/Unit/AbstractTestCase.php +25 -0
- package/template/tests/Unit/AssetsTest.php +58 -0
- package/template/tests/Unit/MenuTest.php +38 -0
- package/template/tests/bootstrap.php +56 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sabbir1991/plugin-skeleton",
|
|
3
|
+
"type": "wordpress-plugin",
|
|
4
|
+
"description": "A WordPress plugin skeleton for rapid development.",
|
|
5
|
+
"license": "GPL-2.0-or-later",
|
|
6
|
+
"require": {},
|
|
7
|
+
"require-dev": {
|
|
8
|
+
"wp-coding-standards/wpcs": "^3.1",
|
|
9
|
+
"phpcompatibility/phpcompatibility-wp": "*",
|
|
10
|
+
"sirbrillig/phpcs-variable-analysis": "^2.11",
|
|
11
|
+
"brain/monkey": "^2.6",
|
|
12
|
+
"yoast/phpunit-polyfills": "^2.0",
|
|
13
|
+
"phpunit/phpunit": "^9.5 || ^10.5"
|
|
14
|
+
},
|
|
15
|
+
"autoload": {
|
|
16
|
+
"psr-4": {
|
|
17
|
+
"PluginVendor\\PluginSkeleton\\": "includes/"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"autoload-dev": {
|
|
21
|
+
"psr-4": {
|
|
22
|
+
"PluginVendor\\PluginSkeleton\\Tests\\": "tests/"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"cs": "@php ./vendor/bin/phpcs",
|
|
27
|
+
"cs:fix": "@php ./vendor/bin/phpcbf",
|
|
28
|
+
"test": "@php ./vendor/bin/phpunit"
|
|
29
|
+
},
|
|
30
|
+
"config": {
|
|
31
|
+
"allow-plugins": {
|
|
32
|
+
"dealerdirect/phpcodesniffer-composer-installer": true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Admin menu registration.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace PluginVendor\PluginSkeleton\Admin;
|
|
11
|
+
|
|
12
|
+
use PluginVendor\PluginSkeleton\Traits\Singleton;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class Menu.
|
|
16
|
+
*/
|
|
17
|
+
class Menu {
|
|
18
|
+
|
|
19
|
+
use Singleton;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*/
|
|
24
|
+
protected function __construct() {
|
|
25
|
+
$this->setup_hooks();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Register WordPress hooks.
|
|
30
|
+
*
|
|
31
|
+
* @return void
|
|
32
|
+
*/
|
|
33
|
+
private function setup_hooks(): void {
|
|
34
|
+
add_action( 'admin_menu', [ $this, 'register_menu' ] );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Register the top-level admin menu page.
|
|
39
|
+
*
|
|
40
|
+
* @return void
|
|
41
|
+
*/
|
|
42
|
+
public function register_menu(): void {
|
|
43
|
+
add_menu_page(
|
|
44
|
+
__( 'Plugin Skeleton', 'plugin-skeleton' ),
|
|
45
|
+
__( 'Plugin Skeleton', 'plugin-skeleton' ),
|
|
46
|
+
'manage_options',
|
|
47
|
+
'plugin-skeleton',
|
|
48
|
+
[ $this, 'render_page' ],
|
|
49
|
+
'dashicons-admin-generic',
|
|
50
|
+
'99'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Render the admin page.
|
|
56
|
+
*
|
|
57
|
+
* @return void
|
|
58
|
+
*/
|
|
59
|
+
public function render_page(): void {
|
|
60
|
+
?>
|
|
61
|
+
<div class="wrap">
|
|
62
|
+
<h1><?php esc_html_e( 'Plugin Skeleton', 'plugin-skeleton' ); ?></h1>
|
|
63
|
+
<p><?php esc_html_e( 'Plugin Skeleton is working! Start building your plugin here.', 'plugin-skeleton' ); ?></p>
|
|
64
|
+
</div>
|
|
65
|
+
<?php
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Assets class — script and style registration.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace PluginVendor\PluginSkeleton;
|
|
11
|
+
|
|
12
|
+
use PluginVendor\PluginSkeleton\Traits\Singleton;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class Assets.
|
|
16
|
+
*/
|
|
17
|
+
class Assets {
|
|
18
|
+
|
|
19
|
+
use Singleton;
|
|
20
|
+
|
|
21
|
+
/* @skeleton-admin */
|
|
22
|
+
/**
|
|
23
|
+
* Constructor.
|
|
24
|
+
*/
|
|
25
|
+
protected function __construct() {
|
|
26
|
+
$this->setup_hooks();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Register WordPress hooks.
|
|
31
|
+
*
|
|
32
|
+
* @return void
|
|
33
|
+
*/
|
|
34
|
+
private function setup_hooks(): void {
|
|
35
|
+
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Register admin scripts and styles.
|
|
40
|
+
*
|
|
41
|
+
* @return void
|
|
42
|
+
*/
|
|
43
|
+
public function admin_scripts(): void {
|
|
44
|
+
$this->register_script( 'plugin-skeleton-admin', 'build/admin.js', [], PLUGIN_SKELETON_VERSION, true );
|
|
45
|
+
$this->register_style( 'plugin-skeleton-admin', 'build/admin.css', [], PLUGIN_SKELETON_VERSION );
|
|
46
|
+
wp_enqueue_script( 'plugin-skeleton-admin' );
|
|
47
|
+
wp_enqueue_style( 'plugin-skeleton-admin' );
|
|
48
|
+
}
|
|
49
|
+
/* @skeleton-admin-end */
|
|
50
|
+
/* @skeleton-block-only */
|
|
51
|
+
/**
|
|
52
|
+
* Constructor — no hooks needed for block-only plugins.
|
|
53
|
+
*/
|
|
54
|
+
protected function __construct() {
|
|
55
|
+
}
|
|
56
|
+
/* @skeleton-block-only-end */
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Load asset metadata from generated .asset.php file.
|
|
60
|
+
*
|
|
61
|
+
* @param string $file Relative path under assets/.
|
|
62
|
+
* @param array $deps Additional dependency handles.
|
|
63
|
+
* @param mixed $ver Fallback version.
|
|
64
|
+
* @return array
|
|
65
|
+
*/
|
|
66
|
+
public function get_asset_meta( string $file, array $deps = [], $ver = false ): array {
|
|
67
|
+
$asset_meta_file = sprintf(
|
|
68
|
+
'%s/%s.asset.php',
|
|
69
|
+
untrailingslashit( PLUGIN_SKELETON_ASSET_PATH ),
|
|
70
|
+
preg_replace( '/\.[^.]+$/', '', $file )
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
$asset_meta = is_readable( $asset_meta_file )
|
|
74
|
+
? require $asset_meta_file
|
|
75
|
+
: [
|
|
76
|
+
'dependencies' => [],
|
|
77
|
+
'version' => $this->get_file_version( $file, $ver ),
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
$asset_meta['dependencies'] = array_merge( $deps, $asset_meta['dependencies'] );
|
|
81
|
+
|
|
82
|
+
return $asset_meta;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get a file's version (filemtime or provided fallback).
|
|
87
|
+
*
|
|
88
|
+
* @param string $file Relative path under assets/build/.
|
|
89
|
+
* @param mixed $ver Explicit version override.
|
|
90
|
+
* @return string|false
|
|
91
|
+
*/
|
|
92
|
+
public function get_file_version( string $file, $ver = false ) {
|
|
93
|
+
if ( ! empty( $ver ) ) {
|
|
94
|
+
return $ver;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
$file_path = sprintf( '%s/%s', PLUGIN_SKELETON_ASSET_PATH, $file );
|
|
98
|
+
|
|
99
|
+
return file_exists( $file_path ) ? (string) filemtime( $file_path ) : false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Register a script.
|
|
104
|
+
*
|
|
105
|
+
* @param string $handle Script handle.
|
|
106
|
+
* @param string $file Path relative to assets/ (or full URL).
|
|
107
|
+
* @param string[] $deps Additional dependencies.
|
|
108
|
+
* @param mixed $ver Version override.
|
|
109
|
+
* @param bool $in_footer Enqueue in footer.
|
|
110
|
+
* @return bool
|
|
111
|
+
*/
|
|
112
|
+
public function register_script( string $handle, string $file, array $deps = [], $ver = false, bool $in_footer = true ): bool {
|
|
113
|
+
$src = str_starts_with( $file, 'https://' ) ? $file : sprintf( '%s/%s', PLUGIN_SKELETON_ASSET_URL, $file );
|
|
114
|
+
$asset_meta = $this->get_asset_meta( $file, $deps, $ver );
|
|
115
|
+
|
|
116
|
+
return wp_register_script( $handle, $src, $asset_meta['dependencies'], $asset_meta['version'], $in_footer );
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Register a stylesheet.
|
|
121
|
+
*
|
|
122
|
+
* @param string $handle Script handle.
|
|
123
|
+
* @param string $file Path relative to assets/ (or full URL).
|
|
124
|
+
* @param string[] $deps Additional dependencies.
|
|
125
|
+
* @param mixed $ver Version override.
|
|
126
|
+
* @param string $media Media type.
|
|
127
|
+
* @return bool
|
|
128
|
+
*/
|
|
129
|
+
public function register_style( string $handle, string $file, array $deps = [], $ver = false, string $media = 'all' ): bool {
|
|
130
|
+
if ( str_starts_with( $file, 'https://' ) ) {
|
|
131
|
+
$src = $file;
|
|
132
|
+
$ver = PLUGIN_SKELETON_VERSION;
|
|
133
|
+
} else {
|
|
134
|
+
$src = sprintf( '%s/%s', PLUGIN_SKELETON_ASSET_URL, $file );
|
|
135
|
+
$ver = $this->get_file_version( $file, $ver );
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return wp_register_style( $handle, $src, $deps, $ver, $media );
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Block registration.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace PluginVendor\PluginSkeleton;
|
|
11
|
+
|
|
12
|
+
use PluginVendor\PluginSkeleton\Traits\Singleton;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class Blocks.
|
|
16
|
+
*/
|
|
17
|
+
class Blocks {
|
|
18
|
+
|
|
19
|
+
use Singleton;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*/
|
|
24
|
+
protected function __construct() {
|
|
25
|
+
$this->setup_hooks();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Register WordPress hooks.
|
|
30
|
+
*
|
|
31
|
+
* @return void
|
|
32
|
+
*/
|
|
33
|
+
private function setup_hooks(): void {
|
|
34
|
+
add_action( 'init', [ $this, 'register_blocks' ] );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Register all plugin blocks from the build directory.
|
|
39
|
+
*
|
|
40
|
+
* @return void
|
|
41
|
+
*/
|
|
42
|
+
public function register_blocks(): void {
|
|
43
|
+
$build_dir = PLUGIN_SKELETON_PATH . '/build';
|
|
44
|
+
|
|
45
|
+
if ( ! is_dir( $build_dir ) ) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
foreach ( glob( $build_dir . '/*/block.json' ) ?: [] as $block_json ) {
|
|
50
|
+
register_block_type( dirname( $block_json ) );
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Main plugin class.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace PluginVendor\PluginSkeleton;
|
|
11
|
+
|
|
12
|
+
/* @skeleton-admin */
|
|
13
|
+
use PluginVendor\PluginSkeleton\Admin\Menu;
|
|
14
|
+
/* @skeleton-admin-end */
|
|
15
|
+
/* @skeleton-block */
|
|
16
|
+
use PluginVendor\PluginSkeleton\Blocks;
|
|
17
|
+
/* @skeleton-block-end */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Class Plugin.
|
|
21
|
+
*/
|
|
22
|
+
class Plugin {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Bootstrap the plugin.
|
|
26
|
+
*
|
|
27
|
+
* @return void
|
|
28
|
+
*/
|
|
29
|
+
public function run(): void {
|
|
30
|
+
$this->load_textdomain();
|
|
31
|
+
$this->load();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Load plugin text domain.
|
|
36
|
+
*
|
|
37
|
+
* @return void
|
|
38
|
+
*/
|
|
39
|
+
private function load_textdomain(): void {
|
|
40
|
+
load_plugin_textdomain( 'plugin-skeleton', false, plugin_basename( PLUGIN_SKELETON_PATH ) . '/languages' );
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Instantiate service classes.
|
|
45
|
+
*
|
|
46
|
+
* @return void
|
|
47
|
+
*/
|
|
48
|
+
private function load(): void {
|
|
49
|
+
Assets::get_instance();
|
|
50
|
+
/* @skeleton-admin */
|
|
51
|
+
if ( is_admin() ) {
|
|
52
|
+
Menu::get_instance();
|
|
53
|
+
}
|
|
54
|
+
/* @skeleton-admin-end */
|
|
55
|
+
/* @skeleton-block */
|
|
56
|
+
Blocks::get_instance();
|
|
57
|
+
/* @skeleton-block-end */
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Singleton trait.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace PluginVendor\PluginSkeleton\Traits;
|
|
11
|
+
|
|
12
|
+
trait Singleton {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Protected constructor — override in child class to hook actions/filters.
|
|
16
|
+
*/
|
|
17
|
+
protected function __construct() {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Prevent cloning.
|
|
22
|
+
*/
|
|
23
|
+
final protected function __clone() {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Return the singleton instance.
|
|
28
|
+
*
|
|
29
|
+
* @param mixed ...$args Constructor arguments.
|
|
30
|
+
* @return static
|
|
31
|
+
*/
|
|
32
|
+
final public static function get_instance( ...$args ) {
|
|
33
|
+
static $instances = [];
|
|
34
|
+
|
|
35
|
+
$called_class = get_called_class();
|
|
36
|
+
$key = $called_class . maybe_serialize( $args );
|
|
37
|
+
|
|
38
|
+
if ( ! isset( $instances[ $key ] ) ) {
|
|
39
|
+
$instances[ $key ] = new $called_class( ...$args );
|
|
40
|
+
|
|
41
|
+
do_action( sprintf( 'plugin_skeleton_singleton_init_%s', $called_class ) ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return $instances[ $key ];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<?xml version="1.0" ?>
|
|
2
|
+
<ruleset name="Plugin Skeleton Coding Standards">
|
|
3
|
+
<config name="minimum_supported_wp_version" value="6.4" />
|
|
4
|
+
<config name="testVersion" value="8.1-"/>
|
|
5
|
+
<rule ref="PHPCompatibilityWP"/>
|
|
6
|
+
|
|
7
|
+
<file>includes</file>
|
|
8
|
+
<file>plugin-skeleton.php</file>
|
|
9
|
+
|
|
10
|
+
<arg value="ps"/>
|
|
11
|
+
<arg name="colors"/>
|
|
12
|
+
<arg name="extensions" value="php"/>
|
|
13
|
+
|
|
14
|
+
<rule ref="WordPress-Core">
|
|
15
|
+
<exclude name="Universal.Arrays.DisallowShortArraySyntax" />
|
|
16
|
+
<exclude name="Universal.Operators.DisallowShortTernary" />
|
|
17
|
+
</rule>
|
|
18
|
+
|
|
19
|
+
<rule ref="WordPress-Docs">
|
|
20
|
+
<exclude-pattern>tests/*</exclude-pattern>
|
|
21
|
+
</rule>
|
|
22
|
+
|
|
23
|
+
<rule ref="WordPress-Extra">
|
|
24
|
+
<exclude name="WordPress.Files.FileName" />
|
|
25
|
+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
|
|
26
|
+
</rule>
|
|
27
|
+
|
|
28
|
+
<rule ref="WordPress.WP.I18n">
|
|
29
|
+
<properties>
|
|
30
|
+
<property name="text_domain" type="array">
|
|
31
|
+
<element value="plugin-skeleton" />
|
|
32
|
+
</property>
|
|
33
|
+
</properties>
|
|
34
|
+
</rule>
|
|
35
|
+
|
|
36
|
+
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis" />
|
|
37
|
+
|
|
38
|
+
<exclude-pattern>*/vendor/*</exclude-pattern>
|
|
39
|
+
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
|
40
|
+
<exclude-pattern>*/assets/*</exclude-pattern>
|
|
41
|
+
<exclude-pattern>*/build/*</exclude-pattern>
|
|
42
|
+
</ruleset>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<phpunit
|
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
4
|
+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
|
5
|
+
bootstrap="tests/bootstrap.php"
|
|
6
|
+
cacheResultFile=".phpunit.result.cache"
|
|
7
|
+
colors="true"
|
|
8
|
+
>
|
|
9
|
+
<testsuites>
|
|
10
|
+
<testsuite name="unit">
|
|
11
|
+
<directory suffix="Test.php">tests/Unit</directory>
|
|
12
|
+
</testsuite>
|
|
13
|
+
</testsuites>
|
|
14
|
+
<source>
|
|
15
|
+
<include>
|
|
16
|
+
<directory suffix=".php">includes</directory>
|
|
17
|
+
</include>
|
|
18
|
+
</source>
|
|
19
|
+
</phpunit>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Plugin Name: Plugin Skeleton
|
|
4
|
+
* Plugin URI: https://github.com/sabbir1991/plugin-skeleton
|
|
5
|
+
* Description: A WordPress plugin skeleton for rapid development.
|
|
6
|
+
* Version: 1.0.0
|
|
7
|
+
* Author: Your Name
|
|
8
|
+
* Author URI: https://yoursite.com
|
|
9
|
+
* License: GPL-2.0-or-later
|
|
10
|
+
* Text Domain: plugin-skeleton
|
|
11
|
+
* Domain Path: /languages
|
|
12
|
+
*
|
|
13
|
+
* @package PluginVendor\PluginSkeleton
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
declare(strict_types=1);
|
|
17
|
+
|
|
18
|
+
namespace PluginVendor\PluginSkeleton;
|
|
19
|
+
|
|
20
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
21
|
+
exit;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
define( 'PLUGIN_SKELETON_VERSION', '1.0.0' );
|
|
25
|
+
define( 'PLUGIN_SKELETON_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
|
|
26
|
+
define( 'PLUGIN_SKELETON_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
|
|
27
|
+
define( 'PLUGIN_SKELETON_ASSET_PATH', untrailingslashit( PLUGIN_SKELETON_PATH . '/assets' ) );
|
|
28
|
+
define( 'PLUGIN_SKELETON_ASSET_URL', untrailingslashit( PLUGIN_SKELETON_URL . '/assets' ) );
|
|
29
|
+
|
|
30
|
+
$autoload_file = __DIR__ . '/vendor/autoload.php';
|
|
31
|
+
|
|
32
|
+
if ( ! file_exists( $autoload_file ) ) {
|
|
33
|
+
add_action(
|
|
34
|
+
'admin_notices',
|
|
35
|
+
function () {
|
|
36
|
+
echo '<div class="error"><p>' . esc_html__( 'Plugin Skeleton: Run composer install to load dependencies.', 'plugin-skeleton' ) . '</p></div>';
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
require_once $autoload_file;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the main Plugin instance.
|
|
46
|
+
*
|
|
47
|
+
* @return Plugin
|
|
48
|
+
*/
|
|
49
|
+
function plugin_skeleton(): Plugin {
|
|
50
|
+
static $plugin;
|
|
51
|
+
|
|
52
|
+
if ( null === $plugin ) {
|
|
53
|
+
$plugin = new Plugin();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return $plugin;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
add_action(
|
|
60
|
+
'plugins_loaded',
|
|
61
|
+
function () {
|
|
62
|
+
plugin_skeleton()->run();
|
|
63
|
+
}
|
|
64
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
=== Plugin Skeleton ===
|
|
2
|
+
Contributors: yourname
|
|
3
|
+
Tags: wordpress, plugin
|
|
4
|
+
Requires at least: 6.4
|
|
5
|
+
Tested up to: 7.0
|
|
6
|
+
Stable tag: 1.0.0
|
|
7
|
+
Requires PHP: 8.1
|
|
8
|
+
License: GPLv2 or later
|
|
9
|
+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
10
|
+
|
|
11
|
+
A WordPress plugin skeleton for rapid development.
|
|
12
|
+
|
|
13
|
+
== Description ==
|
|
14
|
+
|
|
15
|
+
A WordPress plugin skeleton for rapid development.
|
|
16
|
+
|
|
17
|
+
== Installation ==
|
|
18
|
+
|
|
19
|
+
1. Upload the plugin files to `/wp-content/plugins/plugin-skeleton/`.
|
|
20
|
+
2. Activate the plugin through the Plugins screen in WordPress.
|
|
21
|
+
|
|
22
|
+
== Changelog ==
|
|
23
|
+
|
|
24
|
+
= 1.0.0 =
|
|
25
|
+
* Initial release.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
|
+
"apiVersion": 3,
|
|
4
|
+
"name": "plugin-skeleton/plugin-skeleton",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"title": "Plugin Skeleton Block",
|
|
7
|
+
"category": "widgets",
|
|
8
|
+
"description": "A WordPress plugin skeleton for rapid development.",
|
|
9
|
+
"supports": {
|
|
10
|
+
"html": false
|
|
11
|
+
},
|
|
12
|
+
"textdomain": "plugin-skeleton",
|
|
13
|
+
"editorScript": "file:./index.js",
|
|
14
|
+
"style": "file:./style-index.css",
|
|
15
|
+
"render": "file:./render.php",
|
|
16
|
+
"viewScript": "file:./view.js"
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block editor component for Plugin Skeleton.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { useBlockProps } from '@wordpress/block-editor';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Edit component rendered in the block editor.
|
|
10
|
+
*/
|
|
11
|
+
export default function Edit() {
|
|
12
|
+
return (
|
|
13
|
+
<div { ...useBlockProps() }>
|
|
14
|
+
<p>{ __( 'Edit view.', 'plugin-skeleton' ) }</p>
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block registration for Plugin Skeleton.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { registerBlockType } from '@wordpress/blocks';
|
|
6
|
+
import './style.scss';
|
|
7
|
+
import Edit from './edit';
|
|
8
|
+
import metadata from './block.json';
|
|
9
|
+
|
|
10
|
+
registerBlockType( metadata.name, {
|
|
11
|
+
edit: Edit,
|
|
12
|
+
save: () => null,
|
|
13
|
+
} );
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Block render template for Plugin Skeleton.
|
|
4
|
+
*
|
|
5
|
+
* @package PluginVendor\PluginSkeleton
|
|
6
|
+
* @var array $attributes Block attributes.
|
|
7
|
+
* @var string $content Inner block content.
|
|
8
|
+
* @var WP_Block $block Block instance.
|
|
9
|
+
*/
|
|
10
|
+
?>
|
|
11
|
+
<div <?php echo get_block_wrapper_attributes(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
|
|
12
|
+
<p><?php esc_html_e( 'Plugin Skeleton block.', 'plugin-skeleton' ); ?></p>
|
|
13
|
+
</div>
|