PHP [PLUGIN]第一次访问的Wordpress特定模板(并写一个cookie)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP [PLUGIN]第一次访问的Wordpress特定模板(并写一个cookie)相关的知识,希望对你有一定的参考价值。

<?php
/*
Plugin Name: first-visit-template
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.
Author: G.Lachance
Author URI: http://tinyurl.com/9wb48o
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/)
which was released under the GNU General Public License.
Version: 1

*/

//for testing your template, uncomment line 30.


function welcome_visitor_reloaded() {

	if(is_new_visitor()) {
		$tpl_file = TEMPLATEPATH . '/welcome.php';
		if ( file_exists($tpl_file) ) {
			include($tpl_file);
			exit;
		}
	}				
}

function is_new_visitor()
{

	//return true; //uncomment this for testing.
 	
	global $visits;
	
	if (!is_admin())
	{
		if (isset($_COOKIE['visits']))
			$visits = $_COOKIE['visits'] + 1;
		else
			$visits = 1;
			
		$url = parse_url(get_option('home'));
		setcookie('visits', $visits, time()+60*60*24*365, $url['path'] . '/');
	}
	else return false;

	return $visits == 1;
}

///
add_action('template_redirect', 'welcome_visitor_reloaded');


?>

以上是关于PHP [PLUGIN]第一次访问的Wordpress特定模板(并写一个cookie)的主要内容,如果未能解决你的问题,请参考以下文章

应用中心无法访问时后台插件列表访问慢的优化

Slick slider ().slick 不是 Wordpress PHP 的函数

您的 PHP 安装似乎缺少 WordPress 所需的 MySQL 扩展

统计分析日志

创建一个plugin - drupal 8

php plugin.php