Skip to content
Snippets Groups Projects
Commit c6936202 authored by Krzysiek's avatar Krzysiek
Browse files

Static factory/builder for plugins

parent 34a543ed
Branches
Tags
1 merge request!1Devel 1.10 - Wymagana wersja PHP i Wordpress
...@@ -6,14 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) { ...@@ -6,14 +6,6 @@ if ( ! defined( 'ABSPATH' ) ) {
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
require_once( 'classes/wpdesk/class-plugin.php' ); require_once( 'classes/wpdesk/class-plugin.php' );
require_once( 'classes/plugin-template-plugin.php' ); require_once( 'classes/plugin-template-factory.php' );
$wpdesk_plugin_template_plugin_data = array(
'plugin' => plugin_basename( __FILE__ ),
'product_id' => 'WP Desk Plugin Template',
'version' => '1.0',
'config_uri' => admin_url( 'edit.php?post_type=inspire_invoice&page=plugin_template' )
);
(new WPDesk_Plugin_Template_Plugin( __FILE__, $wpdesk_plugin_template_plugin_data ));
WPDesk_Plugin_Template_Factory::get_instance();
\ No newline at end of file
<?php
require_once( 'wpdesk/class-plugin.php' );
require_once( 'wpdesk/interface-plugin-builder.php' );
require_once( 'plugin-template-plugin.php' );
final class WPDesk_Plugin_Template_Factory implements WPDesk_Plugin_Factory_1_10 {
/** @var WPDesk_Plugin_Template_Plugin */
private static $instance = null;
/**
* Builds instance of plugin. If called more than once then more than one instance is created.
*
* @return WPDesk_Plugin_Template_Plugin
*/
public static function build() {
$wpdesk_plugin_template_plugin_data = array(
'plugin' => plugin_basename( __FILE__ ),
'product_id' => 'WP Desk Plugin Template',
'version' => '1.0',
'config_uri' => admin_url( 'edit.php?post_type=inspire_invoice&page=plugin_template' )
);
$class_name = apply_filters( self::WPDESK_FILTER_PLUGIN_CLASS, WPDesk_Plugin_Template_Plugin::class );
return new $class_name( __FILE__, $wpdesk_plugin_template_plugin_data );
}
/**
* Builds instance if needed and ensures there is only one instance.
*
* @return WPDesk_Plugin_Template_Plugin
*/
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = self::build();
}
return self::$instance;
}
}
\ No newline at end of file
...@@ -52,7 +52,7 @@ class WPDesk_Plugin_Template_Plugin extends WPDesk_Plugin_1_10 { ...@@ -52,7 +52,7 @@ class WPDesk_Plugin_Template_Plugin extends WPDesk_Plugin_1_10 {
* Load installer for the WP Desk Helper. * Load installer for the WP Desk Helper.
* @return $api Object * @return $api Object
*/ */
function wpdesk_helper_install( $api, $action, $args ) { public function wpdesk_helper_install( $api, $action, $args ) {
$download_url = 'http://www.wpdesk.pl/wp-content/uploads/wpdesk-helper.zip'; $download_url = 'http://www.wpdesk.pl/wp-content/uploads/wpdesk-helper.zip';
if ( 'plugin_information' != $action || if ( 'plugin_information' != $action ||
...@@ -75,7 +75,7 @@ class WPDesk_Plugin_Template_Plugin extends WPDesk_Plugin_1_10 { ...@@ -75,7 +75,7 @@ class WPDesk_Plugin_Template_Plugin extends WPDesk_Plugin_1_10 {
* Display a notice if the "WP Desk Helper" plugin hasn't been installed. * Display a notice if the "WP Desk Helper" plugin hasn't been installed.
* @return void * @return void
*/ */
function wpdesk_helper_notice() { public function wpdesk_helper_notice() {
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) ); $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
if ( in_array( 'wpdesk-helper/wpdesk-helper.php', $active_plugins ) ) { if ( in_array( 'wpdesk-helper/wpdesk-helper.php', $active_plugins ) ) {
......
...@@ -346,7 +346,7 @@ if ( ! class_exists( 'WPDesk_Requirement_Checker_1_10' ) ) { ...@@ -346,7 +346,7 @@ if ( ! class_exists( 'WPDesk_Requirement_Checker_1_10' ) ) {
* @return bool * @return bool
*/ */
public static function is_wc_at_least( $min_version ) { public static function is_wc_at_least( $min_version ) {
return defined(WC_VERSION) && return defined('WC_VERSION') &&
version_compare( WC_VERSION, $min_version, '>=' ); version_compare( WC_VERSION, $min_version, '>=' );
} }
} }
......
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
interface WPDesk_Plugin_Factory_1_10 {
const WPDESK_FILTER_PLUGIN_CLASS = 'wpdesk_plugin_class';
static function build();
static function get_instance();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment