From 4ce1cea8f95011ca2a4af5e8bc23bf340ba2cabe Mon Sep 17 00:00:00 2001 From: Stefan Hudson Date: Thu, 26 Oct 2023 22:48:14 -0700 Subject: [PATCH] Update lib to release version 1.6.5 --- lib/Lib/Container.php | 198 ++++++++++++++++++++++++++++++++++++ lib/Lib/Model.php | 93 ++++++++--------- lib/Lib/Plugin.php | 82 ++++++++++----- lib/Lib/PluginInterface.php | 10 +- lib/Lib/Settings.php | 111 +++++++++++++++----- 5 files changed, 387 insertions(+), 107 deletions(-) create mode 100644 lib/Lib/Container.php diff --git a/lib/Lib/Container.php b/lib/Lib/Container.php new file mode 100644 index 00000000..41d912db --- /dev/null +++ b/lib/Lib/Container.php @@ -0,0 +1,198 @@ + $value ) { + $this->add( $value, $key ); + } + + return; + } + + if ( empty( $name ) || is_numeric( $name ) ) { + $name = is_object( $service ) ? get_class( $service ) : $service; + } + $name = $this->sanitize_name( $name ); + + // If the service already exists bail. + if ( isset( $this->services[ $name ] ) ) { + return; + } + if ( is_string( $service ) && class_exists( $service ) ) { + $service = new $service(); + } + $this->services[ $name ] = $service; + } + + /** + * Get a service from the container by name. + * + * @param string $name The service name. + * + * @since 1.0.0 + * + * @return mixed|null + */ + public function get( $name ) { + $name = $this->sanitize_name( $name ); + + if ( isset( $this->services[ $name ] ) ) { + return $this->services[ $name ]; + } + + // If the name does not contain a slash, try to find the service by its class name. + if ( false === str_contains( $name, '/' ) && isset( $this->services[ "$name/$name" ] ) ) { + return $this->services[ "$name/$name" ]; + } + + return null; + } + + /** + * Remove a service from the container. + * + * @param string $name The service name. + * + * @since 1.0.0 + * + * @return void + */ + public function remove( $name ) { + $name = $this->sanitize_name( $name ); + if ( isset( $this->services[ $name ] ) ) { + unset( $this->services[ $name ] ); + } + } + + /** + * Has a service. + * + * @param string $name The service name. + * + * @since 1.0.0 + * @return bool + */ + public function has( $name ) { + $name = $this->sanitize_name( $name ); + + if ( isset( $this->services[ $name ] ) ) { + return true; + } + + if ( false === str_contains( $name, '/' ) && isset( $this->services[ "$name/$name" ] ) ) { + return true; + } + + return false; + } + + /** + * Whether a offset exists. + * + * @param mixed $offset An offset to check for. + * + * @since 1.0.0 + * + * @return boolean + */ + #[ReturnTypeWillChange] + public function offsetExists( $offset ) { + return $this->has( $offset ); + } + + /** + * Offset to retrieve. + * + * @param mixed $offset The offset to retrieve. + * + * @since 1.0.0 + * + * @return mixed + */ + #[ReturnTypeWillChange] + public function offsetGet( $offset ) { + return $this->get( $offset ); + } + + /** + * Offset to set. + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + * + * @since 1.0.0 + * + * @return void + */ + #[ReturnTypeWillChange] + public function offsetSet( $offset, $value ) { + $this->add( $value, $offset ); + } + + /** + * Offset to unset. + * + * @param mixed $offset The offset to unset. + * + * @since 1.0.0 + * + * @return void + */ + #[ReturnTypeWillChange] + public function offsetUnset( $offset ) { + $this->remove( $offset ); + } + + /** + * Sanitize a service name. + * + * @param string $name The service name. + * + * @return string + */ + private function sanitize_name( $name ) { + // We will remove the base namespace from the name then convert the name to snake case. + // Find the root namespace. + $root_namespace = explode( '\\', __NAMESPACE__ )[0]; + // Remove the root namespace from the name. + $name = str_replace( $root_namespace . '\\', '', $name ); + + // Convert the name to snake case and change the backslashes to forward slashes. + return strtolower( preg_replace( '/(?get_hook_prefix() . '_insert_data', $data, $this ); if ( false === $wpdb->insert( $wpdb->{$this->table_name}, $data ) ) { // translators: %s: database error message. - return new \WP_Error( 'db_insert_error', sprintf( __( 'Could not insert item into the database error %s', 'wc-serial-numbers' ), $wpdb->last_error ) ); + return new \WP_Error( 'db_insert_error', sprintf( __( 'Could not insert item into the database error %s', 'framework-text-domain' ), $wpdb->last_error ) ); } $this->set_prop( $this->primary_key, $wpdb->insert_id ); @@ -467,7 +467,7 @@ protected function update() { */ do_action( $this->get_hook_prefix() . '_pre_update', $this, $changes ); - $data = $this->array_slice_assoc( $changes, $this->get_core_data_keys() ); + $data = wp_array_slice_assoc( $changes, $this->get_core_data_keys() ); /** * Filters the data to be updated in the database. @@ -485,8 +485,8 @@ protected function update() { $data[ $key ] = maybe_serialize( $value ); } } - if ( false === $wpdb->update( $wpdb->{$this->table_name}, $data, [ $this->primary_key => $this->get_prop( $this->primary_key ) ] ) ) { - return new \WP_Error( 'db_update_error', __( 'Could not update item in the database.', 'wc-serial-numbers' ), $wpdb->last_error ); + if ( false === $wpdb->update( $wpdb->{$this->table_name}, $data, array( $this->primary_key => $this->get_prop( $this->primary_key ) ) ) ) { + return new \WP_Error( 'db_update_error', __( 'Could not update item in the database.', 'framework-text-domain' ), $wpdb->last_error ); } } @@ -503,10 +503,6 @@ protected function update() { return true; } - function array_slice_assoc($array,$keys) { - return array_intersect_key($array,array_flip($keys)); - } - /** * Deletes the object from database. * @@ -934,10 +930,10 @@ public function all( $args = array() ) { */ $items = apply_filters( $this->get_hook_prefix() . '_query_items', $items, $args ); - $result = (object) [ + $result = (object) array( 'items' => $items, 'total' => $total, - ]; + ); wp_cache_add( $cache_key, $result, $this->cache_group ); } @@ -1219,125 +1215,125 @@ protected function prepare_where_query( $clauses, $args = array() ) { foreach ( $this->get_core_data_keys() as $column ) { // equals clause. if ( ! empty( $args[ $column ] ) ) { - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column ], 'compare' => false !== strpos( $column, '_ids' ) ? 'FIND_IN_SET' : '=', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - ]; + ); } elseif ( ! empty( $args[ $column . '__in' ] ) ) { - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__in' ], 'compare' => false !== strpos( $column, '_ids' ) ? 'FIND_IN_SET' : 'IN', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - ]; + ); } elseif ( ! empty( $args[ $column . '__not_in' ] ) ) { // __not_in clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__not_in' ], 'compare' => false !== strpos( $column, '_ids' ) ? 'NOT_IN_SET' : 'NOT IN', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query - ]; + ); } elseif ( ! empty( $args[ $column . '__between' ] ) ) { // __between clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__between' ], 'compare' => 'BETWEEN', - ]; + ); } elseif ( ! empty( $args[ $column . '__not_between' ] ) ) { // __not_between clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__not_between' ], 'compare' => 'NOT BETWEEN', - ]; + ); } elseif ( ! empty( $args[ $column . '__exists' ] ) ) { // __exists clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'compare' => 'EXISTS', - ]; + ); } elseif ( ! empty( $args[ $column . '__not_exists' ] ) ) { // __not_exists clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'compare' => 'NOT EXISTS', - ]; + ); } elseif ( ! empty( $args[ $column . '__like' ] ) ) { // __like clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__like' ], 'compare' => 'LIKE', - ]; + ); } elseif ( ! empty( $args[ $column . '__not_like' ] ) ) { // __not_like clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__not_like' ], 'compare' => 'NOT LIKE', - ]; + ); } elseif ( ! empty( $args[ $column . '__starts_with' ] ) ) { // __starts_with clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__starts_with' ], 'compare' => 'LIKE', - ]; + ); } elseif ( ! empty( $args[ $column . '__ends_with' ] ) ) { // __ends_with clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__ends_with' ], 'compare' => 'ENDS WITH', - ]; + ); } elseif ( ! empty( $args[ $column . '__is_null' ] ) ) { // __is_null clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'compare' => 'IS NULL', - ]; + ); } elseif ( ! empty( $args[ $column . '__is_not_null' ] ) ) { // __is_not_null clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'compare' => 'IS NOT NULL', - ]; + ); } elseif ( ! empty( $args[ $column . '__gt' ] ) ) { // __gt clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__gt' ], 'compare' => 'GREATER THAN', - ]; + ); } elseif ( ! empty( $args[ $column . '__lt' ] ) ) { // __lt clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__lt' ], 'compare' => 'LESS THAN', - ]; + ); } elseif ( ! empty( $args[ $column . '__find_in_set' ] ) ) { // find_in_set clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'compare' => 'FIND_IN_SET', 'value' => $args[ $column . '__find_in_set' ], - ]; + ); } elseif ( ! empty( $args[ $column . '__find_not_in_set' ] ) ) { // find_in_set clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'compare' => 'NOT_IN_SET', 'value' => $args[ $column . '__find_not_in_set' ], - ]; + ); } elseif ( ! empty( $args[ $column . '__regexp' ] ) ) { // __regexp clause. - $query_where[] = [ + $query_where[] = array( 'column' => "{$this->table_name}.{$column}", 'value' => $args[ $column . '__regexp' ], 'compare' => 'REGEXP', - ]; + ); } } @@ -1582,7 +1578,7 @@ function ( $cols ) use ( $wp_columns ) { // Restore the original columns. add_filter( 'date_query_valid_columns', - function ( $cols ) use ( $wp_columns ) { + function () use ( $wp_columns ) { return $wp_columns; } ); @@ -1771,7 +1767,6 @@ protected function prepare_having_query( $clauses, $args = array() ) { * @since 1.0.0 */ return apply_filters( $this->get_hook_prefix() . '_setup_having_query', $clauses, $args, $this ); - } /** diff --git a/lib/Lib/Plugin.php b/lib/Lib/Plugin.php index 8af0935e..d961cb4c 100644 --- a/lib/Lib/Plugin.php +++ b/lib/Lib/Plugin.php @@ -8,7 +8,7 @@ * Template for encapsulating some of the most often required abilities of a plugin instance. * * @since 1.0.0 - * @version 1.0.5 + * @version 1.0.8 * @author Sultan Nasir Uddin * @package WooCommerceSerialNumbers\Lib * @subpackage Lib/Plugin @@ -30,9 +30,9 @@ abstract class Plugin implements PluginInterface { * The plugin services. * * @since 1.0.0 - * @var array + * @var Container */ - public $services = array(); + public $services; /** * The single instance of the class. @@ -74,10 +74,23 @@ final public static function create( $data = null ) { * Gets the instance of the class. * * @since 1.0.0 + * @depecated 1.0.5 * * @return static */ final public static function get_instance() { + _doing_it_wrong( __FUNCTION__, 'Use static::create() instead.', '1.0.5' ); + return static::instance(); + } + + /** + * Gets the instance of the class. + * + * @since 1.0.0 + * + * @return static + */ + final public static function instance() { if ( null === static::$instance ) { _doing_it_wrong( __FUNCTION__, 'Plugin instance called before initiating the instance.', '1.0.0' ); } @@ -93,6 +106,7 @@ final public static function get_instance() { * @since 1.0.0 */ protected function __construct( $data ) { + $this->services = new Container(); // Only set the data keys that are not already set. $this->data = array_merge( $this->data, $data ); // If the slug is not set, then set it. @@ -110,6 +124,7 @@ protected function __construct( $data ) { // Register hooks. add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); + if ( is_admin() ) { add_filter( 'wp_redirect', array( $this, 'save_notices' ), 1 ); add_action( 'init', array( $this, 'load_notices' ), 1 ); @@ -272,7 +287,7 @@ public function plugin_row_meta( $links, $file ) { * @return array */ public function plugin_action_links( $links ) { - $actions = []; + $actions = array(); foreach ( $this->get_action_links() as $key => $link ) { $actions[ $key ] = sprintf( '%2$s', esc_url( $link['url'] ), wp_kses_post( $link['label'] ) ); } @@ -291,7 +306,7 @@ public function plugin_action_links( $links ) { ), $this->get_premium_url() ); - $links['go_pro'] = sprintf( '%2$s', esc_url( $pro_link ), esc_html__( 'Go Pro', 'wc-serial-numbers' ) ); + $links['go_pro'] = sprintf( '%2$s', esc_url( $pro_link ), esc_html__( 'Go Pro', 'framework-text-domain' ) ); } return $links; @@ -634,30 +649,30 @@ public function get_assets_url() { * @return array */ public function get_meta_links() { - $links = []; + $links = array(); if ( ! empty( $this->get_docs_url() ) ) { $links['docs'] = array( - 'label' => __( 'Documentation', 'wc-serial-numbers' ), + 'label' => __( 'Documentation', 'framework-text-domain' ), 'url' => $this->get_docs_url(), ); } if ( ! empty( $this->get_support_url() ) ) { $links['support'] = array( - 'label' => __( 'Support', 'wc-serial-numbers' ), + 'label' => __( 'Support', 'framework-text-domain' ), 'url' => $this->get_support_url(), ); } if ( ! empty( $this->get_review_url() ) ) { $links['review'] = array( - 'label' => __( 'Review', 'wc-serial-numbers' ), + 'label' => __( 'Review', 'framework-text-domain' ), 'url' => $this->get_review_url(), ); } $links['plugins'] = array( - 'label' => __( 'More Plugins', 'wc-serial-numbers' ), + 'label' => __( 'More Plugins', 'framework-text-domain' ), 'url' => $this->get_store_url(), ); @@ -671,10 +686,10 @@ public function get_meta_links() { * @return array */ public function get_action_links() { - $links = []; + $links = array(); if ( ! empty( $this->get_settings_url() ) ) { $links['settings'] = array( - 'label' => __( 'Settings', 'wc-serial-numbers' ), + 'label' => __( 'Settings', 'framework-text-domain' ), 'url' => $this->get_settings_url(), ); } @@ -690,6 +705,21 @@ public function get_action_links() { | This section is for helper methods. | */ + + /** + * Define constant if not already set. + * + * @param string $name Constant name. + * @param string|bool $value Constant value. + * @since 1.0.6 + * @return void + */ + protected function define( $name, $value ) { + if ( ! defined( $name ) ) { + define( $name, $value ); + } + } + /** * Get plugin database version. * @@ -733,14 +763,14 @@ public function update_db_version( $version = null, $update = true ) { * @return void */ public function add_notice( $notice, $type = 'success' ) { - if ( empty( $notice ) && ! in_array( $type, [ 'success', 'info', 'warning', 'error' ], true ) ) { + if ( empty( $notice ) && ! in_array( $type, array( 'success', 'info', 'warning', 'error' ), true ) ) { $type = 'success'; } - $this->data['notices'][] = [ + $this->data['notices'][] = array( 'type' => $type, 'message' => $notice, - ]; + ); } /** @@ -754,7 +784,7 @@ public function add_notice( $notice, $type = 'success' ) { * @since 1.0.0 * @return void */ - public function register_script( $handle, $src, $deps = [], $in_footer = false ) { + public function register_script( $handle, $src, $deps = array(), $in_footer = false ) { // check if $src is relative or absolute. if ( ! preg_match( '/^(http|https):\/\//', $src ) ) { $url = $this->get_assets_url() . ltrim( $src ); @@ -764,17 +794,17 @@ public function register_script( $handle, $src, $deps = [], $in_footer = false ) $path = str_replace( $this->get_dir_url(), $this->get_dir_path(), $src ); } $php_file = str_replace( '.js', '.asset.php', $path ); - $asset = $php_file && file_exists( $php_file ) ? require $php_file : [ - 'dependencies' => [], + $asset = $php_file && file_exists( $php_file ) ? require $php_file : array( + 'dependencies' => array(), 'version' => $this->get_version(), - ]; + ); $deps = array_merge( $asset['dependencies'], $deps ); $ver = $asset['version']; wp_register_script( $handle, $url, $deps, $ver, $in_footer ); - if ( array_intersect( $deps, [ 'react', 'react-dom' ] ) ) { + if ( array_intersect( $deps, array( 'react', 'react-dom' ) ) ) { // add text domain to the script. $text_domain = $this->get_data( 'text_domain' ); $domain_path = $this->get_data( 'domain_path' ); @@ -793,7 +823,7 @@ public function register_script( $handle, $src, $deps = [], $in_footer = false ) * @since 1.0.0 * @return void */ - public function register_style( $handle, $src, $deps = [], $media = 'all' ) { + public function register_style( $handle, $src, $deps = array(), $media = 'all' ) { if ( ! preg_match( '/^(http|https):\/\//', $src ) ) { $url = $this->get_assets_url() . ltrim( $src ); $path = $this->get_assets_path() . ltrim( $src ); @@ -802,10 +832,10 @@ public function register_style( $handle, $src, $deps = [], $media = 'all' ) { $path = str_replace( $this->get_dir_url(), $this->get_dir_url(), $src ); } $php_file = str_replace( '.css', '.asset.php', $path ); - $asset = $php_file && file_exists( $php_file ) ? require $php_file : [ - 'dependencies' => [], + $asset = $php_file && file_exists( $php_file ) ? require $php_file : array( + 'dependencies' => array(), 'version' => $this->get_version(), - ]; + ); $deps = array_merge( $asset['dependencies'], $deps ); $ver = $asset['version']; @@ -823,7 +853,7 @@ public function register_style( $handle, $src, $deps = [], $media = 'all' ) { * @since 1.0.0 * @return void */ - public function enqueue_script( $handle, $src, $deps = [], $in_footer = false ) { + public function enqueue_script( $handle, $src, $deps = array(), $in_footer = false ) { $this->register_script( $handle, $src, $deps, $in_footer ); wp_enqueue_script( $handle ); } @@ -839,7 +869,7 @@ public function enqueue_script( $handle, $src, $deps = [], $in_footer = false ) * @since 1.0.0 * @return void */ - public function enqueue_style( $handle, $src, $deps = [], $media = 'all' ) { + public function enqueue_style( $handle, $src, $deps = array(), $media = 'all' ) { $this->register_style( $handle, $src, $deps, $media ); wp_enqueue_style( $handle ); } diff --git a/lib/Lib/PluginInterface.php b/lib/Lib/PluginInterface.php index ae8a9d8c..1d3aa0f2 100644 --- a/lib/Lib/PluginInterface.php +++ b/lib/Lib/PluginInterface.php @@ -8,7 +8,7 @@ * Describes a plugin instance. * * @since 1.0.0 - * @version 1.0.2 + * @version 1.0.8 * @author Sultan Nasir Uddin * @package WooCommerceSerialNumbers\Lib * @subpackage Lib/Plugin @@ -259,7 +259,7 @@ public function update_db_version( $version = null ); * @since 1.0.0 * @return void */ - public function register_script( $handle, $src, $deps = [], $in_footer = false ); + public function register_script( $handle, $src, $deps = array(), $in_footer = false ); /** * Enqueue styles helper. @@ -272,7 +272,7 @@ public function register_script( $handle, $src, $deps = [], $in_footer = false ) * @since 1.0.0 * @return void */ - public function register_style( $handle, $src, $deps = [], $media = 'all' ); + public function register_style( $handle, $src, $deps = array(), $media = 'all' ); /** * Enqueue scripts helper. @@ -285,7 +285,7 @@ public function register_style( $handle, $src, $deps = [], $media = 'all' ); * @since 1.0.0 * @return void */ - public function enqueue_script( $handle, $src, $deps = [], $in_footer = false ); + public function enqueue_script( $handle, $src, $deps = array(), $in_footer = false ); /** * Enqueue styles helper. @@ -298,7 +298,7 @@ public function enqueue_script( $handle, $src, $deps = [], $in_footer = false ); * @since 1.0.0 * @return void */ - public function enqueue_style( $handle, $src, $deps = [], $media = 'all' ); + public function enqueue_style( $handle, $src, $deps = array(), $media = 'all' ); /** * Check if the plugin is active. diff --git a/lib/Lib/Settings.php b/lib/Lib/Settings.php index d6e1d089..3606c40a 100644 --- a/lib/Lib/Settings.php +++ b/lib/Lib/Settings.php @@ -8,7 +8,7 @@ * Class Settings * * @since 1.0.0 - * @version 1.0.2 + * @version 1.0.4 * @subpackage WooCommerceSerialNumbers\Lib\Settings * @package WooCommerceSerialNumbers\Lib */ @@ -16,10 +16,10 @@ abstract class Settings { /** * Init settings. * - * @since 1.0.0 + * @since 1.0.3 * @return self */ - public static function get_instance() { + public static function instance() { static $instance = null; $class_name = get_called_class(); if ( null === $instance ) { @@ -29,6 +29,18 @@ public static function get_instance() { return $instance; } + /** + * Init settings. + * + * @since 1.0.0 + * @depecated 1.0.3 + * @return self + */ + public static function get_instance() { + _doing_it_wrong( __FUNCTION__, 'Use static::instance() instead.', '1.0.3' ); + return static::instance(); + } + /** * Settings constructor. * @@ -81,7 +93,7 @@ public function save_settings() { $current_tab = $this->get_current_tab(); $settings = $this->get_settings( $current_tab ); if ( class_exists( '\WC_Admin_Settings' ) && ! empty( $settings ) && \WC_Admin_Settings::save_fields( $settings ) ) { - add_settings_error( $class_name, 'response', __( 'Settings saved.', 'wc-serial-numbers' ), 'updated' ); + add_settings_error( $class_name, 'response', __( 'Settings saved.', 'framework-text-domain' ), 'updated' ); return true; } @@ -147,7 +159,7 @@ public function output_settings() { } if (show) { - $this.closest('tr').style.display = 'block'; + $this.closest('tr').style.display = 'table-row'; } else { $this.closest('tr').style.display = 'none'; } @@ -155,6 +167,56 @@ public function output_settings() { $conditional_field.dispatchEvent(new Event('change')); }); + + // if Jquery is not loaded, return. + if (typeof jQuery === 'undefined') { + return; + } + + // trigger change event on load. + jQuery(document).ready(function ($) { + // check if iris is loaded. + if (typeof $.fn.iris !== 'undefined') { + // Color picker. + $('.colorpick') + .iris({ + change: function (event, ui) { + $(this) + .parent() + .find('.colorpickpreview') + .css({backgroundColor: ui.color.toString()}); + }, + hide: true, + border: true, + }) + .on('click focus', function (event) { + event.stopPropagation(); + $('.iris-picker').hide(); + $(this).closest('td').find('.iris-picker').show(); + $(this).data('originalValue', $(this).val()); + }) + .on('change', function () { + if ($(this).is('.iris-error')) { + var original_value = $(this).data('originalValue'); + if ( + original_value.match( + /^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ + ) + ) { + $(this) + .val($(this).data('originalValue')) + .trigger('change'); + } else { + $(this).val('').trigger('change'); + } + } + }); + + $('body').on('click', function () { + $('.iris-picker').hide(); + }); + } + }); }); @@ -245,8 +307,8 @@ protected function output_plugins_widget() { 'description' => '', 'basename' => '', 'slug' => '', - 'badge' => esc_html__( 'Recommended', 'wc-serial-numbers' ), - 'button' => esc_html__( 'Install Now', 'wc-serial-numbers' ), + 'badge' => esc_html__( 'Recommended', 'framework-text-domain' ), + 'button' => esc_html__( 'Install Now', 'framework-text-domain' ), 'installed' => false, ) ); @@ -279,9 +341,7 @@ protected function output_plugins_widget() {
- - <?php echo esc_attr( $promo_plugin['name'] ); ?> - +

