WordPress.org

Forums

add_shortcode parsed incorrectly. (1 post)

  1. Jixun.Moe
    Member
    Posted 1 year ago #

    The short-code parser incorrectly parsed the attribute value even when the magic character "]" within the quote mark.

    Sample code: info-box-parser.php

    <?php
    /*
     * Plugin Name: Short-Code Bug Test
     * Description: Short-Code Bug Test
     * Version: 1.0
     * Author: Jixun.Moe
     */
    
    function infobox_parse ($atts, $content = null) {
    	echo "--- [  ATTS   ] ---\n";
    	var_dump ($atts);
    	echo "--- [ CONTENT ] ---\n";
    	var_dump ($content);
    	echo "--- --- --- --- ---";
        return $content;
    }
    
    add_shortcode ('infobox', 'infobox_parse');

    Post content:
    [infobox title="[tag1] [tag2] title"][/infobox]

    Expected result:

    --- [  ATTS   ] ---
    array(1) {
      ["title"]=>
      string(19) "[tag1] [tag2] title"
    }
    --- [ CONTENT ] ---
    string(0) ""
    --- --- --- --- ---

    Actual output:

    --- [  ATTS   ] ---
    array(1) {
      [0]=>
      string(12) "title="[tag1"
    }
    --- [ CONTENT ] ---
    string(21) " [tag2] titleā€]"
    --- --- --- --- ---

    Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic