Skip to content

Commit

Permalink
initial commit to match .org repo
Browse files Browse the repository at this point in the history
  • Loading branch information
norcross committed Mar 19, 2019
0 parents commit fd5ab11
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 0 deletions.
190 changes: 190 additions & 0 deletions extra-authors-redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?php
/*
Plugin Name: Extra Authors Redirect
Plugin URI: http://andrewnorcross.com/plugins/
Description: Adds a checkbox to author profiles to redirect.
Version: 1.2
Author: Andrew Norcross
Author URI: http://andrewnorcross.com
Copyright 2013 Andrew Norcross
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// Start up the engine
class Extra_Authors_Redirect
{

/**
* Static property to hold our singleton instance
*
* @since 1.0
*/
static $instance = false;

/**
* This is our constructor
*
* @since 1.0
*/
public function __construct() {
add_action ( 'plugins_loaded', array( $this, 'textdomain' ) );
add_action ( 'personal_options', array( $this, 'author_redirect_show' ), 20 );
add_action ( 'personal_options_update', array( $this, 'author_redirect_save' ) );
add_action ( 'edit_user_profile_update', array( $this, 'author_redirect_save' ) );
add_action ( 'template_redirect', array( $this, 'author_redirect_fire' ), 1 );
add_action ( 'template_redirect', array( $this, 'forum_redirect_fire' ), 1 );
}

/**
* If an instance exists, this returns it. If not, it creates one and
* retuns it.
*
* @since 1.0
*/

public static function getInstance() {
if ( !self::$instance )
self::$instance = new self;
return self::$instance;
}

/**
* load textdomain
*
* @since 1.0
*/


public function textdomain() {

load_plugin_textdomain( 'exar', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

/**
* save new updated item
*
* @since 1.0
*/

public function author_redirect_save( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) )
return false;

if ( isset( $_POST['author_redirect'] ) )
update_usermeta( $user_id, 'author_redirect', $_POST['author_redirect'] );

}

/**
* display checkbox option
*
* @since 1.0
*/

public function author_redirect_show( $profileuser ) {

// get potential metadata
$redirect = get_user_meta( $profileuser->ID, 'author_redirect', true );
?>
<table class="form-table">
<tr>
<th scope="row"><?php _e( 'Author Redirect', 'exar' ); ?></th>
<td>
<label for="author_redirect">
<input type="checkbox" name="author_redirect" id="author_redirect" value="true" <?php if ( !empty($profileuser->author_redirect) ) checked('true', $profileuser->author_redirect); ?> /> <?php _e('Redirect this author template page to the home page', 'exar'); ?>
</label>
</td>
</tr>
</table>
<?php
}

/**
* redirect author template if applicable
*
* @since 1.0
*/

public function author_redirect_fire() {

// bail if we aren't on an author page
if ( !is_author() )
return;

// get author ID of template
$author_id = get_query_var('author');

// bail if we somehow came back with empty
if ( empty( $author_id ) )
return;

$redirect = get_user_meta( $author_id, 'author_redirect', true );

if ( empty ($redirect) )
return;

// get default URL and apply filter
$location = get_bloginfo('url').'/';
$location = apply_filters( 'extra_author_redirect_url', $location );

wp_redirect( esc_url_raw( $location ), 301 );
exit();

}

/**
* redirect forum profile template if applicable
*
* @since 1.0
*/

public function forum_redirect_fire() {

// Bail if no bbPress
if ( !function_exists( 'is_bbpress') )
return;

// bail if we aren't on an author page
if ( !bbp_is_single_user_profile() )
return;

// get author ID of template
$author_id = get_query_var('author');

// bail if we somehow came back with empty
if ( empty( $author_id ) )
return;

$redirect = get_user_meta( $author_id, 'author_redirect', true );

if ( empty ($redirect) )
return;

// get default URL and apply filter
$location = get_bloginfo('url').'/';
$location = apply_filters( 'extra_author_redirect_url', $location );

wp_redirect( esc_url_raw( $location ), 301 );
exit();

}

/// end class
}

// Instantiate our class
$Extra_Authors_Redirect = Extra_Authors_Redirect::getInstance();
Binary file added languages/default.mo
Binary file not shown.
22 changes: 22 additions & 0 deletions languages/default.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
msgid ""
msgstr ""
"Project-Id-Version: exar\n"
"POT-Creation-Date: 2013-03-04 11:28-0500\n"
"PO-Revision-Date: 2013-03-04 11:28-0500\n"
"Last-Translator: Andrew Norcross <[email protected]>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.5\n"
"X-Poedit-KeywordsList: _;__;_e\n"
"X-Poedit-Basepath: ../\n"
"X-Poedit-SearchPath-0: .\n"

#: extra-authors-redirect.php:102
msgid "Author Redirect"
msgstr ""

#: extra-authors-redirect.php:105
msgid "Redirect this author template page to the home page"
msgstr ""
64 changes: 64 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
=== Extra Authors Redirect ===
Contributors: norcross, jjeaton, reaktivstudios
Website Link: http://andrewnorcross.com/plugins/
Donate link: https://andrewnorcross.com/donate
Tags: author-page, authors, redirects
Requires at least: 3.3
Tested up to: 3.9
Stable tag: 1.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Adds a checkbox to author profiles for redirecting to other parts of the site.

== Description ==

Adds a checkbox to author profiles to redirect. Useful for sites that have occasional authors or user accounts not intended for display.

== Installation ==

This section describes how to install the plugin and get it working.

1. Upload `extra-authors-redirect` to the `/wp-content/plugins/` directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Check the author(s) you want redirected.

== Frequently Asked Questions ==


= Does this affect posts / pages / admin / ??? =

No. this only affects people going to the /author/ template page on a site, and only affects those that have been marked to redirect.

= Can I change where the redirect goes? =

Yes. There is a filter to change the default behavior. In your functions file, include the following:

`function new_auth_url($location) {
$location = 'http://google.com';
return $location;
}
add_filter( 'extra_author_redirect_url', 'new_auth_url' );`

== Screenshots ==

1. The checkbox


== Changelog ==

= 1.2 =
* Will also redirect for bbPress profile pages

= 1.1 =
* Cleaner meta check for adding author meta entry

= 1.0 =
* First release!


== Upgrade Notice ==


= 1.0 =
* First release!

0 comments on commit fd5ab11

Please sign in to comment.