@@ -307,7 +367,7 @@ protected function output_support_widget() { if ( ! empty( $support_links ) ) { ?>
-

+

  • @@ -331,31 +391,28 @@ protected function output_support_widget() { public function get_promo_plugins() { return array( array( - 'name' => 'Min Max Quantity for WooCommerce', + 'name' => 'WC Min Max Quantities', 'slug' => 'wc-min-max-quantities', 'description' => 'Set minimum and maximum price or quantity for WooCommerce products.', - 'thumbnail' => 'https://ps.w.org/wc-min-max-quantities/assets/icon-256x256.png?rev=2775545', 'link' => 'https://wordpress.org/plugins/wc-min-max-quantities/', - 'badge' => esc_html__( 'Recommended', 'wc-serial-numbers' ), - 'button' => esc_html__( 'Install Now', 'wc-serial-numbers' ), + 'badge' => esc_html__( 'Recommended', 'framework-text-domain' ), + 'button' => esc_html__( 'Install Now', 'framework-text-domain' ), ), array( 'name' => 'Product Category Showcase for WooCommerce', 'slug' => 'wc-category-showcase', 'description' => 'Display WooCommerce categories in a beautiful way.', - 'thumbnail' => 'https://ps.w.org/wc-category-showcase/assets/icon-256x256.png?rev=2775545', 'link' => 'https://wordpress.org/plugins/wc-category-showcase/', - 'badge' => esc_html__( 'Recommended', 'wc-serial-numbers' ), - 'button' => esc_html__( 'Install Now', 'wc-serial-numbers' ), + 'badge' => esc_html__( 'Recommended', 'framework-text-domain' ), + 'button' => esc_html__( 'Install Now', 'framework-text-domain' ), ), array( 'name' => 'Product Category Slider for WooCommerce', 'basename' => 'woo-category-slider-by-pluginever/woo-category-slider.php', 'description' => 'Display WooCommerce categories in a beautiful way.', - 'thumbnail' => 'https://ps.w.org/woo-category-slider-by-pluginever/assets/icon-256x256.png?rev=2775545', 'link' => 'https://wordpress.org/plugins/woo-category-slider-by-pluginever/', - 'badge' => esc_html__( 'Recommended', 'wc-serial-numbers' ), - 'button' => esc_html__( 'Install Now', 'wc-serial-numbers' ), + 'badge' => esc_html__( 'Recommended', 'framework-text-domain' ), + 'button' => esc_html__( 'Install Now', 'framework-text-domain' ), ), ); } @@ -369,15 +426,15 @@ public function get_promo_plugins() { public function get_support_links() { return array( 'facebook' => array( - 'label' => __( 'Join our Community', 'wc-serial-numbers' ), + 'label' => __( 'Join our Community', 'framework-text-domain' ), 'url' => 'https://www.facebook.com/groups/pluginever', ), 'feature-request' => array( - 'label' => __( 'Request a Feature', 'wc-serial-numbers' ), + 'label' => __( 'Request a Feature', 'framework-text-domain' ), 'url' => 'https://www.pluginever.com/contact/', ), 'bug-report' => array( - 'label' => __( 'Report a Bug', 'wc-serial-numbers' ), + 'label' => __( 'Report a Bug', 'framework-text-domain' ), 'url' => 'https://www.pluginever.com/contact/', ), ); @@ -390,7 +447,7 @@ public function get_support_links() { * @return string */ public function get_current_page() { - $page = filter_input( INPUT_GET, 'page' ); + $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_SPECIAL_CHARS ); return ! empty( $page ) ? sanitize_text_field( wp_unslash( $page ) ) : ''; } @@ -402,7 +459,7 @@ public function get_current_page() { */ protected function get_current_tab() { $tabs = $this->get_tabs(); - $tab = filter_input( INPUT_GET, 'tab' ); + $tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_SPECIAL_CHARS ); $tab = ! empty( $tab ) ? sanitize_text_field( wp_unslash( $tab ) ) : ''; if ( ! array_key_exists( $tab, $tabs ) ) { @@ -439,6 +496,6 @@ public function save_defaults() { * @return void */ public static function output() { - self::get_instance()->output_settings(); + self::instance()->output_settings(); } }