/** * Admin settings. */ public static function settings() { if (!current_user_can('manage_options')) { wp_die(__('Access denied.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN)); } if (!self::groups_is_active()) { echo '<p>'; echo __('Please install and activate <a href="http://wordpress.org/extend/plugins/groups/">Groups</a> to use this plugin.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; return; } $http_status_codes = array('301' => __('Moved Permanently', GROUPS_404_REDIRECT_PLUGIN_DOMAIN), '302' => __('Found', GROUPS_404_REDIRECT_PLUGIN_DOMAIN), '303' => __('See Other', GROUPS_404_REDIRECT_PLUGIN_DOMAIN), '307' => __('Temporary Redirect', GROUPS_404_REDIRECT_PLUGIN_DOMAIN)); if (isset($_POST['action']) && $_POST['action'] == 'save' && wp_verify_nonce($_POST['groups-404-redirect'], 'admin')) { $redirect_to = 'post'; if (!empty($_POST['redirect_to'])) { switch ($_POST['redirect_to']) { case 'post': case 'login': Groups_Options::update_option('groups-404-redirect-to', $_POST['redirect_to']); break; } } if (!empty($_POST['post_id'])) { Groups_Options::update_option('groups-404-redirect-post-id', intval($_POST['post_id'])); } else { Groups_Options::delete_option('groups-404-redirect-post-id'); } Groups_Options::update_option('groups-404-redirect-restricted-terms', !empty($_POST['redirect_restricted_terms'])); if (key_exists($_POST['status'], $http_status_codes)) { Groups_Options::update_option('groups-404-redirect-status', $_POST['status']); } echo '<p class="info">' . __('The settings have been saved.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN) . '</p>'; } $redirect_to = Groups_Options::get_option('groups-404-redirect-to', 'post'); $post_id = Groups_Options::get_option('groups-404-redirect-post-id', ''); $redirect_status = Groups_Options::get_option('groups-404-redirect-status', '301'); $redirect_restricted_terms = Groups_Options::get_option('groups-404-redirect-restricted-terms', false); echo '<h1>'; echo __('Groups 404 Redirect', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</h1>'; echo '<p>'; echo __('Redirect settings when a visitor tries to access a page protected by Groups.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; echo '<div class="settings">'; echo '<form name="settings" method="post" action="">'; echo '<div>'; echo '<label>'; echo sprintf('<input type="radio" name="redirect_to" value="post" %s />', $redirect_to == 'post' ? ' checked="checked" ' : ''); echo ' '; echo __('Redirect to a page or post', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</label>'; echo '<div style="margin: 1em 0 0 2em">'; echo '<label>'; echo __('Page or Post ID', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo ' '; echo sprintf('<input type="text" name="post_id" value="%s" />', $post_id); echo '</label>'; if (!empty($post_id)) { $post_title = get_the_title($post_id); echo '<p>'; echo sprintf(__('Title: <em>%s</em>', GROUPS_404_REDIRECT_PLUGIN_DOMAIN), $post_title); echo '</p>'; } echo '<p class="description">'; echo __('Indicate the ID of a page or a post to redirect to, leave it empty to redirect to the home page.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '<br/>'; echo __('The title of the page will be shown if a valid ID has been given.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; echo '<p class="description">'; echo __('If the <strong>Redirect to the WordPress login</strong> option is chosen instead, visitors who are logged in but may not access a requested page, can be redirected to a specific page by setting the Page or Post ID here.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; echo '</div>'; echo '<br/>'; echo '<label>'; echo sprintf('<input type="radio" name="redirect_to" value="login" %s />', $redirect_to == 'login' ? ' checked="checked" ' : ''); echo ' '; echo __('Redirect to the WordPress login', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</label>'; echo '<div style="margin: 1em 0 0 2em">'; echo '<p class="description">'; echo __('If the visitor is logged in but is not allowed to access the requested page, the visitor will be taken to the home page, or, if a Page or Post ID is set, to the page indicated above.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; echo '</div>'; echo '<br/>'; echo '<label>'; echo sprintf('<input type="checkbox" name="redirect_restricted_terms" %s />', $redirect_restricted_terms ? ' checked="checked" ' : ''); echo ' '; echo __('Redirect restricted categories, tags and taxonomy terms …', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</label>'; echo '<div style="margin: 1em 0 0 2em">'; echo '<p class="description">'; echo __('If the visitor is not allowed to access the requested taxonomy term, including restricted categories and tags, the visitor will be redirected as indicated above.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; echo '<p class="description">'; echo __('This option will only take effect if <a href="http://www.itthinx.com/shop/groups-restrict-categories/">Groups Restrict Categories</a> is used.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; echo '</div>'; echo '<br/>'; echo '<p style="border-top:1px solid #eee; margin-top:1em; padding-top: 1em;">' . '<label>' . __('Redirect Status Code', GROUPS_404_REDIRECT_PLUGIN_DOMAIN) . ' ' . '<select name="status">'; foreach ($http_status_codes as $code => $name) { echo '<option value="' . esc_attr($code) . '" ' . ($redirect_status == $code ? ' selected="selected" ' : '') . '>' . $name . ' (' . $code . ')' . '</option>'; } echo '</select>' . '</label>' . '</p>'; echo '<p class="description">'; echo __('<a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">RFC 2616</a> provides details on <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">Status Code Definitions</a>.', GROUPS_404_REDIRECT_PLUGIN_DOMAIN); echo '</p>'; wp_nonce_field('admin', 'groups-404-redirect', true, true); echo '<br/>'; echo '<div class="buttons">'; echo sprintf('<input class="create button" type="submit" name="submit" value="%s" />', __('Save', GROUPS_404_REDIRECT_PLUGIN_DOMAIN)); echo '<input type="hidden" name="action" value="save" />'; echo '</div>'; echo '</div>'; echo '</form>'; echo '</div>'; }