From 82249faaab1c94c8c41b32a4e31dad6c6339fe50 Mon Sep 17 00:00:00 2001 From: algoritmika Date: Thu, 5 Sep 2024 13:50:11 +0300 Subject: [PATCH] v2.3.0 --- custom-css.php | 4 +- includes/class-alg-custom-css-js-php-core.php | 6 +- includes/class-alg-custom-css-js-php.php | 18 +++- .../class-alg-custom-css-js-php-settings.php | 94 +++++++++++++++---- langs/custom-css.pot | 86 ++++++++--------- readme.txt | 12 ++- 6 files changed, 152 insertions(+), 68 deletions(-) diff --git a/custom-css.php b/custom-css.php index a9dbbf8..6710449 100644 --- a/custom-css.php +++ b/custom-css.php @@ -3,7 +3,7 @@ Plugin Name: Custom CSS, JS & PHP Plugin URI: https://wpfactory.com Description: Just another custom CSS, JavaScript & PHP tool for WordPress. -Version: 2.2.1 +Version: 2.3.0 Author: WPFactory Author URI: https://wpfactory.com Text Domain: custom-css @@ -12,7 +12,7 @@ defined( 'ABSPATH' ) || exit; -defined( 'ALG_CCJP_VERSION' ) || define( 'ALG_CCJP_VERSION', '2.2.1' ); +defined( 'ALG_CCJP_VERSION' ) || define( 'ALG_CCJP_VERSION', '2.3.0' ); defined( 'ALG_CCJP_ID' ) || define( 'ALG_CCJP_ID', 'alg_custom_css' ); // Should be named `alg_ccjp`, but is named `alg_custom_css` for backwards compatibility diff --git a/includes/class-alg-custom-css-js-php-core.php b/includes/class-alg-custom-css-js-php-core.php index 3a6acec..501de7d 100644 --- a/includes/class-alg-custom-css-js-php-core.php +++ b/includes/class-alg-custom-css-js-php-core.php @@ -8,7 +8,7 @@ * @author Algoritmika Ltd. */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'Alg_Custom_CSS_JS_PHP_Core' ) ) : @@ -20,8 +20,8 @@ class Alg_Custom_CSS_JS_PHP_Core { * @version 2.2.0 * @since 1.0.0 * - * @todo [next] (feature) add option to set "custom CSS / JS" on per product basis (i.e. single product page) - * @todo [next] (feature) CSS and JS minimization + * @todo (feature) add option to set "custom CSS / JS" on per product basis (i.e., single product page) + * @todo (feature) CSS and JS minimization */ function __construct() { // CSS & JS diff --git a/includes/class-alg-custom-css-js-php.php b/includes/class-alg-custom-css-js-php.php index 5cc13c0..de7a33f 100644 --- a/includes/class-alg-custom-css-js-php.php +++ b/includes/class-alg-custom-css-js-php.php @@ -2,7 +2,7 @@ /** * Custom CSS, JS & PHP - Main Class * - * @version 2.2.0 + * @version 2.3.0 * @since 1.0.0 * * @author Algoritmika Ltd. @@ -20,6 +20,22 @@ final class Alg_CCJP { */ protected static $_instance = null; + /** + * core. + * + * @version 2.3.0 + * @since 2.3.0 + */ + public $core; + + /** + * settings. + * + * @version 2.3.0 + * @since 2.3.0 + */ + public $settings; + /** * Main Alg_CCJP Instance * diff --git a/includes/settings/class-alg-custom-css-js-php-settings.php b/includes/settings/class-alg-custom-css-js-php-settings.php index a746aa1..711e3f8 100644 --- a/includes/settings/class-alg-custom-css-js-php-settings.php +++ b/includes/settings/class-alg-custom-css-js-php-settings.php @@ -2,13 +2,13 @@ /** * Custom CSS, JS & PHP - Settings Class * - * @version 2.1.0 + * @version 2.3.0 * @since 1.0.0 * * @author Algoritmika Ltd. */ -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly +defined( 'ABSPATH' ) || exit; if ( ! class_exists( 'Alg_Custom_CSS_JS_PHP_Settings' ) ) : @@ -17,21 +17,77 @@ class Alg_Custom_CSS_JS_PHP_Settings { /** * Constructor. * - * @version 2.1.0 + * @version 2.3.0 * @since 1.0.0 * - * @todo [next] (feature) add option to set custom PHP file path (i.e. dir and name) (instead of `uploads_dir/alg-custom-php/custom-php.php`) - * @todo [next] (feature) implement CSS, JS, PHP editors instead of simple textareas - * @todo [next] (dev) allow "tab" in content - * @todo [next] (dev) `require_once( untrailingslashit( plugin_dir_path( ALG_CCJP_PLUGIN_FILE ) ) . '/includes/lib/csstidy-1.3/class.csstidy.php' );` and `$this->csstidy = new csstidy();` + * @todo (feature) add option to set custom PHP file path (i.e., dir and name) (instead of `uploads_dir/alg-custom-php/custom-php.php`) + * @todo (dev) `require_once( untrailingslashit( plugin_dir_path( ALG_CCJP_PLUGIN_FILE ) ) . '/includes/lib/csstidy-1.3/class.csstidy.php' );` and `$this->csstidy = new csstidy();` */ function __construct() { if ( is_admin() ) { add_action( 'admin_init', array( $this, 'save_options' ) ); add_action( 'admin_menu', array( $this, 'add_plugin_options_pages' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_code_editor_scripts' ) ); } } + /** + * enqueue_code_editor_scripts. + * + * @version 2.3.0 + * @since 2.3.0 + * + * @see https://developer.wordpress.org/reference/functions/wp_enqueue_code_editor/ + * + * @todo (dev) make this optional? + */ + function enqueue_code_editor_scripts() { + + // Get type + if ( ! function_exists( 'get_current_screen' ) ) { + return; + } + $type = false; + $screen = get_current_screen(); + switch ( $screen->id ) { + case 'tools_page_alg-custom-css': + $type = 'css'; + $ids = array( 'alg_custom_css_front_end_css', 'alg_custom_css_back_end_css' ); + break; + case 'tools_page_alg-custom-js': + $type = 'javascript'; + $ids = array( 'alg_custom_css_front_end_js', 'alg_custom_css_back_end_js' ); + break; + case 'tools_page_alg-custom-php': + $type = 'php'; + $ids = array( 'alg_custom_css_php' ); + break; + } + if ( ! $type ) { + return; + } + + // Enqueue code editor and settings + if ( false === ( $settings = wp_enqueue_code_editor( array( 'type' => $type ) ) ) ) { + return; + } + + // Add inline script + $script = array(); + foreach ( $ids as $id ) { + $script[] = sprintf( + 'jQuery( function () { wp.codeEditor.initialize( "%s", %s ); } );', + $id, + wp_json_encode( $settings ) + ); + } + wp_add_inline_script( + 'code-editor', + implode( PHP_EOL, $script ) + ); + + } + /* * add_plugin_options_pages. * @@ -71,7 +127,7 @@ function add_plugin_options_pages() { * @version 2.0.0 * @since 1.0.0 * - * @todo [next] (dev) `$this->csstidy->parse( $value );` and `$this->csstidy->print->plain();` (but preserve spaces at line start, disable optimization etc.) + * @todo (dev) `$this->csstidy->parse( $value );` and `$this->csstidy->print->plain();` (but preserve spaces at line start, disable optimization etc.) */ function sanitize_content( $value ) { return stripslashes( $value ); @@ -115,7 +171,7 @@ function save_options() { /** * handle_custom_php_file. * - * @version 2.0.0 + * @version 2.3.0 * @since 2.0.0 */ function handle_custom_php_file() { @@ -124,7 +180,10 @@ function handle_custom_php_file() { $file_content = get_alg_ccjp_option( 'php', '' ); if ( '' !== $file_content ) { $file_path = alg_ccjp()->core->get_custom_php_file_path( true ); - file_put_contents( $file_path, '' . $settings['desc_tip'] . '

' : '' ) . '' . - ( isset( $settings['desc'] ) ? '' . $settings['desc'] . '' : '' ), + ( isset( $settings['desc'] ) ? '

' . '' . $settings['desc'] . '' . '

' : '' ), ); break; case 'select': @@ -232,6 +291,7 @@ function create_plugin_options_page( $section ) { strtoupper( $_section ) . ''; } $html = ''; + $html .= ''; $html .= '
'; $html .= '

' . __( 'Custom CSS, JS & PHP', 'custom-css' ) . '

'; $html .= '

' . __( 'Just another custom CSS, JavaScript & PHP tool for WordPress.', 'custom-css' ) . '

'; @@ -239,7 +299,7 @@ function create_plugin_options_page( $section ) { $html .= '
'; $html .= $this->get_table_html( $table_data, array( 'table_style' => 'width:100%;', - 'table_class' => 'widefat striped', + 'table_class' => 'widefat alg_ccjp_striped', 'table_heading_type' => 'vertical', 'columns_styles' => array( 'width:20%', 'width:80%' ) ) ); @@ -253,10 +313,10 @@ function create_plugin_options_page( $section ) { /** * get_settings. * - * @version 2.1.0 + * @version 2.3.0 * @since 1.0.0 * - * @todo [maybe] (desc) custom PHP: `if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly` + * @todo (desc) custom PHP: `defined( 'ABSPATH' ) || exit;` */ function get_settings( $section ) { $textarea_style = 'width:100%; min-height:300px; font-family:Courier New,Courier,monospace; color: black;'; @@ -396,7 +456,7 @@ function get_settings( $section ) { 'type' => 'checkbox', ), array( - 'desc_tip' => sprintf( __( 'PHP code (without the %s tag):', 'custom-css' ), '' . esc_html( '' ), + 'desc_tip' => sprintf( __( 'PHP code (start with the %s tag):', 'custom-css' ), '' . esc_html( '' ), 'id' => 'php', 'default' => '', 'type' => 'textarea', diff --git a/langs/custom-css.pot b/langs/custom-css.pot index 1a9477a..ed47590 100644 --- a/langs/custom-css.pot +++ b/langs/custom-css.pot @@ -1,97 +1,97 @@ -#: includes/settings/class-alg-custom-css-js-php-settings.php:44 -#: includes/settings/class-alg-custom-css-js-php-settings.php:45 -#: includes/settings/class-alg-custom-css-js-php-settings.php:266 +#: includes/settings/class-alg-custom-css-js-php-settings.php:100 +#: includes/settings/class-alg-custom-css-js-php-settings.php:101 +#: includes/settings/class-alg-custom-css-js-php-settings.php:326 msgid "Custom CSS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:52 -#: includes/settings/class-alg-custom-css-js-php-settings.php:53 +#: includes/settings/class-alg-custom-css-js-php-settings.php:108 +#: includes/settings/class-alg-custom-css-js-php-settings.php:109 msgid "Custom JS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:60 -#: includes/settings/class-alg-custom-css-js-php-settings.php:61 -#: includes/settings/class-alg-custom-css-js-php-settings.php:383 +#: includes/settings/class-alg-custom-css-js-php-settings.php:116 +#: includes/settings/class-alg-custom-css-js-php-settings.php:117 +#: includes/settings/class-alg-custom-css-js-php-settings.php:443 msgid "Custom PHP" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:236 +#: includes/settings/class-alg-custom-css-js-php-settings.php:296 msgid "Custom CSS, JS & PHP" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:237 +#: includes/settings/class-alg-custom-css-js-php-settings.php:297 msgid "Just another custom CSS, JavaScript & PHP tool for WordPress." msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:247 +#: includes/settings/class-alg-custom-css-js-php-settings.php:307 msgid "Save changes" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:271 -#: includes/settings/class-alg-custom-css-js-php-settings.php:294 +#: includes/settings/class-alg-custom-css-js-php-settings.php:331 +#: includes/settings/class-alg-custom-css-js-php-settings.php:354 msgid "CSS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:271 -#: includes/settings/class-alg-custom-css-js-php-settings.php:329 +#: includes/settings/class-alg-custom-css-js-php-settings.php:331 +#: includes/settings/class-alg-custom-css-js-php-settings.php:389 msgid "front-end" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:272 +#: includes/settings/class-alg-custom-css-js-php-settings.php:332 msgid "Enable custom front-end CSS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:282 -#: includes/settings/class-alg-custom-css-js-php-settings.php:305 -#: includes/settings/class-alg-custom-css-js-php-settings.php:340 -#: includes/settings/class-alg-custom-css-js-php-settings.php:363 +#: includes/settings/class-alg-custom-css-js-php-settings.php:342 +#: includes/settings/class-alg-custom-css-js-php-settings.php:365 +#: includes/settings/class-alg-custom-css-js-php-settings.php:400 +#: includes/settings/class-alg-custom-css-js-php-settings.php:423 msgid "Load in header" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:283 -#: includes/settings/class-alg-custom-css-js-php-settings.php:306 -#: includes/settings/class-alg-custom-css-js-php-settings.php:341 -#: includes/settings/class-alg-custom-css-js-php-settings.php:364 +#: includes/settings/class-alg-custom-css-js-php-settings.php:343 +#: includes/settings/class-alg-custom-css-js-php-settings.php:366 +#: includes/settings/class-alg-custom-css-js-php-settings.php:401 +#: includes/settings/class-alg-custom-css-js-php-settings.php:424 msgid "Load in footer" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:287 -#: includes/settings/class-alg-custom-css-js-php-settings.php:310 +#: includes/settings/class-alg-custom-css-js-php-settings.php:347 +#: includes/settings/class-alg-custom-css-js-php-settings.php:370 msgid "CSS code:" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:294 -#: includes/settings/class-alg-custom-css-js-php-settings.php:352 +#: includes/settings/class-alg-custom-css-js-php-settings.php:354 +#: includes/settings/class-alg-custom-css-js-php-settings.php:412 msgid "back-end (admin)" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:295 +#: includes/settings/class-alg-custom-css-js-php-settings.php:355 msgid "Enable custom back-end CSS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:324 +#: includes/settings/class-alg-custom-css-js-php-settings.php:384 msgid "Custom JavaScript" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:329 -#: includes/settings/class-alg-custom-css-js-php-settings.php:352 +#: includes/settings/class-alg-custom-css-js-php-settings.php:389 +#: includes/settings/class-alg-custom-css-js-php-settings.php:412 msgid "JS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:330 +#: includes/settings/class-alg-custom-css-js-php-settings.php:390 msgid "Enable custom front-end JS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:345 -#: includes/settings/class-alg-custom-css-js-php-settings.php:368 +#: includes/settings/class-alg-custom-css-js-php-settings.php:405 +#: includes/settings/class-alg-custom-css-js-php-settings.php:428 msgid "JS code:" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:353 +#: includes/settings/class-alg-custom-css-js-php-settings.php:413 msgid "Enable custom back-end JS" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:387 +#: includes/settings/class-alg-custom-css-js-php-settings.php:447 #, php-format msgid "" "Please note that if you enable custom PHP and enter non-valid PHP code here, " @@ -100,25 +100,25 @@ msgid "" "reason custom PHP code is not executed on %s page))." msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:389 +#: includes/settings/class-alg-custom-css-js-php-settings.php:449 #, php-format msgid "E.g.: %s" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:392 +#: includes/settings/class-alg-custom-css-js-php-settings.php:452 msgid "PHP" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:393 +#: includes/settings/class-alg-custom-css-js-php-settings.php:453 msgid "Enable custom PHP" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:399 +#: includes/settings/class-alg-custom-css-js-php-settings.php:459 #, php-format -msgid "PHP code (without the %s tag):" +msgid "PHP code (start with the %s tag):" msgstr "" -#: includes/settings/class-alg-custom-css-js-php-settings.php:405 +#: includes/settings/class-alg-custom-css-js-php-settings.php:465 #, php-format msgid "Automatically created PHP file: %s" msgstr "" diff --git a/readme.txt b/readme.txt index 1e7a825..56de6f0 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: wpcodefactory, algoritmika, anbinder Tags: css, js, php, javascript, custom css, custom js, custom php, custom javascript Requires at least: 4.4 -Tested up to: 6.1 -Stable tag: 2.2.1 +Tested up to: 6.6 +Stable tag: 2.3.0 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -35,6 +35,14 @@ Just another custom CSS, JavaScript & PHP tool for WordPress. == Changelog == += 2.3.0 - 05/09/2024 = +* Dev - Code editors added. +* Dev - Custom PHP - Now allows/recommends the opening tag. +* Dev - PHP 8.2 compatibility - "Creation of dynamic property is deprecated" notice fixed. +* Dev - Admin settings restyled. +* Dev - Code refactoring. +* Tested up to: 6.6. + = 2.2.1 - 09/12/2022 = * Tested up to: 6.1. * Readme.txt updated.