Created
October 30, 2015 01:00
-
-
Save DevinVinson/7951207a70eba5f3cc48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Verified Users | |
Version: 1.0 | |
Description: Very simple verified users option | |
Author: Devin Vinson | |
Text Domain: verified-users | |
Domain Path: /languages | |
*/ | |
/** | |
* Class Verified_Users | |
* | |
* @since 1.0 | |
* @author [email protected] | |
*/ | |
class Verified_Users { | |
static private $instance = null; | |
/** | |
* Quick and simple singleton | |
* | |
* @return null|Verified_Users | |
*/ | |
static public function getInstance() { | |
if ( self::$instance == null ) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} | |
/** | |
* Hook into WP | |
*/ | |
private function __construct() { | |
add_action( 'show_user_profile', array( $this, 'verified_user_option' ) ); | |
add_action( 'edit_user_profile', array( $this, 'verified_user_option' ) ); | |
add_action( 'edit_user_profile_update', array( $this, 'save_verified_user_option' ) ); | |
add_action( 'personal_options_update', array( $this, 'save_verified_user_option' ) ); | |
} | |
/** | |
* Add the Verification setting to User Profile | |
* | |
* Check for 'verified' when using get_user_meta | |
* | |
* @param $user | |
*/ | |
public function verified_user_option( $user ) { | |
$user_verification = get_the_author_meta( 'user_verification', $user->ID ); | |
?> | |
<h3>User Verification</h3> | |
<p>Verification can be set by site administrators only.</p> | |
<table class="form-table"> | |
<tr> | |
<th><label for="user_verification">Verified:</label></th> | |
<td> | |
<input <?php if ( !current_user_can( 'edit_theme_options', $user->ID ) ){ echo 'disabled="disabled"'; } ?> name="user_verification" type="checkbox" id="user_verification" value="verified" <?php checked( $user_verification, "verified"); ?> /> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
public function save_verified_user_option( $user_id ) { | |
if ( !current_user_can( 'edit_theme_options', $user_id ) ) { | |
return false; | |
} else { | |
update_user_meta( $user_id, 'user_verification', $_POST['user_verification'] ); | |
} | |
} | |
} | |
$verified_users_plugin = Verified_Users::getInstance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment