Skip to content
Snippets Groups Projects
Commit 56d29f12 authored by dyszczo's avatar dyszczo
Browse files

interface with info about domain

parent 0a4b2cc9
Branches
Tags
1 merge request!2interface with info about domain
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Checks requirements for plugin * Checks requirements for plugin
* have to be compatible with PHP 5.2.x * have to be compatible with PHP 5.2.x
*/ */
class WPDesk_Basic_Requirement_Checker { class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
/** @var string */ /** @var string */
private $plugin_name = ''; private $plugin_name = '';
...@@ -29,22 +29,32 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -29,22 +29,32 @@ class WPDesk_Basic_Requirement_Checker {
/** @var array */ /** @var array */
private $notices; private $notices;
/** @var @string */
private $text_domain;
/** /**
* @param string $plugin_file * @param string $plugin_file
* @param string $plugin_name * @param string $plugin_name
* @param string $text_domain
* @param string $php_version * @param string $php_version
* @param string $wp_version * @param string $wp_version
*/ */
public function __construct( $plugin_file, $plugin_name, $php_version, $wp_version ) { public function __construct( $plugin_file, $plugin_name, $text_domain, $php_version, $wp_version ) {
$this->plugin_file = $plugin_file; $this->plugin_file = $plugin_file;
$this->plugin_name = $plugin_name; $this->plugin_name = $plugin_name;
$this->text_domain = $text_domain;
$this->set_min_php_require( $php_version ); $this->set_min_php_require( $php_version );
$this->set_min_wp_require( $wp_version ); $this->set_min_wp_require( $wp_version );
$this->plugin_require = array(); $this->plugin_require = [];
$this->module_require = array(); $this->module_require = [];
$this->setting_require = array(); $this->setting_require = [];
$this->notices = array(); $this->notices = [];
}
public function get_text_domain() {
return $this->text_domain;
} }
/** /**
...@@ -137,12 +147,14 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -137,12 +147,14 @@ class WPDesk_Basic_Requirement_Checker {
* @return array * @return array
*/ */
private function prepare_requirement_notices() { private function prepare_requirement_notices() {
$notices = array(); $notices = [];
if ( ! $this->is_php_at_least( $this->min_php_version ) ) { if ( ! $this->is_php_at_least( $this->min_php_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run on PHP versions older than %s. Please contact your host and ask them to upgrade.', 'wpdesk-plugin' ), esc_html( $this->plugin_name ), $this->min_php_version ) ); $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run on PHP versions older than %s. Please contact your host and ask them to upgrade.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_php_version ) );
} }
if ( ! $this->is_wp_at_least( $this->min_wp_version ) ) { if ( ! $this->is_wp_at_least( $this->min_wp_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run on WordPress versions older than %s. Please update WordPress.', 'wpdesk-plugin' ), esc_html( $this->plugin_name ), $this->min_wp_version ) ); $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run on WordPress versions older than %s. Please update WordPress.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wp_version ) );
} }
$notices = $this->append_plugin_require_notices( $notices ); $notices = $this->append_plugin_require_notices( $notices );
$notices = $this->append_module_require_notices( $notices ); $notices = $this->append_module_require_notices( $notices );
...@@ -160,7 +172,9 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -160,7 +172,9 @@ class WPDesk_Basic_Requirement_Checker {
if ( count( $this->module_require ) > 0 ) { if ( count( $this->module_require ) > 0 ) {
foreach ( $this->module_require as $module_name => $nice_module_name ) { foreach ( $this->module_require as $module_name => $nice_module_name ) {
if ( ! $this->is_module_active( $module_name ) ) { if ( ! $this->is_module_active( $module_name ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php module installed. Please contact your host and ask them to install %s.', 'wpdesk-plugin' ), esc_html( $this->plugin_name ), esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) ); $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php module installed. Please contact your host and ask them to install %s.',
$this->get_text_domain() ), esc_html( $this->plugin_name ),
esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) );
} }
} }
} }
...@@ -177,7 +191,9 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -177,7 +191,9 @@ class WPDesk_Basic_Requirement_Checker {
if ( count( $this->setting_require ) > 0 ) { if ( count( $this->setting_require ) > 0 ) {
foreach ( $this->setting_require as $setting => $value ) { foreach ( $this->setting_require as $setting => $value ) {
if ( ! $this->is_setting_set( $setting, $value ) ) { if ( ! $this->is_setting_set( $setting, $value ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php setting set to %s. Please contact your host and ask them to set %s.', 'wpdesk-plugin' ), esc_html( $this->plugin_name ), esc_html( basename( $setting ) ), esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) ); $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s php setting set to %s. Please contact your host and ask them to set %s.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), esc_html( basename( $setting ) ),
esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) );
} }
} }
} }
...@@ -194,7 +210,9 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -194,7 +210,9 @@ class WPDesk_Basic_Requirement_Checker {
if ( count( $this->plugin_require ) > 0 ) { if ( count( $this->plugin_require ) > 0 ) {
foreach ( $this->plugin_require as $plugin_name => $nice_plugin_name ) { foreach ( $this->plugin_require as $plugin_name => $nice_plugin_name ) {
if ( ! $this->is_wp_plugin_active( $plugin_name ) ) { if ( ! $this->is_wp_plugin_active( $plugin_name ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s active. Please install and activate %s plugin.', 'wpdesk-plugin' ), esc_html( $this->plugin_name ), esc_html( basename( $nice_plugin_name ) ), esc_html( basename( $nice_plugin_name ) ) ) ); $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin cannot run without %s active. Please install and activate %s plugin.',
$this->get_text_domain() ), esc_html( $this->plugin_name ),
esc_html( basename( $nice_plugin_name ) ), esc_html( basename( $nice_plugin_name ) ) ) );
} }
} }
} }
...@@ -225,8 +243,8 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -225,8 +243,8 @@ class WPDesk_Basic_Requirement_Checker {
* @return void * @return void
*/ */
public function disable_plugin_render_notice() { public function disable_plugin_render_notice() {
add_action( 'admin_notices', array( $this, 'deactivate_action' ) ); add_action( 'admin_notices', [ $this, 'deactivate_action' ] );
add_action( 'admin_notices', array( $this, 'render_notices_action' ) ); add_action( 'admin_notices', [ $this, 'render_notices_action' ] );
} }
/** /**
...@@ -286,10 +304,10 @@ class WPDesk_Basic_Requirement_Checker { ...@@ -286,10 +304,10 @@ class WPDesk_Basic_Requirement_Checker {
* @return bool * @return bool
*/ */
public static function is_wp_plugin_active( $plugin_file ) { public static function is_wp_plugin_active( $plugin_file ) {
$active_plugins = (array) get_option( 'active_plugins', array() ); $active_plugins = (array) get_option( 'active_plugins', [] );
if ( is_multisite() ) { if ( is_multisite() ) {
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', [] ) );
} }
return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins ); return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins );
......
<?php
/**
* Have info about what class should be built
* have to be compatible with PHP 5.2.x
*/
interface WPDesk_Buildable {
/** @return string */
public function get_class_name();
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Structure with core info about plugin * Structure with core info about plugin
* have to be compatible with PHP 5.2.x * have to be compatible with PHP 5.2.x
*/ */
class WPDesk_Plugin_Info { class WPDesk_Plugin_Info implements WPDesk_Translable, WPDesk_Buildable {
/** @var string */ /** @var string */
private $plugin_file_name; private $plugin_file_name;
...@@ -93,6 +93,9 @@ class WPDesk_Plugin_Info { ...@@ -93,6 +93,9 @@ class WPDesk_Plugin_Info {
$this->release_date = $release_date; $this->release_date = $release_date;
} }
/**
* @return string
*/
public function get_class_name() { public function get_class_name() {
return $this->class_name; return $this->class_name;
} }
...@@ -104,12 +107,10 @@ class WPDesk_Plugin_Info { ...@@ -104,12 +107,10 @@ class WPDesk_Plugin_Info {
$this->class_name = $class_name; $this->class_name = $class_name;
} }
public function get_build_priority() { /**
return 0; * @return string
} */
public function get_text_domain() {
public function get_post_load_file() { return strtolower( $this->get_plugin_dir() );
} }
} }
\ No newline at end of file
<?php
/**
* Have info about textdomain
* have to be compatible with PHP 5.2.x
*/
interface WPDesk_Translable {
/** @return string */
public function get_text_domain();
}
\ 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