| 1 |
<?php if (!defined('ProfileBuilderVersion')) exit('No direct script access allowed'); |
| 2 |
/* |
| 3 |
Original Plugin Name: OptionTree |
| 4 |
Original Plugin URI: http://wp.envato.com |
| 5 |
Original Author: Derek Herman |
| 6 |
Original Author URI: http://valendesigns.com |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Profile Builder Admin |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
class PB_Admin{ |
| 15 |
private $version = NULL; |
| 16 |
|
| 17 |
function __construct(){ |
| 18 |
$this->version = ProfileBuilderVersion; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Initiate Plugin & setup main options |
| 23 |
* |
| 24 |
* @uses get_option() |
| 25 |
* @uses add_option() |
| 26 |
* @uses profile_builder_activate() |
| 27 |
* @uses wp_redirect() |
| 28 |
* @uses admin_url() |
| 29 |
* |
| 30 |
* @access public |
| 31 |
* |
| 32 |
* |
| 33 |
* @return bool |
| 34 |
*/ |
| 35 |
function profile_builder_initialize(){ |
| 36 |
// check for activation |
| 37 |
$check = get_option( 'profile_builder_activation' ); |
| 38 |
|
| 39 |
// redirect on activation |
| 40 |
if ($check != "set") { |
| 41 |
// add theme options |
| 42 |
add_option( 'profile_builder_activation', 'set'); |
| 43 |
|
| 44 |
// load DB activation function if updating plugin |
| 45 |
$this->profile_builder_activate(); |
| 46 |
|
| 47 |
// Redirect |
| 48 |
wp_redirect( admin_url().'users.php?page=ProfileBuilderOptionsAndSettings' ); |
| 49 |
} |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Plugin Activation |
| 56 |
* |
| 57 |
* |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
function profile_builder_activate(){ |
| 62 |
global $wp_roles; |
| 63 |
|
| 64 |
// check for installed version |
| 65 |
$installed_ver = get_option( 'profile_builder_version' ); |
| 66 |
|
| 67 |
// New Version Update |
| 68 |
if ( $installed_ver != $this->version ){ |
| 69 |
update_option( 'profile_builder_version', $this->version ); |
| 70 |
} |
| 71 |
else if ( !$installed_ver ) { |
| 72 |
add_option( 'profile_builder_version', $this->version ); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
$wppb_default_settings = array( 'username' => 'show', |
| 77 |
'firstname'=> 'show', |
| 78 |
'lastname' => 'show', |
| 79 |
'nickname' => 'show', |
| 80 |
'dispname' => 'show', |
| 81 |
'email' => 'show', |
| 82 |
'website' => 'show', |
| 83 |
'aim' => 'show', |
| 84 |
'yahoo' => 'show', |
| 85 |
'jabber' => 'show', |
| 86 |
'bio' => 'show', |
| 87 |
'password' => 'show'); |
| 88 |
add_option( 'wppb_default_settings', $wppb_default_settings ); //set all fields visible on first activation of the plugin |
| 89 |
add_option( 'wppb_default_style', 'yes'); |
| 90 |
$all_roles = $wp_roles->roles; |
| 91 |
$editable_roles = apply_filters('editable_roles', $all_roles); |
| 92 |
|
| 93 |
$admintSettingsPresent = get_option('wppb_display_admin_settings','not_found'); |
| 94 |
|
| 95 |
if ($admintSettingsPresent == 'not_found'){ // if the field doesn't exists, then create it |
| 96 |
$rolesArray = array(); |
| 97 |
foreach ( $editable_roles as $key => $data ) |
| 98 |
$rolesArray = array( $key => 'show' ) + $rolesArray; |
| 99 |
$rolesArray = array_reverse($rolesArray,true); |
| 100 |
add_option( 'wppb_display_admin_settings', $rolesArray); |
| 101 |
} |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Plugin Deactivation delete options |
| 107 |
* |
| 108 |
* @uses delete_option() |
| 109 |
* |
| 110 |
* @access public |
| 111 |
* |
| 112 |
* |
| 113 |
* @return void |
| 114 |
*/ |
| 115 |
function profile_builder_deactivate() { |
| 116 |
// remove activation check & version |
| 117 |
delete_option( 'profile_builder_activation' ); |
| 118 |
delete_option( 'profile_builder_version' ); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Add Admin Menu Items & Test Actions |
| 123 |
* |
| 124 |
* |
| 125 |
* @return void |
| 126 |
*/ |
| 127 |
function profile_builder_admin(){ |
| 128 |
// create menu item |
| 129 |
$profile_builder_options = add_submenu_page( 'users.php', 'Profile Builder', 'Profile Builder', 'delete_users', 'ProfileBuilderOptionsAndSettings', array( $this, 'profile_builder_options_page' ) ); |
| 130 |
|
| 131 |
// add menu item |
| 132 |
add_action( "admin_print_styles-$profile_builder_options", array( $this, 'profile_builder_load' ) ); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Load Scripts & Styles |
| 137 |
* |
| 138 |
* @uses wp_enqueue_style() |
| 139 |
* |
| 140 |
* |
| 141 |
* @return void |
| 142 |
*/ |
| 143 |
function profile_builder_load(){ |
| 144 |
// enqueue styles |
| 145 |
wp_enqueue_style( 'profile-builder-style', wppb_plugin_url.'/assets/css/style.css', false, $this->version, 'screen'); |
| 146 |
|
| 147 |
// enqueue scripts |
| 148 |
add_thickbox(); |
| 149 |
wp_enqueue_script( 'jquery-extra-profile-fields', wppb_plugin_url.'/assets/js/jquery.extra.fields.js', array('jquery','media-upload','thickbox','jquery-ui-core','jquery-ui-tabs', 'jquery-ui-sortable'), $this->version ); |
| 150 |
|
| 151 |
// remove GD star rating conflicts |
| 152 |
wp_deregister_style( 'gdsr-jquery-ui-core' ); |
| 153 |
wp_deregister_style( 'gdsr-jquery-ui-theme' ); |
| 154 |
} |
| 155 |
|
| 156 |
function profile_builder_options_page() { |
| 157 |
// Grab Options Page |
| 158 |
include( wppb_plugin_dir.'/front-end/options.php' ); |
| 159 |
} |
| 160 |
|
| 161 |
} |