• Resolved pauldotmac

    (@pauldotmac)


    Hi,
    I followed the other posting instructions re parameter passing with the following code snipett

    add_shortcode( ‘introduction’, function($atts){

    $locn = $atts[“locn”];
    $output = “”;
    $output .= ‘<h1>Assessment Planner – ‘.$locn.'</h1>’;
    $output .= ‘<table id=”chance”><tr><td style=”width: 12%”>% Chance:</td><td><span id=”legendContainer” class=”legend” style=”border-style: solid; border-color: threedface; width: 100%”> </span></td></tr></table>’;

    return $output;
    });http://localhost/risk/wp-admin/edit.php?post_type=page

    and get the following error report

    Warning: Illegal string offset ‘locn’ in H:\sites.web\risk\wp-content\plugins\code-snippets\php\snippet-ops.php(446) : eval()’d code on line 3
    Call Stack
    # Time Memory Function Location
    1 0.0002 410016 {main}( ) …\index.php:0
    2 0.0005 410288 require( ‘H:\sites.web\risk\wp-blog-header.php’ ) …\index.php:17
    3 0.1488 5806184 require_once( ‘H:\sites.web\risk\wp-includes\template-loader.php’ ) …\wp-blog-header.php:19
    4 0.1573 5894984 include( ‘H:\sites.web\risk\wp-content\themes\catch-kathmandu-pro\page.php’ ) …\template-loader.php:106
    5 0.2095 6080256 get_template_part( ) …\page.php:22
    6 0.2096 6086408 locate_template( ) …\general-template.php:204
    7 0.2576 6086520 load_template( ) …\template.php:676
    8 0.2577 6086856 require( ‘H:\sites.web\risk\wp-content\themes\catch-kathmandu-pro\content-page.php’ ) …\template.php:732
    9 0.2599 6153896 the_content( ) …\content-page.php:25
    10 0.2601 6153920 apply_filters( ) …\post-template.php:253
    11 0.2601 6154320 WP_Hook->apply_filters( ) …\plugin.php:206
    12 0.2609 6157080 do_shortcode( ) …\class-wp-hook.php:287
    13 0.2609 6159408 preg_replace_callback ( ) …\shortcodes.php:218
    14 0.2609 6160024 do_shortcode_tag( ) …\shortcodes.php:218
    15 0.2610 6160024 {closure:H:\sites.web\risk\wp-content\plugins\code-snippets\php\snippet-ops.php(446) : eval()’d code:1-9}( ) …\shortcodes.php:343

    The shortccode on the page is

    [introduction locn=”UNITED KINGDOM”]

    It works fine without reference to $atts[“locn”] in line 3 and $locn in line 5

    Any suggestions?

    Thanks

    Paul

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    You should be using the shortcode_atts function to ensure that all attributes are present before attempting to access them. Change the first line of the snippet to this:

    add_shortcode( 'introduction', function ( $atts ) {
        $atts = shortcode_atts( array(
            'locn' => '',
        ), $atts );
    
    Thread Starter pauldotmac

    (@pauldotmac)

    Hi,

    Thanks for the quick response. I’ve made the change and I no longer get the error message but the passed parameter is not being picked up.

    The line $output .= ‘<h1>Assessment Planner – ‘.$locn.'</h1>’; just produces “Assessment Planner – ” without UNITED KINGDOM.

    Thanks

    Paul

    • This reply was modified 5 years, 8 months ago by pauldotmac.
    Thread Starter pauldotmac

    (@pauldotmac)

    Don’t what happened but it now working. Thanks.

    Paul

    Plugin Author Shea Bunge

    (@bungeshea)

    Glad to hear, Paul – might have been a caching issue.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Parameter passing’ is closed to new replies.