1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
<?php
/*
Plugin Name: danixland User Panel
Plugin URI: http://danixland.net/blog/2010/603-danixland-user-panel-plugin/
Description: A modified version of the meta widget which gives more info about the user.
Version: 1.4.2
Author: Danilo 'danix' Macri
Author URI: http://danixland.net
Text Domain: dnxup
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.
*/
/**************************************************************************************
Since Version 1.1.1 this plugin uses some code and inspiration from the sidebar-login
plugin by Mike Jolley < http://blue-anvil.com > < http://mikejolley.com >
big kudos to him!!!
**************************************************************************************/
/**
* Add plugin i18n domain: dnxup
* @since 1.1.1
*/
load_plugin_textdomain('dnxup', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
/**
* Include settings options for our plugin
* @since 1.1.1
*/
function dnxup_settings() {
add_options_page('danixland User Panel Settings', __('User Panel Options', 'dnxup'), 'manage_options', 'dnxup_options', 'dnxup_settings_display');
}
add_action('admin_menu', 'dnxup_settings' );
/**
* The function that outputs our admin page
* @since 1.1.1
*/
function dnxup_settings_display() {
?>
<div class="wrap">
<h2><?php _e('danixland User Panel Settings', 'dnxup') ?></h2>
<form method="post" action="options.php">
<?php
settings_fields('dnxup_options');
do_settings_sections('dnxup_settings_sections');
?>
<p class="submit">
<input name="dnxup_options[submit]" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'dnxup') ?>" />
<input name="dnxup_options[reset]" type="submit" class="button-secondary" value="<?php esc_attr_e('Reset Defaults', 'dnxup'); ?>" />
</p>
</form>
</div>
<?php
}
/**
* Settings API options initilization and validation
* @since 1.1.1
*/
function dnxup_register_options() {
require( dirname( __FILE__ ) . '/include/options-register.php' );
}
add_action('admin_init', 'dnxup_register_options');
/**
* DataBase initilization and update procedure
* @since 1.1.2
*/
// helper function that returns DB defaults
function dnxup_db_defaults() {
$defaults = array(
'show_gravatar' => true,
'logged_out_heading' => 'Howdy Guest',
'logged_in_heading' => 'Howdy %username%',
'logged_in_links' => "<a href=\"" . admin_url() . "\">" . __('Dashboard','dnxup') . "</a>\n<a href=\"" . admin_url('profile.php') . "\">" . __('Profile','dnxup') . "</a>",
// database version
'dnxup_DB_VERSION' => '1'
);
return $defaults;
}
// helper function that starts up the DB
function dnxup_db_init() {
global $dnxup_options;
$dnxup_options = get_option('dnxup_options');
if( false === $dnxup_options ) {
$dnxup_options = dnxup_db_defaults();
}
update_option('dnxup_options', $dnxup_options);
}
// helper function that performs a DB version update when needed
function dnxup_db_update($db_version) {
global $dnxup_options;
$db_defaults = dnxup_db_defaults();
$merge = wp_parse_args( $dnxup_options, $db_defaults );
// update DB version
$merge['dnxup_DB_VERSION'] = $db_version;
update_option('dnxup_options', $merge);
}
// helper function that performs a DB check and then an init/update action
function dnxup_db_check() {
global $dnxup_options;
if(false === $dnxup_options) {
dnxup_db_init();
}
$old_db_version = $dnxup_options['dnxup_DB_VERSION'];
$new_db_version = DNXUP_CURRENT_DB_VERSION;
if(empty($old_db_version)) {
dnxup_db_init();
}
if( intval($old_db_version) < intval($new_db_version) ) {
dnxup_db_update( $new_db_version );
}
}
function dnxup_set_db_version() {
// Define plugin database version. This should only change when new settings are added.
if ( ! defined( 'DNXUP_CURRENT_DB_VERSION' ) ) {
define( 'DNXUP_CURRENT_DB_VERSION', 2 );
}
}
/**
* Add function on plugin activation that'll set our DB version and perform a check for update
* @since 1.1.3
*/
register_activation_hook( __FILE__, 'dnxup_set_db_version' );
register_activation_hook( __FILE__, 'dnxup_db_check' );
/**
* function that returns the actual url for redirection after logout
* as seen on sidebar-login by Mike Jolley with small modifications
* @since 1.1.3
*/
function dnxup_current_url($url = '') {
global $wpdb, $post, $cat, $tag, $author, $year, $monthnum, $day, $wp_query;
$pageURL = "";
if ( is_home() && $wp_query->is_posts_page==1)
{
$pageURL = get_permalink(get_option('page_for_posts'));
}
elseif (is_home() || is_front_page())
{
$pageURL = get_bloginfo('url');
}
elseif (is_post_type_archive())
{
$pageURL = get_post_type_archive_link( get_query_var('post_type') );
}
elseif (is_single() || is_page())
{
$pageURL = get_permalink($wp_query->post->ID);
}
elseif (is_category())
{
$pageURL = get_category_link($cat);
}
elseif (is_tag())
{
$tag_id = $wpdb->get_var("SELECT ".$wpdb->terms.".term_id FROM $wpdb->term_taxonomy
LEFT JOIN $wpdb->terms
ON (".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id)
WHERE ".$wpdb->terms.".slug = '$tag'
AND ".$wpdb->term_taxonomy.".taxonomy = 'post_tag' LIMIT 1");
$pageURL = get_tag_link($tag_id);
}
elseif (is_author())
{
$pageURL = get_author_posts_url($author);
}
elseif (is_date())
{
if ($day)
{
$pageURL = get_day_link( $year, $monthnum, $day);
}
elseif ($monthnum)
{
$pageURL = get_month_link( $year, $monthnum, $day);
}
elseif ($year)
{
$pageURL = get_year_link( $year, $monthnum, $day);
}
}
elseif (is_search())
{
$pageURL = get_bloginfo('wpurl');
if ("/" != substr($pageURL, -1)) $pageURL = $pageURL . "/";
$pageURL .= '?s='.stripslashes(strip_tags($_REQUEST['s'])).'';
}
if (!$pageURL || $pageURL=="" || !is_string($pageURL)) {
$pageURL = "";
$pageURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
//————–added by mick
if (!strstr(get_bloginfo('url'),'www.')) $pageURL = str_replace('www.','', $pageURL );
//——————–
}
if ($pageURL && !is_search()) if ("/" != substr($pageURL, -1)) $pageURL = $pageURL . "/";
return $pageURL;
}
/**
* Add function to widgets_init that'll load our widget.
* @since 0.1
*/
add_action( 'widgets_init', 'danixland_user_panel' );
/**
* Register our widget.
* 'User_Panel' is the widget class used below.
*
* @since 0.1
*/
function danixland_user_panel() {
register_widget( 'User_Panel' );
}
/**
* User_Panel class.
* This class handles everything that needs to be handled with the widget:
* the settings, form, display, and update. Nice!
*
* @since 0.1
*/
class User_Panel extends WP_Widget {
/**
* Widget setup.
*/
function __construct() {
parent::__construct(
'dnx-user-panel', // id_base
__('danixland User Panel', 'dnxup' ), // Name
array( 'description' => __('An improved version of the meta widget', 'dnxup') )
);
}
/**
* How to display the widget on the public side of the site.
*/
public function widget( $args, $instance ) {
extract( $args );
global $user_ID, $current_user;
$dnxup_options = get_option('dnxup_options');
extract( $dnxup_options );
// Let's use our title
if($user_ID != '') { // if user is logged in let's greet him good
$current_user = wp_get_current_user();
if( '' != $logged_in_heading ) {
$title = apply_filters('widget_title', str_replace('%username%',ucwords($current_user->display_name),$logged_in_heading));
} else {
$title = false;
}
} else { // user is not logged in, let's treat him as a guest
if( '' != $logged_out_heading ) {
$title = apply_filters('widget_title', str_replace('%username%',ucwords($current_user->display_name),$logged_out_heading));
} else {
$title = false;
}
}
/* Before widget (defined by themes). */
echo $before_widget;
/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;
/**
* if user is logged in to your site
* @since 0.8
*/
if( $user_ID != '' ) {
/* If show_gravatar was selected, show the User's Gravatar. */
if ( $show_gravatar ) {
echo get_avatar($user_ID, 75);
}
echo '<ul id="dnxup_login_links" class="user_logged_in">';
echo '<li id="dashboard"><a href="' . get_bloginfo('url') . '/wp-admin/">' . __('Dashboard', 'dnxup') . '</a></li>';
echo '<li id="profile"><a href="' . get_bloginfo('url') . '/wp-admin/profile.php">' . __('Profile and personal options', 'dnxup') . '</a></li>';
/**
* custom links functionality
* @since 1.1.4
*/
$links = do_shortcode(trim($logged_in_links));
$links = explode("\n", $links);
if (sizeof($links)>0) {
foreach ($links as $l) {
$l = trim($l);
if (!empty($l)) {
$link = explode('|',$l);
if (isset($link[1])) {
$cap = strtolower(trim($link[1]));
if ($cap=='true') {
if (!current_user_can( 'manage_options' )) continue;
} else {
if (!current_user_can( $cap )) continue;
}
}
// Parse %USERNAME%
$link[0] = str_replace('%USERNAME%',$current_user->user_login,$link[0]);
$link[0] = str_replace('%username%',$current_user->user_login,$link[0]);
// Parse %USERID%
$link[0] = str_replace('%USERID%',$current_user->ID,$link[0]);
$link[0] = str_replace('%userid%',$current_user->ID,$link[0]);
echo '<li class="dnxup_custom_link">'.$link[0].'</li>';
}
}
}
echo('<li id="logout"><a href="' . wp_logout_url( dnxup_current_url() ) . '">' . __('Exit', 'dnxup') . '</a></li>');
echo '</ul>';
/**
* else if user is logged out and registration is disabled
* @since 0.8
*/
} else {
if( ! get_option('users_can_register') ) {
echo '<ul id="dnxup_login_links" class="logged_out_noreg">';
echo '<li id="login"><a href="' . wp_login_url( dnxup_current_url() ) . '">' . __('Login', 'dnxup') . '</a></li>';
echo '<li id="lostpassword"><a href="' . wp_lostpassword_url( dnxup_current_url() ) . '">' . __('Forgot your password?', 'dnxup') . '</a></li>';
echo '</ul>';
/**
* or if user is still logged out but user registration is enabled
* @since 0.9
*/
} else {
echo '<ul id="dnxup_login_links" class="logged_out_yesreg">';
echo '<li id="register"><a href="' . get_option('siteurl') . '/wp-register.php">' . __('Register', 'dnxup') . '</a></li>';
echo '<li id="login"><a href="' . wp_login_url( dnxup_current_url() ) . '">' . __('Login', 'dnxup') . '</a></li>';
echo '<li id="lostpassword"><a href="' . wp_lostpassword_url( dnxup_current_url() ) . '">' . __('Forgot your password?', 'dnxup') . '</a></li>';
echo '</ul>';
}
}
/* After widget (defined by themes). */
echo $after_widget;
}
/**
* Displays just a quick notice with a link to the Settings page
*/
public function form( $instance ) {
?>
<!-- No settings here, -->
<p>
<?php echo sprintf( __('Nothing to set here, already had a look at the <a href="%1$s">Settings Page</a>?', 'dnxup'),
admin_url('options-general.php?page=dnxup_options')
); ?>
</p>
<?php
}
}
?>
|