• Resolved sulive

    (@sulive)


    Hi,

    I’m using a plugin to restrict certain content by using a shortcode the plugin has provided.

    Now I want to use this shortcode only when someone is logged in.

    So my php code on my WordPress page is:

    <?php
    if ( is_user_logged_in() ) {
    echo “[pms-register]”;
    }
    ?>

    But this doesn’t work. Does someone know the solution?

    Thanks,
    Sylvia

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Thread Starter sulive

    (@sulive)

    Many thanks Steve!

    Sylvia

    Thread Starter sulive

    (@sulive)

    Quick question, suppose I have shortcodes that have parameters with double quotes. I tried using \ to escape it but it doesnt work. Can you help?

    echo do_shortcode( ‘[pay name=”Form name” description=”Payment description”]’ );
    echo do_shortcode( ‘[pay_field type=”Email” label=”Your email” required=”true” /]’ );

    Thanks
    Sylvia

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Double quotes are OK when inside single quotes. You’d only have to escape if you had double quoted strings inside a double quoted string.

    Thread Starter sulive

    (@sulive)

    It doesn’t work

    [pay_field type=”label” label=”Product ABC for €19,95″ amount=”19,95″ /]
    [pay_total /]
    [pay_button label=”Pay” /]
    [/pay]

    For instance I can see the last command whereas the code above is parsed

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    If do_shortcode returns the string you provided, then it’s not finding the shortcode (in this case, the shortcode [pay])

    https://developer.www.ads-software.com/reference/functions/is_user_logged_in/

    is_user_logged_in() returns TRUE or FALSE.

    So you would use something like

    <?php
    if (is_user_logged_in() === TRUE)
       { echo '[pms-register]'; }
    ?>
    Thread Starter sulive

    (@sulive)

    Yes so the shortcode that I need in php is:

    [pay name=”Form name” description=”Payment description”]
    [pay_field type=”email” label=”Your email” required=”true” /]
    [pay_field type=”label” label=”Product ABC for €19,95″ amount=”19,95″ /]
    [pay_total /]
    [pay_button label=”Pay” /]
    [/pay]

    I added echo do_shortcode. When I click on the Pay button it says that the amount it not valid.

    Thanks
    Sylvia

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Contact the dev of the plugin that’s provide the shortcode(s) as your code is correct, as far as I can see.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Php and shortcodes’ is closed to new replies.