Plugin Directory

Changeset 3365809


Ignore:
Timestamp:
09/22/2025 12:14:21 PM (6 months ago)
Author:
diagnoseo
Message:

custom script support improved

Location:
diagnoseo
Files:
3 edited
51 copied

Legend:

Unmodified
Added
Removed
  • diagnoseo/tags/1.2.54/diagnoseo.php

    r3364584 r3365809  
    44 * Plugin URI: https://diagnoseo.com/wordpress-seo-plugin/
    55 * Description: Powerful SEO plugin for WordPress. The most lightweight and complete SEO solution on the market! It includes best-in-class content analyzer and keyword placement checkpoints.
    6  * Version: 1.2.53
     6 * Version: 1.2.54
    77 * Author: DiagnoSEO
    88 * Author URI: https://diagnoseo.com/
  • diagnoseo/tags/1.2.54/includes/class-diagnoseo-scripts.php

    r3364584 r3365809  
    2727     */
    2828    public function embed_header_scripts() {
    29         $script = get_option( 'diagnoseo_header_scripts' );
    30         if ( ! empty( $script ) ) {
    31             echo '<script>' . wp_strip_all_tags( $script ) . '</script>'; //phpcs:ignore
    32         }
     29        echo $this::prepare_output( 'diagnoseo_header_scripts' ); //phpcs:ignore
    3330    }
    3431    /**
     
    3633     */
    3734    public function embed_body_scripts() {
    38         $script = get_option( 'diagnoseo_body_scripts' );
    39         if ( ! empty( $script ) ) {
    40             echo '<script>' . wp_strip_all_tags( $script ) . '</script>'; //phpcs:ignore
    41         }
     35        echo $this::prepare_output( 'diagnoseo_body_scripts' ); //phpcs:ignore
    4236    }
    4337
     
    4640     */
    4741    public function embed_footer_scripts() {
    48         $script = get_option( 'diagnoseo_footer_scripts' );
    49         if ( ! empty( $script ) ) {
    50             echo '<script>' . wp_strip_all_tags( $script ) . '</script>'; //phpcs:ignore
     42        echo $this::prepare_output( 'diagnoseo_footer_scripts' ); //phpcs:ignore
     43    }
     44
     45    /**
     46     * Prepares script output - checks if <script> tags are present and adds them if necessary
     47     *
     48     * Returns the original string if it already contains both an opening <script ...>
     49     * and a closing </script> tag (in any case and with any attributes). Otherwise,
     50     * it wraps the content in <script>...</script>.
     51     *
     52     * @param string $option_name Option to fetch the script from.
     53     * @return string Prepared script block ready for output.
     54     */
     55    public static function prepare_output( $option_name ) {
     56        $script = get_option( $option_name, '' );
     57        if ( empty( $script ) ) {
     58            return '';
    5159        }
     60
     61        $script = trim( (string) $script );
     62
     63        $has_open  = (bool) preg_match( '/<\s*script\b[^>]*>/i', $script );
     64        $has_close = (bool) preg_match( '/<\s*\/\s*script\s*>/i', $script );
     65
     66        if ( $has_open && $has_close ) {
     67            return $script;
     68        }
     69
     70        return "<script>\n{$script}\n</script>";
    5271    }
    5372}
  • diagnoseo/tags/1.2.54/readme.txt

    r3364584 r3365809  
    44Requires at least: 4.7
    55Tested up to: 6.8
    6 Stable tag: 1.2.53
     6Stable tag: 1.2.54
    77Requires PHP: 7.2
    88License: GPLv2 or later
  • diagnoseo/trunk/diagnoseo.php

    r3364584 r3365809  
    44 * Plugin URI: https://diagnoseo.com/wordpress-seo-plugin/
    55 * Description: Powerful SEO plugin for WordPress. The most lightweight and complete SEO solution on the market! It includes best-in-class content analyzer and keyword placement checkpoints.
    6  * Version: 1.2.53
     6 * Version: 1.2.54
    77 * Author: DiagnoSEO
    88 * Author URI: https://diagnoseo.com/
  • diagnoseo/trunk/includes/class-diagnoseo-scripts.php

    r3364584 r3365809  
    2727     */
    2828    public function embed_header_scripts() {
    29         $script = get_option( 'diagnoseo_header_scripts' );
    30         if ( ! empty( $script ) ) {
    31             echo '<script>' . wp_strip_all_tags( $script ) . '</script>'; //phpcs:ignore
    32         }
     29        echo $this::prepare_output( 'diagnoseo_header_scripts' ); //phpcs:ignore
    3330    }
    3431    /**
     
    3633     */
    3734    public function embed_body_scripts() {
    38         $script = get_option( 'diagnoseo_body_scripts' );
    39         if ( ! empty( $script ) ) {
    40             echo '<script>' . wp_strip_all_tags( $script ) . '</script>'; //phpcs:ignore
    41         }
     35        echo $this::prepare_output( 'diagnoseo_body_scripts' ); //phpcs:ignore
    4236    }
    4337
     
    4640     */
    4741    public function embed_footer_scripts() {
    48         $script = get_option( 'diagnoseo_footer_scripts' );
    49         if ( ! empty( $script ) ) {
    50             echo '<script>' . wp_strip_all_tags( $script ) . '</script>'; //phpcs:ignore
     42        echo $this::prepare_output( 'diagnoseo_footer_scripts' ); //phpcs:ignore
     43    }
     44
     45    /**
     46     * Prepares script output - checks if <script> tags are present and adds them if necessary
     47     *
     48     * Returns the original string if it already contains both an opening <script ...>
     49     * and a closing </script> tag (in any case and with any attributes). Otherwise,
     50     * it wraps the content in <script>...</script>.
     51     *
     52     * @param string $option_name Option to fetch the script from.
     53     * @return string Prepared script block ready for output.
     54     */
     55    public static function prepare_output( $option_name ) {
     56        $script = get_option( $option_name, '' );
     57        if ( empty( $script ) ) {
     58            return '';
    5159        }
     60
     61        $script = trim( (string) $script );
     62
     63        $has_open  = (bool) preg_match( '/<\s*script\b[^>]*>/i', $script );
     64        $has_close = (bool) preg_match( '/<\s*\/\s*script\s*>/i', $script );
     65
     66        if ( $has_open && $has_close ) {
     67            return $script;
     68        }
     69
     70        return "<script>\n{$script}\n</script>";
    5271    }
    5372}
  • diagnoseo/trunk/readme.txt

    r3364584 r3365809  
    44Requires at least: 4.7
    55Tested up to: 6.8
    6 Stable tag: 1.2.53
     6Stable tag: 1.2.54
    77Requires PHP: 7.2
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.