Posted By

grosbouff on 01/19/09


Tagged

plugin template wordpress cookie first visit


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

Bluewall
umang_nine
1man
maxvee8
BrianCoyDesign


[PLUGIN] Wordpress specific template for first visit (and writes a cookie)


 / Published in: PHP
 

  1. <?php
  2. /*
  3. Plugin Name: first-visit-template
  4. Description: Loads a welcome.php template in theme directory if it is the first visit (the function is not lauched if you're logged as admin), and writes a cookie so it's shown only once.
  5. Author: G.Lachance
  6. Author URI: http://tinyurl.com/9wb48o
  7. Credits: Based upon the "Welcome Visitor! Reloaded" plugin from Alaeddin, which is largely based upon the original Welcome Visitor! plugin by Kaf (http://guff.szub.net/2006/04/12/welcome-visitor/)
  8. which was released under the GNU General Public License.
  9. Version: 1
  10.  
  11. */
  12.  
  13. //for testing your template, uncomment line 30.
  14.  
  15.  
  16. function welcome_visitor_reloaded() {
  17.  
  18. if(is_new_visitor()) {
  19. $tpl_file = TEMPLATEPATH . '/welcome.php';
  20. if ( file_exists($tpl_file) ) {
  21. include($tpl_file);
  22. }
  23. }
  24. }
  25.  
  26. function is_new_visitor()
  27. {
  28.  
  29. //return true; //uncomment this for testing.
  30.  
  31. global $visits;
  32.  
  33. if (!is_admin())
  34. {
  35. if (isset($_COOKIE['visits']))
  36. $visits = $_COOKIE['visits'] + 1;
  37. else
  38. $visits = 1;
  39.  
  40. $url = parse_url(get_option('home'));
  41. setcookie('visits', $visits, time()+60*60*24*365, $url['path'] . '/');
  42. }
  43. else return false;
  44.  
  45. return $visits == 1;
  46. }
  47.  
  48. ///
  49. add_action('template_redirect', 'welcome_visitor_reloaded');
  50.  
  51.  
  52. ?>

Report this snippet  

You need to login to post a comment.