Skip to content

Commit 48fdea6

Browse files
committed
update plugin files to meet new phpcs standards + version bump
1 parent 9ae40b8 commit 48fdea6

File tree

8 files changed

+174
-178
lines changed

8 files changed

+174
-178
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ performance matters...).
1212

1313
4. Generate New Plugin or access resource guides.
1414

15-
### Offline Development Mode
15+
## UPDATING `/lib` files
16+
17+
Lib files come from composer, but you need to ensure you run the command without the composer autoloader:
18+
```
19+
composer update --no-dev --no-autoloader
20+
```
21+
22+
## Offline Development Mode
1623

1724
The plugin uses the GitHub API to fetch the latest copy of the Abstract Plugin Base to include in the plugin. You can alternatively set:
1825
```php
1926
define( 'WP_DEV_KIT_AIRPLANE_MODE', true )
2027
```
2128
to pull the ABP powering this plugin for internet-less development.
29+
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
11
<?php
2+
/**
3+
* Main App File
4+
*
5+
* @package WordPress
6+
* @subpackage <%= PKG %>
7+
*/
28

3-
namespace <%= PRIMARY_NAMESPACE %>\<%= SECONDARY_NAMESPACE %>\Admin;
9+
namespace < %= PRIMARY_NAMESPACE %>\< %= SECONDARY_NAMESPACE %>\Admin;
410

511
/**
612
* Class App
7-
* @package <%= PKG %>
813
*/
914
class App {
1015

1116
/**
12-
* @var string
17+
* Plugins class object installed directory on the server
18+
*
19+
* @var string $installed_dir Installed server directory
1320
*/
1421
public $installed_dir;
1522

1623
/**
17-
* @var string
24+
* Plugins URL for access to any static files or assets like css, js, or media
25+
*
26+
* @var string $installed_url Installed URL
1827
*/
1928
public $installed_url;
2029

2130
/**
22-
* @var string
31+
* If plugin_data is built, this represents the version number defined the the main plugin file meta
32+
*
33+
* @var string $version Version
2334
*/
2435
public $version;
2536

2637
/**
2738
* Add auth'd/admin functionality via new Class() instantiation, add_action() and add_filter() in this method.
2839
*
29-
* @param string $installed_dir
30-
* @param string $installed_url
31-
* @param string $version
40+
* @param string $installed_dir Installed server directory
41+
* @param string $installed_url Installed URL
42+
* @param string $version Version
3243
*/
3344
function __construct( $installed_dir, $installed_url, $version ) {
3445
$this->installed_dir = $installed_dir;
3546
$this->installed_url = $installed_url;
3647
$this->version = $version;
3748

38-
// put your new Class() or add_action() here.
49+
// Put your new Class() or add_action() here.
3950
}
4051

4152
}

app/boilerplates/simple/app/class-plugin.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?php
2+
/**
3+
* Plugin <%= SECONDARY_NAMESPACE %>
4+
*
5+
* @package WordPress
6+
* @subpackage <%= PKG %>
7+
*/
28

39
namespace <%= PRIMARY_NAMESPACE %>\<%= SECONDARY_NAMESPACE %>;
410

5-
use <%= PRIMARY_NAMESPACE %>\<%= SECONDARY_NAMESPACE %>\Admin;
11+
use <%= PRIMARY_NAMESPACE %>\< %= SECONDARY_NAMESPACE %>\Admin;;
612
use <%= ABSTRACT_PLUGIN_NAMESPACE %>\Abstract_Plugin;
713

