Display a text message if the shortcode is not found?2019 Community Moderator ElectionWrap text around...

N.B. ligature in Latex

Is Social Media Science Fiction?

What is the white spray-pattern residue inside these Falcon Heavy nozzles?

DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?

The use of multiple foreign keys on same column in SQL Server

The magic money tree problem

Is there a familial term for apples and pears?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

What is the meaning of "of trouble" in the following sentence?

What is the command to reset a PC without deleting any files

whey we use polarized capacitor?

Why is "Reports" in sentence down without "The"

Download, install and reboot computer at night if needed

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Concept of linear mappings are confusing me

I probably found a bug with the sudo apt install function

My colleague's body is amazing

What makes Graph invariants so useful/important?

Email Account under attack (really) - anything I can do?

"which" command doesn't work / path of Safari?

How can bays and straits be determined in a procedurally generated map?

Can I make popcorn with any corn?

Are white and non-white police officers equally likely to kill black suspects?



Display a text message if the shortcode is not found?



2019 Community Moderator ElectionWrap text around shortcodeShortcode does not display paginationShortcode in Text Widget not workingShortcode display outside the divWordPress shortcode display as plain textShortcode - Display inline icon before textCustom Registration username_exists / email_existsShortcode cannot be foundDisplay a text message if the shortcode is found?Display a text message if the field is not found and not if found





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content() {
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) ) {
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
}
else {
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';
}
?>
</div>
</article>
</main>
</div>

<?php
}


I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?





When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve










share|improve this question




















  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41


















3















I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content() {
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) ) {
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
}
else {
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';
}
?>
</div>
</article>
</main>
</div>

<?php
}


I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?





When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve










share|improve this question




















  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41














3












3








3








I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content() {
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) ) {
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
}
else {
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';
}
?>
</div>
</article>
</main>
</div>

<?php
}


I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?





When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve










share|improve this question
















I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content() {
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) ) {
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
}
else {
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';
}
?>
</div>
</article>
</main>
</div>

<?php
}


I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?





When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve







php plugin-development shortcode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 3 at 22:18









Jack Johansson

11.8k81845




11.8k81845










asked Mar 30 at 14:36









Nicolas LogerotNicolas Logerot

375




375








  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41














  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41








1




1





Have you tried the core function shortcode_exists( 'picu_list_collections' )?

– bueltge
Mar 31 at 12:41





Have you tried the core function shortcode_exists( 'picu_list_collections' )?

– bueltge
Mar 31 at 12:41










2 Answers
2






active

oldest

votes


















1














do_shortcode() returns content with shortcodes filtered out. Assuming that your shortcode returns "" if user has no gallery, then you can check the return value and display your message.



$output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

// the shortcode returns an empty <ul> tag, if there is no gallery
// https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
else echo $output;


I hope this may help!






share|improve this answer


























  • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

    – Nicolas Logerot
    Mar 30 at 15:31











  • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

    – Qaisar Feroz
    Mar 30 at 15:35











  • Thank you very much but I don't know how to find the output of shot code when is no gallery

    – Nicolas Logerot
    Mar 30 at 15:40











  • What is output just after the this is your galleries USER_NAME when page is loaded?

    – Qaisar Feroz
    Mar 30 at 15:53











  • OK, Can you share screenshots in cases of a user has no galleries?

    – Qaisar Feroz
    Mar 30 at 16:12



















1














This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



$gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "110"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333009%2fdisplay-a-text-message-if-the-shortcode-is-not-found%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    do_shortcode() returns content with shortcodes filtered out. Assuming that your shortcode returns "" if user has no gallery, then you can check the return value and display your message.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!






    share|improve this answer


























    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12
















    1














    do_shortcode() returns content with shortcodes filtered out. Assuming that your shortcode returns "" if user has no gallery, then you can check the return value and display your message.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!






    share|improve this answer


























    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12














    1












    1








    1







    do_shortcode() returns content with shortcodes filtered out. Assuming that your shortcode returns "" if user has no gallery, then you can check the return value and display your message.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!






    share|improve this answer















    do_shortcode() returns content with shortcodes filtered out. Assuming that your shortcode returns "" if user has no gallery, then you can check the return value and display your message.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 30 at 16:24

























    answered Mar 30 at 15:19









    Qaisar FerozQaisar Feroz

    1,4071217




    1,4071217













    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12



















    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12

















    Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

    – Nicolas Logerot
    Mar 30 at 15:31





    Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

    – Nicolas Logerot
    Mar 30 at 15:31













    @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

    – Qaisar Feroz
    Mar 30 at 15:35





    @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

    – Qaisar Feroz
    Mar 30 at 15:35













    Thank you very much but I don't know how to find the output of shot code when is no gallery

    – Nicolas Logerot
    Mar 30 at 15:40





    Thank you very much but I don't know how to find the output of shot code when is no gallery

    – Nicolas Logerot
    Mar 30 at 15:40













    What is output just after the this is your galleries USER_NAME when page is loaded?

    – Qaisar Feroz
    Mar 30 at 15:53





    What is output just after the this is your galleries USER_NAME when page is loaded?

    – Qaisar Feroz
    Mar 30 at 15:53













    OK, Can you share screenshots in cases of a user has no galleries?

    – Qaisar Feroz
    Mar 30 at 16:12





    OK, Can you share screenshots in cases of a user has no galleries?

    – Qaisar Feroz
    Mar 30 at 16:12













    1














    This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



    Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



    If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



    $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
    if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





    share|improve this answer




























      1














      This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



      Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



      If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



      $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
      if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





      share|improve this answer


























        1












        1








        1







        This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



        Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



        If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



        $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
        if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





        share|improve this answer













        This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



        Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



        If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



        $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
        if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 30 at 15:04









        cjbjcjbj

        11.1k102967




        11.1k102967






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to WordPress Development Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333009%2fdisplay-a-text-message-if-the-shortcode-is-not-found%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Webac Holding Inhaltsverzeichnis Geschichte | Organisationsstruktur | Tochterfirmen |...

            What's the meaning of a knight fighting a snail in medieval book illustrations?What is the meaning of a glove...

            Salamanca Inhaltsverzeichnis Lage und Klima | Bevölkerungsentwicklung | Geschichte | Kultur und...