• Hi,

    after updating on the dev environment my formulars, that use short codes for easy value handling are broken.

    I have looked a bit into the wp code and found out, what causes this, but not, if its intended or not.

    Steps to reproduce:

    1. Create a short code like this:

    function scTest($atts) {
      return 'TEST: ' . $atts['var'];
    }
    add_shortcode('TEST_SHORT_CODE', 'scTest');

    2. Create a page using the short code like this:

    Works: "[TEST_SHORT_CODE var='user.test']"
    
    <p class="[TEST_SHORT_CODE var='user.test']">Works</p>
    
    <div class="form-group">
      <label for="test">Does not work</label>
      <input id="test" class="form-control" name="user[test]" type="text" value="[TEST_SHORT_CODE var='user.test']" />
    </div>

    You will see, that the short code works stand alone, in the p.class attribute, but not in the input.value attribute.

    This is due to the changes in shortcodes.php and kses.php – particulary caused by kses.php:856.

    The reason is that $allowedposttags does not contain “input”. Therefor using short codes in input fields won’t work.

    How can I solve this problem (ofcourse without chaning wp-code)? I need short tags working there for easy use of formulas within my wp-page or I need to know, how it is intended in WP, to get the values back in the formulars, if short codes are not the way to go.

    Last but not least it would be nice to know, if this is not a bug, why it is not allowed to use short codes in input fields.

    Best regards

Viewing 10 replies - 1 through 10 (of 10 total)
  • I have a similar problem and really need to know how to fix it. I have this little form on every page of my site and use a simple shortcode to get the name of the page and pop it in the form. Now that wordpress has updated it doesn’t work so the whole site is broken. I’ve tried changing double to single quotes but neither works.

    <input type=hidden name=itemname value='[page_title] 11x8 Unmounted Print'>

    can you help?
    regards
    Denise

    Thread Starter Iramon

    (@iramon)

    Your problem is also caused by the same code changes, which disallows using short codes in input elements. Let’s hope someone can help us.

    Thread Starter Iramon

    (@iramon)

    @denl: A possible hotfix for you would be to add the following lines of code to kses.php e.g. at line 241:

    'input' => array(
          'id' => true,
          'name' => true,
          'type' => false,
          'class' => true,
          'value' => true,
        ),

    But I would not recommend doing this. This adds the ‘input’ element to the list of $allowedposttags. It will work afterwords, but I have not checked, what impacts it also may have. A better solution for you would be, to stay with or upgrade to 4.2.2 and wait for a proper fix of this.

    Thanks Iramom. Trouble is my whole site is now broken. 🙁 I was wondering if I could generate the input tag and the page title as a function, so it becomes one function. I think that would work because it wouldn’t be in the html as such because it would be putting the html in, if you understand me.
    But I can’t work out any way to do it as I don’t know php. I only know enough to copy what somebody else has done a maybe tweak it a little.

    Thread Starter Iramon

    (@iramon)

    If your live site is already broken, try to downgrade to 4.2.2 by downloading 4.2.2 sources and copy them to your installation directory. Before better make a backup. If that solves your problem, just wait for the bugfix to arrive. If that does not solve the problem try my hotfix from above. Open “wp-includes/kses.php” with a editor and add the above lines to kses.php line 241 between the following two lines:

    ),
      'ins' => array(

    Thanks I think I’ll do that. Although I’m not sure there will be a fix, from what I’ve read so far you won’t be able to use shortcodes in an input tag. 🙁

    Just updated one of my sites and ran into this problem. In case someone is looking for a solution that doesn’t require modifying WordPress code, here’s what I did:

    1) If you don’t already have it on your site, install & activate the fantastic “Shortcode Exec PHP” plugin.

    2) Within the Shortcode Exec PHP Admin area create a new shortcode (I called mine “gen_input_with_shortcode”) with the following PHP code:

    $content = do_shortcode( $content );
    $content = str_replace( array( '’','“', '”' ), array( "'", '"', '"' ), $content );
    echo '<input '.$content;
    if ( !isset( $atts[ 'close' ] )
    or ( 'n' != strtolower( $atts[ 'close' ] )
     and 'no' != strtolower( $atts[ 'close' ] ) ) )
       echo ' />';

    3) Wherever you have input fields that require shortcodes, change the ‘<input’ to ‘[gen_input_with_shortcode]’ (or whatever name you chose) and replace the ‘/>’ at the end of the input statement with ‘[/gen_input_with_shortcode]’

    If you don’t want gen_input_with_shortcode to generate the closing tag (‘ />’) then specify close=no. I.e. [gen_input_with_shortcode close=no] and then provide your own closing tag later.

    See this solution in action at getiplocation.net which includes within the <form>:

    Lookup another IP Address: [gen_input_with_shortcode] type=’text’ name=”ip” value=”[geo_list]{ipAddress}[/geo_list]”[/gen_input_with_shortcode]

    Hope this helps someone.

    Well, this is embarrassing. I just looked for the “Shortcode Exec PHP” plugin in the WordPress repository and it’s not there. I did find a replacement. Using the “Add Shortcodes Actions And Filters” plugin, I had to modify the code slightly:

    $content = do_shortcode( $content );
    $content = str_replace( array( '&'.'#8217;','&'.'#8220;', '&'.'#8221;' ), array( "'", '"', '"' ), $content );
    echo '<input '.$content;
    if ( !isset( $atts[ 'close' ] )
    or ( 'n' != strtolower( $atts[ 'close' ] )
     and 'no' != strtolower( $atts[ 'close' ] ) ) )
       echo ' />';

    Good luck

    dimabuko

    (@dimabuko)

    Well, this is embarrassing. I just looked for the “Shortcode Exec PHP” plugin in the WordPress repository and it’s not there. I did find a replacement. Using the “Add Shortcodes Actions And Filters” plugin, I had to modify the code slightly:

    $content = do_shortcode( $content );
    $content = str_replace( array( ‘&’.’#8217;’,’&’.’#8220;’, ‘&’.’#8221;’ ), array( “‘”, ‘”‘, ‘”‘ ), $content );
    echo ‘<input ‘.$content;
    if ( !isset( $atts[ ‘close’ ] )
    or ( ‘n’ != strtolower( $atts[ ‘close’ ] )
    and ‘no’ != strtolower( $atts[ ‘close’ ] ) ) )
    echo ‘ />’;
    Good luck

    Thanks @wescleveland so much! It helps me a lot!!!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘shortcodes not working in input element after update to 4.2.3’ is closed to new replies.