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 .= '