admin管理员组文章数量:1433500
I am trying to set up a redirect that is toggleable via admin backend, using a checkbox. Here is my redirect function:
function redirect_to_prelaunch_page()
{
if (get_current_user_id() == 0 && !is_page("pre-launch.html"))
{
wp_redirect( '.html', 301 );
exit;
}
}
This redirect works great in my theme's functions.php, but i'd like to include it in my plugin.
Below is the code i've got for my plugin:
<?php
//redirect to pre-launch page if not logged in and not on pre-launch page already
function redirect_to_prelaunch_page()
{
if (get_current_user_id() == 0 && !is_page("pre-launch.html"))
{
wp_redirect( '.html', 301 );
exit;
}
}
//create custom plugin settings menu
add_action('admin_menu', 'pg_base_plugin_create_menu');
function pg_base_plugin_create_menu() {
//create new top level menu
add_menu_page('PrettyGals Base','PrettyGals Base', 'administrator', __FILE__, 'pg_base_plugin_settings_page', '', 9999999 );
//call register settings function
add_action('admin_init', 'register_pg_base_plugin_settings');
}
function register_pg_base_plugin_settings() {
//register settings
register_setting('pg_base', 'pg-prelaunch');
}
function pg_base_plugin_settings_page() {
?>
<div class="wrap">
<h1>PrettyGals Base</h1>
<form method="post" action="options.php">
<?php settings_fields('pg_base'); ?>
<?php do_settings_sections('pg_base'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Pre-Launch</th>
<td><input type="checkbox" name="pg-prelaunch" value="1" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
It all works as it should (as in the checkbox etc shows up as it should), but i'm not sure where to go from here.
I figured i'd use IF checkbox == checked then call the function the redirect is in. Is this right?
Also, the checkbox doesn't stay checked when submitting, any idea why or how to fix this?
I am still learning so any help is greatly appreciated. I was referencing this page to create this.
Cheers, D
本文标签: Toggle Redirect Function OnOff With Checkbox
版权声明:本文标题:Toggle Redirect Function OnOff With Checkbox 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745595809a2665471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论