* * wpDirAuth: WordPress Directory Authentication * Copyright (C) 2007 Stephane Daury * * wpDirAuth is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * wpDirAuth is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * Default WordPress custom field key name. */ define('WPREDIRECT_DEFAULT_META', 'redirect_me'); /** * Safe and convenient redirection mechanism. * * @param string $url Fully qualified URL or local path web to redirect to. * @return boolean false || exit */ function wpRedirect($url) { if ($url) { @ob_end_clean(); if (headers_sent()) { $caption = __('The page you are trying to access is located at the following address:'); echo<<<____________EOS Redirect

$caption
$url

____________EOS; } else{ @header("Location:$url\n"); } exit; } else{ return false; } } /** * Gets the appropriate WP post meta key to to retrieve the redirect url. * * @return string Custom or default field key name. */ function wpRedirect_metaKey() { $metaKey = get_option("wpRedirectMeta"); if (!$metaKey) $metaKey = WPREDIRECT_DEFAULT_META; return $metaKey; } /** * wpRedirect wrapper for WordPress add_action(); checks if post is * single or page, tries to get content of `redirect_me` custom field, * then redirects if necessary. * * @return void */ function wpRedirect_init() { if (!is_single() && !is_page()) return false; global $post; $url = get_post_meta($post->ID, wpRedirect_metaKey(), true); if ($url) wpRedirect($url); } /** * wpRedirect plugin configuration panel. * Used in wpRedirect_addMenu(); * * @return void */ function wpRedirect_optionsPanel() { if ($_POST['wpRedirectOptionsSave']) { update_option('wpRedirectMeta', $_POST['wpRedirectMeta']); echo '

Your new settings were saved successfully.

'; } $metaKey = wpRedirect_metaKey(); $defMeta = WPREDIRECT_DEFAULT_META; echo <<

Redirection Options



The custom field key to scan for when displaying a single post or page. Defaults to "$defMeta".
EG: Can be set to an existing custom field, such as the one set by the built-in Import feature.

Powered by wpRedirect.

DirAuthForm; } /** * Adds the Menu for Wordpress Admin Panel. * Used in add_action('admin_menu', 'wpDirAuth_addmenu'); * * @return void */ function wpRedirect_addMenu() { if (function_exists('add_options_page')) { add_options_page('Redirection Options', 'Redirection', 9, basename(__FILE__), 'wpRedirect_optionsPanel'); } } /** * Add custom WordPress actions */ if (function_exists('add_action')) { add_action('wp', 'wpRedirect_init',1); add_action('admin_menu', 'wpRedirect_addMenu'); } ?>