Skip to content
Snippets Groups Projects
Commit 65faf398 authored by dyszczo's avatar dyszczo
Browse files

plugin template with scoped libraries

parent 0975d24d
No related branches found
No related tags found
No related merge requests found
WP_ROOT_FOLDER="${APACHE_DOCUMENT_ROOT}"
TEST_SITE_WP_ADMIN_PATH="/wp-admin"
TEST_SITE_DB_NAME="wptest"
TEST_SITE_DB_HOST="mysqltests"
TEST_SITE_DB_USER="mysql"
TEST_SITE_DB_PASSWORD="mysql"
TEST_SITE_TABLE_PREFIX="wp_"
TEST_DB_NAME="wptest"
TEST_DB_HOST="mysqltests"
TEST_DB_USER="mysql"
TEST_DB_PASSWORD="mysql"
TEST_TABLE_PREFIX="wp_"
TEST_SITE_WP_URL="http://${WOOTESTS_IP}"
TEST_SITE_WP_DOMAIN="${WOOTESTS_IP}"
TEST_SITE_ADMIN_EMAIL="grola@seostudio.pl"
TEST_SITE_ADMIN_USERNAME="admin"
TEST_SITE_ADMIN_PASSWORD="admin"
/vendor/
/vendor_prefixed/
.idea
build-coverage
*.phar
\ No newline at end of file
.DS_Store
.commit
lang/plugin-template-pl_PL.po
lang/plugin-template-pl_PL.mo
......@@ -6,11 +6,11 @@ source:
exclude:
- vendor
- tests
- lang
- languages
charset: [UTF-8]
main: Wordpress plugin
title: Plugin template more info
title: flexible-shipping-fedex
baseUrl: "/"
templateTheme: default
......
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
require_once __DIR__ . '/vendor/autoload.php';
require_once( 'classes/wpdesk/class-plugin.php' );
require_once( 'classes/plugin-template-factory.php' );
WPDesk_Plugin_Template_Factory::get_plugin_instance();
\ No newline at end of file
*** plugin-template Changelog ***
1.10.2 - 2018-03-21
* environments
1.0.0 - 2018-03-16
* deploy test
\ No newline at end of file
## [1.0.0] - 2017-06-20
### Added
- use https://keepachangelog.com/en/1.0.0/ standards in your changelog
paths:
tests: tests/codeception/tests
output: tests/codeception/tests/_output
data: tests/codeception/tests/_data
support: tests/codeception/tests/_support
envs: tests/codeception/tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
# - Codeception\Extension\Recorder:
# module: WPWebDriver
# delete_successful: false # keep screenshots of successful tests
commands:
- Codeception\Command\GenerateWPUnit
- Codeception\Command\GenerateWPRestApi
- Codeception\Command\GenerateWPRestController
- Codeception\Command\GenerateWPRestPostTypeController
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
- WPDesk\Codeception\Command\GeneratePluginActivation
- WPDesk\Codeception\Command\GenerateWooCommerce
params:
- .env.testing
......@@ -3,32 +3,54 @@
"authors": [
{
"name": "Krzysiek",
"email": "krzysiek@wpdesk.pl"
"email": "krzysiek@wpdesk.net"
}
],
"autoload": {
"classmap": ["legacy"],
"psr-4": {
"WPDesk\\PluginTemplate\\": "src/"
}
"WPDesk\\PluginTemplate\\": "src/Plugin"
},
"classmap": [
"vendor_prefixed"
]
},
"autoload-dev": {
"classmap": [
"tests/unit",
"tests/integration"
]
},
"config": {
"sort-packages": true
"sort-packages": true,
"platform": {
"php": "5.6"
}
},
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": ">=5.6",
"wpdesk/wp-plugin-flow": "^1.5"
"wpdesk/wp-wpdesk-helper-override": "^1.1.0",
"psr/log": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "<7",
"wp-coding-standards/wpcs": "^0.14.1",
"squizlabs/php_codesniffer": "^3.0.2",
"mockery/mockery": "*",
"10up/wp_mock": "*",
"phpcompatibility/php-compatibility": "^9.1"
"wpdesk/wp-plugin-flow": "^2",
"phpunit/phpunit": "<7",
"wpdesk/wp-wpdesk-composer": "^2.2",
"wpdesk/wp-codeception": "^1.1.13"
},
"autoload-dev": {
"extra": {
"text-domain": "plugin-template",
"translations-folder": "lang",
"translation-file-headers": {
"Project-Id-Version": "Plugin Template",
"Last-Translator": "Grzegorz Rola <grola@wpdesk.pl>",
"X-Poedit-WPHeader": "plugin-template.php"
},
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": {
"test": "echo composer is alive",
......
This diff is collapsed.
*
!.gitignore
!pl_PL.po
msgid ""
msgstr ""
"Project-Id-Version: Plugin Template\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-29 20:03+0100\n"
"PO-Revision-Date: 2019-11-29 20:03+0100\n"
"Last-Translator: Krzysztof Dyszczyk <krzysztof.dyszczyk@gmail.com>\n"
"Language-Team: Polish\n"
"Language: pl_PL\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10 >= 2 && n%10<=4 &&(n"
"%100<10||n%100 >= 20)? 1 : 2);\n"
"X-Generator: Poedit 2.2.4\n"
"X-Loco-Version: 2.3.0; wp-5.2.2X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SearchPathExcluded-1: vendor\n"
"X-Poedit-SearchPathExcluded-2: vendor_prefixed\n"
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WPDesk_Helper_Plugin' ) ) {
class WPDesk_Helper_Plugin {
protected $plugin_data;
protected $text_domain;
protected $ame_activated_key;
protected $ame_activation_tab_key;
function __construct( $plugin_data ) {
global $wpdesk_helper_plugins;
$this->plugin_data = $plugin_data;
if ( ! isset( $wpdesk_helper_plugins ) ) $wpdesk_helper_plugins = array();
$plugin_data['helper_plugin'] = $this;
$wpdesk_helper_plugins[] = $plugin_data;
$this->ame_activated_key = 'api_' . dirname($plugin_data['plugin']) . '_activated';
$this->ame_activation_tab_key = 'api_' . dirname($plugin_data['plugin']) . '_dashboard';
}
public function inactive_notice() { ?>
<?php if ( ! current_user_can( 'manage_options' ) ) return; ?>
<?php if ( 1==1 && isset( $_GET['page'] ) && $this->ame_activation_tab_key == $_GET['page'] ) return; ?>
<div class="update-nag">
<?php printf( __( 'The %s%s%s License Key has not been activated, so the plugin is inactive! %sClick here%s to activate the license key and the plugin.', 'wpdesk-plugin' ), '<strong>', $this->plugin_data['product_id'], '</strong>', '<a href="' . esc_url( admin_url( 'admin.php?page='.$this->ame_activation_tab_key ) ) . '">', '</a>' ); ?>
</div>
<?php
}
function is_active( $add_notice = false ) {
if ( get_option( $this->ame_activated_key, '0' ) != 'Activated' ) {
if ( $add_notice ) {
add_action( 'admin_notices', array( $this, 'inactive_notice' ) );
}
return false;
}
else {
return true;
}
}
}
}
......@@ -2,17 +2,28 @@
<ruleset name="WordPress Coding Standards for WP Desk Plugin">
<description>Sniffs for WordPress WPDesk plugins</description>
<config name="installed_paths" value="vendor/wp-coding-standards/wpcs,vendor/wimg/php-compatibility" />
<config name="testVersion" value="5.6-"/>
<config name="text_domain" value="wpdesk-plugin,default,s214-settings-demo,flexible-shipping-fedex"/>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.5-"/>
<arg name="extensions" value="php"/>
<exclude-pattern>*/settings-api/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>scoper\.inc\.php</exclude-pattern>
<rule ref="PHPCompatibility"/>
<rule ref="WordPress"/>
<config name="text_domain" value="wpdesk-plugin,default,s214-settings-demo"/>
<!-- Remove checking if classes are in class- files -->
<rule ref="WordPress.Files.FileName">
<exclude-pattern>/src/.*\.php</exclude-pattern>
</rule>
<arg name="extensions" value="php"/>
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/src/.*\.php</exclude-pattern>
</rule>
<file>./classes</file>
<exclude-pattern>*/settings-api/*</exclude-pattern>
<rule ref="WordPress.NamingConventions.ValidVariableName">
<exclude-pattern>/src/.*\.php</exclude-pattern>
</rule>
</ruleset>
# Start command: composer update --classmap-authoritative && vendor/bin/phpstan analyze
includes:
# https://github.com/phpstan/phpstan/blob/master/conf/bleedingEdge.neon
- vendor/wpdesk/wp-wpdesk-composer/director/vendor/phpstan/phpstan/conf/bleedingEdge.neon
# - phar://phpstan.phar/conf/bleedingEdge.neon
- vendor/wpdesk/wp-wpdesk-composer/director/vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: max
paths:
- %currentWorkingDirectory%/src/
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
- %currentWorkingDirectory%/vendor/wpdesk/wp-wpdesk-composer/director/woocommerce-stubs-3.6.1.php
excludes_analyse:
- %currentWorkingDirectory%/src/Plugin/view/
ignoreErrors:
- '/FedExVendor\\WPDesk_Plugin_Info/'
# autoload_files:
# # Missing constants, function and class stubs
# - %currentWorkingDirectory%/tests/phpstan/bootstrap.php
# # Plugin stubs
# - %currentWorkingDirectory%/tests/phpstan/PLUGIN-stubs.php
# # Procedural code
# - %currentWorkingDirectory%/myplugin-functions.php
# autoload_directories:
# - %currentWorkingDirectory%/../woocommerce/
......@@ -9,16 +9,14 @@
<filter>
<whitelist>
<directory suffix=".php">classes</directory>
<directory suffix=".php">src</directory>
<exclude>
<directory suffix=".php">src/WooCommerceShipping/CustomFields/Templates</directory>
<directory suffix=".php">src/plugin/view</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="junit" target="build-coverage/report.junit.xml"/>
<log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build-coverage/coverage.txt"/>
<log type="coverage-clover" target="build-coverage/clover.xml"/>
</logging>
<php>
<env name="WP_DEVELOP_DIR" value="/tmp/wordpress-develop"/>
<env name="WC_DEVELOP_DIR" value="/tmp/woocommerce"/>
......
<phpunit bootstrap="tests/unit/bootstrap.php">
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/unit/</directory>
<directory suffix="Test.php">./tests/unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">classes</directory>
<directory suffix=".php">src</directory>
<exclude>
<directory suffix=".php">src/WooCommerceShipping/CustomFields/Templates</directory>
<directory suffix=".php">src/plugin/view</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="junit" target="build-coverage/report.junit.xml"/>
<log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build-coverage/coverage.txt"/>
<log type="coverage-clover" target="build-coverage/clover.xml"/>
</logging>
</phpunit>
......@@ -37,22 +37,23 @@ if ( ! defined( 'ABSPATH' ) ) {
$plugin_version = '1.0.0';
$plugin_release_timestamp = '2020-05-09';
$plugin_name = 'PluginTemplate';
$plugin_class_name = '\WPDesk\WooCommerceFakturownia\Plugin';
$plugin_name = 'WP Desk Plugin Template';
$plugin_class_name = '\WPDesk\PluginTemplate\Plugin';
$plugin_text_domain = 'plugin-template';
$product_id = 'plugin-template';
$plugin_file = __FILE__;
$plugin_dir = dirname( __FILE__ );
$requirements = array(
$requirements = [
'php' => '5.6',
'wp' => '4.5',
'plugins' => array(
array(
'plugins' => [
[
'name' => 'woocommerce/woocommerce.php',
'nice_name' => 'WooCommerce',
)
)
);
'version' => '3.0',
],
],
];
require __DIR__ . '/vendor/wpdesk/wp-plugin-flow/src/plugin-init-php52.php';
\ No newline at end of file
require __DIR__ . '/vendor_prefixed/wpdesk/wp-plugin-flow/src/plugin-init-php52.php';
<?php
declare(strict_types=1);
use Isolated\Symfony\Component\Finder\Finder;
return [
// The prefix configuration. If a non null value will be used, a random prefix will be generated.
'prefix' => 'PluginTemplateVendor',
// By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
// directory. You can however define which files should be scoped by defining a collection of Finders in the
// following configuration key.
//
// For more see: https://github.com/humbug/php-scoper#finders-and-paths
'finders' => [
Finder::create()
->files()
->ignoreVCS(true)
->name(['*.php', 'composer.json', '*.css', '*.js', '*.jpg', '*.png', '*.wsdl'])
->exclude([
'doc',
'test',
'test_old',
'tests',
'Tests',
'vendor-bin',
'wp-wpdesk-composer',
'wp-wpdesk-helper-override'
])
->in(['vendor/monolog', 'vendor/wpdesk']),
],
// Whitelists a list of files. Unlike the other whitelist related features, this one is about completely leaving
// a file untouched.
// Paths are relative to the configuration file unless if they are already absolute
'files-whitelist' => [
],
// When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
// original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
// support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
// heart contents.
//
// For more see: https://github.com/humbug/php-scoper#patchers
'patchers' => [
],
// PHP-Scoper's goal is to make sure that all code for a project lies in a distinct PHP namespace. However, you
// may want to share a common API between the bundled code of your PHAR and the consumer code. For example if
// you have a PHPUnit PHAR with isolated code, you still want the PHAR to be able to understand the
// PHPUnit\Framework\TestCase class.
//
// A way to achieve this is by specifying a list of classes to not prefix with the following configuration key. Note
// that this does not work with functions or constants neither with classes belonging to the global namespace.
//
// Fore more see https://github.com/humbug/php-scoper#whitelist
'whitelist' => [
],
// If `true` then the user defined constants belonging to the global namespace will not be prefixed.
//
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
'whitelist-global-constants' => false,
// If `true` then the user defined functions belonging to the global namespace will not be prefixed.
//
// For more see https://github.com/humbug/php-scoper#constants--constants--functions-from-the-global-namespace
'whitelist-global-functions' => false,
'whitelist-global-classes' => false,
];
<?php
namespace WPDesk\PluginTemplate;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use WPDesk\Logger\WPDeskLoggerFactory;
use WPDesk\PluginBuilder\Plugin\AbstractPlugin;
use WPDesk_Helper_Plugin;
class Plugin extends AbstractPlugin implements LoggerAwareInterface {
use LoggerAwareTrait;
public function __construct( \WPDesk_Plugin_Info $plugin_info ) {
parent::__construct( $plugin_info );
$this->setLogger( ( new WPDeskLoggerFactory() )->createWPDeskLogger() );
}
public function init() {
if ( $this->is_active() ) {
parent::init();
}
}
/**
* Check plugin activation.
*
* @return bool
*/
private function is_active() {
$plugin_data = array(
'plugin' => $this->plugin_info->get_plugin_file_name(),
'product_id' => $this->plugin_info->get_product_id(),
'version' => $this->plugin_info->get_version(),
'config_uri' => admin_url( 'admin.php?page=wc-settings&tab=integration' ),
);
return ( new WPDesk_Helper_Plugin( $plugin_data ) )->is_active();
}
}
\ No newline at end of file
<?php
/**
* Plugin main class.
*
* @package WPDesk\PluginTemplate
*/
namespace WPDesk\PluginTemplate;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use PluginTemplateVendor\WPDesk_Plugin_Info;
use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin;
use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\HookableCollection;
use PluginTemplateVendor\WPDesk\PluginBuilder\Plugin\HookableParent;
/**
* Main plugin class. The most important flow decisions are made here.
*
* @package WPDesk\PluginTemplate
*/
class Plugin extends AbstractPlugin implements LoggerAwareInterface, HookableCollection {
use LoggerAwareTrait;
use HookableParent;
/**
* Plugin constructor.
*
* @param WPDesk_Plugin_Info $plugin_info Plugin info.
*/
public function __construct( WPDesk_Plugin_Info $plugin_info ) {
parent::__construct( $plugin_info );
$this->setLogger( new NullLogger() );
$this->plugin_url = $this->plugin_info->get_plugin_url();
$this->plugin_namespace = $this->plugin_info->get_text_domain();
}
/**
* Initializes plugin external state.
*
* The plugin internal state is initialized in the constructor and the plugin should be internally consistent after creation.
* The external state includes hooks execution, communication with other plugins, integration with WC etc.
*
* @return void
*/
public function init() {
parent::init();
}
/**
* Integrate with WordPress and with other plugins using action/filter system.
*
* @return void
*/
public function hooks() {
parent::hooks();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment