_name = "all_author_plug";
$this->page_title = 'All Authors Page';
$this->page_name = $this->_name;
$this->page_id = '0';
$this->admin_option = __FILE__;
$this->admin_action =
trailingslashit(get_bloginfo('wpurl')) . 'wp-admin/'
. ($this->wp27 ? 'options-general.php' : 'admin.php')
. '?page=' . $this->admin_option;
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
register_uninstall_hook(__FILE__, array($this, 'uninstall'));
add_filter('parse_query', array($this, 'query_parser'));
add_filter('the_posts', array($this, 'page_filter'));
//add_filter('plugin_action_links', array($this, 'plugin_options_link'), 10, 2);
add_action('admin_menu', array($this,'authorlistpage_create_menu'));
add_action('user_contactmethods', array($this, 'change_contactmethod'));
//add_action('personal_options_update', array($this, 'aap_save_user_setting'));
}
// Add a custom field to the form in "Profile"
function aap_user_setting($user) {
$meta = get_userdata($user->ID);
echo "";
if($meta->google_profile){
$google = $meta->google_profile;
}else{
$google = '';
}
if($meta->linkedin_profile){
$linkedin = $meta->linkedin_profile;
}else{
$linkedin = "";
}
if($meta->twitter_profile){
$twitter = $meta->twitter_profile;
}else{
$twitter = "";
}
?>
|
|
|
|
|
|
|
|
addPluginSettingLinks($links, $file);
} else {
$this_plugin = plugin_basename(__FILE__);
if ($file == $this_plugin) {
$settings_link = '' . __('Settings') . '';
array_unshift($links, $settings_link); // before other links
}
}
return $links;
}
public function activate()
{
global $wpdb;
delete_option($this->_name.'_page_id');
add_option($this->_name.'_page_id', $this->page_id, '', 'yes');
delete_option($this->_name.'_page_title');
add_option($this->_name.'_page_title', $this->page_title, '', 'yes');
delete_option($this->_name.'_page_name');
add_option($this->_name.'_page_name', $this->page_name, '', 'yes');
delete_option($this->_name.'_role_check');
add_option($this->_name.'_role_check', 'author');
delete_option($this->_name.'_show_email');
add_option($this->_name.'_show_email','true');
$the_page = get_page_by_title($this->page_title);
if (!$the_page)
{
$_p = array();
$_p['post_title'] = $this->page_title;
$_p['post_content'] = $this->listAllAuthors();
$_p['post_status'] = 'publish';
$_p['post_type'] = 'page';
$_p['comment_status'] = 'closed';
$_p['ping_status'] = 'closed';
$_p['post_category'] = array(1); // 'Uncatrgorised'
$this->page_id = wp_insert_post($_p);
}
else
{
// the plugin may have been previously active and the page may just be trashed...
$this->page_id = $the_page->ID;
//make sure the page is not trashed...
$the_page->post_status = 'publish';
$this->page_id = wp_update_post($the_page);
}
delete_option($this->_name.'_page_id');
add_option($this->_name.'_page_id', $this->page_id);
}
public function deactivate()
{
$this->deletePage();
$this->deleteOptions();
}
public function listAllAuthors()
{
$output = "";
$roleCheck = get_option($this->_name.'_role_check');
$output .= "";
$athr = strpos($roleCheck, 'author');
$adm = strpos($roleCheck, 'admin');
$ctrbr = strpos($roleCheck, 'contributor');
$edtr = strpos($roleCheck, 'editor');
if ($roleCheck){
if($athr !== false){
$output .= "";
$output .= $this->printRole('author');
}
if($adm !== false){
$output .= "";
$output .= $this->printRole('administrator');
}
if($ctrbr !== false ){
$output .= "";
$output .= $this->printRole('contributor');
}
if($edtr !== false ){
$output .= "";
$output .= $this->printRole('editor');
}
}else{
$output .= "There is no roles selected to display on this page, please select some roles from the settings menu and then all the information for these people will be displayed here";
}
return $output;
}
public function printRole($role){
$output = "";
$wp_user_query = new WP_User_Query( array( 'role' => $role, 'fields' => 'all_with_meta' ) );
$authors = $wp_user_query->get_results();
if (!empty($authors))
{
$output .= '';
foreach ($authors as $author)
{
$curauth = get_userdata($author->ID);
$output .= '' . $curauth->first_name . ' ' . $curauth->last_name;
$email = $curauth->user_email;
$img = $this->get_gravatar($email);
$imagesPath = plugins_url( 'images/', __FILE__ );
$output .= $img;
if(!empty($curauth->google_profile)){
$gPlus = '
';
}else{
$gPlus = '';
}
if(!empty($curauth->linkedin_profile)){
$li = '
';
}else{
$li = '';
}
if(!empty($curauth->twitter_profile)){
$twit = '
';
}else{
$twit = '';
}
if(!empty($curauth->facebook_profile)){
$fcbk = '
';
}else{
$fcbk = '';
}
$showMail = get_option($this->_name.'_show_email');
if($showMail == "true"){
$output .= '
- Social Networks
- ' . $gPlus . $li . $twit . $fcbk .'
- Website
- ' . $curauth->user_url . '
- Email
- ' . $curauth->user_email . '
- Profile
- ' . $curauth->user_description . '
';
}else{
$output .= '
- Social Networks
- ' . $gPlus . $li . $twit . $fcbk .'
- Website
- ' . $curauth->user_url . '
- Profile
- ' . $curauth->user_description . '
';
}
/*
if ( have_posts() ) : while ( have_posts() ) : the_post()
$output .= '
' . the_title() . ',
' . the_time('d M Y') . ' in ' . the_category('&') . '
';
endwhile else:
$output .= '' . _e('No posts by this author.') . '
';
endif
*/
}
}
return $output;
}
public function uninstall()
{
$this->deletePage(true);
$this->deleteOptions();
}
public function query_parser($q)
{
if(isset($q->query_vars['page_id']) AND (intval($q->query_vars['page_id']) == $this->page_id ))
{
$q->set($this->_name.'_page_is_called', true);
}
elseif(isset($q->query_vars['pagename']) AND (($q->query_vars['pagename'] == $this->page_name) OR ($_pos_found = strpos($q->query_vars['pagename'],$this->page_name.'/') === 0)))
{
$q->set($this->_name.'_page_is_called', true);
}
else
{
$q->set($this->_name.'_page_is_called', false);
}
}
function page_filter($posts)
{
global $wp_query;
foreach ($posts as $p){
if($p->post_title == 'All Authors Page')
{
$p->post_content = $this->listAllAuthors();
}
}
return $posts;
}
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param string $s Size in pixels, defaults to 80px [ 1 - 512 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param boole $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @return String containing either just a URL or a complete image tag
* @source http://gravatar.com/site/implement/images/php/
*/
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'pg', $img = true, $atts = array() ) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '
$val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
private function deletePage($hard = false)
{
global $wpdb;
$id = get_option($this->_name.'_page_id');
if($id && $hard == true)
wp_delete_post($id, true);
elseif($id && $hard == false)
wp_delete_post($id);
}
private function deleteOptions()
{
delete_option($this->_name.'_page_title');
delete_option($this->_name.'_page_name');
delete_option($this->_name.'_page_id');
delete_option($this->_name.'_role_check');
delete_option($this->_name.'_show_email');
}
function authorlistpage_create_menu() {
//create new top-level menu
add_options_page('All Author Settings', 'All Author Settings', 'manage_options', __FILE__, array($this,'authorlistpage_settings_page'));
//call register settings function
//add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
//register our settings
register_setting( 'authorlistpage-settings-group', 'aap-roles' );
}
function authorlistpage_settings_page() {
$roleCheck = $this->_name . '_role_check';
$role_val = get_option($this->_name.'_role_check');
echo "";
$email_val = get_option($this->_name.'_show_email');
echo "";
if(isset($_POST)){
if($_POST['all_author_plug_role_check'] != "" || $_POST['all_author_plug_role_check'] != null){
if(update_option('all_author_plug_role_check',$_POST['all_author_plug_role_check'])){
echo "Roles to show on 'All Author Page' Updated!
";
}else{
echo "There was a problem updating the database
";
}
}
if($_POST['email'] == "true" || $_POST['email'] == "false"){
if(update_option($this->_name.'_show_email',$_POST['email'])){
echo "Email show settings on 'All Author Page' Updated!
";
}else{
echo "There was a problem updating the database
";
}
}
}
$email_val = get_option($this->_name.'_show_email');
$role_val = get_option($this->_name.'_role_check');
?>
All Authors Options
Current roles being displayed on Authors Page:
Author email addresses being shown on Authors Page: