Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31d475beca |
No files matched your search
@@ -27,7 +27,15 @@ jobs:
|
||||
tools: composer:v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress
|
||||
run: |
|
||||
if [[ "${{ matrix.php-versions }}" == "7.0" ]]; then
|
||||
composer require --dev phpunit/phpunit:"^6.5" --update-with-dependencies
|
||||
composer require --dev 10up/wp_mock:"0.3.0" --update-with-dependencies
|
||||
composer require --dev antecedent/patchwork:"^2.1.21" --update-with-dependencies
|
||||
else
|
||||
composer install --prefer-dist --no-progress
|
||||
composer require --dev 10up/wp_mock:"0.3.0" --update-with-dependencies
|
||||
fi
|
||||
|
||||
- name: Run tests
|
||||
run: ./vendor/bin/phpunit
|
||||
@@ -51,4 +59,4 @@ jobs:
|
||||
run: composer install --prefer-dist --no-progress
|
||||
|
||||
- name: Run PHPCS
|
||||
run: ./vendor/bin/phpcs --standard=WordPress --runtime-set installed_paths vendor/wp-coding-standards/wpcs
|
||||
run: ./vendor/bin/phpcs --standard=WordPress --runtime-set installed_paths vendor/wp-coding-standards/wpcs ./includes ./admin ./wp-plugin-starter-template.php
|
||||
@@ -1 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin functionality
|
||||
*
|
||||
* @package WPALLSTARS\PluginStarterTemplate
|
||||
*/
|
||||
|
||||
namespace WPALLSTARS\PluginStarterTemplate\Admin;
|
||||
|
||||
use WPALLSTARS\PluginStarterTemplate\Core;
|
||||
|
||||
/**
|
||||
* Admin class
|
||||
*/
|
||||
class Admin {
|
||||
|
||||
/**
|
||||
* Core instance
|
||||
*
|
||||
* @var Core
|
||||
*/
|
||||
private $core;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Core $core Core instance.
|
||||
*/
|
||||
public function __construct( $core ) {
|
||||
$this->core = $core;
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize admin
|
||||
*/
|
||||
public function init() {
|
||||
// Initialize admin
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue admin assets
|
||||
*
|
||||
* @param string $hook Current admin page.
|
||||
*/
|
||||
public function enqueue_admin_assets( $hook ) {
|
||||
wp_enqueue_style(
|
||||
'wpst-admin-styles',
|
||||
WPST_PLUGIN_URL . 'assets/css/admin.css',
|
||||
[],
|
||||
WPST_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'wpst-admin-scripts',
|
||||
WPST_PLUGIN_URL . 'assets/js/admin.js',
|
||||
[ 'jquery' ],
|
||||
WPST_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'wpst-admin-scripts',
|
||||
'wpstData',
|
||||
[
|
||||
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'wpst-admin-nonce' ),
|
||||
'strings' => [
|
||||
'success' => esc_html__( 'Success!', 'wp-plugin-starter-template' ),
|
||||
'error' => esc_html__( 'Error!', 'wp-plugin-starter-template' ),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -14,10 +14,12 @@
|
||||
"php": ">=7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
|
||||
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.0 || ^9.0",
|
||||
"squizlabs/php_codesniffer": "^3.5",
|
||||
"wp-coding-standards/wpcs": "^2.3",
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0"
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
|
||||
"10up/wp_mock": "0.3.0",
|
||||
"antecedent/patchwork": "^2.1.21"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
@@ -1 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Core functionality for the plugin
|
||||
*
|
||||
* @package WPALLSTARS\PluginStarterTemplate
|
||||
*/
|
||||
|
||||
namespace WPALLSTARS\PluginStarterTemplate;
|
||||
|
||||
/**
|
||||
* Core class
|
||||
*/
|
||||
class Core {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// Initialize hooks
|
||||
}
|
||||
|
||||
/**
|
||||
* Example method to filter content
|
||||
*
|
||||
* @param string $content The content to filter.
|
||||
* @return string The filtered content.
|
||||
*/
|
||||
public function filter_content( $content ) {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -1 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Main plugin class
|
||||
*
|
||||
* @package WPALLSTARS\PluginStarterTemplate
|
||||
*/
|
||||
|
||||
namespace WPALLSTARS\PluginStarterTemplate;
|
||||
|
||||
/**
|
||||
* Plugin class
|
||||
*/
|
||||
class Plugin {
|
||||
|
||||
/**
|
||||
* Core instance
|
||||
*
|
||||
* @var Core
|
||||
*/
|
||||
private $core;
|
||||
|
||||
/**
|
||||
* Plugin file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_file;
|
||||
|
||||
/**
|
||||
* Plugin version
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $plugin_file Main plugin file path.
|
||||
* @param string $version Plugin version.
|
||||
*/
|
||||
public function __construct($plugin_file, $version) {
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->version = $version;
|
||||
$this->core = new Core();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the plugin
|
||||
*/
|
||||
public function init() {
|
||||
// Initialize plugin.
|
||||
}
|
||||
}
|
||||
@@ -1 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Updater functionality for the plugin
|
||||
*
|
||||
* @package WPALLSTARS\PluginStarterTemplate
|
||||
*/
|
||||
|
||||
namespace WPALLSTARS\PluginStarterTemplate;
|
||||
|
||||
/**
|
||||
* Updater class
|
||||
*/
|
||||
class Updater {
|
||||
|
||||
/**
|
||||
* Plugin file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_file;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $plugin_file Main plugin file path.
|
||||
*/
|
||||
public function __construct($plugin_file) {
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the updater
|
||||
*/
|
||||
public function init() {
|
||||
add_filter('plugin_action_links_' . plugin_basename($this->plugin_file), array($this, 'add_update_source_link'));
|
||||
add_action('admin_post_wpst_update_source', array($this, 'handle_update_source'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add update source link to plugin actions
|
||||
*
|
||||
* @param array $links Plugin action links.
|
||||
* @return array Modified plugin action links.
|
||||
*/
|
||||
public function add_update_source_link($links) {
|
||||
$update_source_link = '<a href="' . admin_url('admin-post.php?action=wpst_update_source&plugin=' . plugin_basename($this->plugin_file)) . '">' . esc_html__('Update Source', 'wp-plugin-starter-template') . '</a>';
|
||||
array_unshift($links, $update_source_link);
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle update source selection
|
||||
*/
|
||||
public function handle_update_source() {
|
||||
// Handle update source selection.
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -11,7 +11,7 @@ use WPALLSTARS\PluginStarterTemplate\Core;
|
||||
/**
|
||||
* Admin test case.
|
||||
*/
|
||||
class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
class AdminTest extends \WP_Mock\Tools\TestCase {
|
||||
|
||||
/**
|
||||
* Test instance
|
||||
@@ -30,21 +30,21 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Set up test environment
|
||||
*/
|
||||
public function setUp(): void {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
||||
// Set up mocks
|
||||
WP_Mock::setUp();
|
||||
|
||||
|
||||
// Mock Core class
|
||||
$this->core = $this->createMock(Core::class);
|
||||
|
||||
|
||||
// Set up WordPress function mocks
|
||||
WP_Mock::userFunction('add_action', [
|
||||
'times' => 1,
|
||||
'args' => ['admin_enqueue_scripts', \WP_Mock\Functions::type('array')],
|
||||
]);
|
||||
|
||||
|
||||
// Create instance of Admin class
|
||||
$this->admin = new Admin($this->core);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Tear down test environment
|
||||
*/
|
||||
public function tearDown(): void {
|
||||
public function tearDown() {
|
||||
WP_Mock::tearDown();
|
||||
parent::tearDown();
|
||||
}
|
||||
@@ -74,38 +74,38 @@ class AdminTest extends WP_Mock\Tools\TestCase {
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-styles', \WP_Mock\Functions::type('string'), [], \WP_Mock\Functions::type('string')],
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('wp_enqueue_script', [
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-scripts', \WP_Mock\Functions::type('string'), ['jquery'], \WP_Mock\Functions::type('string'), true],
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('wp_localize_script', [
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-scripts', 'wpstData', \WP_Mock\Functions::type('array')],
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('esc_html__', [
|
||||
'times' => 2,
|
||||
'args' => [\WP_Mock\Functions::type('string'), 'wp-plugin-starter-template'],
|
||||
'return' => 'Translated string',
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('admin_url', [
|
||||
'times' => 1,
|
||||
'args' => ['admin-ajax.php'],
|
||||
'return' => 'http://example.org/wp-admin/admin-ajax.php',
|
||||
]);
|
||||
|
||||
|
||||
WP_Mock::userFunction('wp_create_nonce', [
|
||||
'times' => 1,
|
||||
'args' => ['wpst-admin-nonce'],
|
||||
'return' => '1234567890',
|
||||
]);
|
||||
|
||||
|
||||
// Call the method
|
||||
$this->admin->enqueue_admin_assets('plugins.php');
|
||||
|
||||
|
||||
// If we get here, the test passed
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
+6
-6
@@ -10,7 +10,7 @@ use WPALLSTARS\PluginStarterTemplate\Core;
|
||||
/**
|
||||
* Core test case.
|
||||
*/
|
||||
class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
class CoreTest extends \WP_Mock\Tools\TestCase {
|
||||
|
||||
/**
|
||||
* Test instance
|
||||
@@ -22,12 +22,12 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Set up test environment
|
||||
*/
|
||||
public function setUp(): void {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
||||
// Set up mocks
|
||||
WP_Mock::setUp();
|
||||
|
||||
|
||||
// Create instance of Core class
|
||||
$this->core = new Core();
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
/**
|
||||
* Tear down test environment
|
||||
*/
|
||||
public function tearDown(): void {
|
||||
public function tearDown() {
|
||||
WP_Mock::tearDown();
|
||||
parent::tearDown();
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class CoreTest extends WP_Mock\Tools\TestCase {
|
||||
*/
|
||||
public function test_filter_content() {
|
||||
$content = 'Test content';
|
||||
|
||||
|
||||
// Test that filter_content returns the content
|
||||
$this->assertEquals($content, $this->core->filter_content($content));
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
*/
|
||||
|
||||
// If this file is called directly, abort.
|
||||
if (!defined('WPINC')) {
|
||||
die;
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
// Load the main plugin class
|
||||
require_once plugin_dir_path(__FILE__) . 'includes/plugin.php';
|
||||
// Load the main plugin class.
|
||||
require_once plugin_dir_path( __FILE__ ) . 'includes/plugin.php';
|
||||
|
||||
// Initialize the plugin
|
||||
new WPALLSTARS\PluginStarterTemplate\Plugin(__FILE__, '0.1.6');
|
||||
// Initialize the plugin.
|
||||
new WPALLSTARS\PluginStarterTemplate\Plugin( __FILE__, '0.1.7' );
|
||||
Reference in new issue
Block a user