Skip to content
Snippets Groups Projects
Commit a379d45a authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Usunięcie Singleton, wersja 1.6

parent 2b16eb4c
Branches
Tags
No related merge requests found
......@@ -11,15 +11,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class WPDesk_Plugin_Template_Settings_Hooks {
private $_plugin;
private $plugin;
public function __construct( WPDesk_Plugin_1_6 $plugin ) {
$this->_plugin = $plugin;
$this->plugin = $plugin;
$this->hooks();
}
public function hooks() {
$func = str_replace( '-', '_', $this->_plugin->get_namespace() );
$func = str_replace( '-', '_', $this->plugin->get_namespace() );
// settings menu
add_filter( $func . '_menu', array( $this, 'settings_menu' ) );
......@@ -42,7 +42,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
}
public function get_text_domain() {
return $this->_plugin->get_text_domain();
return $this->plugin->get_text_domain();
}
public function settings_menu( array $menu ) {
......@@ -59,7 +59,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
}
public function settings_tabs( $tabs ) {
public function settings_tabs() {
$tabs = array(
'welcome' => __( 'Welcome', 's214-settings-demo' ),
'fields' => __( 'Fields', 's214-settings-demo' )
......@@ -67,14 +67,14 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
return $tabs;
}
public function unsavable_tabs( $tabs ) {
public function unsavable_tabs() {
$tabs = array(
'welcome'
);
return $tabs;
}
public function registered_settings_sections( $sections ) {
public function registered_settings_sections() {
$sections = array(
'welcome' => array(
'main' => __( 'Welcome Aboard!', 's214-settings-demo' )
......
......@@ -18,53 +18,36 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
const VERSION = '1.6';
private $_plugin_is_active = true;
protected $plugin_is_active = true;
protected $_plugin_data = false;
//protected $plugin_data = false;
protected $_default_view_args; // default args given to template
protected $default_view_args;
public $_plugin_namespace = 'wpdesk_plugin';
public $_plugin_text_domain = 'wpdesk-plugin';
public $_plugin_has_settings = true;
public $plugin_namespace = 'wpdesk_plugin';
public $plugin_text_domain = 'wpdesk-plugin';
public $plugin_has_settings = false;
public $_plugin_path;
public $_template_path;
public $_plugin_file_path;
public $_plugin_url;
public $plugin_path;
public $template_path;
public $plugin_file_path;
public $plugin_url;
public $_settings_url = false;
public $_docs_url = false;
public $settings_url = false;
public $docs_url = false;
public $_default_settings_tab = 'general';
public $default_settings_tab = 'general';
public $settings = null;
public $options = null;
protected function __construct( $plugin_data = false ) {
$this->init_base_variables();
if ( is_array( $plugin_data ) && count( $plugin_data ) ) {
if ( ! class_exists( 'WPDesk_Helper_Plugin' ) ) {
require_once( 'class-helper.php' );
add_filter( 'plugins_api', array( $this, 'wpdesk_helper_install' ), 10, 3 );
add_action( 'admin_notices', array( $this, 'wpdesk_helper_notice' ) );
}
$helper = new WPDesk_Helper_Plugin( $plugin_data );
if ( !$helper->is_active() ) {
$this->_plugin_is_active = false;
}
}
if ( $this->_plugin_is_active ) {
if ( $this->_plugin_has_settings ) {
$this->settings = new WPDesk_Settings_1_6( $this, $this->get_namespace(), $this->_default_settings_tab );
$this->options = $this->settings->get_settings();
}
}
$this->hooks();
}
public function plugin_is_active() {
return $this->_plugin_is_active;
return $this->plugin_is_active;
}
public function get_settings() {
......@@ -84,7 +67,7 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
}
public function get_text_domain() {
return $this->_plugin_text_domain;
return $this->plugin_text_domain;
}
public function load_plugin_text_domain() {
......@@ -99,16 +82,16 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
$reflection = new ReflectionClass( $this );
// Set Plugin Path
$this->_plugin_path = dirname( $reflection->getFileName() );
$this->plugin_path = dirname( $reflection->getFileName() );
// Set Plugin URL
$this->_plugin_url = plugin_dir_url( $reflection->getFileName() );
$this->plugin_url = plugin_dir_url( $reflection->getFileName() );
$this->_plugin_file_path = $reflection->getFileName();
$this->plugin_file_path = $reflection->getFileName();
$this->_template_path = $this->get_namespace();
$this->template_path = $this->get_namespace();
$this->_default_view_args = array(
$this->default_view_args = array(
'plugin_url' => $this->get_plugin_url()
);
......@@ -134,7 +117,7 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
* @return string
*/
public function get_plugin_url() {
return esc_url( trailingslashit( $this->_plugin_url ) );
return esc_url( trailingslashit( $this->plugin_url ) );
}
public function get_plugin_assets_url() {
......@@ -145,15 +128,15 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
* @return string
*/
public function get_template_path() {
return trailingslashit( $this->_template_path );
return trailingslashit( $this->template_path );
}
public function get_plugin_file_path() {
return $this->_plugin_file_path;
return $this->plugin_file_path;
}
public function get_namespace() {
return $this->_plugin_namespace;
return $this->plugin_namespace;
}
......@@ -171,7 +154,7 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
$template_name = implode( '/', array( get_template_directory(), $this->get_template_path(), $path, $name . '.php' ) );
if ( !file_exists( $template_name ) ) {
$template_name = implode( '/', array( untrailingslashit( $this->_plugin_path ), 'templates', $path, $name . '.php' ) );
$template_name = implode( '/', array( untrailingslashit( $this->plugin_path ), 'templates', $path, $name . '.php' ) );
}
extract( $args );
ob_start();
......@@ -201,16 +184,16 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
);
$links = array_merge( $plugin_links, $links );
if ( $this->_docs_url ) {
if ( $this->docs_url ) {
$plugin_links = array(
'<a href="' . $this->_docs_url . '">' . __( 'Docs', 'wpdesk-plugin' ) . '</a>',
'<a href="' . $this->docs_url . '">' . __( 'Docs', 'wpdesk-plugin' ) . '</a>',
);
$links = array_merge( $plugin_links, $links );
}
if ( $this->_settings_url ) {
if ( $this->settings_url ) {
$plugin_links = array(
'<a href="' . $this->_settings_url . '">' . __( 'Settings', 'wpdesk-plugin' ) . '</a>',
'<a href="' . $this->settings_url . '">' . __( 'Settings', 'wpdesk-plugin' ) . '</a>',
);
$links = array_merge( $plugin_links, $links );
}
......@@ -218,55 +201,6 @@ if ( ! class_exists( 'WPDesk_Plugin_1_6' ) ) {
return $links;
}
/**
* Helper functions
*/
/**
* Load installer for the WP Desk Helper.
* @return $api Object
*/
function wpdesk_helper_install( $api, $action, $args ) {
$download_url = 'http://www.wpdesk.pl/wp-content/uploads/wpdesk-helper.zip';
if ( 'plugin_information' != $action ||
false !== $api ||
! isset( $args->slug ) ||
'wpdesk-helper' != $args->slug
) return $api;
$api = new stdClass();
$api->name = 'WP Desk Helper';
$api->version = '1.0';
$api->download_link = esc_url( $download_url );
return $api;
}
/**
* Display a notice if the "WP Desk Helper" plugin hasn't been installed.
* @return void
*/
function wpdesk_helper_notice() {
$active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) );
if ( in_array( 'wpdesk-helper/wpdesk-helper.php', $active_plugins ) ) return;
$slug = 'wpdesk-helper';
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
$activate_url = 'plugins.php?action=activate&plugin=' . urlencode( 'wpdesk-helper/wpdesk-helper.php' ) . '&plugin_status=all&paged=1&s&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_wpdesk-helper/wpdesk-helper.php' ) );
$message = sprintf( wp_kses( __( '<a href="%s">Install the WP Desk Helper plugin</a> to activate and get updates for your WP Desk plugins.', 'wpdesk-plugin' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $install_url ) );
$is_downloaded = false;
$plugins = array_keys( get_plugins() );
foreach ( $plugins as $plugin ) {
if ( strpos( $plugin, 'wpdesk-helper.php' ) !== false ) {
$is_downloaded = true;
$message = sprintf( wp_kses( __( '<a href="%s">Activate the WP Desk Helper plugin</a> to activate and get updates for your WP Desk plugins.', 'wpdesk-plugin' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( $activate_url ) ) );
}
}
echo '<div class="error fade"><p>' . $message . '</p></div>' . "\n";
}
}
}
......@@ -16,9 +16,11 @@ if ( ! class_exists( 'WPDesk_Settings_1_6' ) ) {
*/
class WPDesk_Settings_1_6 extends WPDesk_S214_Settings_1_6 {
private $slug;
protected $version = '1.0';
protected $_plugin_text_domain = 'wpdesk-plugin';
protected $plugin_text_domain = 'wpdesk-plugin';
protected $plugin = null;
......@@ -333,12 +335,12 @@ if ( ! class_exists( 'WPDesk_Settings_1_6' ) ) {
echo apply_filters( $this->func . '_after_setting_output', $html, $args );
}
public function set_text_domain( $_plugin_text_domain ) {
$this->_plugin_text_domain = $_plugin_text_domain;
public function set_text_domain( $plugin_text_domain ) {
$this->plugin_text_domain = $plugin_text_domain;
}
public function get_text_domain() {
return $this->_plugin_text_domain;
return $this->plugin_text_domain;
}
}
......
......@@ -31,27 +31,53 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$plugin_data = array(
$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' )
);
$plugin_data = array();
$wpdesk_plugin_template_plugin_data = array();
require_once( plugin_basename( 'classes/wpdesk/class-plugin.php' ) );
require_once( 'classes/wpdesk/class-plugin.php' );
class WPDesk_Plugin_Template_Plugin extends WPDesk_Plugin_1_6 {
/**
* WPDesk_Plugin_Template_Plugin constructor.
*
* @param array $plugin_data
*/
public function __construct( $plugin_data ) {
$this->_plugin_namespace = 'plugin-template';
$this->_plugin_text_domain = 'plugin-template';
$this->plugin_namespace = 'plugin-template';
$this->plugin_text_domain = 'plugin-template';
$this->plugin_has_settings = true;
$this->default_settings_tab = 'welcome';
$this->_default_settings_tab = 'welcome';
if ( is_array( $plugin_data ) && count( $plugin_data ) ) {
if ( ! class_exists( 'WPDesk_Helper_Plugin' ) ) {
require_once( 'classes/wpdesk/class-helper.php' );
add_filter( 'plugins_api', array( $this, 'wpdesk_helper_install' ), 10, 3 );
add_action( 'admin_notices', array( $this, 'wpdesk_helper_notice' ) );
}
$helper = new WPDesk_Helper_Plugin( $plugin_data );
if ( !$helper->is_active() ) {
$this->plugin_is_active = false;
}
}
if ( $this->plugin_is_active ) {
if ( $this->plugin_has_settings ) {
$this->settings = new WPDesk_Settings_1_6( $this, $this->get_namespace(), $this->default_settings_tab );
$this->options = $this->settings->get_settings();
}
}
parent::__construct( $plugin_data );
if ( $this->plugin_is_active() ) {
require_once 'classes/class-plugin-template-settings-hooks.php';
$this->init();
......@@ -66,9 +92,56 @@
parent::hooks();
}
/**
* Helper functions
*/
/**
* Load installer for the WP Desk Helper.
* @return $api Object
*/
function wpdesk_helper_install( $api, $action, $args ) {
$download_url = 'http://www.wpdesk.pl/wp-content/uploads/wpdesk-helper.zip';
if ( 'plugin_information' != $action ||
false !== $api ||
! isset( $args->slug ) ||
'wpdesk-helper' != $args->slug
) return $api;
$api = new stdClass();
$api->name = 'WP Desk Helper';
$api->version = '1.0';
$api->download_link = esc_url( $download_url );
return $api;
}
/**
* Display a notice if the "WP Desk Helper" plugin hasn't been installed.
* @return void
*/
function wpdesk_helper_notice() {
$active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) );
if ( in_array( 'wpdesk-helper/wpdesk-helper.php', $active_plugins ) ) return;
$slug = 'wpdesk-helper';
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug );
$activate_url = 'plugins.php?action=activate&plugin=' . urlencode( 'wpdesk-helper/wpdesk-helper.php' ) . '&plugin_status=all&paged=1&s&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_wpdesk-helper/wpdesk-helper.php' ) );
$message = sprintf( wp_kses( __( '<a href="%s">Install the WP Desk Helper plugin</a> to activate and get updates for your WP Desk plugins.', 'wpdesk-plugin' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( $install_url ) );
$plugins = array_keys( get_plugins() );
foreach ( $plugins as $plugin ) {
if ( strpos( $plugin, 'wpdesk-helper.php' ) !== false ) {
$message = sprintf( wp_kses( __( '<a href="%s">Activate the WP Desk Helper plugin</a> to activate and get updates for your WP Desk plugins.', 'wpdesk-plugin' ), array( 'a' => array( 'href' => array() ) ) ), esc_url( admin_url( $activate_url ) ) );
}
}
echo '<div class="error fade"><p>' . $message . '</p></div>' . "\n";
}
}
$wpdesk_plugin_template_plugin_data = $plugin_data;
function wpdesk_plugin_template() {
global $wpdesk_plugin_template;
global $wpdesk_plugin_template_plugin_data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment