This commit is contained in:
commit
ae634c10b1
@ -1,5 +1,10 @@
|
|||||||
# Notice Manager Changelog
|
# Notice Manager Changelog
|
||||||
|
|
||||||
|
## 0.16
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add plugin action link to Notice Manager settings page.
|
||||||
|
|
||||||
## 0.15
|
## 0.15
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
"name": "abuyoyo/notice-manager",
|
"name": "abuyoyo/notice-manager",
|
||||||
"description": "Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.",
|
"description": "Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.",
|
||||||
"type": "wordpress-plugin",
|
"type": "wordpress-plugin",
|
||||||
|
"version": "0.16",
|
||||||
"repositories": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"type": "vcs",
|
"type": "vcs",
|
||||||
@ -10,6 +11,6 @@
|
|||||||
],
|
],
|
||||||
"require":{
|
"require":{
|
||||||
"abuyoyo/screen-meta-links": "~0.11",
|
"abuyoyo/screen-meta-links": "~0.11",
|
||||||
"abuyoyo/plugincore": "~0.20"
|
"abuyoyo/plugincore": "~0.21"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
composer.lock
generated
14
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4dab38fa2dcb106e4f136a0273e46552",
|
"content-hash": "9554dcf8ad998875bf543a75631cb463",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "abuyoyo/adminmenupage",
|
"name": "abuyoyo/adminmenupage",
|
||||||
@ -46,16 +46,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "abuyoyo/plugincore",
|
"name": "abuyoyo/plugincore",
|
||||||
"version": "0.20",
|
"version": "0.21",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/abuyoyo/PluginCore.git",
|
"url": "https://github.com/abuyoyo/PluginCore.git",
|
||||||
"reference": "0f8de7be654880adc850610f045f22cd7923c3cc"
|
"reference": "9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/0f8de7be654880adc850610f045f22cd7923c3cc",
|
"url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa",
|
||||||
"reference": "0f8de7be654880adc850610f045f22cd7923c3cc",
|
"reference": "9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -75,9 +75,9 @@
|
|||||||
"description": "WordPress plugin core helper class",
|
"description": "WordPress plugin core helper class",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/abuyoyo/PluginCore/issues",
|
"issues": "https://github.com/abuyoyo/PluginCore/issues",
|
||||||
"source": "https://github.com/abuyoyo/PluginCore/tree/0.20"
|
"source": "https://github.com/abuyoyo/PluginCore/tree/0.21"
|
||||||
},
|
},
|
||||||
"time": "2022-07-29T00:00:00+00:00"
|
"time": "2022-08-05T00:00:00+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "abuyoyo/screen-meta-links",
|
"name": "abuyoyo/screen-meta-links",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* Plugin Name: Notice Manager
|
* Plugin Name: Notice Manager
|
||||||
* Description: Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.
|
* Description: Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.
|
||||||
* Version: 0.15
|
* Version: 0.16
|
||||||
* Author: abuyoyo
|
* Author: abuyoyo
|
||||||
* Author URI: https://github.com/abuyoyo/
|
* Author URI: https://github.com/abuyoyo/
|
||||||
* Plugin URI: https://github.com/abuyoyo/notice-manager
|
* Plugin URI: https://github.com/abuyoyo/notice-manager
|
||||||
@ -21,6 +21,12 @@ new PluginCore(
|
|||||||
__FILE__,
|
__FILE__,
|
||||||
[
|
[
|
||||||
'update_checker' => true,
|
'update_checker' => true,
|
||||||
|
'action_links' => [
|
||||||
|
'settings' => [
|
||||||
|
'text' => 'Settings',
|
||||||
|
'href' => 'menu_page' // reserved option_name
|
||||||
|
],
|
||||||
|
],
|
||||||
'admin_page' => [
|
'admin_page' => [
|
||||||
'parent' => 'options',
|
'parent' => 'options',
|
||||||
'render' => 'settings-page', // built-in settings page
|
'render' => 'settings-page', // built-in settings page
|
||||||
|
|||||||
1671
package-lock.json
generated
Normal file
1671
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "notice-manager",
|
"name": "notice-manager",
|
||||||
"version": "0.15.0",
|
"version": "0.16.0",
|
||||||
"description": "Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.",
|
"description": "Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link.",
|
||||||
"author": "abuyoyo",
|
"author": "abuyoyo",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
14
vendor/abuyoyo/plugincore/CHANGELOG.md
vendored
14
vendor/abuyoyo/plugincore/CHANGELOG.md
vendored
@ -1,5 +1,17 @@
|
|||||||
# WPHelper\PluginCore Changelog
|
# WPHelper\PluginCore Changelog
|
||||||
|
|
||||||
|
## 0.21
|
||||||
|
Release Date: Aug 5, 2022
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add `action_links` option. Accepts standard `plugin_action_links_` callback filter function. Alternatively accepts array of links. links can be HTML tag strings (`'<a href="/link">Link</a>'`) or arrays with keys `href` and `text`. Special use case `'href' => 'menu_page'` available for quick Settings link generation.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Plugin updater - prefer plugin header `Update URI` for plugin update checker, if no URI provided in options.
|
||||||
|
- Validate class `WPHelper\AdminPage` exists - required for `admin_page` option/settings.
|
||||||
|
- Significant code cleanup, notes, doc blocks and reorganizing of PluginCore class.
|
||||||
|
|
||||||
## 0.20
|
## 0.20
|
||||||
Release Date: Jul 29, 2022
|
Release Date: Jul 29, 2022
|
||||||
|
|
||||||
@ -87,7 +99,7 @@ Release Date: Feb 7, 2021
|
|||||||
- Fix wrong `plugin_basename` constant.
|
- Fix wrong `plugin_basename` constant.
|
||||||
|
|
||||||
## 0.7
|
## 0.7
|
||||||
- Don't use `extarct` in constructor
|
- Don't use `extract` in constructor
|
||||||
- Add sanity checks and normalize getter/setter functions
|
- Add sanity checks and normalize getter/setter functions
|
||||||
- Add `file()` getter function.
|
- Add `file()` getter function.
|
||||||
|
|
||||||
|
|||||||
401
vendor/abuyoyo/plugincore/PluginCore.php
vendored
401
vendor/abuyoyo/plugincore/PluginCore.php
vendored
@ -3,12 +3,6 @@ namespace WPHelper;
|
|||||||
|
|
||||||
use Puc_v4_Factory;
|
use Puc_v4_Factory;
|
||||||
|
|
||||||
use function add_action;
|
|
||||||
use function get_plugin_data;
|
|
||||||
use function register_activation_hook;
|
|
||||||
use function register_deactivation_hook;
|
|
||||||
use function register_uninstall_hook;
|
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || die( 'No soup for you!' );
|
defined( 'ABSPATH' ) || die( 'No soup for you!' );
|
||||||
|
|
||||||
if( ! function_exists('get_plugin_data') ) {
|
if( ! function_exists('get_plugin_data') ) {
|
||||||
@ -24,12 +18,15 @@ if ( ! class_exists( 'WPHelper/PluginCore' ) ):
|
|||||||
* Defines PLUGIN_PATH, PLUGIN_URL (etc.) constants
|
* Defines PLUGIN_PATH, PLUGIN_URL (etc.) constants
|
||||||
* (@see README.md)
|
* (@see README.md)
|
||||||
*
|
*
|
||||||
* @version 0.20
|
* @version 0.21
|
||||||
*
|
|
||||||
* @todo plugin_action_links - on Plugins page
|
|
||||||
*/
|
*/
|
||||||
class PluginCore {
|
class PluginCore {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Plugin filename
|
||||||
|
*/
|
||||||
|
private $plugin_file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -41,14 +38,24 @@ class PluginCore {
|
|||||||
private $slug;
|
private $slug;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Plugin filename
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $plugin_file;
|
private $const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $const;
|
private $path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $plugin_basename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var callable
|
* @var callable
|
||||||
@ -70,6 +77,11 @@ class PluginCore {
|
|||||||
*/
|
*/
|
||||||
public $upgrade_cb;
|
public $upgrade_cb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array|callable
|
||||||
|
*/
|
||||||
|
public $action_links;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var AdminPage
|
* @var AdminPage
|
||||||
*/
|
*/
|
||||||
@ -123,27 +135,11 @@ class PluginCore {
|
|||||||
|
|
||||||
$options = (object) $options;
|
$options = (object) $options;
|
||||||
|
|
||||||
if ( isset( $options->title ) ) {
|
$this->title( $options->title ?? null ); // fallback: get title from header plugin_data
|
||||||
$this->title( $options->title );
|
|
||||||
}else{
|
|
||||||
$this->title(); // get title from header plugin_data
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $options->slug ) ) {
|
$this->slug( $options->slug ?? null ); // fallback: guess slug from plugin basename
|
||||||
$this->slug( $options->slug );
|
|
||||||
}else{
|
|
||||||
$this->slug(); // guess slug from plugin basename
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $options->const ) ) {
|
$this->const( $options->const ?? null ); // fallback: generate const from slug
|
||||||
$this->const( $options->const );
|
|
||||||
}else{
|
|
||||||
$this->const();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $options->admin_page ) ) {
|
|
||||||
$this->admin_page( $options->admin_page );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $options->activate_cb ) )
|
if ( isset( $options->activate_cb ) )
|
||||||
$this->activate_cb( $options->activate_cb );
|
$this->activate_cb( $options->activate_cb );
|
||||||
@ -157,50 +153,66 @@ class PluginCore {
|
|||||||
if ( isset( $options->upgrade_cb ) )
|
if ( isset( $options->upgrade_cb ) )
|
||||||
$this->upgrade_cb( $options->upgrade_cb );
|
$this->upgrade_cb( $options->upgrade_cb );
|
||||||
|
|
||||||
if ( isset( $options->update_checker ) ) {
|
if ( isset( $options->action_links ) )
|
||||||
|
$this->action_links( $options->action_links );
|
||||||
|
|
||||||
|
if ( isset( $options->admin_page ) )
|
||||||
|
$this->admin_page( $options->admin_page ); // creates AdminPage instance
|
||||||
|
|
||||||
|
if ( isset( $options->update_checker ) )
|
||||||
$this->update_checker( $options->update_checker );
|
$this->update_checker( $options->update_checker );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setup();
|
$this->bootstrap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Bootstrap
|
||||||
|
*
|
||||||
|
* Setup url, path, plugin_basename variables
|
||||||
|
* Add PluginCore instance to static $cores
|
||||||
* Define plugin constants (_PATH, _URL, _BASENAME, _FILE etc.)
|
* Define plugin constants (_PATH, _URL, _BASENAME, _FILE etc.)
|
||||||
* Register activation, deactivation, uninstall, upgrade hooks.
|
* Register activation, deactivation, uninstall, upgrade hooks.
|
||||||
* Init PUC update checker.
|
* Init PUC update checker.
|
||||||
* Add PluginCore instance to static $cores
|
|
||||||
*
|
*
|
||||||
* @todo rename method bootstrap()
|
|
||||||
* @todo set plugin_dir_path, plugin_basename as accessible public variables (available thru methods atm)
|
* @todo set plugin_dir_path, plugin_basename as accessible public variables (available thru methods atm)
|
||||||
*/
|
*/
|
||||||
function setup() {
|
private function bootstrap() {
|
||||||
|
|
||||||
// init path and url
|
// validate basic variables (in case no options array were given)
|
||||||
// redundant init() and path() are getter/setter methods.
|
$this->title();
|
||||||
|
$this->slug();
|
||||||
|
$this->const();
|
||||||
|
|
||||||
|
// set variables
|
||||||
$this->path();
|
$this->path();
|
||||||
$this->url();
|
$this->url();
|
||||||
|
$this->plugin_basename();
|
||||||
|
|
||||||
define( $this->const() . '_PATH', $this->path() );
|
/**
|
||||||
define( $this->const() . '_DIR', $this->path() );
|
* Add this PluginCore instance to static list of PluginCore instances (key = slug).
|
||||||
|
* @see static function get()
|
||||||
|
*/
|
||||||
|
self::$cores[ $this->slug ] = $this;
|
||||||
|
|
||||||
define( $this->const() . '_URL', $this->url() );
|
// define constants
|
||||||
define( $this->const() . '_BASENAME', $this->plugin_basename() );
|
define( $this->const . '_PATH', $this->path );
|
||||||
|
define( $this->const . '_DIR', $this->path );
|
||||||
|
|
||||||
define( $this->const() . '_PLUGIN_FILE', $this->plugin_file );
|
define( $this->const . '_URL', $this->url );
|
||||||
define( $this->const() . '_FILE', $this->plugin_file );
|
define( $this->const . '_BASENAME', $this->plugin_basename );
|
||||||
|
|
||||||
|
define( $this->const . '_PLUGIN_FILE', $this->plugin_file );
|
||||||
|
define( $this->const . '_FILE', $this->plugin_file );
|
||||||
|
|
||||||
$this->register_hooks();
|
$this->register_hooks();
|
||||||
|
|
||||||
self::$cores[ $this->slug() ] = $this; // using slug() method
|
$this->add_plugin_action_links();
|
||||||
|
|
||||||
|
if ( $this->update_checker === true ) {
|
||||||
if ( $this->update_checker == true ) {
|
$this->build_update_checker();
|
||||||
// run early - before Puc_v4p8_Scheduler->maybeCheckForUpdates() [admin_init 10]
|
|
||||||
// hooking on admin_init does not work with wp_plugin_updates as it requires user logged-in
|
|
||||||
// add_action( 'admin_init', [$this, 'init_update_checker'], 9 );
|
|
||||||
$this->init_update_checker();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,24 +240,16 @@ class PluginCore {
|
|||||||
* @return string $this->title
|
* @return string $this->title
|
||||||
*/
|
*/
|
||||||
public function title( $title = null ) {
|
public function title( $title = null ) {
|
||||||
|
return $this->title ??= esc_html( $title ) ?: $this->plugin_data()['Title'];
|
||||||
if ( ! empty( $title ) ) {
|
|
||||||
$title = esc_html( $title );
|
|
||||||
$this->title = $title;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $this->title ) ) {
|
|
||||||
$this->plugin_data();
|
|
||||||
$this->title = $this->plugin_data['Title'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper function for $this->title()
|
* Wrapper function for $this->title()
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public function name( $title = null ) {
|
public function name( $title = null ) {
|
||||||
|
_doing_it_wrong( __METHOD__, 'Use PluginCore::title instead.', '0.21' );
|
||||||
return $this->title( $title );
|
return $this->title( $title );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +262,6 @@ class PluginCore {
|
|||||||
* @return string $this->slug
|
* @return string $this->slug
|
||||||
*/
|
*/
|
||||||
public function slug( $slug = null ) {
|
public function slug( $slug = null ) {
|
||||||
// doing it this way means slug can only be set once.
|
|
||||||
return $this->slug ??= $slug ?: basename( $this->plugin_file, '.php' );
|
return $this->slug ??= $slug ?: basename( $this->plugin_file, '.php' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,8 +273,7 @@ class PluginCore {
|
|||||||
* @return string $this->plugin_file
|
* @return string $this->plugin_file
|
||||||
*/
|
*/
|
||||||
public function plugin_file( $plugin_file ) {
|
public function plugin_file( $plugin_file ) {
|
||||||
$this->plugin_file = $plugin_file;
|
return $this->plugin_file ??= $plugin_file;
|
||||||
return $this->plugin_file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -286,106 +288,179 @@ class PluginCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter/Setter - plugin data array
|
||||||
|
*/
|
||||||
public function plugin_data() {
|
public function plugin_data() {
|
||||||
if ( empty( $this->plugin_data ) ) {
|
return $this->plugin_data ??= get_plugin_data( $this->plugin_file, false);
|
||||||
$this->plugin_data = get_plugin_data( $this->plugin_file, false);
|
|
||||||
}
|
|
||||||
return $this->plugin_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter/Setter - const
|
* Getter/Setter - const
|
||||||
* Prefix of plugin specific defines (PLUGIN_NAME_PATH etc.)
|
* Prefix of plugin specific defines (PLUGIN_NAME_PATH etc.)
|
||||||
* If not provided - plugin slug will be uppercased.
|
* If not provided - plugin slug will be uppercase.
|
||||||
*
|
*
|
||||||
* @param string|null $const (string should be uppercased)
|
* @param string|null $const (string should be uppercase)
|
||||||
* @return string $this->const
|
* @return string $this->const
|
||||||
*/
|
*/
|
||||||
public function const( $const = null ) {
|
public function const( $const = null ) {
|
||||||
|
return $this->const ??= $const ?: str_replace( '-', '_' , strtoupper( $this->slug() ) );
|
||||||
// if $const provided - use that
|
|
||||||
if ( ! empty( $const ) ) {
|
|
||||||
$this->const = $const;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no $const provided - generate from slug()
|
/**
|
||||||
if ( empty( $this->const ) ) {
|
* Getter/setter
|
||||||
$this->const = str_replace( '-', '_' , strtoupper( $this->slug() ) ); // using slug() getter/setter
|
*/
|
||||||
|
public function path() {
|
||||||
|
return $this->path ??= plugin_dir_path( $this->plugin_file );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->const;
|
/**
|
||||||
|
* Getter/Setter
|
||||||
|
*/
|
||||||
|
public function url() {
|
||||||
|
return $this->url ??= plugin_dir_url( $this->plugin_file );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter/Setter
|
||||||
|
*/
|
||||||
|
public function plugin_basename() {
|
||||||
|
return $this->plugin_basename ??= plugin_basename( $this->plugin_file );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter - Activation callback
|
||||||
|
* Callback runs on 'register_activation_hook'
|
||||||
|
* PluginCore does not validate. Authors must ensure valid callback.
|
||||||
|
*
|
||||||
|
* @param callable $activate_cb - Activation callback
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function activate_cb( $activate_cb ) {
|
||||||
|
$this->activate_cb = $activate_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter - Deactivation callback
|
||||||
|
* Callback runs on 'register_deactivation_hook'
|
||||||
|
* PluginCore does not validate. Authors must ensure valid callback.
|
||||||
|
*
|
||||||
|
* @param callable $deactivate_cb - Deactivation callback.
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function deactivate_cb( $deactivate_cb ) {
|
||||||
|
$this->deactivate_cb = $deactivate_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter - Uninstall callback
|
||||||
|
* Callback runs on 'register_uninstall_hook'
|
||||||
|
* PluginCore does not validate. Authors must ensure valid callback.
|
||||||
|
*
|
||||||
|
* @param callable $uninstall_cb - Uninstall callback.
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function uninstall_cb( $uninstall_cb ) {
|
||||||
|
$this->uninstall_cb = $uninstall_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter - Upgrade callback
|
||||||
|
* Callback runs on 'upgrader_process_complete' hook - only for our plugin.
|
||||||
|
* Runs inside wrapper function that ensures our plugin was updated.
|
||||||
|
* (@see upgrade_cb_wrapper() below)
|
||||||
|
*
|
||||||
|
* PluginCore does not validate. Authors must ensure valid callback.
|
||||||
|
*
|
||||||
|
* @param callable $upgrade_cb - Upgrade callback.
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function upgrade_cb( $upgrade_cb ) {
|
||||||
|
$this->upgrade_cb = $upgrade_cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter - Plugin action links
|
||||||
|
*
|
||||||
|
* Add links to plugin action links on Plugins page.
|
||||||
|
* Accepts callable hooked to 'plugin_action_links_{$plugin}'
|
||||||
|
* Alternatively accepts array of key => string/HTML tag (eg. [ 'settings' => '<a href="foo" />' ] )
|
||||||
|
* Alternatively accepts array of key => [ 'text' => 'My Link', 'href' => 'foo' ]
|
||||||
|
* Special case: Settings Page
|
||||||
|
* [ 'settings' => [ 'href' => 'menu_page', 'text' => 'Settings' ] ] will generate link to plugin menu page url (@see menu_page_url() )
|
||||||
|
* (@see add_plugin_action_links() below)
|
||||||
|
*
|
||||||
|
* @since 0.21
|
||||||
|
*
|
||||||
|
* @param callable|array $action_links - filter function or custom action links array
|
||||||
|
*
|
||||||
|
* @todo perhaps have separate action_links_array + action_links_cb variables
|
||||||
|
*/
|
||||||
|
private function action_links( $action_links ) {
|
||||||
|
$this->action_links = $action_links;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter/Setter - AdminPage
|
||||||
|
*
|
||||||
|
* Construct AdminPage instance for plugin.
|
||||||
|
*
|
||||||
|
* @param array $admin_page - AdminPage settings array
|
||||||
|
*
|
||||||
|
* @return AdminPage
|
||||||
|
*/
|
||||||
public function admin_page( $admin_page ) {
|
public function admin_page( $admin_page ) {
|
||||||
if ( empty( $admin_page['slug'] ) ) {
|
|
||||||
$admin_page['slug'] = $this->slug();
|
if ( ! class_exists( 'WPHelper\AdminPage' ) )
|
||||||
}
|
return;
|
||||||
if ( empty( $admin_page['title'] ) ) {
|
|
||||||
$admin_page['title'] = $this->title();
|
// validate
|
||||||
}
|
$admin_page['slug'] ??= $this->slug();
|
||||||
|
$admin_page['title'] ??= $this->title();
|
||||||
|
|
||||||
$this->admin_page = new AdminPage( $admin_page );
|
$this->admin_page = new AdminPage( $admin_page );
|
||||||
|
|
||||||
|
// validate for older versions of AdminPage
|
||||||
if ( method_exists( $this->admin_page, 'plugin_core' ) ) {
|
if ( method_exists( $this->admin_page, 'plugin_core' ) ) {
|
||||||
$this->admin_page->plugin_core( $this );
|
$this->admin_page->plugin_core( $this ); // back-reference
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->admin_page;
|
return $this->admin_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public function path() {
|
* Setter
|
||||||
if ( empty( $this->path ) )
|
*
|
||||||
$this->path = plugin_dir_path( $this->plugin_file );
|
* Setup info used by Puc_v4_Factory
|
||||||
return $this->path;
|
*
|
||||||
}
|
* set $update_checker (bool)
|
||||||
|
* set $update_repo_uri (string)
|
||||||
public function url() {
|
* set $update_auth (optional)
|
||||||
if ( empty( $this->url ) )
|
* set $update_branch (optional)
|
||||||
$this->url = plugin_dir_url( $this->plugin_file );
|
*
|
||||||
return $this->url;
|
* @param bool|string|array $update_checker
|
||||||
}
|
*/
|
||||||
|
|
||||||
public function plugin_basename() {
|
|
||||||
if ( empty( $this->plugin_basename ) )
|
|
||||||
$this->plugin_basename = plugin_basename( $this->plugin_file );
|
|
||||||
return $this->plugin_basename;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function activate_cb( $activate_cb ) {
|
|
||||||
// test is_callable() ? or is it too soon?
|
|
||||||
$this->activate_cb = $activate_cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function deactivate_cb( $deactivate_cb ) {
|
|
||||||
// test is_callable() ? or is it too soon?
|
|
||||||
$this->deactivate_cb = $deactivate_cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function uninstall_cb( $uninstall_cb ) {
|
|
||||||
// test is_callable() ? or is it too soon?
|
|
||||||
$this->uninstall_cb = $uninstall_cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function upgrade_cb( $upgrade_cb ) {
|
|
||||||
// test is_callable() ? or is it too soon?
|
|
||||||
$this->upgrade_cb = $upgrade_cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function update_checker( $update_checker ) {
|
private function update_checker( $update_checker ) {
|
||||||
// Puc_v4_Factory::buildUpdateChecker
|
|
||||||
if ( empty( $update_checker ) ) {
|
if ( empty( $update_checker ) ) {
|
||||||
$this->update_checker = false;
|
$this->update_checker = false;
|
||||||
}else{
|
}
|
||||||
|
|
||||||
if ( is_bool( $update_checker ) ) {
|
if ( is_bool( $update_checker ) ) {
|
||||||
$this->update_checker = $update_checker;
|
$this->update_checker = $update_checker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// option 'update_checker' accepts string - repo uri
|
||||||
if ( is_string( $update_checker ) ) {
|
if ( is_string( $update_checker ) ) {
|
||||||
$this->update_checker = true;
|
$this->update_checker = true;
|
||||||
$this->update_repo_uri = $update_checker;
|
$this->update_repo_uri = $update_checker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// option 'update_checker' accepts array: ['uri'=> , 'auth'=>, 'branch'=> ]
|
||||||
if ( is_array( $update_checker ) ) {
|
if ( is_array( $update_checker ) ) {
|
||||||
$this->update_checker = true;
|
$this->update_checker = true;
|
||||||
|
|
||||||
@ -395,28 +470,33 @@ class PluginCore {
|
|||||||
if ( isset( $update_checker['auth'] ) ) {
|
if ( isset( $update_checker['auth'] ) ) {
|
||||||
$this->update_auth = $update_checker['auth'];
|
$this->update_auth = $update_checker['auth'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $update_checker['branch'] ) ) {
|
if ( isset( $update_checker['branch'] ) ) {
|
||||||
$this->update_branch = $update_checker['branch'];
|
$this->update_branch = $update_checker['branch'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Use plugin header 'UpdateURI' or fallback to 'PluginURI'
|
||||||
|
// call plugin_data() to init var plugin_data
|
||||||
|
$this->update_repo_uri ??= $this->plugin_data()['UpdateURI'] ?: $this->plugin_data['PluginURI'] ?: null;
|
||||||
|
|
||||||
|
// validate
|
||||||
|
// If no repo uri - update checker is disabled.
|
||||||
|
if ( empty( $this->update_repo_uri ) ) {
|
||||||
|
$this->update_checker = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init_update_checker() {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init Puc update checker instance
|
||||||
|
*
|
||||||
|
* @uses Puc_v4_Factory::buildUpdateChecker
|
||||||
|
*/
|
||||||
|
private function build_update_checker() {
|
||||||
|
|
||||||
if ( ! class_exists('Puc_v4_Factory') )
|
if ( ! class_exists('Puc_v4_Factory') )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( ! isset( $this->update_repo_uri ) ) {
|
|
||||||
$this->plugin_data();
|
|
||||||
|
|
||||||
if ( isset( $this->plugin_data['PluginURI'] ) )
|
|
||||||
$this->update_repo_uri = $this->plugin_data['PluginURI'];
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// wp_dump($this);
|
|
||||||
$update_checker = Puc_v4_Factory::buildUpdateChecker(
|
$update_checker = Puc_v4_Factory::buildUpdateChecker(
|
||||||
$this->update_repo_uri,
|
$this->update_repo_uri,
|
||||||
$this->plugin_file,
|
$this->plugin_file,
|
||||||
@ -465,5 +545,44 @@ class PluginCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add plugin_action_links
|
||||||
|
*
|
||||||
|
* Parse action_links (callable or array).
|
||||||
|
* Generate callback if action_links provided as array.
|
||||||
|
* Add callback to 'plugin_action_links_{$plugin}' hook.
|
||||||
|
*
|
||||||
|
* @since 0.21
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
private function add_plugin_action_links() {
|
||||||
|
if ( empty( $this->action_links ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( is_callable( $this->action_links ) ) { // default - pass a filter method
|
||||||
|
$action_links_cb = $this->action_links;
|
||||||
|
} else if ( is_array( $this->action_links ) ) { // array of links - PluginCore will do the heavy lifting
|
||||||
|
$action_links_cb = function( $links ) {
|
||||||
|
foreach( $this->action_links as $key => $link ) {
|
||||||
|
if ( is_string( $link ) ) { // we assume a straight HTML tag string
|
||||||
|
$links[ $key ] = $link; // just print it
|
||||||
|
} else if ( is_array( $link ) ) { // accepts ['href'=>'/my-href', 'text'=>'My Action Link']
|
||||||
|
$links[ $key ] = sprintf(
|
||||||
|
'<a href="%s">%s</a>',
|
||||||
|
$link['href'] == 'menu_page' // reserved parameter value
|
||||||
|
? esc_url( menu_page_url( $this->slug, false ) )
|
||||||
|
: $link['href'],
|
||||||
|
$link['text'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $links;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
add_filter( 'plugin_action_links_' . $this->plugin_basename(), $action_links_cb );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
||||||
22
vendor/abuyoyo/plugincore/README.md
vendored
22
vendor/abuyoyo/plugincore/README.md
vendored
@ -1,6 +1,6 @@
|
|||||||
# WPHelper \ PluginCore
|
# WPHelper \ PluginCore
|
||||||
|
|
||||||
> Helper class for registering plugins.
|
> Helper class for registering WordPress plugins.
|
||||||
|
|
||||||
Plugin Boilerplates and boilerplate generator are a hassle. The file structure they impose is way too cumbersome (and redundant) to push into every single plugin. WPHelper\PluginCore replaces boilerplates with one simple class (usually hidden away somewhere in your ``vendor/`` dir).
|
Plugin Boilerplates and boilerplate generator are a hassle. The file structure they impose is way too cumbersome (and redundant) to push into every single plugin. WPHelper\PluginCore replaces boilerplates with one simple class (usually hidden away somewhere in your ``vendor/`` dir).
|
||||||
|
|
||||||
@ -50,8 +50,8 @@ use WPHelper\PluginCore;
|
|||||||
|
|
||||||
// Register the plugin
|
// Register the plugin
|
||||||
$args = [
|
$args = [
|
||||||
'title' => 'My Awesome Plugin',
|
'title' => 'My Awesome Plugin', // Optional - will fallback to plugin header Plugin Name.
|
||||||
'slug' => 'my-awesome-plugin',
|
'slug' => 'my-awesome-plugin', // Optional - will generate slug based on plugin header Plugin Name
|
||||||
'const' => 'MYPLUGIN' // Optional - slug used to define constants: MYPLUGIN_DIR, MYPLUGIN_URL etc. (if not provided will use 'slug' in ALLCAPS)
|
'const' => 'MYPLUGIN' // Optional - slug used to define constants: MYPLUGIN_DIR, MYPLUGIN_URL etc. (if not provided will use 'slug' in ALLCAPS)
|
||||||
'activate_cb' => 'activate_callback' // Optional - Provide a callable function to run on activation
|
'activate_cb' => 'activate_callback' // Optional - Provide a callable function to run on activation
|
||||||
'deactivate_cb' => 'deactivate_callback' // Optional - Provide a callable function to run on deactivation
|
'deactivate_cb' => 'deactivate_callback' // Optional - Provide a callable function to run on deactivation
|
||||||
@ -59,14 +59,18 @@ $args = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Setup plugin constants and activation/deactivation hooks
|
// Setup plugin constants and activation/deactivation hooks
|
||||||
$my_plugin_core = new PluginCore( __FILE__, $args );
|
new PluginCore( __FILE__, $args );
|
||||||
|
|
||||||
// Start writing your code here..
|
// Start writing your code here..
|
||||||
|
include '/foo.php';
|
||||||
|
add_action( 'plugins_loaded' function() {
|
||||||
|
// whatever..
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Constants
|
### Constants
|
||||||
|
|
||||||
WPHelper\PluginCore defines constants for use in your code. Where ``__FILE__`` is the filename provided to the class and ``%PLUGIN%`` is the ``'const_slug'`` provided.
|
WPHelper\PluginCore defines constants for use in your code. Where ``__FILE__`` is the filename provided to the class and ``%PLUGIN%`` is the ``'const'`` option.
|
||||||
Like so:
|
Like so:
|
||||||
|
|
||||||
```PHP
|
```PHP
|
||||||
@ -79,7 +83,13 @@ These are the constants defined by WPHelper\PluginCore. There are some redundanc
|
|||||||
* %PLUGIN%_PATH: ``plugin_dir_path( __FILE__ ) )``
|
* %PLUGIN%_PATH: ``plugin_dir_path( __FILE__ ) )``
|
||||||
* %PLUGIN%_DIR: ``plugin_dir_path( __FILE__ ) )``
|
* %PLUGIN%_DIR: ``plugin_dir_path( __FILE__ ) )``
|
||||||
* %PLUGIN%_URL: ``plugin_dir_url( __FILE__ ) )``
|
* %PLUGIN%_URL: ``plugin_dir_url( __FILE__ ) )``
|
||||||
* %PLUGIN%_URI: ``plugin_dir_url( __FILE__ ) )``
|
|
||||||
* %PLUGIN%_BASENAME: ``plugin_basename( __FILE__ ) )``
|
* %PLUGIN%_BASENAME: ``plugin_basename( __FILE__ ) )``
|
||||||
* %PLUGIN%_FILE: ``__FILE__``
|
* %PLUGIN%_FILE: ``__FILE__``
|
||||||
* %PLUGIN%_PLUGIN_FILE: ``__FILE__``
|
* %PLUGIN%_PLUGIN_FILE: ``__FILE__``
|
||||||
|
|
||||||
|
### Get Instance
|
||||||
|
|
||||||
|
All PluginCore instances can be referenced anywhere in your code using static method `get()` and the plugin slug. Available on `plugins_loaded` hook or later.
|
||||||
|
```PHP
|
||||||
|
PluginCore::get('my-awesome-plugin'); // returns PluginCore instance constructed with slug 'my-awesome-plugin'
|
||||||
|
```
|
||||||
|
|||||||
4
vendor/abuyoyo/plugincore/composer.json
vendored
4
vendor/abuyoyo/plugincore/composer.json
vendored
@ -2,8 +2,8 @@
|
|||||||
"name": "abuyoyo/plugincore",
|
"name": "abuyoyo/plugincore",
|
||||||
"description": "WordPress plugin core helper class",
|
"description": "WordPress plugin core helper class",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"version": "0.20",
|
"version": "0.21",
|
||||||
"time": "2022-07-29",
|
"time": "2022-08-05",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"require": {
|
"require": {
|
||||||
"yahnis-elsts/plugin-update-checker": "~4.12",
|
"yahnis-elsts/plugin-update-checker": "~4.12",
|
||||||
|
|||||||
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
@ -43,24 +43,24 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "abuyoyo/plugincore",
|
"name": "abuyoyo/plugincore",
|
||||||
"version": "0.20",
|
"version": "0.21",
|
||||||
"version_normalized": "0.20.0.0",
|
"version_normalized": "0.21.0.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/abuyoyo/PluginCore.git",
|
"url": "https://github.com/abuyoyo/PluginCore.git",
|
||||||
"reference": "0f8de7be654880adc850610f045f22cd7923c3cc"
|
"reference": "9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/0f8de7be654880adc850610f045f22cd7923c3cc",
|
"url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa",
|
||||||
"reference": "0f8de7be654880adc850610f045f22cd7923c3cc",
|
"reference": "9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"abuyoyo/adminmenupage": "~0.20",
|
"abuyoyo/adminmenupage": "~0.20",
|
||||||
"yahnis-elsts/plugin-update-checker": "~4.12"
|
"yahnis-elsts/plugin-update-checker": "~4.12"
|
||||||
},
|
},
|
||||||
"time": "2022-07-29T00:00:00+00:00",
|
"time": "2022-08-05T00:00:00+00:00",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"installation-source": "dist",
|
"installation-source": "dist",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -75,7 +75,7 @@
|
|||||||
"description": "WordPress plugin core helper class",
|
"description": "WordPress plugin core helper class",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/abuyoyo/PluginCore/issues",
|
"issues": "https://github.com/abuyoyo/PluginCore/issues",
|
||||||
"source": "https://github.com/abuyoyo/PluginCore/tree/0.20"
|
"source": "https://github.com/abuyoyo/PluginCore/tree/0.21"
|
||||||
},
|
},
|
||||||
"install-path": "../abuyoyo/plugincore"
|
"install-path": "../abuyoyo/plugincore"
|
||||||
},
|
},
|
||||||
|
|||||||
18
vendor/composer/installed.php
vendored
18
vendor/composer/installed.php
vendored
@ -1,11 +1,11 @@
|
|||||||
<?php return array(
|
<?php return array(
|
||||||
'root' => array(
|
'root' => array(
|
||||||
'pretty_version' => 'dev-next',
|
'pretty_version' => '0.16',
|
||||||
'version' => 'dev-next',
|
'version' => '0.16.0.0',
|
||||||
'type' => 'wordpress-plugin',
|
'type' => 'wordpress-plugin',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => '3ef2aa48dd941df15c08c6f17cd649c9754fa1fc',
|
'reference' => NULL,
|
||||||
'name' => 'abuyoyo/notice-manager',
|
'name' => 'abuyoyo/notice-manager',
|
||||||
'dev' => true,
|
'dev' => true,
|
||||||
),
|
),
|
||||||
@ -20,21 +20,21 @@
|
|||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'abuyoyo/notice-manager' => array(
|
'abuyoyo/notice-manager' => array(
|
||||||
'pretty_version' => 'dev-next',
|
'pretty_version' => '0.16',
|
||||||
'version' => 'dev-next',
|
'version' => '0.16.0.0',
|
||||||
'type' => 'wordpress-plugin',
|
'type' => 'wordpress-plugin',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => '3ef2aa48dd941df15c08c6f17cd649c9754fa1fc',
|
'reference' => NULL,
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'abuyoyo/plugincore' => array(
|
'abuyoyo/plugincore' => array(
|
||||||
'pretty_version' => '0.20',
|
'pretty_version' => '0.21',
|
||||||
'version' => '0.20.0.0',
|
'version' => '0.21.0.0',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../abuyoyo/plugincore',
|
'install_path' => __DIR__ . '/../abuyoyo/plugincore',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => '0f8de7be654880adc850610f045f22cd7923c3cc',
|
'reference' => '9c398bdf05dc2cecf30eb0ac53558b3d37ecc4aa',
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'abuyoyo/screen-meta-links' => array(
|
'abuyoyo/screen-meta-links' => array(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user