我想wp_redirect在此函式中使用,但目前出現錯誤:
無法修改標題資訊。感謝您提供任何幫助。
這是我的代碼:
function add_listing_dashboard_content() {
global $post;
global $page_id_dashboard;
global $page_id_user_profile;
global $page_id_submit_listing;
global $page_id_success;
$page_id_dashboard = get_field( 'dashboard_page', 'option');
$page_id_user_profile = get_field( 'user_profile_page', 'option');
$page_id_submit_listing = get_field( 'submit_listing_page', 'option');
$page_id_success = get_field( 'success_page', 'option');
if ( is_page( $page_id_dashboard ) && is_user_logged_in() ) :
include( plugin_dir_path( __FILE__ ) . '../templates/partials/dashboard-dashboard.php');
elseif ( is_page( $page_id_success ) && is_user_logged_in() ) :
include( plugin_dir_path( __FILE__ ) . '../templates/partials/dashboard-dashboard.php');
elseif ( is_page( $page_id_user_profile ) && is_user_logged_in() ) :
include( plugin_dir_path( __FILE__ ) . '../templates/partials/dashboard-profile.php');
elseif ( is_page( $page_id_submit_listing ) && is_user_logged_in() ) :
include( plugin_dir_path( __FILE__ ) . '../templates/partials/dashboard-submission.php');
elseif ( is_page( $page_id_dashboard ) || is_page( $page_id_user_profile ) || is_page( $page_id_submit_listing ) && !is_user_logged_in() ) :
include( plugin_dir_path( __FILE__ ) . '../templates/partials/dashboard-loggedout.php');
elseif ( is_page( $page_id_success ) && !is_user_logged_in() ) :
wp_redirect( get_permalink($page_id_dashboard) );
exit;
endif;
}
add_action( 'astra_entry_content_after', 'add_listing_dashboard_content' );
uj5u.com熱心網友回復:
就像我在評論中所說的那樣,astra_entry_content_after執行重定向為時已晚。因此,您可以單獨使用template_redirect鉤子和astra_entry_content_after鉤子,而不是“在彼此內部”。在functions.php檔案中使用以下代碼段:
add_action("template_redirect", "redirecting_users_on_page_id_success");
function redirecting_users_on_page_id_success()
{
global $page_id_dashboard;
global $page_id_success;
$page_id_dashboard = get_field('dashboard_page', 'option');
$page_id_success = get_field('success_page', 'option');
if ((is_page($page_id_success) && !is_user_logged_in()))
{
wp_safe_redirect(get_permalink($page_id_dashboard));
exit;
}
};
add_action('astra_entry_content_after', 'add_listing_dashboard_content');
function add_listing_dashboard_content()
{
global $page_id_dashboard;
global $page_id_user_profile;
global $page_id_submit_listing;
global $page_id_success;
$page_id_dashboard = get_field('dashboard_page', 'option');
$page_id_user_profile = get_field('user_profile_page', 'option');
$page_id_submit_listing = get_field('submit_listing_page', 'option');
$page_id_success = get_field('success_page', 'option');
if (is_page($page_id_dashboard) && is_user_logged_in()) :
include(plugin_dir_path(__FILE__) . '../templates/partials/dashboard-dashboard.php');
elseif (is_page($page_id_success) && is_user_logged_in()) :
include(plugin_dir_path(__FILE__) . '../templates/partials/dashboard-dashboard.php');
elseif (is_page($page_id_user_profile) && is_user_logged_in()) :
include(plugin_dir_path(__FILE__) . '../templates/partials/dashboard-profile.php');
elseif (is_page($page_id_submit_listing) && is_user_logged_in()) :
include(plugin_dir_path(__FILE__) . '../templates/partials/dashboard-submission.php');
elseif (is_page($page_id_dashboard) || is_page($page_id_user_profile) || is_page($page_id_submit_listing) && !is_user_logged_in()) :
include(plugin_dir_path(__FILE__) . '../templates/partials/dashboard-loggedout.php');
endif;
}
讓我知道你是否可以讓它作業!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/406289.html
標籤:
上一篇:以實模式訪問pci配置空間
