Skip to content

Commit

Permalink
v2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
algoritmika committed Jan 6, 2025
1 parent bb5a38a commit 4d2ea0f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
4 changes: 2 additions & 2 deletions custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.0
Version: 2.4.1
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: custom-css
Expand All @@ -14,7 +14,7 @@

defined( 'ABSPATH' ) || exit;

defined( 'ALG_CCJP_VERSION' ) || define( 'ALG_CCJP_VERSION', '2.4.0' );
defined( 'ALG_CCJP_VERSION' ) || define( 'ALG_CCJP_VERSION', '2.4.1' );

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

Expand Down
34 changes: 30 additions & 4 deletions includes/class-alg-custom-css-js-php-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Custom CSS, JS & PHP - Core Class
*
* @version 2.2.0
* @version 2.4.1
* @since 1.0.0
*
* @author Algoritmika Ltd.
Expand All @@ -17,13 +17,14 @@ class Alg_Custom_CSS_JS_PHP_Core {
/**
* Constructor.
*
* @version 2.2.0
* @version 2.4.1
* @since 1.0.0
*
* @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
foreach ( array( 'css', 'js' ) as $css_or_js ) {
foreach ( array( 'front', 'back' ) as $front_or_back ) {
Expand All @@ -39,10 +40,35 @@ function __construct() {
}
}
}

// PHP
if ( 'yes' === get_alg_ccjp_option( 'php_enabled', 'no' ) ) {
$this->run_custom_php();
$php_execute = get_alg_ccjp_option( 'php_execute', 'plugins_loaded' );
switch ( $php_execute ) {
case 'plugins_loaded':
$this->run_custom_php();
break;
case 'shortcode':
add_shortcode( 'alg_custom_php', array( $this, 'add_custom_php_shortcode' ) );
break;
}
}

}

/**
* add_custom_php_shortcode.
*
* @version 2.4.1
* @since 2.4.1
*/
function add_custom_php_shortcode( $atts, $content ) {
ob_start();
$file_path = $this->get_custom_php_file_path();
if ( file_exists( $file_path ) ) {
include_once $file_path;
}
return ob_get_clean();
}

/**
Expand Down Expand Up @@ -89,7 +115,7 @@ function run_custom_php() {
// Executing custom PHP code
$file_path = $this->get_custom_php_file_path();
if ( file_exists( $file_path ) ) {
include_once( $file_path );
include_once $file_path;
}
}

Expand Down
17 changes: 13 additions & 4 deletions includes/settings/class-alg-custom-css-js-php-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Custom CSS, JS & PHP - Settings Class
*
* @version 2.4.0
* @version 2.4.1
* @since 1.0.0
*
* @author Algoritmika Ltd.
Expand Down Expand Up @@ -336,7 +336,7 @@ function create_plugin_options_page( $section ) {
/**
* get_settings.
*
* @version 2.4.0
* @version 2.4.1
* @since 1.0.0
*
* @todo (desc) custom PHP: `defined( 'ABSPATH' ) || exit;`
Expand Down Expand Up @@ -468,8 +468,8 @@ function get_settings( $section ) {
'id' => 'php_options',
'desc_tip' =>
sprintf(
/* Translators: %1$s: Attribute name, %2$s: WordPress login page. */
__( 'Please note that if you enable custom PHP and enter non-valid PHP code here, your site will become unavailable. To fix this you will have to add %1$s attribute to the URL (you must be logged as shop manager or admin (for this reason custom PHP code is not executed on %2$s page)).', 'custom-css' ),
/* Translators: %1$s: Parameter name, %2$s: WordPress login page. */
__( 'Please note that if you enable custom PHP and enter non-valid PHP code here, your site will become unavailable. To fix this you will have to add %1$s parameter to the URL (you must be logged as shop manager or admin (for this reason custom PHP code is not executed on %2$s page)).', 'custom-css' ),
'<code>alg_disable_custom_php</code>',
'<strong>wp-login.php</strong>'
) . ' ' .
Expand All @@ -488,6 +488,15 @@ function get_settings( $section ) {
'default' => 'no',
'type' => 'checkbox',
),
array(
'id' => 'php_execute',
'default' => 'plugins_loaded',
'type' => 'select',
'options' => array(
'plugins_loaded' => __( 'Execute on `plugins_loaded` action', 'custom-css' ),
'shortcode' => __( 'Execute in `[alg_custom_php]` shortcode', 'custom-css' ),
),
),
array(
'desc_tip' => sprintf(
/* Translators: %s: Tag name. */
Expand Down
14 changes: 11 additions & 3 deletions langs/custom-css.pot
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ msgstr ""
msgid ""
"Please note that if you enable custom PHP and enter non-valid PHP code here, "
"your site will become unavailable. To fix this you will have to add %1$s "
"attribute to the URL (you must be logged as shop manager or admin (for this "
"parameter to the URL (you must be logged as shop manager or admin (for this "
"reason custom PHP code is not executed on %2$s page))."
msgstr ""

Expand All @@ -113,12 +113,20 @@ msgstr ""
msgid "Enable custom PHP"
msgstr ""

#: includes/settings/class-alg-custom-css-js-php-settings.php:494
#: includes/settings/class-alg-custom-css-js-php-settings.php:496
msgid "Execute on `plugins_loaded` action"
msgstr ""

#: includes/settings/class-alg-custom-css-js-php-settings.php:497
msgid "Execute in `[alg_custom_php]` shortcode"
msgstr ""

#: includes/settings/class-alg-custom-css-js-php-settings.php:503
#, php-format
msgid "PHP code (start with the %s tag):"
msgstr ""

#: includes/settings/class-alg-custom-css-js-php-settings.php:505
#: includes/settings/class-alg-custom-css-js-php-settings.php:514
#, php-format
msgid "Automatically created PHP file: %s"
msgstr ""
11 changes: 10 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: wpcodefactory, algoritmika, anbinder, karzin, omardabbas
Tags: css, js, php, javascript
Requires at least: 4.4
Tested up to: 6.7
Stable tag: 2.4.0
Stable tag: 2.4.1
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -21,6 +21,12 @@ Just another custom CSS, JavaScript & PHP tool for WordPress.

* We are open to your suggestions and feedback. Thank you for using or trying out one of our plugins!

== Frequently Asked Questions ==

= How do I disable (non-valid) PHP code? =

Add `alg_disable_custom_php` parameter to the URL, e.g.: `http://example.com/wp-admin/tools.php?page=alg-custom-php&alg_disable_custom_php`.

== Installation ==

1. Upload the entire plugin folder to the `/wp-content/plugins/` directory.
Expand All @@ -35,6 +41,9 @@ Just another custom CSS, JavaScript & PHP tool for WordPress.

== Changelog ==

= 2.4.1 - 06/01/2025 =
* Dev - Custom PHP - "Execute" option added. Defaults to "Execute on `plugins_loaded` action". New option: "Execute in `[alg_custom_php]` shortcode".

= 2.4.0 - 22/11/2024 =
* Dev - Security - Output escaped.
* Dev - Coding standards improved.
Expand Down

0 comments on commit 4d2ea0f

Please sign in to comment.