| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Profile Builder |
| 4 |
Plugin URI: http://www.cozmoslabs.com/2011/04/12/wordpress-profile-builder-a-front-end-user-registration-login-and-edit-profile-plugin/ |
| 5 |
Description: Login, registration and edit profile shortcodes for the front-end. Also you can chose what fields should be displayed. |
| 6 |
Version: 1.0.9 |
| 7 |
Author: Reflection Media |
| 8 |
Author URI: http://reflectionmedia.ro |
| 9 |
License: GPL2 |
| 10 |
|
| 11 |
== Copyright == |
| 12 |
Copyright 2011 Reflection Media (wwww.reflectionmedia.ro) |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License as published by |
| 16 |
the Free Software Foundation; either version 2 of the License, or |
| 17 |
(at your option) any later version. |
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
along with this program; if not, write to the Free Software |
| 24 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
*/ |
| 26 |
|
| 27 |
register_activation_hook( __FILE__ , 'wppb_initialize_variables' ); //initialize some values upon plug-in activation |
| 28 |
|
| 29 |
function wppb_initialize_variables(){ |
| 30 |
$wppb_default_settings = array( 'username' => 'show', |
| 31 |
'firstname'=> 'show', |
| 32 |
'lastname' => 'show', |
| 33 |
'nickname' => 'show', |
| 34 |
'dispname' => 'show', |
| 35 |
'email' => 'show', |
| 36 |
'website' => 'show', |
| 37 |
'aim' => 'show', |
| 38 |
'yahoo' => 'show', |
| 39 |
'jabber' => 'show', |
| 40 |
'bio' => 'show', |
| 41 |
'password' => 'show' ); |
| 42 |
add_option( 'wppb_default_settings', $wppb_default_settings ); //set all fields visible on first activation of the plugin |
| 43 |
add_option( 'wppb_default_style', 'yes'); |
| 44 |
|
| 45 |
global $wp_roles; |
| 46 |
$all_roles = $wp_roles->roles; |
| 47 |
$editable_roles = apply_filters('editable_roles', $all_roles); |
| 48 |
|
| 49 |
$admintSettingsPresent = get_option('wppb_display_admin_settings','not_found'); |
| 50 |
|
| 51 |
if ($admintSettingsPresent == 'not_found'){ // if the field doesn't exists, then create it |
| 52 |
$rolesArray = array(); |
| 53 |
foreach ( $editable_roles as $key => $data ) |
| 54 |
$rolesArray = array( $key => 'show' ) + $rolesArray; |
| 55 |
$rolesArray = array_reverse($rolesArray,true); |
| 56 |
add_option( 'wppb_display_admin_settings', $rolesArray); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
function wppb_create_menu(){ |
| 62 |
add_submenu_page('users.php', 'Profile Builder', 'Profile Builder', 'delete_users', 'ProfileBuilderSettings', 'wppb_display_menu'); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
function wppb_register_settings() { // whitelist options, you can add more register_settings changing the second parameter |
| 67 |
register_setting( 'wppb-option-group', 'wppb_default_settings' ); |
| 68 |
register_setting( 'wppb_default_style', 'wppb_default_style' ); |
| 69 |
register_setting( 'wppb_display_admin_settings', 'wppb_display_admin_settings' ); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
function wppb_add_plugin_stylesheet() { |
| 74 |
$wppb_showDefaultCss = get_option('wppb_default_style'); |
| 75 |
$styleUrl = WP_PLUGIN_URL . '/profile-builder/css/style.css'; |
| 76 |
$styleFile = WP_PLUGIN_DIR . '/profile-builder/css/style.css'; |
| 77 |
if ( file_exists($styleFile) && $wppb_showDefaultCss == 'yes') { |
| 78 |
wp_register_style('wppb_stylesheet', $styleUrl); |
| 79 |
wp_enqueue_style( 'wppb_stylesheet'); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
function wppb_show_admin_bar($content){ |
| 85 |
global $current_user; |
| 86 |
$admintSettingsPresent = get_option('wppb_display_admin_settings','not_found'); |
| 87 |
if ($admintSettingsPresent != 'not_found'){ |
| 88 |
$wppb_showAdminBar = get_option('wppb_display_admin_settings'); |
| 89 |
$userRole = ($current_user->data->wp_capabilities); |
| 90 |
if ($userRole != NULL){ |
| 91 |
$currentRole = key($userRole); |
| 92 |
$getSettings = $wppb_showAdminBar[$currentRole]; |
| 93 |
if ($getSettings == 'show') |
| 94 |
return true; |
| 95 |
elseif ($getSettings == 'hide') |
| 96 |
return false; |
| 97 |
} |
| 98 |
} |
| 99 |
else |
| 100 |
return true; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
if (is_admin() ){ // if we are in the admin menu |
| 105 |
include_once('includes/wppb-menu-file.php'); // include the menu file |
| 106 |
add_action('admin_init', 'wppb_register_settings'); // register the settings for the menu only display sidebar menu for a user with a certain capability, in this case only the "admin" |
| 107 |
add_action('admin_menu','wppb_create_menu'); // call the wppb_create_menu function |
| 108 |
}else{ // if we aren't in the admin back-end menu, aka we are in the front-end view |
| 109 |
add_action('wp_print_styles', 'wppb_add_plugin_stylesheet'); // include the standard style-sheet or specify the path to a new one |
| 110 |
include_once('includes/wppb-front-end-profile.php'); // include the menu file for the profile informations |
| 111 |
add_shortcode('wppb-edit-profile', 'wppb_front_end_profile_info'); |
| 112 |
include_once('includes/wppb-front-end-login.php'); // include the menu file for the login screen |
| 113 |
add_shortcode('wppb-login', 'wppb_front_end_login'); |
| 114 |
include_once('includes/wppb-front-end-register.php'); // include the menu file for the register screen |
| 115 |
add_shortcode('wppb-register', 'wppb_front_end_register'); |
| 116 |
add_filter( 'show_admin_bar' , 'wppb_show_admin_bar'); // set the front-end admin bar to show/hide |
| 117 |
|
| 118 |
/* Allow shortcodes to be used in the text widgets */ |
| 119 |
add_filter('widget_text', 'do_shortcode'); |
| 120 |
} |
| 121 |
|