Support Forum

Template Tag PM inbox

DH Dietmar Herian
Dietmar Herian
Member

Hi SP team,

my first attempt to use a template tag seems to be not successful. I just tried to put

<?php sf_pm_tag(true, false); ?>

in one of my side templates and also the shortcode version

[sf_pm_tag]

but both won’t work.

From the code version I get a fatal php error ‘call to a undefined function in …’ and from the short code version I get nothing.

The plugin ‘Template Tags’ is installed and activated. Am I missing something?

15 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

That’s old V4 syntax as far as I can remember.
And PM template tags will be in the PM plugin.
But… I am not sure which one replaces this in V5 and I am going to have to ask…
So – someone will come back to you.

DH Dietmar Herian
Dietmar Herian
Member

Thanks for your quick reply.

I found out my version mistake meanwhile – tried

sp_pm_do_inbox()

but likewise to no avail.

Hope one of the experts can hint me to that.

YS Yellow Swordfish
Yellow Swordfish
Member

I think you found it except it is just sp_pm_inbox()

DH Dietmar Herian
Dietmar Herian
Member

Yes, it is! Works pefect for me.

Occassionally, you could let me know how this translation from function name to tag name works – or is there a reference list somewhere? Maybe, I have to wait for the official docs.

YS Yellow Swordfish
Yellow Swordfish
Member

We are slowly compiling them and I did think that one was actually done but I was wrong.
The names of the functions in the actual template tag files themselves are not public names. The public names are contained in the main plugin file in each case. If it has a ‘do’ in the name then it s the wrong one basically!

DH Dietmar Herian
Dietmar Herian
Member

Sorry to bother – but I still need some help with this. The tag works fine when used in a side template.

Now I am trying to invoke it triggered by a WP login filter like this

add_filter(‘wp_login’, ‘PN_check’, 10, 3);

function PN_check($user, $username, $password){
   ?>
    <div style=”display:none” class=”fancybox-hidden”><div id=”popup” style=”width: auto; padding: 5px”>
    <?php
        global $wpdb;
//        sf_pm_tag(TRUE, FALSE);
        $pm = sf_pm_tag(FALSE, FALSE);
        echo ‘In Deinem Posteingang befinden sich ‘.$pm[‘count’]. ‘ ungeöffnete Nachrichten’;
          ?>
        <a href=”<?php echo $pm[‘url’] ?>”>Zum Posteingang</a>
<!–<a href=”#” onclick=”javascript:jQuery.fancybox.close();return false;”>Close this window</a>–>
</div>
</div>
<a id=”fancybox-auto” class=”fancybox” href=”#popup”></a>
<?php
return $user;
}

in my theme’s functions.php so that users should get a popup message when logging in.

But the returned string $pm is empty in this environment

Array

(

    [count] => -1

    [url] =>

)

 

How comes? Is the tag not valid here? Is it only valid in side templates?

But users can log in and out at any time when the site is up.

YS Yellow Swordfish
Yellow Swordfish
Member

there os no such function as sf_pm_tag(). Were you not using sp_pm_inbox()?

Just for the record, WP filters are not intended to be used for displaying content directly like that. All content should be compiled up and then returned, in this case, in the $user variable. Except that would create chaos. ‘Actions; should really be used for this sort of thing instead of ‘Filters’.

DH Dietmar Herian
Dietmar Herian
Member

Sorry, forgot to mention – this one is back to V4.5.1. And the sf_pm_tag-function returned a proper array in a side template. I’d like to try this first in my local (old) install rather than in the remote server which is already SP5.1.2.

You are right with filters and actions – this was just ‘quick and dirty’ to see wether it works.

What about validity? If I were using sp_pm_inbox in a WP login action hook, would it return proper array content?

YS Yellow Swordfish
Yellow Swordfish
Member

As far as I am aware it should work.
Your problem may be one of the code being out of scope. Check for the function using function_exists() to see if it is actually available for use from that place.

DH Dietmar Herian
Dietmar Herian
Member

I replaced the code snippet like this

add_action(‘wp_login’, ‘PN_check’, 10, 3);

