Plugin Directory

Changeset 3460471


Ignore:
Timestamp:
02/13/2026 03:51:07 AM (6 days ago)
Author:
webbiztw
Message:

Release 1.0.1 - Fix emphasis styles not displaying on frontend

Location:
webbiz-toolkit
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • webbiz-toolkit/tags/1.0.1/includes/class-wbz-toolkit-admin.php

    r3459973 r3460471  
    7171        add_action( 'admin_init', array( $this, 'register_settings' ) );
    7272        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
    73         add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_dynamic_css' ) );
    7473        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_dynamic_css' ) );
    7574
     
    492491                <p>
    493492                    <strong>WebBiz Toolkit</strong> v<?php echo esc_html( WEBBIZ_TOOLKIT_VERSION ); ?> |
    494                     <a href="https://webbiz.tw/" target="_blank">WebBiz</a>
     493                    <a href="<?php echo esc_url( 'https://webbiz.tw/' ); ?>" target="_blank">WebBiz</a>
    495494                </p>
    496495            </div>
     
    508507        $settings_link = sprintf(
    509508            '<a href="%s">%s</a>',
    510             admin_url( 'options-general.php?page=webbiz-toolkit' ),
    511             __( '設定', 'webbiz-toolkit' )
     509            esc_url( admin_url( 'options-general.php?page=webbiz-toolkit' ) ),
     510            esc_html__( '設定', 'webbiz-toolkit' )
    512511        );
    513512        array_unshift( $links, $settings_link );
  • webbiz-toolkit/tags/1.0.1/includes/class-wbz-toolkit.php

    r3459973 r3460471  
    5757        // 載入前台樣式
    5858        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_styles' ) );
     59
     60        // 載入前台動態 CSS(強調樣式等)
     61        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_dynamic_css' ) );
    5962    }
    6063
     
    7275
    7376    /**
     77     * 透過 wp_add_inline_style 輸出前台動態 CSS
     78     */
     79    public function enqueue_dynamic_css() {
     80        // 如果強調模組未啟用,不輸出
     81        if ( empty( $this->options['modules']['emphasis'] ) ) {
     82            return;
     83        }
     84
     85        $emphasis_styles = isset( $this->options['emphasis_styles'] ) ? $this->options['emphasis_styles'] : array();
     86
     87        // 預設樣式
     88        $defaults = array(
     89            1 => array(
     90                'text_color'   => '#1e40af',
     91                'bg_color'     => 'rgba(239, 246, 255, 0.8)',
     92                'border_color' => '#3b82f6',
     93                'border_style' => 'left',
     94                'border_width' => '2',
     95                'font_weight'  => 'bold',
     96            ),
     97            2 => array(
     98                'text_color'   => '#991b1b',
     99                'bg_color'     => 'rgba(254, 242, 242, 0.8)',
     100                'border_color' => '#dc2626',
     101                'border_style' => 'all',
     102                'border_width' => '1',
     103                'font_weight'  => 'bold',
     104            ),
     105            3 => array(
     106                'text_color'   => '#92400e',
     107                'bg_color'     => 'transparent',
     108                'border_color' => '#f59e0b',
     109                'border_style' => 'bottom',
     110                'border_width' => '2',
     111                'font_weight'  => 'bold',
     112            ),
     113        );
     114
     115        $css = '';
     116
     117        foreach ( $defaults as $key => $default ) {
     118            $style = isset( $emphasis_styles[ $key ] ) ? wp_parse_args( $emphasis_styles[ $key ], $default ) : $default;
     119
     120            $safe_key = absint( $key );
     121            $selector = ".webbiz-emphasis-{$safe_key}";
     122
     123            $css .= "{$selector} {\n";
     124            $css .= "    display: inline !important;\n";
     125            $css .= "    white-space: normal !important;\n";
     126            $css .= "    border-radius: 2px !important;\n";
     127            $css .= "    transition: all 0.2s ease !important;\n";
     128            $css .= "    box-decoration-break: clone;\n";
     129            $css .= "    -webkit-box-decoration-break: clone;\n";
     130
     131            $text_color = $this->sanitize_css_color( $style['text_color'] ?? '' );
     132            if ( ! empty( $text_color ) ) {
     133                $css .= "    color: {$text_color} !important;\n";
     134            }
     135
     136            $bg_color = $this->sanitize_css_color( $style['bg_color'] ?? '' );
     137            if ( ! empty( $bg_color ) ) {
     138                $css .= "    background: {$bg_color} !important;\n";
     139            }
     140
     141            $font_weight = 'bold' === $style['font_weight'] ? '600' : 'normal';
     142            $css .= "    font-weight: {$font_weight} !important;\n";
     143
     144            $border_width = absint( $style['border_width'] );
     145            $border_color = $this->sanitize_css_color( $style['border_color'] ?? '' );
     146            if ( empty( $border_color ) ) {
     147                $border_color = '#000';
     148            }
     149
     150            $css .= "    border: none !important;\n";
     151
     152            switch ( $style['border_style'] ) {
     153                case 'left':
     154                    $css .= "    border-left: {$border_width}px solid {$border_color} !important;\n";
     155                    $css .= "    padding: 0 4px 0 6px !important;\n";
     156                    break;
     157                case 'all':
     158                    $css .= "    border: {$border_width}px solid {$border_color} !important;\n";
     159                    $css .= "    padding: 0 4px !important;\n";
     160                    break;
     161                case 'bottom':
     162                    $css .= "    border-bottom: {$border_width}px solid {$border_color} !important;\n";
     163                    $css .= "    padding: 0 2px 1px 2px !important;\n";
     164                    break;
     165                case 'none':
     166                    $css .= "    padding: 0 4px !important;\n";
     167                    break;
     168            }
     169
     170            $css .= "}\n\n";
     171        }
     172
     173        wp_register_style( 'webbiz-emphasis-dynamic', false, array(), WEBBIZ_TOOLKIT_VERSION );
     174        wp_enqueue_style( 'webbiz-emphasis-dynamic' );
     175        wp_add_inline_style( 'webbiz-emphasis-dynamic', $css );
     176    }
     177
     178    /**
     179     * 清理 CSS 顏色值(output escaping)
     180     *
     181     * @param string $color 顏色值。
     182     * @return string 安全的顏色值,無效時回傳空字串。
     183     */
     184    private function sanitize_css_color( $color ) {
     185        if ( empty( $color ) || ! is_string( $color ) ) {
     186            return '';
     187        }
     188
     189        if ( preg_match( '/^#([A-Fa-f0-9]{3}){1,2}$/', $color ) ) {
     190            return $color;
     191        }
     192
     193        if ( preg_match( '/^rgba?\(\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*(,\s*[\d]?\.?[\d]+\s*)?\)$/', $color ) ) {
     194            return $color;
     195        }
     196
     197        if ( 'transparent' === $color ) {
     198            return $color;
     199        }
     200
     201        return '';
     202    }
     203
     204    /**
    74205     * 載入啟用的模組
    75206     */
  • webbiz-toolkit/tags/1.0.1/modules/emphasis/emphasis.js

    r3459973 r3460471  
    99
    1010    if (!window.wp?.richText || !window.wp?.element) {
    11         console.warn('Webbiz Emphasis: WordPress editor APIs not available');
    1211        return;
    1312    }
     
    4241            return result;
    4342        } catch (error) {
    44             console.error('Webbiz Emphasis: Format toggle error', error);
    4543            return toggleFormat(value, format);
    4644        }
  • webbiz-toolkit/tags/1.0.1/modules/pangu/pangu.js

    r3459973 r3460471  
    1212    // 安全檢查
    1313    if (!window.wp?.data || !window.wp?.hooks || !window.wp?.element) {
    14         console.warn('Webbiz Pangu: WordPress editor APIs not available');
    1514        return;
    1615    }
  • webbiz-toolkit/tags/1.0.1/modules/qa-reveal/qa-reveal.js

    r3459973 r3460471  
    1313    // 安全檢查
    1414    if (!window.wp?.blocks || !window.wp?.element || !window.wp?.blockEditor) {
    15         console.warn('Webbiz QA Reveal: WordPress block APIs not available');
    1615        return;
    1716    }
  • webbiz-toolkit/tags/1.0.1/modules/spoiler/spoiler.js

    r3459973 r3460471  
    1313    // 安全檢查
    1414    if (!window.wp?.richText || !window.wp?.element) {
    15         console.warn('Webbiz Spoiler: WordPress editor APIs not available');
    1615        return;
    1716    }
  • webbiz-toolkit/tags/1.0.1/readme.txt

    r3459973 r3460471  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9898= Is this plugin translation-ready? =
    9999
    100 Yes, WebBiz Toolkit is fully internationalized and ready for translation. The admin interface is available in Traditional Chinese.
     100Yes, WebBiz Toolkit is fully internationalized and ready for translation.
    101101
    102102== Screenshots ==
     
    109109
    110110== Changelog ==
     111
     112= 1.0.1 =
     113* Fixed: Text emphasis styles not displaying on the frontend (CSS was only loaded in admin context)
    111114
    112115= 1.0.0 =
  • webbiz-toolkit/tags/1.0.1/webbiz-toolkit.php

    r3459973 r3460471  
    33 * Plugin Name: WebBiz Toolkit
    44 * Description: WordPress 部落客工具箱 - 文字強調樣式、劇透遮罩、中英文自動加空格、互動問答
    5  * Version: 1.0.0
     5 * Version: 1.0.1
    66 * Author: WebBiz
    77 * Author URI: https://webbiz.tw/
     
    2020
    2121// 外掛常數
    22 define( 'WEBBIZ_TOOLKIT_VERSION', '1.0.0' );
     22define( 'WEBBIZ_TOOLKIT_VERSION', '1.0.1' );
    2323define( 'WEBBIZ_TOOLKIT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    2424define( 'WEBBIZ_TOOLKIT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  • webbiz-toolkit/trunk/includes/class-wbz-toolkit-admin.php

    r3459973 r3460471  
    7171        add_action( 'admin_init', array( $this, 'register_settings' ) );
    7272        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
    73         add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_dynamic_css' ) );
    7473        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_dynamic_css' ) );
    7574
     
    492491                <p>
    493492                    <strong>WebBiz Toolkit</strong> v<?php echo esc_html( WEBBIZ_TOOLKIT_VERSION ); ?> |
    494                     <a href="https://webbiz.tw/" target="_blank">WebBiz</a>
     493                    <a href="<?php echo esc_url( 'https://webbiz.tw/' ); ?>" target="_blank">WebBiz</a>
    495494                </p>
    496495            </div>
     
    508507        $settings_link = sprintf(
    509508            '<a href="%s">%s</a>',
    510             admin_url( 'options-general.php?page=webbiz-toolkit' ),
    511             __( '設定', 'webbiz-toolkit' )
     509            esc_url( admin_url( 'options-general.php?page=webbiz-toolkit' ) ),
     510            esc_html__( '設定', 'webbiz-toolkit' )
    512511        );
    513512        array_unshift( $links, $settings_link );
  • webbiz-toolkit/trunk/includes/class-wbz-toolkit.php

    r3459973 r3460471  
    5757        // 載入前台樣式
    5858        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_styles' ) );
     59
     60        // 載入前台動態 CSS(強調樣式等)
     61        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_dynamic_css' ) );
    5962    }
    6063
     
    7275
    7376    /**
     77     * 透過 wp_add_inline_style 輸出前台動態 CSS
     78     */
     79    public function enqueue_dynamic_css() {
     80        // 如果強調模組未啟用,不輸出
     81        if ( empty( $this->options['modules']['emphasis'] ) ) {
     82            return;
     83        }
     84
     85        $emphasis_styles = isset( $this->options['emphasis_styles'] ) ? $this->options['emphasis_styles'] : array();
     86
     87        // 預設樣式
     88        $defaults = array(
     89            1 => array(
     90                'text_color'   => '#1e40af',
     91                'bg_color'     => 'rgba(239, 246, 255, 0.8)',
     92                'border_color' => '#3b82f6',
     93                'border_style' => 'left',
     94                'border_width' => '2',
     95                'font_weight'  => 'bold',
     96            ),
     97            2 => array(
     98                'text_color'   => '#991b1b',
     99                'bg_color'     => 'rgba(254, 242, 242, 0.8)',
     100                'border_color' => '#dc2626',
     101                'border_style' => 'all',
     102                'border_width' => '1',
     103                'font_weight'  => 'bold',
     104            ),
     105            3 => array(
     106                'text_color'   => '#92400e',
     107                'bg_color'     => 'transparent',
     108                'border_color' => '#f59e0b',
     109                'border_style' => 'bottom',
     110                'border_width' => '2',
     111                'font_weight'  => 'bold',
     112            ),
     113        );
     114
     115        $css = '';
     116
     117        foreach ( $defaults as $key => $default ) {
     118            $style = isset( $emphasis_styles[ $key ] ) ? wp_parse_args( $emphasis_styles[ $key ], $default ) : $default;
     119
     120            $safe_key = absint( $key );
     121            $selector = ".webbiz-emphasis-{$safe_key}";
     122
     123            $css .= "{$selector} {\n";
     124            $css .= "    display: inline !important;\n";
     125            $css .= "    white-space: normal !important;\n";
     126            $css .= "    border-radius: 2px !important;\n";
     127            $css .= "    transition: all 0.2s ease !important;\n";
     128            $css .= "    box-decoration-break: clone;\n";
     129            $css .= "    -webkit-box-decoration-break: clone;\n";
     130
     131            $text_color = $this->sanitize_css_color( $style['text_color'] ?? '' );
     132            if ( ! empty( $text_color ) ) {
     133                $css .= "    color: {$text_color} !important;\n";
     134            }
     135
     136            $bg_color = $this->sanitize_css_color( $style['bg_color'] ?? '' );
     137            if ( ! empty( $bg_color ) ) {
     138                $css .= "    background: {$bg_color} !important;\n";
     139            }
     140
     141            $font_weight = 'bold' === $style['font_weight'] ? '600' : 'normal';
     142            $css .= "    font-weight: {$font_weight} !important;\n";
     143
     144            $border_width = absint( $style['border_width'] );
     145            $border_color = $this->sanitize_css_color( $style['border_color'] ?? '' );
     146            if ( empty( $border_color ) ) {
     147                $border_color = '#000';
     148            }
     149
     150            $css .= "    border: none !important;\n";
     151
     152            switch ( $style['border_style'] ) {
     153                case 'left':
     154                    $css .= "    border-left: {$border_width}px solid {$border_color} !important;\n";
     155                    $css .= "    padding: 0 4px 0 6px !important;\n";
     156                    break;
     157                case 'all':
     158                    $css .= "    border: {$border_width}px solid {$border_color} !important;\n";
     159                    $css .= "    padding: 0 4px !important;\n";
     160                    break;
     161                case 'bottom':
     162                    $css .= "    border-bottom: {$border_width}px solid {$border_color} !important;\n";
     163                    $css .= "    padding: 0 2px 1px 2px !important;\n";
     164                    break;
     165                case 'none':
     166                    $css .= "    padding: 0 4px !important;\n";
     167                    break;
     168            }
     169
     170            $css .= "}\n\n";
     171        }
     172
     173        wp_register_style( 'webbiz-emphasis-dynamic', false, array(), WEBBIZ_TOOLKIT_VERSION );
     174        wp_enqueue_style( 'webbiz-emphasis-dynamic' );
     175        wp_add_inline_style( 'webbiz-emphasis-dynamic', $css );
     176    }
     177
     178    /**
     179     * 清理 CSS 顏色值(output escaping)
     180     *
     181     * @param string $color 顏色值。
     182     * @return string 安全的顏色值,無效時回傳空字串。
     183     */
     184    private function sanitize_css_color( $color ) {
     185        if ( empty( $color ) || ! is_string( $color ) ) {
     186            return '';
     187        }
     188
     189        if ( preg_match( '/^#([A-Fa-f0-9]{3}){1,2}$/', $color ) ) {
     190            return $color;
     191        }
     192
     193        if ( preg_match( '/^rgba?\(\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*,\s*[\d]{1,3}\s*(,\s*[\d]?\.?[\d]+\s*)?\)$/', $color ) ) {
     194            return $color;
     195        }
     196
     197        if ( 'transparent' === $color ) {
     198            return $color;
     199        }
     200
     201        return '';
     202    }
     203
     204    /**
    74205     * 載入啟用的模組
    75206     */
  • webbiz-toolkit/trunk/modules/emphasis/emphasis.js

    r3459973 r3460471  
    99
    1010    if (!window.wp?.richText || !window.wp?.element) {
    11         console.warn('Webbiz Emphasis: WordPress editor APIs not available');
    1211        return;
    1312    }
     
    4241            return result;
    4342        } catch (error) {
    44             console.error('Webbiz Emphasis: Format toggle error', error);
    4543            return toggleFormat(value, format);
    4644        }
  • webbiz-toolkit/trunk/modules/pangu/pangu.js

    r3459973 r3460471  
    1212    // 安全檢查
    1313    if (!window.wp?.data || !window.wp?.hooks || !window.wp?.element) {
    14         console.warn('Webbiz Pangu: WordPress editor APIs not available');
    1514        return;
    1615    }
  • webbiz-toolkit/trunk/modules/qa-reveal/qa-reveal.js

    r3459973 r3460471  
    1313    // 安全檢查
    1414    if (!window.wp?.blocks || !window.wp?.element || !window.wp?.blockEditor) {
    15         console.warn('Webbiz QA Reveal: WordPress block APIs not available');
    1615        return;
    1716    }
  • webbiz-toolkit/trunk/modules/spoiler/spoiler.js

    r3459973 r3460471  
    1313    // 安全檢查
    1414    if (!window.wp?.richText || !window.wp?.element) {
    15         console.warn('Webbiz Spoiler: WordPress editor APIs not available');
    1615        return;
    1716    }
  • webbiz-toolkit/trunk/readme.txt

    r3459973 r3460471  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9898= Is this plugin translation-ready? =
    9999
    100 Yes, WebBiz Toolkit is fully internationalized and ready for translation. The admin interface is available in Traditional Chinese.
     100Yes, WebBiz Toolkit is fully internationalized and ready for translation.
    101101
    102102== Screenshots ==
     
    109109
    110110== Changelog ==
     111
     112= 1.0.1 =
     113* Fixed: Text emphasis styles not displaying on the frontend (CSS was only loaded in admin context)
    111114
    112115= 1.0.0 =
  • webbiz-toolkit/trunk/webbiz-toolkit.php

    r3459973 r3460471  
    33 * Plugin Name: WebBiz Toolkit
    44 * Description: WordPress 部落客工具箱 - 文字強調樣式、劇透遮罩、中英文自動加空格、互動問答
    5  * Version: 1.0.0
     5 * Version: 1.0.1
    66 * Author: WebBiz
    77 * Author URI: https://webbiz.tw/
     
    2020
    2121// 外掛常數
    22 define( 'WEBBIZ_TOOLKIT_VERSION', '1.0.0' );
     22define( 'WEBBIZ_TOOLKIT_VERSION', '1.0.1' );
    2323define( 'WEBBIZ_TOOLKIT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    2424define( 'WEBBIZ_TOOLKIT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.