Moving admin to it's own directory, trying to fix up docblocks and stuff
This commit is contained in:
parent
c94414dc0e
commit
ecd4099038
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
### Project Specific
|
||||
# Files
|
||||
.env
|
||||
phpcs.xml
|
||||
phpunit.xml
|
||||
.phpunit.result.cache
|
||||
|
90
admin/class-settings.php
Normal file
90
admin/class-settings.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace PluginNamespace\Admin;
|
||||
|
||||
class Settings {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'append_to_admin_menu' ), 12 );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to the admin menu (prevents doubling).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function append_to_admin_menu(): void {
|
||||
$parent_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$page_title = __( 'Namespace Plugin Name - Settings', 'nmsp_plugin_name_settings_title' );
|
||||
$menu_title = __( 'Settings', 'nmsp_plugin_name_settings_title' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = $parent_slug;
|
||||
$callback = array( $this, 'show_main_settings_page' );
|
||||
|
||||
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function show_main_settings_page(): string {
|
||||
$data = array();
|
||||
|
||||
$this->localize_script();
|
||||
|
||||
ob_start();
|
||||
echo nmsp_plugin_app()->blade->run( 'admin.settings', $data );
|
||||
$output = ob_get_clean();
|
||||
return wp_kses_post( $output );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and enqueue stylesheets and javascript files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-name-admin-css', plugins_url( '../assets/css/nmsp-plugin-name-admin.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
|
||||
wp_register_script( 'nmsp-plugin-name-admin-js', plugins_url( '../assets/js/nmsp-plugin-name-admin.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $additional_data (optional) Additional key-value paired data to pass to JavaScript.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function localize_script( array $additional_data = array() ): void {
|
||||
wp_enqueue_script( 'nmsp-plugin-name-admin-js' );
|
||||
|
||||
$payload = array(
|
||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'_nonce' => wp_create_nonce( NMSP_PLUGIN_NONCE ),
|
||||
);
|
||||
wp_localize_script( 'nmsp-plugin-name-admin-js', 'nmspPluginAdminApi', $payload );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new Settings();
|
1
admin/index.php
Normal file
1
admin/index.php
Normal file
@ -0,0 +1 @@
|
||||
<?php // silence is golden
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
use PluginNamespace\App;
|
||||
|
||||
/**
|
||||
| ----------------------------------------------------------------
|
||||
| Bootstrap
|
||||
@ -18,7 +16,7 @@ require_once 'constants/base.php';
|
||||
require_once 'constants/rewrites.php';
|
||||
|
||||
if ( ! function_exists( 'nmsp_plugin_app' ) ) {
|
||||
function nmsp_plugin_app(): App {
|
||||
return App::get_instance();
|
||||
function nmsp_plugin_app(): \PluginNamespace\App {
|
||||
return \PluginNamespace\App::get_instance();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
"eftec/bladeone": "^3.52"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-parallel-lint/php-parallel-lint": "^1.3.0",
|
||||
"wp-cli/i18n-command": "^2.2.8",
|
||||
"wp-coding-standards/wpcs": "^2.3.0"
|
||||
},
|
||||
"config": {
|
||||
@ -41,6 +43,9 @@
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"scripts": {
|
||||
"lint:wpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs -p -v --no-cache --ignore=*/tests/,*/vendor/ --extensions=php .",
|
||||
"lint:php": "@php ./vendor/bin/parallel-lint --exclude .git --exclude vendor .",
|
||||
"make-pot": "wp i18n make-pot --include=constants,includes,templates . languages/nmsp-plugin-name.pot",
|
||||
"post-autoload-dump": [],
|
||||
"post-root-package-install": []
|
||||
}
|
||||
|
662
composer.lock
generated
662
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ee716afb08c53b3b3561235990805632",
|
||||
"content-hash": "2684d1770bbee2bb8f671fbbb3919f1e",
|
||||
"packages": [
|
||||
{
|
||||
"name": "eftec/bladeone",
|
||||
@ -66,6 +66,368 @@
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "gettext/gettext",
|
||||
"version": "v4.8.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-gettext/Gettext.git",
|
||||
"reference": "58bc0f7f37e78efb0f9758f93d4a0f669f0f84a1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-gettext/Gettext/zipball/58bc0f7f37e78efb0f9758f93d4a0f669f0f84a1",
|
||||
"reference": "58bc0f7f37e78efb0f9758f93d4a0f669f0f84a1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"gettext/languages": "^2.3",
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/view": "*",
|
||||
"phpunit/phpunit": "^4.8|^5.7|^6.5",
|
||||
"squizlabs/php_codesniffer": "^3.0",
|
||||
"symfony/yaml": "~2",
|
||||
"twig/extensions": "*",
|
||||
"twig/twig": "^1.31|^2.0"
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/view": "Is necessary if you want to use the Blade extractor",
|
||||
"symfony/yaml": "Is necessary if you want to use the Yaml extractor/generator",
|
||||
"twig/extensions": "Is necessary if you want to use the Twig extractor",
|
||||
"twig/twig": "Is necessary if you want to use the Twig extractor"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Gettext\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Oscar Otero",
|
||||
"email": "oom@oscarotero.com",
|
||||
"homepage": "http://oscarotero.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "PHP gettext manager",
|
||||
"homepage": "https://github.com/oscarotero/Gettext",
|
||||
"keywords": [
|
||||
"JS",
|
||||
"gettext",
|
||||
"i18n",
|
||||
"mo",
|
||||
"po",
|
||||
"translation"
|
||||
],
|
||||
"support": {
|
||||
"email": "oom@oscarotero.com",
|
||||
"issues": "https://github.com/oscarotero/Gettext/issues",
|
||||
"source": "https://github.com/php-gettext/Gettext/tree/v4.8.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://paypal.me/oscarotero",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/oscarotero",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/misteroom",
|
||||
"type": "patreon"
|
||||
}
|
||||
],
|
||||
"time": "2021-03-10T19:35:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "gettext/languages",
|
||||
"version": "2.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-gettext/Languages.git",
|
||||
"reference": "38ea0482f649e0802e475f0ed19fa993bcb7a618"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-gettext/Languages/zipball/38ea0482f649e0802e475f0ed19fa993bcb7a618",
|
||||
"reference": "38ea0482f649e0802e475f0ed19fa993bcb7a618",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^2.16.0",
|
||||
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.4"
|
||||
},
|
||||
"bin": [
|
||||
"bin/export-plural-rules"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Gettext\\Languages\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michele Locati",
|
||||
"email": "mlocati@gmail.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "gettext languages with plural rules",
|
||||
"homepage": "https://github.com/php-gettext/Languages",
|
||||
"keywords": [
|
||||
"cldr",
|
||||
"i18n",
|
||||
"internationalization",
|
||||
"l10n",
|
||||
"language",
|
||||
"languages",
|
||||
"localization",
|
||||
"php",
|
||||
"plural",
|
||||
"plural rules",
|
||||
"plurals",
|
||||
"translate",
|
||||
"translations",
|
||||
"unicode"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-gettext/Languages/issues",
|
||||
"source": "https://github.com/php-gettext/Languages/tree/2.6.0"
|
||||
},
|
||||
"time": "2019-11-13T10:30:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "mck89/peast",
|
||||
"version": "v1.13.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mck89/peast.git",
|
||||
"reference": "db38b1524f5bda921cbda2385e440c2bb71d18b4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mck89/peast/zipball/db38b1524f5bda921cbda2385e440c2bb71d18b4",
|
||||
"reference": "db38b1524f5bda921cbda2385e440c2bb71d18b4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.13.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Peast\\": "lib/Peast/",
|
||||
"Peast\\test\\": "test/Peast/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marco Marchiò",
|
||||
"email": "marco.mm89@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Peast is PHP library that generates AST for JavaScript code",
|
||||
"support": {
|
||||
"issues": "https://github.com/mck89/peast/issues",
|
||||
"source": "https://github.com/mck89/peast/tree/v1.13.0"
|
||||
},
|
||||
"time": "2021-05-22T16:06:09+00:00"
|
||||
},
|
||||
{
|
||||
"name": "mustache/mustache",
|
||||
"version": "v2.13.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bobthecow/mustache.php.git",
|
||||
"reference": "e95c5a008c23d3151d59ea72484d4f72049ab7f4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/e95c5a008c23d3151d59ea72484d4f72049ab7f4",
|
||||
"reference": "e95c5a008c23d3151d59ea72484d4f72049ab7f4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "~1.11",
|
||||
"phpunit/phpunit": "~3.7|~4.0|~5.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Mustache": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Justin Hileman",
|
||||
"email": "justin@justinhileman.info",
|
||||
"homepage": "http://justinhileman.com"
|
||||
}
|
||||
],
|
||||
"description": "A Mustache implementation in PHP.",
|
||||
"homepage": "https://github.com/bobthecow/mustache.php",
|
||||
"keywords": [
|
||||
"mustache",
|
||||
"templating"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/bobthecow/mustache.php/issues",
|
||||
"source": "https://github.com/bobthecow/mustache.php/tree/master"
|
||||
},
|
||||
"time": "2019-11-23T21:40:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-parallel-lint/php-parallel-lint",
|
||||
"version": "v1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git",
|
||||
"reference": "772a954e5f119f6f5871d015b23eabed8cbdadfb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/772a954e5f119f6f5871d015b23eabed8cbdadfb",
|
||||
"reference": "772a954e5f119f6f5871d015b23eabed8cbdadfb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"replace": {
|
||||
"grogy/php-parallel-lint": "*",
|
||||
"jakub-onderka/php-parallel-lint": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"nette/tester": "^1.3 || ^2.0",
|
||||
"php-parallel-lint/php-console-highlighter": "~0.3",
|
||||
"squizlabs/php_codesniffer": "^3.5"
|
||||
},
|
||||
"suggest": {
|
||||
"php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet"
|
||||
},
|
||||
"bin": [
|
||||
"parallel-lint"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"./"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-2-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jakub Onderka",
|
||||
"email": "ahoj@jakubonderka.cz"
|
||||
}
|
||||
],
|
||||
"description": "This tool check syntax of PHP files about 20x faster than serial check.",
|
||||
"homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint",
|
||||
"support": {
|
||||
"issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues",
|
||||
"source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.3.0"
|
||||
},
|
||||
"time": "2021-04-07T14:42:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "rmccue/requests",
|
||||
"version": "v1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/WordPress/Requests.git",
|
||||
"reference": "afbe4790e4def03581c4a0963a1e8aa01f6030f1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/WordPress/Requests/zipball/afbe4790e4def03581c4a0963a1e8aa01f6030f1",
|
||||
"reference": "afbe4790e4def03581c4a0963a1e8aa01f6030f1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
|
||||
"php-parallel-lint/php-console-highlighter": "^0.5.0",
|
||||
"php-parallel-lint/php-parallel-lint": "^1.3",
|
||||
"phpcompatibility/php-compatibility": "^9.0",
|
||||
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5",
|
||||
"requests/test-server": "dev-master",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"wp-coding-standards/wpcs": "^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Requests": "library/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"ISC"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ryan McCue",
|
||||
"homepage": "http://ryanmccue.info"
|
||||
}
|
||||
],
|
||||
"description": "A HTTP library written in PHP, for human beings.",
|
||||
"homepage": "http://github.com/WordPress/Requests",
|
||||
"keywords": [
|
||||
"curl",
|
||||
"fsockopen",
|
||||
"http",
|
||||
"idna",
|
||||
"ipv6",
|
||||
"iri",
|
||||
"sockets"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/WordPress/Requests/issues",
|
||||
"source": "https://github.com/WordPress/Requests/tree/v1.8.0"
|
||||
},
|
||||
"time": "2021-04-27T11:05:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "squizlabs/php_codesniffer",
|
||||
"version": "3.6.0",
|
||||
@ -122,6 +484,304 @@
|
||||
},
|
||||
"time": "2021-04-09T00:54:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/finder",
|
||||
"version": "v5.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/finder.git",
|
||||
"reference": "0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/finder/zipball/0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6",
|
||||
"reference": "0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Finder\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/finder/tree/v5.3.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-05-26T12:52:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wp-cli/i18n-command",
|
||||
"version": "v2.2.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/wp-cli/i18n-command.git",
|
||||
"reference": "8bc234617edc533590ac0f41080164a8d85ec9ce"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/wp-cli/i18n-command/zipball/8bc234617edc533590ac0f41080164a8d85ec9ce",
|
||||
"reference": "8bc234617edc533590ac0f41080164a8d85ec9ce",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"gettext/gettext": "^4.8",
|
||||
"mck89/peast": "^1.8",
|
||||
"wp-cli/wp-cli": "^2.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"wp-cli/scaffold-command": "^1.2 || ^2",
|
||||
"wp-cli/wp-cli-tests": "^3.0.11"
|
||||
},
|
||||
"type": "wp-cli-package",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
},
|
||||
"bundled": true,
|
||||
"commands": [
|
||||
"i18n",
|
||||
"i18n make-pot",
|
||||
"i18n make-json"
|
||||
]
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WP_CLI\\I18n\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"i18n-command.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Pascal Birchler",
|
||||
"homepage": "https://pascalbirchler.com/"
|
||||
}
|
||||
],
|
||||
"description": "Provides internationalization tools for WordPress projects.",
|
||||
"homepage": "https://github.com/wp-cli/i18n-command",
|
||||
"support": {
|
||||
"issues": "https://github.com/wp-cli/i18n-command/issues",
|
||||
"source": "https://github.com/wp-cli/i18n-command/tree/v2.2.8"
|
||||
},
|
||||
"time": "2021-05-10T10:24:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wp-cli/mustangostang-spyc",
|
||||
"version": "0.6.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/wp-cli/spyc.git",
|
||||
"reference": "6aa0b4da69ce9e9a2c8402dab8d43cf32c581cc7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/wp-cli/spyc/zipball/6aa0b4da69ce9e9a2c8402dab8d43cf32c581cc7",
|
||||
"reference": "6aa0b4da69ce9e9a2c8402dab8d43cf32c581cc7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.3.*@dev"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "0.5.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mustangostang\\": "src/"
|
||||
},
|
||||
"files": [
|
||||
"includes/functions.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "mustangostang",
|
||||
"email": "vlad.andersen@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A simple YAML loader/dumper class for PHP (WP-CLI fork)",
|
||||
"homepage": "https://github.com/mustangostang/spyc/",
|
||||
"support": {
|
||||
"source": "https://github.com/wp-cli/spyc/tree/autoload"
|
||||
},
|
||||
"time": "2017-04-25T11:26:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wp-cli/php-cli-tools",
|
||||
"version": "v0.11.12",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/wp-cli/php-cli-tools.git",
|
||||
"reference": "e472e08489f7504d9e8c5c5a057e1419cd1b2b3e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/e472e08489f7504d9e8c5c5a057e1419cd1b2b3e",
|
||||
"reference": "e472e08489f7504d9e8c5c5a057e1419cd1b2b3e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">= 5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"cli": "lib/"
|
||||
},
|
||||
"files": [
|
||||
"lib/cli/cli.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniel Bachhuber",
|
||||
"email": "daniel@handbuilt.co",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "James Logsdon",
|
||||
"email": "jlogsdon@php.net",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Console utilities for PHP",
|
||||
"homepage": "http://github.com/wp-cli/php-cli-tools",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"console"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/wp-cli/php-cli-tools/issues",
|
||||
"source": "https://github.com/wp-cli/php-cli-tools/tree/v0.11.12"
|
||||
},
|
||||
"time": "2021-03-03T12:43:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wp-cli/wp-cli",
|
||||
"version": "v2.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/wp-cli/wp-cli.git",
|
||||
"reference": "0bcf0c54f4d35685211d435e25219cc7acbe6d48"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/0bcf0c54f4d35685211d435e25219cc7acbe6d48",
|
||||
"reference": "0bcf0c54f4d35685211d435e25219cc7acbe6d48",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"mustache/mustache": "~2.13",
|
||||
"php": "^5.6 || ^7.0 || ^8.0",
|
||||
"rmccue/requests": "^1.8",
|
||||
"symfony/finder": ">2.7",
|
||||
"wp-cli/mustangostang-spyc": "^0.6.3",
|
||||
"wp-cli/php-cli-tools": "~0.11.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"roave/security-advisories": "dev-master",
|
||||
"wp-cli/db-command": "^1.3 || ^2",
|
||||
"wp-cli/entity-command": "^1.2 || ^2",
|
||||
"wp-cli/extension-command": "^1.1 || ^2",
|
||||
"wp-cli/package-command": "^1 || ^2",
|
||||
"wp-cli/wp-cli-tests": "^3.0.7"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-readline": "Include for a better --prompt implementation",
|
||||
"ext-zip": "Needed to support extraction of ZIP archives when doing downloads or updates"
|
||||
},
|
||||
"bin": [
|
||||
"bin/wp",
|
||||
"bin/wp.bat"
|
||||
],
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.5.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"WP_CLI\\": "php/"
|
||||
},
|
||||
"classmap": [
|
||||
"php/class-wp-cli.php",
|
||||
"php/class-wp-cli-command.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "WP-CLI framework",
|
||||
"homepage": "https://wp-cli.org",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"wordpress"
|
||||
],
|
||||
"support": {
|
||||
"docs": "https://make.wordpress.org/cli/handbook/",
|
||||
"issues": "https://github.com/wp-cli/wp-cli/issues",
|
||||
"source": "https://github.com/wp-cli/wp-cli"
|
||||
},
|
||||
"time": "2021-05-14T13:44:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wp-coding-standards/wpcs",
|
||||
"version": "2.3.0",
|
||||
|
@ -13,11 +13,11 @@
|
||||
*/
|
||||
|
||||
const NMSP_PLUGIN_SLUG_REWRITE_NAMES = array(
|
||||
'NMSP_PLUGIN_SLUG_PAGE_NAME' => 'nmsp_plugin_slug_page_name',
|
||||
'NMSP_PLUGIN_SLUG_PAGE_NAME' => 'nmsp_plugin_slug_page_name',
|
||||
);
|
||||
|
||||
foreach ( NMSP_PLUGIN_SLUG_REWRITE_NAMES as $page_slug => $page_name ) {
|
||||
if ( ! defined( $page_slug ) ) {
|
||||
define( $page_slug, $page_name );
|
||||
}
|
||||
if ( ! defined( $page_slug ) ) {
|
||||
define( $page_slug, $page_name );
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace PluginNamespace;
|
||||
|
||||
class Settings {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_menu', array( $this, 'append_to_admin_menu' ), 12 );
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to the admin menu (prevents doubling).
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function append_to_admin_menu(): void {
|
||||
$parent_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$page_title = __( 'Namespace Plugin Name - Settings', 'nmsp_plugin_name_settings_title' );
|
||||
$menu_title = __( 'Settings', 'nmsp_plugin_name_settings_title' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = $parent_slug;
|
||||
$callback = array( $this, 'show_main_settings_page' );
|
||||
|
||||
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show_main_settings_page(): void {
|
||||
$data = array();
|
||||
|
||||
echo nmsp_plugin_app()->blade->run( 'admin.settings', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and enqueue stylesheets and javascript files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-name-admin-css', plugins_url( '../../assets/css/nmsp-plugin-name-admin.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
|
||||
wp_register_script( 'nmsp-plugin-name-admin-js', plugins_url( '../../assets/js/nmsp-plugin-name-admin.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
|
||||
wp_enqueue_script( 'nmsp-plugin-name-admin-js' );
|
||||
|
||||
$payload = array(
|
||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'_nonce' => wp_create_nonce( NMSP_PLUGIN_NONCE ),
|
||||
);
|
||||
wp_localize_script( 'nmsp-plugin-name-admin-js', 'nmspPluginAdminApi', $payload );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new Settings();
|
@ -7,162 +7,160 @@ use Exception;
|
||||
|
||||
class App {
|
||||
|
||||
/** @var \PluginNamespace\App */
|
||||
public static $instance;
|
||||
/** @var \PluginNamespace\App */
|
||||
public static $instance;
|
||||
|
||||
/** @var \eftec\bladeone\BladeOne */
|
||||
public $blade;
|
||||
/** @var \eftec\bladeone\BladeOne */
|
||||
public $blade;
|
||||
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is activated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_activation(): void {
|
||||
self::ensure_template_cache_dir_exists();
|
||||
}
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is activated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_activation(): void {
|
||||
self::ensure_template_cache_dir_exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is deactivated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_deactivation(): void {
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Any logic that needs executed when the plugin is deactivated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function plugin_deactivation(): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the cache directory for Blade exists and
|
||||
* if not then attempt to create it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ensure_template_cache_dir_exists(): void {
|
||||
if ( ! file_exists( NMSP_PLUGIN_BASE_DIR . '/cache/blade/.gitignore' ) ) {
|
||||
try {
|
||||
mkdir( NMSP_PLUGIN_BASE_DIR . '/cache/blade', 0755, true );
|
||||
} catch ( Exception $e ) {
|
||||
$error_payload = array(
|
||||
'level' => 'critical',
|
||||
'message' => $e->getMessage(),
|
||||
'context' => array(
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
),
|
||||
);
|
||||
error_log( json_encode( $error_payload, JSON_PRETTY_PRINT ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check that the cache directory for Blade exists and
|
||||
* if not then attempt to create it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ensure_template_cache_dir_exists(): void {
|
||||
if ( ! file_exists( NMSP_PLUGIN_BASE_DIR . '/cache/blade/.gitignore' ) ) {
|
||||
try {
|
||||
mkdir( NMSP_PLUGIN_BASE_DIR . '/cache/blade', 0755, true );
|
||||
} catch ( Exception $e ) {
|
||||
$error_payload = array(
|
||||
'level' => 'critical',
|
||||
'message' => $e->getMessage(),
|
||||
'context' => array(
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
),
|
||||
);
|
||||
error_log( json_encode( $error_payload, JSON_PRETTY_PRINT ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of this plugin class. If it has
|
||||
* not been initialized, do so then return it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \PluginNamespace\App
|
||||
*/
|
||||
public static function get_instance(): App {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof App ) ) {
|
||||
self::$instance = new App();
|
||||
/**
|
||||
* Return an instance of this plugin class. If it has
|
||||
* not been initialized, do so then return it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \PluginNamespace\App
|
||||
*/
|
||||
public static function get_instance(): App {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof App ) ) {
|
||||
self::$instance = new App();
|
||||
|
||||
self::$instance->load_plugin_textdomain();
|
||||
self::$instance->scaffold_plugin();
|
||||
self::$instance->includes();
|
||||
}
|
||||
self::$instance->load_plugin_textdomain();
|
||||
self::$instance->scaffold_plugin();
|
||||
self::$instance->includes();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load your translation files for this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_plugin_textdomain(): void {
|
||||
load_plugin_textdomain( 'nmsp-plugin-name-text-domain', false, 'languages' );
|
||||
}
|
||||
/**
|
||||
* Load your translation files for this plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_plugin_textdomain(): void {
|
||||
load_plugin_textdomain( 'nmsp-plugin-name-text-domain', false, 'languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps to take when initializing this plugin??
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scaffold_plugin(): void {
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
}
|
||||
/**
|
||||
* Steps to take when initializing this plugin??
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function scaffold_plugin(): void {
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting up the WordPress dashboard menu for this plugin.
|
||||
* Setting this here to be overriden later so that a base is always available.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_admin_menu(): void {
|
||||
$page_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$menu_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$callback = '';
|
||||
$icon = plugins_url( '../assets/images/menu-icon.svg', __FILE__ );
|
||||
$position = 100;
|
||||
/**
|
||||
* Setting up the WordPress dashboard menu for this plugin.
|
||||
* Setting this here to be overriden later so that a base is always available.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_admin_menu(): void {
|
||||
$page_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$menu_title = __( 'Namespace Plugin Name', 'nmsp_plugin_name_menu' );
|
||||
$capability = 'manage_options';
|
||||
$menu_slug = 'nmsp-plugin-name-menu-slug';
|
||||
$callback = '';
|
||||
$icon = plugins_url( '../assets/images/menu-icon.svg', __FILE__ );
|
||||
$position = 100;
|
||||
|
||||
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback, $icon, $position );
|
||||
}
|
||||
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback, $icon, $position );
|
||||
}
|
||||
|
||||
/**
|
||||
* Other files to include so that this plugin will
|
||||
* have a single entrypoint but be able to break
|
||||
* up code in a logical manor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function includes(): void {
|
||||
// Files to include on the admin.
|
||||
if ( is_admin() ) {
|
||||
require_once __DIR__ . '/admin/class-settings.php';
|
||||
}
|
||||
//
|
||||
/**
|
||||
* Other files to include so that this plugin will
|
||||
* have a single entrypoint but be able to break
|
||||
* up code in a logical manor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function includes(): void {
|
||||
// Files to include on the admin.
|
||||
if ( is_admin() ) {
|
||||
require_once NMSP_PLUGIN_BASE_DIR . '/admin/class-settings.php';
|
||||
}
|
||||
//
|
||||
|
||||
// Files to include on every request.
|
||||
//
|
||||
// Files to include on every request.
|
||||
//
|
||||
|
||||
// Files to include that may be sub-namespaced.
|
||||
if ( is_single() ) {
|
||||
require_once __DIR__ . '/front/class-custompage.php';
|
||||
}
|
||||
}
|
||||
// Files to include that may be sub-namespaced.
|
||||
require_once __DIR__ . '/front/class-custompage.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* .
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \eftec\bladeone\BladeOne $blade
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_blade( BladeOne $blade ): void {
|
||||
$this->blade = $blade;
|
||||
}
|
||||
/**
|
||||
* Load Blade as the templating engine for the plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param \eftec\bladeone\BladeOne $blade
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load_blade( BladeOne $blade ): void {
|
||||
$this->blade = $blade;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,39 +5,39 @@ namespace PluginNamespace;
|
||||
use WP_CLI;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class NmspCli {
|
||||
|
||||
/**
|
||||
* Class constructor. Can add commands here.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
WP_CLI::add_command(
|
||||
'nmsp-plugin do',
|
||||
array( $this, 'do_the_thing' ),
|
||||
array(
|
||||
'shortdesc' => __( 'The short description.', 'nmsp-plugin-name-text-domain' ),
|
||||
'longdesc' => __( "This is the super long description that will go on and on my friend. Some people started writing it not knowing what it was, and we'll continue writing it forever just because this is the description that never ends...", 'nmsp-plugin-name-text-domain' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Class constructor. Can add commands here.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
WP_CLI::add_command(
|
||||
'nmsp-plugin do',
|
||||
array( $this, 'do_the_thing' ),
|
||||
array(
|
||||
'shortdesc' => __( 'The short description.', 'nmsp-plugin-name-text-domain' ),
|
||||
'longdesc' => __( "This is the super long description that will go on and on my friend. Some people started writing it not knowing what it was, and we'll continue writing it forever just because this is the description that never ends...", 'nmsp-plugin-name-text-domain' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A sample method where something is done.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function do_the_thing(): void {
|
||||
WP_CLI::success( __( 'Congradulations, it is working.', 'nmsp-plugin-name-text-domain' ) );
|
||||
}
|
||||
/**
|
||||
* A sample method where something is done by being invoked from WP CLI.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function do_the_thing(): void {
|
||||
WP_CLI::success( __( 'Congradulations, it is working.', 'nmsp-plugin-name-text-domain' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,60 +3,61 @@
|
||||
namespace PluginNamespace\Front;
|
||||
|
||||
class CustomPage {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_shortcode( 'nmsp_plugin_shortcode', array( $this, 'display_custom_page' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and enqueue stylesheets and javascript files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-name-css', plugins_url( '../../assets/css/nmsp-plugin-name.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_shortcode( 'nmsp_plugin_shortcode', array( $this, 'display_custom_page' ) );
|
||||
}
|
||||
|
||||
wp_register_script( 'nmsp-plugin-name-js', plugins_url( '../../assets/js/nmsp-plugin-name.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
|
||||
wp_enqueue_script( 'nmsp-plugin-name-js' );
|
||||
/**
|
||||
* Register and enqueue stylesheets and javascript files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts(): void {
|
||||
wp_enqueue_style( 'nmsp-plugin-name-css', plugins_url( '../../assets/css/nmsp-plugin-name.css', __FILE__ ), array(), '1.0.0', 'screen' );
|
||||
|
||||
$payload = array(
|
||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'_nonce' => wp_create_nonce( NMSP_PLUGIN_NONCE ),
|
||||
);
|
||||
wp_localize_script( 'nmsp-plugin-name-js', 'nmspPluginApi', $payload );
|
||||
}
|
||||
wp_register_script( 'nmsp-plugin-name-js', plugins_url( '../../assets/js/nmsp-plugin-name.js', __FILE__ ), array( 'jquery' ), '1.0.0', false );
|
||||
wp_enqueue_script( 'nmsp-plugin-name-js' );
|
||||
|
||||
/**
|
||||
* Display a page in place of a shortcode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attributes Array of attributes on the shortcode string in the post body.
|
||||
* @param string $content (optional) Text content that is between opening and closing shortcodes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_custom_page( array $attributes = array(), $content = null ) {
|
||||
$data = array(
|
||||
'shortcode' => array(
|
||||
'attributes' => $attributes,
|
||||
'content' => $content,
|
||||
),
|
||||
);
|
||||
$payload = array(
|
||||
'wp_ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'_nonce' => wp_create_nonce( NMSP_PLUGIN_NONCE ),
|
||||
);
|
||||
wp_localize_script( 'nmsp-plugin-name-js', 'nmspPluginApi', $payload );
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.EscapeOutput
|
||||
return nmsp_plugin_app()->blade->run( 'front.custom-page', $data );
|
||||
// phpcs:enable WordPress.Security.EscapeOutput
|
||||
}
|
||||
/**
|
||||
* Display a page in place of a shortcode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $attributes Array of attributes on the shortcode string in the post body.
|
||||
* @param string $content (optional) Text content that is between opening and closing shortcodes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_custom_page( array $attributes = array(), $content = null ) {
|
||||
$data = array(
|
||||
'shortcode' => array(
|
||||
'attributes' => $attributes,
|
||||
'content' => $content,
|
||||
),
|
||||
);
|
||||
|
||||
ob_start();
|
||||
echo nmsp_plugin_app()->blade->run( 'front.custom-page', $data );
|
||||
$output = ob_get_clean();
|
||||
return wp_kses_post( $output );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,90 +4,90 @@ namespace PluginNamespace\Front;
|
||||
|
||||
class Rewrites {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'add_rewrite_rules' ), 5 );
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'add_rewrite_rules' ), 5 );
|
||||
|
||||
add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
|
||||
add_filter( 'nmsp_plugin_name_rewrite_urls', array( $this, 'build_rewrite_urls' ) );
|
||||
}
|
||||
add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
|
||||
add_filter( 'nmsp_plugin_name_rewrite_urls', array( $this, 'build_rewrite_urls' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate new rewrite rules and flush the cached values.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_rewrite_rules(): void {
|
||||
$filters = apply_filters( 'nmsp_plugin_name_rewrite_urls', array() );
|
||||
/**
|
||||
* Generate new rewrite rules and flush the cached values.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_rewrite_rules(): void {
|
||||
$filters = apply_filters( 'nmsp_plugin_name_rewrite_urls', array() );
|
||||
|
||||
add_rewrite_tag( 'foo', '([0-9]+)' );
|
||||
add_rewrite_tag( 'foo', '([0-9]+)' );
|
||||
|
||||
if ( is_iterable( $filters ) && count( $filters ) > 0 ) {
|
||||
foreach ( $filters as $item ) {
|
||||
if ( $item['slug'] ) {
|
||||
$slug = str_replace( home_url() . '/', '', get_permalink( $item['id'] ) );
|
||||
add_rewrite_rule( '^' . $slug . '([^/]*' . $item['var'] . ')/([^/]*)/?', 'index.php?page_id=' . $item['id'] . '&$matches[1]=$matches[2]', 'top' );
|
||||
}
|
||||
}
|
||||
if ( is_iterable( $filters ) && count( $filters ) > 0 ) {
|
||||
foreach ( $filters as $item ) {
|
||||
if ( $item['slug'] ) {
|
||||
$slug = str_replace( home_url() . '/', '', get_permalink( $item['id'] ) );
|
||||
add_rewrite_rule( '^' . $slug . '([^/]*' . $item['var'] . ')/([^/]*)/?', 'index.php?page_id=' . $item['id'] . '&$matches[1]=$matches[2]', 'top' );
|
||||
}
|
||||
}
|
||||
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the array of post IDs that have a slug for the URL
|
||||
* along with what custom query variable to use.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function build_rewrite_urls(): array {
|
||||
$pages = array();
|
||||
/**
|
||||
* Build the array of post IDs that have a slug for the URL
|
||||
* along with what custom query variable to use.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function build_rewrite_urls(): array {
|
||||
$pages = array();
|
||||
|
||||
$page_list = array(
|
||||
'NMSP_PLUGIN_SLUG_PAGE_NAME' => array( 'foo' ),
|
||||
);
|
||||
$page_list = array(
|
||||
'NMSP_PLUGIN_SLUG_PAGE_NAME' => array( 'foo' ),
|
||||
);
|
||||
|
||||
foreach ( $page_list as $key => $params ) {
|
||||
$page_id = get_option( constant( $key ) );
|
||||
$page = ( $page_id ) ? get_post( $page_id ) : false;
|
||||
if ( ! empty( $page ) ) {
|
||||
foreach ( $params as $param ) {
|
||||
$pages[] = array(
|
||||
'id' => $page_id,
|
||||
'slug' => $page->post_name,
|
||||
'var' => $param,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $page_list as $key => $params ) {
|
||||
$page_id = get_option( constant( $key ) );
|
||||
$page = ( $page_id ) ? get_post( $page_id ) : false;
|
||||
if ( ! empty( $page ) ) {
|
||||
foreach ( $params as $param ) {
|
||||
$pages[] = array(
|
||||
'id' => $page_id,
|
||||
'slug' => $page->post_name,
|
||||
'var' => $param,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
return $pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append custom query variables to the list WordPress maintinas
|
||||
* with each request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $variable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function custom_query_vars( array $vars ): array {
|
||||
$vars[] = 'foo';
|
||||
return $vars;
|
||||
}
|
||||
/**
|
||||
* Append custom query variables to the list WordPress maintinas
|
||||
* with each request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $variable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function custom_query_vars( array $vars ): array {
|
||||
$vars[] = 'foo';
|
||||
return $vars;
|
||||
}
|
||||
}
|
||||
|
||||
new Rewrites();
|
||||
|
1
includes/front/index.php
Normal file
1
includes/front/index.php
Normal file
@ -0,0 +1 @@
|
||||
<?php // silence is golden
|
1
includes/index.php
Normal file
1
includes/index.php
Normal file
@ -0,0 +1 @@
|
||||
<?php // silence is golden
|
@ -1,21 +1,30 @@
|
||||
<?php
|
||||
|
||||
use PluginNamespace\App;
|
||||
use eftec\bladeone\BladeOne;
|
||||
|
||||
/*
|
||||
Plugin Name: Boilerplate Plugin
|
||||
Plugin URI: https://domain.com
|
||||
Description: Your plugin description
|
||||
Version: 1.0.0
|
||||
Author: Plugin Author
|
||||
Author URI: https://plugin-author.com
|
||||
License: GPL v2
|
||||
Text Domain: nmsp-plugin-name-text-domain
|
||||
*/
|
||||
/**
|
||||
* Boilerplate Plugin
|
||||
*
|
||||
* @package BoilerplatePlugin
|
||||
* @author
|
||||
* @copyright
|
||||
* @license
|
||||
*
|
||||
* @wordpress-plugin
|
||||
* Plugin Name: Boilerplate Plugin
|
||||
* Description: Your plugin description.
|
||||
* License: GPL v2
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
* Plugin URI: https://domain.com
|
||||
* Update URI: https://example.com/my-plugin/
|
||||
* Version: 1.0.0
|
||||
* Requires at least: 5.2
|
||||
* Requires PHP: 7.2
|
||||
* Author: Plugin Author
|
||||
* Author URI: https://plugin-author.com
|
||||
* Text Domain: nmsp-plugin-name-text-domain
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
define( 'NMSP_PLUGIN_BASE_DIR', __DIR__ );
|
||||
@ -25,12 +34,13 @@ require_once __DIR__ . '/bootstrap.php';
|
||||
|
||||
// include the CLI utility of this plugin if WordPress has CLI functionality
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
require_once __DIR__ . '/includes/class-nmspcli.php';
|
||||
require_once __DIR__ . '/includes/class-nmspcli.php';
|
||||
}
|
||||
|
||||
$blade = new BladeOne( __DIR__ . '/templates', __DIR__ . '/cache/blade', BladeOne::MODE_DEBUG ); // BladeOne::MODE_AUTO
|
||||
$mode = \eftec\bladeone\BladeOne::MODE_AUTO; // Can also be MODE_DEBUG
|
||||
$blade = new \eftec\bladeone\BladeOne( __DIR__ . '/templates', __DIR__ . '/cache/blade', $mode );
|
||||
|
||||
register_activation_hook( __FILE__, array( App::class, 'plugin_activation' ) );
|
||||
register_deactivation_hook( __FILE__, array( App::class, 'plugin_deactivation') );
|
||||
register_activation_hook( __FILE__, array( \PluginNamespace\App::class, 'plugin_activation' ) );
|
||||
register_deactivation_hook( __FILE__, array( \PluginNamespace\App::class, 'plugin_deactivation' ) );
|
||||
|
||||
nmsp_plugin_app()->load_blade( $blade );
|
||||
|
@ -2,7 +2,7 @@
|
||||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
|
||||
<description>CodeSniffing standards for this project.</description>
|
||||
|
||||
<config name="installed_paths" value="./vendor/wp-coding-standards/wpcs" />
|
||||
<config name="installed_paths" value="vendor/wp-coding-standards/wpcs" />
|
||||
|
||||
<file>bootstrap.php</file>
|
||||
<file>nmsp-plugin-name.php</file>
|
||||
@ -10,9 +10,16 @@
|
||||
<file>constants</file>
|
||||
<file>includes</file>
|
||||
|
||||
<exclude-pattern>*/assets/*$</exclude-pattern>
|
||||
<exclude-pattern>*/cache/*$</exclude-pattern>
|
||||
<exclude-pattern>*/languages/*$</exclude-pattern>
|
||||
<exclude-pattern>*/node_modules/*$</exclude-pattern>
|
||||
<exclude-pattern>*/resources/*$</exclude-pattern>
|
||||
<exclude-pattern>*/tests/*$</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*$</exclude-pattern>
|
||||
|
||||
<arg name="basepath" value="./" />
|
||||
<arg name="colors" />
|
||||
<arg name="parallel" value="75" />
|
||||
<arg name="report" value="full" />
|
||||
<arg name="extensions" value="php" />
|
||||
<arg value="nps" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user