function PN_check($user, $username, $password){
   ?>
    <div style=”display:none” class=”fancybox-hidden”><div id=”popup” style=”width: auto; padding: 5px”>
    <?php
        global $wpdb;
        if(function_exists(‘sf_pm_tag’)){
            wp_mail(‘me@home.de’, ‘PM_tag_Ex’, print_r(“sf_pm_tag() existiert!”,TRUE));
        }
//        sf_pm_tag(TRUE, FALSE);
        $pm = sf_pm_tag(FALSE, FALSE);
        echo ‘In Deinem Posteingang befinden sich ‘.$pm[‘count’]. ‘ ungeöffnete Nachrichten’;
        wp_mail(‘me@home.de’, ‘PM_tag2’, print_r($pm,TRUE));     ?>
        <a href=”<?php echo $pm[‘url’] ?>”>Zum Posteingang</a>
<!–<a href=”#” onclick=”javascript:jQuery.fancybox.close();return false;”>Close this window</a>–>
</div>
</div>
<a id=”fancybox-auto” class=”fancybox” href=”#popup”></a>
<?php
}

The resut is: the function exists in this place but returns some invalid array content – the same as before mentioned.

I’ve tried the same in V5.1.2 with sp_pm_inbox() and it is exactly the same .function exists, array invalid.

Obviously, it is a problem of validity of data. Any idea where I can call the function with valid array return?

MP Mr Papa
Mr Papa
Member

not sure what you are trying to do…  if the user is not logged in, the count should be -1…  but the code in 4.5.1 is different than 5.x…

what error are you getting?

perhaps after the call, add some debug code…

ashow($pm);

or

print_r($pm);

and lets see what is returned…

DH Dietmar Herian
Dietmar Herian
Member

I try to use the ‘wp_login’ hook to present a message to the user that he/she has got PMs in the box. It works on a static call in a side template but does not respond proper Array under the hook. I do not get any error message.

I do the debugging via wp_mail() because this is a remote server and I get it printed. The response for $pm is in both cases V(4.5.1 and V5.1.2) the same:

Array

(

    [count] => -1

    [url] =>

)

The first debug email just returns a string to indicate that the function exists in this place. I also tested when the hook event takes place – it is at the end of log-in. The user should be logged in at this time. But with regards to your answer, it seems like this is not yet the case. As always, the WP reference description is not very clear with that.

But wouldn’t that be a nice feature to add to the PM-Plugin. Many blog users do not necessarily go to the forum to check wether they have PM(s) or not. This way, the blog owner can make sure they do not miss any.

MP Mr Papa
Mr Papa
Member

sorry, still not sure what you are trying to do…

the hook you are using, wp_login, is after the sign on process per se, but its before the page reload of logging in… so not sure how or where you think you are going to display the tag…  any output would not show up anyways…

after the login code completes, which is later/after the hook you used, the login redirect takes affect and the user is redirected somewhere…  so any output you attempt to make will not show up…  also, the wp global variable for the user is not set up until that page redirect either…

so not sure what you are trying to gain with the tag on the login hook vs the sidebar which will be display on the login redirect (assuming its to front end)….

where ever you want to display the pm tag, it needs to actually be on a page load, not some intermediate wp logic step…

DH Dietmar Herian
Dietmar Herian
Member

I was hoping to display it via a fancybox inline which is a popup window, anyhow.

But this does not seem to work and what I understand now is, that the user is not fully logged in at this moment and therefor the information for sp_pm_inbox() is not available at this place.

Then I ‘ll try it setting a globally availbale marker that a user has just logged in and call sp_pm_inbox() after redirection has ended on some page. Since the page template is always the same, this should give me the result I am looking for.

Thanks for clarifying.

But tell me one thing: where do you get your more detailled information about the hook from? Is there a second source? I am not very happy with the WP actions/filters reference. It is by far too short and not precise in what the hook or filter is doing – besides the huge number of undocumented items. I am always trapped in things not being completed or data not available. How can one know? Looking into the WP core code seem to be the only possibility.