Php 发送页眉后如何重定向页面?Wordpress
我在wordpress上做了一个插件。当用户单击主页上的“查看帖子”按钮时,它将检查允许或不允许用户查看帖子的某些条件 如果不允许用户查看帖子,页面将重定向到错误页面 但是,问题是,插件是通过快捷方式运行的,因此该功能将在加载帖子页面后运行。结果是,这个错误Php 发送页眉后如何重定向页面?Wordpress,php,wordpress,Php,Wordpress,我在wordpress上做了一个插件。当用户单击主页上的“查看帖子”按钮时,它将检查允许或不允许用户查看帖子的某些条件 如果不允许用户查看帖子,页面将重定向到错误页面 但是,问题是,插件是通过快捷方式运行的,因此该功能将在加载帖子页面后运行。结果是,这个错误无法修改标题信息-标题已经发送(输出从/home/wordpress/wp includes/class.wp styles.php:237开始) 在发送头之后,url如何重定向 另外,我需要让它成为捷径 非常感谢 这是我的密码: fu
无法修改标题信息-标题已经发送(输出从/home/wordpress/wp includes/class.wp styles.php:237开始)
在发送头之后,url如何重定向
另外,我需要让它成为捷径
非常感谢
这是我的密码:
function add_post_condition_vpc($atts, $content = null)
{
$userPoint = getPointFromDb();
if($userPoint > 50)
{
//redirect the the page to the view-post-direct-page.php
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";
header("Location: $url ");
return "redirect";
}
}
add_shortcode('view_post_lmc', 'add_post_condition_vpc');
//redirect the the page to the view-post-direct-page.php
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";
$string = '<script type="text/javascript">';
$string .= 'window.location = "' . $url . '"';
$string .= '</script>';
return $string;
还有“共享”按钮,我使用以下代码获取当前帖子url:
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
然后我在帖子上添加了短代码
我找到了解决办法 这是我的密码:
function add_post_condition_vpc($atts, $content = null)
{
$userPoint = getPointFromDb();
if($userPoint > 50)
{
//redirect the the page to the view-post-direct-page.php
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";
header("Location: $url ");
return "redirect";
}
}
add_shortcode('view_post_lmc', 'add_post_condition_vpc');
//redirect the the page to the view-post-direct-page.php
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";
$string = '<script type="text/javascript">';
$string .= 'window.location = "' . $url . '"';
$string .= '</script>';
return $string;
//将页面重定向到view-post-direct-page.php
$page_file_temp=$_SERVER[“PHP_SELF”];
$url=dirname($page\u file\u temp)。“/view post direct page.php”;
$string='';
$string.='window.location=“.$url.”;
$string.='';
返回$string;
使用Javascript
避免再次发送标题 在functions.php中添加以下内容:
在这里找到它:在functions.php中添加它:
在这里找到它:为什么要使用快捷码进行此检查
我认为你最好使用Wordpress'inithook
。将此项添加到functions.php或插件文件中,将在加载页面之前执行检查:
function add_post_condition_vpc() {
$userPoint = getPointFromDb();
if($userPoint > 50) {
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";
header("Location: $url ");
exit(); // just exit, return is not needed here
}
}
add_action('init', add_post_condition_vpc);
如果帖子附加了某种标签,您可以在这个函数中执行检查。当你运行userpoint检查时。这样,您就不需要快捷码标签。为什么要使用快捷码进行此检查
我认为你最好使用Wordpress'inithook
。将此项添加到functions.php或插件文件中,将在加载页面之前执行检查:
function add_post_condition_vpc() {
$userPoint = getPointFromDb();
if($userPoint > 50) {
$page_file_temp = $_SERVER["PHP_SELF"];
$url= dirname($page_file_temp) . "/view-post-direct-page.php";
header("Location: $url ");
exit(); // just exit, return is not needed here
}
}
add_action('init', add_post_condition_vpc);
如果帖子附加了某种标签,您可以在这个函数中执行检查。当你运行userpoint检查时。这样,您就不需要快捷码标记。使用ob_start()代码>我试图使用ob_start()代码>。这是工作,但它给我带来了另一个问题。因为我在帖子上做了一个Facebook共享按钮
,它无法正确共享链接。URL
将更改为错误页面的URL。显示一些代码。更新的代码。thxHI@Capslock10这个问题可能会得到更多的关注:)使用ob_start()代码>我试图使用ob_start()代码>。这是工作,但它给我带来了另一个问题。因为我在帖子上做了一个Facebook共享按钮
,它无法正确共享链接。URL
将更改为错误页面的URL。显示一些代码。更新的代码。thxHI@Capslock10这个问题可能会得到更多关注:)