From cf8b2a32b2db3329f191169ebcd6778d019e433c Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Sun, 29 Dec 2024 14:13:23 +0200 Subject: [PATCH 1/8] New: Added notifications for Hello Elementor theme [ED-16360] --- assets/dev/js/admin/pages/settings-page.js | 13 ++ composer.json | 13 +- composer.lock | 128 +++++++--- footer.php | 1 - functions.php | 20 ++ header.php | 1 - includes/admin-functions.php | 1 - includes/customizer-functions.php | 1 - .../customizer/customizer-action-links.php | 1 - includes/customizer/customizer-upsell.php | 1 - includes/elementor-functions.php | 1 - includes/notifications.php | 221 ++++++++++++++++++ includes/settings-functions.php | 37 ++- index.php | 1 - sidebar.php | 1 - template-parts/404.php | 2 +- template-parts/archive.php | 2 +- template-parts/dynamic-footer.php | 1 - template-parts/dynamic-header.php | 1 - template-parts/footer.php | 1 - template-parts/header.php | 2 +- template-parts/search.php | 2 +- template-parts/single.php | 1 - 23 files changed, 404 insertions(+), 49 deletions(-) create mode 100644 includes/notifications.php diff --git a/assets/dev/js/admin/pages/settings-page.js b/assets/dev/js/admin/pages/settings-page.js index 10e791bc..b5b735aa 100644 --- a/assets/dev/js/admin/pages/settings-page.js +++ b/assets/dev/js/admin/pages/settings-page.js @@ -116,6 +116,19 @@ export const SettingsPage = () => {

{ __( 'Hello Theme Settings', 'hello-elementor' ) }

+
diff --git a/composer.json b/composer.json index 81ece3d4..8b5991c0 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,13 @@ { "name": "elementor/hello-theme", - "require": { + "require-dev": { "squizlabs/php_codesniffer": "^3.6", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", "wp-coding-standards/wpcs": "^2.3" }, + "require": { + "elementor/wp-notifications-package": "dev-tweak/ED-16360-initial-wip" + }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true @@ -12,5 +15,11 @@ }, "scripts": { "lint": "phpcs --extensions=php -p" - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/elementor/wp-notifications-package" + } + ] } diff --git a/composer.lock b/composer.lock index 11f7fd8e..2a796f04 100644 --- a/composer.lock +++ b/composer.lock @@ -4,31 +4,71 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fb532360aa2153f005e713784f2f1a50", + "content-hash": "986bbddca7dec5609d5a6b3ff85356e8", "packages": [ + { + "name": "elementor/wp-notifications-package", + "version": "dev-tweak/ED-16360-initial-wip", + "source": { + "type": "git", + "url": "https://github.com/elementor/wp-notifications-package.git", + "reference": "db1f35ccf4e9a9d7a681f722108dd8e20a82e4ac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/elementor/wp-notifications-package/zipball/db1f35ccf4e9a9d7a681f722108dd8e20a82e4ac", + "reference": "db1f35ccf4e9a9d7a681f722108dd8e20a82e4ac", + "shasum": "" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^v1.0.0", + "squizlabs/php_codesniffer": "^3.10.2", + "wp-coding-standards/wpcs": "^3.1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Elementor\\WPNotificationsPackage\\": "src/" + } + }, + "scripts": { + "lint": [ + "vendor/bin/phpcs --standard=./phpcs.xml ." + ], + "lint:fix": [ + "vendor/bin/phpcbf ." + ] + }, + "support": { + "source": "https://github.com/elementor/wp-notifications-package/tree/tweak/ED-16360-initial-wip" + }, + "time": "2024-12-26T12:24:55+00:00" + } + ], + "packages-dev": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.7.1", + "version": "v0.7.2", "source": { "type": "git", "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", - "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", + "reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db", "shasum": "" }, "require": { "composer-plugin-api": "^1.0 || ^2.0", "php": ">=5.3", - "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", - "phpcompatibility/php-compatibility": "^9.0", - "sensiolabs/security-checker": "^4.1.0" + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0" }, "type": "composer-plugin", "extra": { @@ -49,6 +89,10 @@ "email": "franck.nijhof@dealerdirect.com", "homepage": "http://www.frenck.nl", "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -60,6 +104,7 @@ "codesniffer", "composer", "installer", + "phpcbf", "phpcs", "plugin", "qa", @@ -74,20 +119,20 @@ "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" }, - "time": "2020-12-07T18:04:37+00:00" + "time": "2022-02-04T12:51:07+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.6.0", + "version": "3.11.2", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", - "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/1368f4a58c3c52114b86b1abe8f4098869cb0079", + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079", "shasum": "" }, "require": { @@ -97,11 +142,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -116,21 +161,45 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, - "time": "2021-04-09T00:54:41+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-12-11T16:04:26+00:00" }, { "name": "wp-coding-standards/wpcs", @@ -184,13 +253,14 @@ "time": "2020-05-13T23:57:56+00:00" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "elementor/wp-notifications-package": 20 + }, "prefer-stable": false, "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.0.0" + "platform": {}, + "platform-dev": {}, + "plugin-api-version": "2.6.0" } diff --git a/footer.php b/footer.php index 06fcc8c1..3b68a623 100644 --- a/footer.php +++ b/footer.php @@ -6,7 +6,6 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } diff --git a/functions.php b/functions.php index 10a4355f..12c5c83b 100644 --- a/functions.php +++ b/functions.php @@ -5,6 +5,8 @@ * @package HelloElementor */ +use Elementor\WPNotificationsPackage\V100\Notifications as ThemeNotifications; + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } @@ -261,3 +263,21 @@ function hello_elementor_body_open() { wp_body_open(); } } + +function hello_elementor_get_theme_notifications(): ThemeNotifications { + static $notifications = null; + + if ( null === $notifications ) { + require get_template_directory() . '/vendor/autoload.php'; + + $notifications = new ThemeNotifications( + 'hello-elementor', + HELLO_ELEMENTOR_VERSION, + 'theme' + ); + } + + return $notifications; +} + +hello_elementor_get_theme_notifications(); diff --git a/header.php b/header.php index 52e737e0..d2b2f29c 100644 --- a/header.php +++ b/header.php @@ -6,7 +6,6 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } diff --git a/includes/admin-functions.php b/includes/admin-functions.php index 37f7c5ae..ba573b0b 100644 --- a/includes/admin-functions.php +++ b/includes/admin-functions.php @@ -1,5 +1,4 @@ app_name = sanitize_title( $app_name ); + $this->app_version = $app_version; + $this->short_app_name = $short_app_name; + + $this->api_endpoint = sprintf( $this->api_endpoint, $this->app_name ); + + $this->transient_key = "_{$this->app_name}_notifications"; + + add_action( 'admin_init', [ $this, 'refresh_notifications' ] ); + add_filter( 'body_class', [ $this, 'add_body_class' ] ); + } + + public function refresh_notifications(): void { + $this->get_notifications(); + } + + public function add_body_class( array $classes ): array { + $classes[] = $this->short_app_name . '-default'; + + return $classes; + } + + public function get_notifications_by_conditions( $force_request = false ) { + $notifications = $this->get_notifications( $force_request ); + + $filtered_notifications = []; + + foreach ( $notifications as $notification ) { + if ( empty( $notification['conditions'] ) ) { + $filtered_notifications = $this->add_to_array( $filtered_notifications, $notification ); + + continue; + } + + if ( ! $this->check_conditions( $notification['conditions'] ) ) { + continue; + } + + $filtered_notifications = $this->add_to_array( $filtered_notifications, $notification ); + } + + return $filtered_notifications; + } + + private function get_notifications( $force_update = false ): array { + $notifications = static::get_transient( $this->transient_key ); + + if ( false === $notifications || $force_update ) { + $notifications = $this->fetch_data(); + static::set_transient( $this->transient_key, $notifications ); + } + + return $notifications; + } + + private function add_to_array( $filtered_notifications, $notification ) { + foreach ( $filtered_notifications as $filtered_notification ) { + if ( $filtered_notification['id'] === $notification['id'] ) { + return $filtered_notifications; + } + } + + $filtered_notifications[] = $notification; + + return $filtered_notifications; + } + + private function check_conditions( $groups ): bool { + foreach ( $groups as $group ) { + if ( $this->check_group( $group ) ) { + return true; + } + } + + return false; + } + + private function check_group( $group ) { + $is_or_relation = ! empty( $group['relation'] ) && 'OR' === $group['relation']; + unset( $group['relation'] ); + $result = false; + + foreach ( $group as $condition ) { + // Reset results for each condition. + $result = false; + switch ( $condition['type'] ) { + case 'wordpress': // phpcs:ignore WordPress.WP.CapitalPDangit + // include an unmodified $wp_version + include ABSPATH . WPINC . '/version.php'; + $result = version_compare( $wp_version, $condition['version'], $condition['operator'] ); + break; + case 'multisite': + $result = is_multisite() === $condition['multisite']; + break; + case 'language': + $in_array = in_array( get_locale(), $condition['languages'], true ); + $result = 'in' === $condition['operator'] ? $in_array : ! $in_array; + break; + case 'plugin': + if ( ! function_exists( 'is_plugin_active' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + $is_plugin_active = is_plugin_active( $condition['plugin'] ); + + if ( empty( $condition['operator'] ) ) { + $condition['operator'] = '=='; + } + + $result = '==' === $condition['operator'] ? $is_plugin_active : ! $is_plugin_active; + break; + case 'theme': + $theme = wp_get_theme(); + if ( wp_get_theme()->parent() ) { + $theme = wp_get_theme()->parent(); + } + + if ( $theme->get_template() === $condition['theme'] ) { + $version = $theme->version; + } else { + $version = ''; + } + + $result = version_compare( $version, $condition['version'], $condition['operator'] ); + break; + + default: + $result = apply_filters( "$this->app_name/notifications/condition/{$condition['type']}", $result, $condition ); + break; + } + + if ( ( $is_or_relation && $result ) || ( ! $is_or_relation && ! $result ) ) { + return $result; + } + } + + return $result; + } + + private function fetch_data(): array { + $response = wp_remote_get( + $this->api_endpoint, + [ + 'timeout' => 10, + 'body' => [ + 'app_name' => $this->app_name, + 'app_version' => $this->app_version, + 'site_lang' => get_bloginfo( 'language' ), + 'site_key' => $this->get_site_key(), + ], + ] + ); + + if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { + return []; + } + + $data = \json_decode( wp_remote_retrieve_body( $response ), true ); + + if ( empty( $data['notifications'] ) || ! is_array( $data['notifications'] ) ) { + return []; + } + + return $data['notifications']; + } + + private function get_site_key() { + $site_key = get_option( 'elementor_connect_site_key' ); + + if ( ! $site_key ) { + $site_key = md5( uniqid( wp_generate_password() ) ); + update_option( 'elementor_connect_site_key', $site_key ); + } + + return $site_key; + } + + private static function get_transient( $cache_key ) { + $cache = get_option( $cache_key ); + + if ( empty( $cache['timeout'] ) ) { + return false; + } + + if ( time() > $cache['timeout'] ) { + return false; + } + + return json_decode( $cache['value'], true ); + } + + private static function set_transient( $cache_key, $value, $expiration = '+12 hours' ) { + $data = [ + 'timeout' => strtotime( $expiration, time() ), + 'value' => wp_json_encode( $value ), + ]; + + return update_option( $cache_key, $data, false ); + } +} diff --git a/includes/settings-functions.php b/includes/settings-functions.php index 208d4778..35c888ec 100644 --- a/includes/settings-functions.php +++ b/includes/settings-functions.php @@ -1,5 +1,4 @@
get_notifications_by_conditions(); + ?> + + + +

+ +

+

+ + +
+
diff --git a/template-parts/archive.php b/template-parts/archive.php index 89dcd2cf..6e359658 100644 --- a/template-parts/archive.php +++ b/template-parts/archive.php @@ -4,10 +4,10 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } + ?>
diff --git a/template-parts/dynamic-footer.php b/template-parts/dynamic-footer.php index fded5724..cfb39994 100644 --- a/template-parts/dynamic-footer.php +++ b/template-parts/dynamic-footer.php @@ -4,7 +4,6 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } diff --git a/template-parts/dynamic-header.php b/template-parts/dynamic-header.php index eaeb399f..d7576aea 100644 --- a/template-parts/dynamic-header.php +++ b/template-parts/dynamic-header.php @@ -4,7 +4,6 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } diff --git a/template-parts/footer.php b/template-parts/footer.php index 408e6ae4..aae95e10 100644 --- a/template-parts/footer.php +++ b/template-parts/footer.php @@ -4,7 +4,6 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } diff --git a/template-parts/header.php b/template-parts/header.php index 86b2fea9..bb5f1eba 100644 --- a/template-parts/header.php +++ b/template-parts/header.php @@ -4,10 +4,10 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } + $site_name = get_bloginfo( 'name' ); $tagline = get_bloginfo( 'description', 'display' ); $header_nav_menu = wp_nav_menu( [ diff --git a/template-parts/search.php b/template-parts/search.php index 9767562c..0b4142c1 100644 --- a/template-parts/search.php +++ b/template-parts/search.php @@ -4,10 +4,10 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } + ?>
diff --git a/template-parts/single.php b/template-parts/single.php index 4d96de11..f16c3e20 100644 --- a/template-parts/single.php +++ b/template-parts/single.php @@ -4,7 +4,6 @@ * * @package HelloElementor */ - if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } From ddfe13f3e15ce7fd56481812a615d840ecb6a4f3 Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Sun, 29 Dec 2024 14:14:19 +0200 Subject: [PATCH 2/8] Removed --- includes/notifications.php | 221 ------------------------------------- 1 file changed, 221 deletions(-) delete mode 100644 includes/notifications.php diff --git a/includes/notifications.php b/includes/notifications.php deleted file mode 100644 index f32f4626..00000000 --- a/includes/notifications.php +++ /dev/null @@ -1,221 +0,0 @@ -app_name = sanitize_title( $app_name ); - $this->app_version = $app_version; - $this->short_app_name = $short_app_name; - - $this->api_endpoint = sprintf( $this->api_endpoint, $this->app_name ); - - $this->transient_key = "_{$this->app_name}_notifications"; - - add_action( 'admin_init', [ $this, 'refresh_notifications' ] ); - add_filter( 'body_class', [ $this, 'add_body_class' ] ); - } - - public function refresh_notifications(): void { - $this->get_notifications(); - } - - public function add_body_class( array $classes ): array { - $classes[] = $this->short_app_name . '-default'; - - return $classes; - } - - public function get_notifications_by_conditions( $force_request = false ) { - $notifications = $this->get_notifications( $force_request ); - - $filtered_notifications = []; - - foreach ( $notifications as $notification ) { - if ( empty( $notification['conditions'] ) ) { - $filtered_notifications = $this->add_to_array( $filtered_notifications, $notification ); - - continue; - } - - if ( ! $this->check_conditions( $notification['conditions'] ) ) { - continue; - } - - $filtered_notifications = $this->add_to_array( $filtered_notifications, $notification ); - } - - return $filtered_notifications; - } - - private function get_notifications( $force_update = false ): array { - $notifications = static::get_transient( $this->transient_key ); - - if ( false === $notifications || $force_update ) { - $notifications = $this->fetch_data(); - static::set_transient( $this->transient_key, $notifications ); - } - - return $notifications; - } - - private function add_to_array( $filtered_notifications, $notification ) { - foreach ( $filtered_notifications as $filtered_notification ) { - if ( $filtered_notification['id'] === $notification['id'] ) { - return $filtered_notifications; - } - } - - $filtered_notifications[] = $notification; - - return $filtered_notifications; - } - - private function check_conditions( $groups ): bool { - foreach ( $groups as $group ) { - if ( $this->check_group( $group ) ) { - return true; - } - } - - return false; - } - - private function check_group( $group ) { - $is_or_relation = ! empty( $group['relation'] ) && 'OR' === $group['relation']; - unset( $group['relation'] ); - $result = false; - - foreach ( $group as $condition ) { - // Reset results for each condition. - $result = false; - switch ( $condition['type'] ) { - case 'wordpress': // phpcs:ignore WordPress.WP.CapitalPDangit - // include an unmodified $wp_version - include ABSPATH . WPINC . '/version.php'; - $result = version_compare( $wp_version, $condition['version'], $condition['operator'] ); - break; - case 'multisite': - $result = is_multisite() === $condition['multisite']; - break; - case 'language': - $in_array = in_array( get_locale(), $condition['languages'], true ); - $result = 'in' === $condition['operator'] ? $in_array : ! $in_array; - break; - case 'plugin': - if ( ! function_exists( 'is_plugin_active' ) ) { - require_once ABSPATH . 'wp-admin/includes/plugin.php'; - } - - $is_plugin_active = is_plugin_active( $condition['plugin'] ); - - if ( empty( $condition['operator'] ) ) { - $condition['operator'] = '=='; - } - - $result = '==' === $condition['operator'] ? $is_plugin_active : ! $is_plugin_active; - break; - case 'theme': - $theme = wp_get_theme(); - if ( wp_get_theme()->parent() ) { - $theme = wp_get_theme()->parent(); - } - - if ( $theme->get_template() === $condition['theme'] ) { - $version = $theme->version; - } else { - $version = ''; - } - - $result = version_compare( $version, $condition['version'], $condition['operator'] ); - break; - - default: - $result = apply_filters( "$this->app_name/notifications/condition/{$condition['type']}", $result, $condition ); - break; - } - - if ( ( $is_or_relation && $result ) || ( ! $is_or_relation && ! $result ) ) { - return $result; - } - } - - return $result; - } - - private function fetch_data(): array { - $response = wp_remote_get( - $this->api_endpoint, - [ - 'timeout' => 10, - 'body' => [ - 'app_name' => $this->app_name, - 'app_version' => $this->app_version, - 'site_lang' => get_bloginfo( 'language' ), - 'site_key' => $this->get_site_key(), - ], - ] - ); - - if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { - return []; - } - - $data = \json_decode( wp_remote_retrieve_body( $response ), true ); - - if ( empty( $data['notifications'] ) || ! is_array( $data['notifications'] ) ) { - return []; - } - - return $data['notifications']; - } - - private function get_site_key() { - $site_key = get_option( 'elementor_connect_site_key' ); - - if ( ! $site_key ) { - $site_key = md5( uniqid( wp_generate_password() ) ); - update_option( 'elementor_connect_site_key', $site_key ); - } - - return $site_key; - } - - private static function get_transient( $cache_key ) { - $cache = get_option( $cache_key ); - - if ( empty( $cache['timeout'] ) ) { - return false; - } - - if ( time() > $cache['timeout'] ) { - return false; - } - - return json_decode( $cache['value'], true ); - } - - private static function set_transient( $cache_key, $value, $expiration = '+12 hours' ) { - $data = [ - 'timeout' => strtotime( $expiration, time() ), - 'value' => wp_json_encode( $value ), - ]; - - return update_option( $cache_key, $data, false ); - } -} From abf32703b73054ed95c795854ea3c479bca296df Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Sun, 29 Dec 2024 14:15:40 +0200 Subject: [PATCH 3/8] lint --- assets/dev/js/admin/pages/settings-page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/dev/js/admin/pages/settings-page.js b/assets/dev/js/admin/pages/settings-page.js index b5b735aa..4abccfd2 100644 --- a/assets/dev/js/admin/pages/settings-page.js +++ b/assets/dev/js/admin/pages/settings-page.js @@ -123,7 +123,7 @@ export const SettingsPage = () => { const dialog = document.getElementById( 'hello-elementor-notifications-dialog' ); if ( dialog ) { - dialog.showModal() + dialog.showModal(); } } } > From 2fd135a20d50dcc4616b31db8f88152a14228601 Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Sun, 29 Dec 2024 14:18:23 +0200 Subject: [PATCH 4/8] lint --- includes/settings-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/settings-functions.php b/includes/settings-functions.php index 35c888ec..9e7df2c1 100644 --- a/includes/settings-functions.php +++ b/includes/settings-functions.php @@ -135,7 +135,7 @@ function hello_elementor_settings_page_footer() {

-

+

From 1e33216e4fe99fd2c0efb0c5fcc0592deb6b3bf0 Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Sun, 29 Dec 2024 14:20:49 +0200 Subject: [PATCH 5/8] Added composer for build --- .github/workflows/build.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aae65597..43a01d1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,8 +25,30 @@ jobs: ${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build- ${{ runner.os }}- + - name: "Debug info: show tooling versions" + continue-on-error: true + run: | + set +e + echo "Start debug Info" + echo "Date: ${{ steps.date.outputs.date }}" + echo "PHP Version: $(php -v)" + echo "Composer Version: $(composer --version)" + echo "Node Version: $(node --version)" + echo "NPM Version: $(npm --version)" + echo "GIT Version: $(git --version)" + echo "The github context is:" + echo "${{ toJson(github) }}" + echo "The Theme version is:" + echo "${{ env.PACKAGE_VERSION }}" + echo "The Theme slug is:" + echo "${{ env.THEME_SLUG }}" + echo "End debug Info" + echo "exitcode=$?" >> $GITHUB_OUTPUT - name: Install Dependencies run: npm ci + - name: Install Composer dependencies + run: + composer install --no-dev - name: Bump version on push to release or develop if: github.event_name == 'push' && (startsWith(github.ref, 'refs/heads/release/') || github.ref == 'refs/heads/develop') run: | From 59c36d5e09edd5e1e2d930f7b46224524366c26e Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Sun, 29 Dec 2024 14:23:00 +0200 Subject: [PATCH 6/8] Added composer for build --- .buildignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.buildignore b/.buildignore index 21e8d383..00142c57 100644 --- a/.buildignore +++ b/.buildignore @@ -15,7 +15,6 @@ package.json phpcs.xml README.md webpack.config.js -vendor/ .github/ .buildignore From b9507f97f55e03a24e8975bc4128d3b4d3ddd4fd Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Wed, 15 Jan 2025 14:29:08 +0200 Subject: [PATCH 7/8] Update the prod package --- composer.json | 2 +- composer.lock | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 8b5991c0..8d3774dc 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "wp-coding-standards/wpcs": "^2.3" }, "require": { - "elementor/wp-notifications-package": "dev-tweak/ED-16360-initial-wip" + "elementor/wp-notifications-package": "1.0.0" }, "config": { "allow-plugins": { diff --git a/composer.lock b/composer.lock index 2a796f04..9eecf3b1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "986bbddca7dec5609d5a6b3ff85356e8", + "content-hash": "ed24e216ae4961c3f07c1dbe359331c1", "packages": [ { "name": "elementor/wp-notifications-package", - "version": "dev-tweak/ED-16360-initial-wip", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/elementor/wp-notifications-package.git", - "reference": "db1f35ccf4e9a9d7a681f722108dd8e20a82e4ac" + "reference": "ba1f449081b3077a1418cfb50e45b89038745ea3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/elementor/wp-notifications-package/zipball/db1f35ccf4e9a9d7a681f722108dd8e20a82e4ac", - "reference": "db1f35ccf4e9a9d7a681f722108dd8e20a82e4ac", + "url": "https://api.github.com/repos/elementor/wp-notifications-package/zipball/ba1f449081b3077a1418cfb50e45b89038745ea3", + "reference": "ba1f449081b3077a1418cfb50e45b89038745ea3", "shasum": "" }, "require-dev": { @@ -40,9 +40,9 @@ ] }, "support": { - "source": "https://github.com/elementor/wp-notifications-package/tree/tweak/ED-16360-initial-wip" + "source": "https://github.com/elementor/wp-notifications-package/tree/v1.0.0" }, - "time": "2024-12-26T12:24:55+00:00" + "time": "2025-01-15T12:20:53+00:00" } ], "packages-dev": [ @@ -255,9 +255,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "elementor/wp-notifications-package": 20 - }, + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": {}, From c452ee965c06d230d5fae3dbccd1663a6372ccc8 Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Wed, 15 Jan 2025 14:32:42 +0200 Subject: [PATCH 8/8] updte the base package --- composer.json | 8 +------- composer.lock | 11 ++--------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 8d3774dc..0fcba73e 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,5 @@ }, "scripts": { "lint": "phpcs --extensions=php -p" - }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/elementor/wp-notifications-package" - } - ] + } } diff --git a/composer.lock b/composer.lock index 9eecf3b1..f7bc3834 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ed24e216ae4961c3f07c1dbe359331c1", + "content-hash": "e472277d42ff79f964e91145a530bd8e", "packages": [ { "name": "elementor/wp-notifications-package", @@ -31,14 +31,7 @@ "Elementor\\WPNotificationsPackage\\": "src/" } }, - "scripts": { - "lint": [ - "vendor/bin/phpcs --standard=./phpcs.xml ." - ], - "lint:fix": [ - "vendor/bin/phpcbf ." - ] - }, + "notification-url": "https://packagist.org/downloads/", "support": { "source": "https://github.com/elementor/wp-notifications-package/tree/v1.0.0" },