814
if ( ! function_exists( 'add_filter' ) ) {
@@ -13,38 +19,38 @@
1319

1420
/**
1521
* Class Plugin
16-
* @package <%= PKG %>
1722
*/
1823
class Plugin extends Abstract_Plugin {
1924

2025
/**
21-
* @var string
26+
* Use magic constant to tell abstract class current namespace as prefix for all other namespaces in the plugin.
27+
*
28+
* @var string $autoload_class_prefix magic constant
2229
*/
2330
public static $autoload_class_prefix = __NAMESPACE__;
2431

2532
/**
26-
* @var string
27-
*/
28-
public static $autoload_type = 'psr-4';
29-
30-
/**
31-
* @var int
32-
*/
33-
public static $autoload_ns_match_depth = 2;
34-
35-
/**
33+
* Action prefix is used to automatically and dynamically assign a prefix to all action hooks.
34+
*
3635
* @var string
3736
*/
3837
public static $action_prefix = '<%= US_SLUG %>_';
3938

4039
/**
41-
* @var string
40+
* Magic constant trick that allows extended classes to pull actual server file location, copy into subclass.
41+
*
42+
* @var string $current_file
4243
*/
4344
protected static $current_file = __FILE__;
4445

4546

4647
/**
47-
* @param mixed $instance
48+
* Initialize the plugin - for public (front end)
49+
*
50+
* @param mixed $instance Parent instance passed through to child.
51+
*
52+
* @since 0.1
53+
* @return void
4854
*/
4955
public function onload( $instance ) {
5056
}
@@ -64,7 +70,7 @@ public function init() {
6470
public function authenticated_init() {
6571
if ( is_user_logged_in() ) {
6672
do_action( static::$action_prefix . 'before_authenticated_init' );
67-
// $this->admin is in the abstract plugin base class
73+
// Object $this->admin is in the abstract plugin base class.
6874
$this->admin = new Admin\App(
6975
$this->installed_dir,
7076
$this->installed_url,

app/boilerplates/simple/composer.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,5 @@
2222
},
2323
"config": {
2424
"vendor-dir": "lib"
25-
},
26-
"autoload": {
27-
"classmap": [
28-
"/"
29-
]
3025
}
3126
}

app/boilerplates/simple/main.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* <%= NAME %>
44
*
55
* @wordpress-plugin
6-
* @package <%= PKG %>
7-
* @author <%= AUTHORS %><%= TEAM %>
8-
* @license <%= LICENSE_TEXT %>
9-
* @link <%= URL %>
10-
* @version <%= VERSION %>
6+
* @package WordPress
7+
* @subpackage <%= PKG %>
8+
* @author <%= AUTHORS %><%= TEAM %>
9+
* @license <%= LICENSE_TEXT %>
10+
* @link <%= URL %>
11+
* @version <%= VERSION %>
1112
*
1213
* Built with WP PHX WordPress Development Toolkit v<%= GENERATOR_VERSION %> on <%= CURRENT_TIME %>
13-
* @link https://github.com/WordPress-Phoenix/wordpress-development-toolkit
14+
* @link https://github.com/WordPress-Phoenix/wordpress-development-toolkit
1415
*
1516
* Plugin Name: <%= NAME %>
1617
* Plugin URI: <%= URL %>
@@ -42,5 +43,4 @@
4243
*/
4344
include_once $current_dir . 'app/class-plugin.php';
4445

45-
<%= PRIMARY_NAMESPACE %>\<%= SECONDARY_NAMESPACE %>\Plugin::run( __FILE__ );
46-
// Please don't edit below this line.
46+
< %= PRIMARY_NAMESPACE %>\< %= SECONDARY_NAMESPACE %>\Plugin::run( __FILE__ );

app/class-plugin.php

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,83 @@
11
<?php
2+
/**
3+
* Main Plugin Class
4+
*
5+
* @package WordPress
6+
*/
27

38
namespace PHX_WP_DEVKIT\V_3_0;
49

510
use PHX_WP_DEVKIT\V_3_0\Admin;
6-
use WPAZ_Plugin_Base\V_2_6\Abstract_Plugin as Base;
11+
use WPAZ_Plugin_Base\V_2_6\Abstract_Plugin;
712

813
/**
914
* Class Plugin
15+
*
1016
* @package Wordpress_development_toolkit
1117
*/
12-
class Plugin extends Base {
18+
class Plugin extends Abstract_Plugin {
1319

1420
/**
15-
* @var string
21+
* Use magic constant to tell abstract class current namespace as prefix for all other namespaces in the plugin.
22+
*
23+
* @var string $autoload_class_prefix magic constant
1624
*/
1725
public static $autoload_class_prefix = __NAMESPACE__;
1826

1927
/**
20-
* @var string
21-
*/
22-
public static $autoload_type = 'psr-4';
23-
24-
/**
25-
* @var int
26-
*/
27-
public static $autoload_ns_match_depth = 2;
28-
29-
/**
30-
* @var string
28+
* Magic constant trick that allows extended classes to pull actual server file location, copy into subclass.
29+
*
30+
* @var string $current_file
3131
*/
3232
protected static $current_file = __FILE__;
3333

3434
/**
35-
* @param mixed $instance
35+
* Initialize the plugin - for public (front end)
36+
*
37+
* @param mixed $instance Parent instance passed through to child.
38+
*
39+
* @return void
3640
*/
3741
public function onload( $instance ) {
3842
}
3943

4044
/**
41-
* Initialize public / shared functionality
45+
* Initialize the plugin - for public (front end)
46+
* Example of building a module of the plugin into init
47+
* ```$this->modules->FS_Mail = new FS_Mail( $this, $this->plugin_object_basedir );```
48+
*
49+
* @since 0.1
50+
* @return void
4251
*/
4352
public function init() {
4453
do_action( get_called_class() . '_before_init' );
45-
// silence is golden :)
54+
// Add hooks and filters, or other init scopped code here.
4655
do_action( get_called_class() . '_after_init' );
4756
}
4857

4958
/**
50-
* Initialize functionality only loaded for logged-in users
59+
* Initialize the plugin - for admin (back end)
60+
* You would expected this to be handled on action admin_init, but it does not properly handle
61+
* the use case for all logged in user actions. Always keep is_user_logged_in() wrapper within
62+
* this function for proper usage.
63+
*
64+
* @return void
5165
*/
5266
public function authenticated_init() {
5367
if ( is_user_logged_in() ) {
5468
do_action( get_called_class() . '_before_authenticated_init' );
5569
new Admin\Init(
56-
trailingslashit( $this->installed_dir ),
57-
trailingslashit( $this->installed_url ),
58-
$this->version
59-
);
70+
trailingslashit( $this->installed_dir ),
71+
trailingslashit( $this->installed_url ),
72+
$this->version
73+
);
6074
do_action( get_called_class() . '_after_authenticated_init' );
6175
}
6276
}
6377

6478
/**
79+
* Enforce that the plugin prepare any defines or globals in a standard location.
80+
*
6581
* @return mixed|void
6682
*/
6783
protected function defines_and_globals() {

0 commit comments

Comments
 (0)