+<?php\r
+/*\r
+Plugin Name: danixland User Panel\r
+Plugin URI: http://danixland.net/blog/2010/603-danixland-user-panel-plugin/\r
+Description: A modified version of the meta widget which gives more info about the user.\r
+Version: 1.4.2\r
+Author: Danilo 'danix' Macri\r
+Author URI: http://danixland.net\r
+Text Domain: dnxup\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
+*/\r
+\r
+/**************************************************************************************\r
+Since Version 1.1.1 this plugin uses some code and inspiration from the sidebar-login\r
+plugin by Mike Jolley < http://blue-anvil.com > < http://mikejolley.com >\r
+big kudos to him!!!\r
+**************************************************************************************/\r
+\r
+/**\r
+ * Add plugin i18n domain: dnxup\r
+ * @since 1.1.1\r
+ */\r
+load_plugin_textdomain('dnxup', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');\r
+\r
+/**\r
+ * Include settings options for our plugin\r
+ * @since 1.1.1\r
+ */\r
+function dnxup_settings() {\r
+ add_options_page('danixland User Panel Settings', __('User Panel Options', 'dnxup'), 'manage_options', 'dnxup_options', 'dnxup_settings_display');\r
+}\r
+add_action('admin_menu', 'dnxup_settings' );\r
+\r
+/**\r
+ * The function that outputs our admin page\r
+ * @since 1.1.1\r
+ */\r
+function dnxup_settings_display() {\r
+?>\r
+ <div class="wrap">\r
+ <h2><?php _e('danixland User Panel Settings', 'dnxup') ?></h2>\r
+ <form method="post" action="options.php">\r
+ <?php\r
+ settings_fields('dnxup_options');\r
+ do_settings_sections('dnxup_settings_sections');\r
+ ?>\r
+ <p class="submit">\r
+ <input name="dnxup_options[submit]" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes', 'dnxup') ?>" />\r
+ <input name="dnxup_options[reset]" type="submit" class="button-secondary" value="<?php esc_attr_e('Reset Defaults', 'dnxup'); ?>" />\r
+ </p>\r
+ </form>\r
+ </div>\r
+<?php\r
+}\r
+\r
+/**\r
+ * Settings API options initilization and validation\r
+ * @since 1.1.1\r
+ */\r
+function dnxup_register_options() {\r
+ require( dirname( __FILE__ ) . '/include/options-register.php' );\r
+}\r
+add_action('admin_init', 'dnxup_register_options');\r
+\r
+/**\r
+ * DataBase initilization and update procedure\r
+ * @since 1.1.2\r
+ */\r
+\r
+// helper function that returns DB defaults\r
+function dnxup_db_defaults() {\r
+ $defaults = array(\r
+ 'show_gravatar' => true,\r
+ 'logged_out_heading' => 'Howdy Guest',\r
+ 'logged_in_heading' => 'Howdy %username%',\r
+ 'logged_in_links' => "<a href=\"" . admin_url() . "\">" . __('Dashboard','dnxup') . "</a>\n<a href=\"" . admin_url('profile.php') . "\">" . __('Profile','dnxup') . "</a>",\r
+ // database version\r
+ 'dnxup_DB_VERSION' => '1'\r
+ );\r
+ return $defaults;\r
+}\r
+\r
+// helper function that starts up the DB\r
+function dnxup_db_init() {\r
+ global $dnxup_options;\r
+ $dnxup_options = get_option('dnxup_options');\r
+ if( false === $dnxup_options ) {\r
+ $dnxup_options = dnxup_db_defaults();\r
+ }\r
+ update_option('dnxup_options', $dnxup_options);\r
+}\r
+\r
+// helper function that performs a DB version update when needed\r
+function dnxup_db_update($db_version) {\r
+ global $dnxup_options;\r
+ $db_defaults = dnxup_db_defaults();\r
+ $merge = wp_parse_args( $dnxup_options, $db_defaults );\r
+ // update DB version\r
+ $merge['dnxup_DB_VERSION'] = $db_version;\r
+ update_option('dnxup_options', $merge);\r
+}\r
+\r
+// helper function that performs a DB check and then an init/update action\r
+function dnxup_db_check() {\r
+ global $dnxup_options;\r
+ if(false === $dnxup_options) {\r
+ dnxup_db_init();\r
+ }\r
+ $old_db_version = $dnxup_options['dnxup_DB_VERSION'];\r
+ $new_db_version = DNXUP_CURRENT_DB_VERSION;\r
+ if(empty($old_db_version)) {\r
+ dnxup_db_init();\r
+ }\r
+ if( intval($old_db_version) < intval($new_db_version) ) {\r
+ dnxup_db_update( $new_db_version );\r
+ }\r
+}\r
+function dnxup_set_db_version() {\r
+ // Define plugin database version. This should only change when new settings are added.\r
+ if ( ! defined( 'DNXUP_CURRENT_DB_VERSION' ) ) {\r
+ define( 'DNXUP_CURRENT_DB_VERSION', 2 );\r
+ }\r
+}\r
+/**\r
+ * Add function on plugin activation that'll set our DB version and perform a check for update\r
+ * @since 1.1.3\r
+ */\r
+register_activation_hook( __FILE__, 'dnxup_set_db_version' );\r
+register_activation_hook( __FILE__, 'dnxup_db_check' );\r
+\r
+\r
+/**\r
+ * function that returns the actual url for redirection after logout\r
+ * as seen on sidebar-login by Mike Jolley with small modifications\r
+ * @since 1.1.3\r
+ */\r
+function dnxup_current_url($url = '') {\r
+\r
+ global $wpdb, $post, $cat, $tag, $author, $year, $monthnum, $day, $wp_query;\r
+ $pageURL = "";\r
+\r
+ if ( is_home() && $wp_query->is_posts_page==1)\r
+ {\r
+ $pageURL = get_permalink(get_option('page_for_posts'));\r
+ }\r
+ elseif (is_home() || is_front_page())\r
+ {\r
+ $pageURL = get_bloginfo('url');\r
+ }\r
+ elseif (is_post_type_archive())\r
+ {\r
+ $pageURL = get_post_type_archive_link( get_query_var('post_type') );\r
+ }\r
+ elseif (is_single() || is_page())\r
+ {\r
+ $pageURL = get_permalink($wp_query->post->ID);\r
+ }\r
+ elseif (is_category())\r
+ {\r
+ $pageURL = get_category_link($cat);\r
+ }\r
+ elseif (is_tag())\r
+ {\r
+ $tag_id = $wpdb->get_var("SELECT ".$wpdb->terms.".term_id FROM $wpdb->term_taxonomy\r
+ LEFT JOIN $wpdb->terms\r
+ ON (".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id)\r
+ WHERE ".$wpdb->terms.".slug = '$tag'\r
+ AND ".$wpdb->term_taxonomy.".taxonomy = 'post_tag' LIMIT 1");\r
+ $pageURL = get_tag_link($tag_id);\r
+ }\r
+ elseif (is_author())\r
+ {\r
+ $pageURL = get_author_posts_url($author);\r
+ }\r
+ elseif (is_date())\r
+ {\r
+\r
+ if ($day)\r
+ {\r
+ $pageURL = get_day_link( $year, $monthnum, $day);\r
+ }\r
+ elseif ($monthnum)\r
+ {\r
+ $pageURL = get_month_link( $year, $monthnum, $day);\r
+ }\r
+ elseif ($year)\r
+ {\r
+ $pageURL = get_year_link( $year, $monthnum, $day);\r
+ }\r
+\r
+ }\r
+ elseif (is_search())\r
+ {\r
+ $pageURL = get_bloginfo('wpurl');\r
+ if ("/" != substr($pageURL, -1)) $pageURL = $pageURL . "/";\r
+ $pageURL .= '?s='.stripslashes(strip_tags($_REQUEST['s'])).'';\r
+ }\r
+\r
+ if (!$pageURL || $pageURL=="" || !is_string($pageURL)) {\r
+ $pageURL = "";\r
+ $pageURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';\r
+\r
+ if ($_SERVER["SERVER_PORT"] != "80") {\r
+ $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];\r
+ } else {\r
+ $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];\r
+ }\r
+\r
+ //————–added by mick\r
+ if (!strstr(get_bloginfo('url'),'www.')) $pageURL = str_replace('www.','', $pageURL );\r
+ //——————–\r
+ }\r
+ if ($pageURL && !is_search()) if ("/" != substr($pageURL, -1)) $pageURL = $pageURL . "/";\r
+\r
+\r
+ return $pageURL;\r
+}\r
+\r
+/**\r
+ * Add function to widgets_init that'll load our widget.\r
+ * @since 0.1\r
+ */\r
+add_action( 'widgets_init', 'danixland_user_panel' );\r
+\r
+/**\r
+ * Register our widget.\r
+ * 'User_Panel' is the widget class used below.\r
+ *\r
+ * @since 0.1\r
+ */\r
+function danixland_user_panel() {\r
+ register_widget( 'User_Panel' );\r
+}\r
+\r
+/**\r
+ * User_Panel class.\r
+ * This class handles everything that needs to be handled with the widget:\r
+ * the settings, form, display, and update. Nice!\r
+ *\r
+ * @since 0.1\r
+ */\r
+class User_Panel extends WP_Widget {\r
+\r
+ /**\r
+ * Widget setup.\r
+ */\r
+ function __construct() {\r
+ parent::__construct(\r
+ 'dnx-user-panel', // id_base\r
+ __('danixland User Panel', 'dnxup' ), // Name\r
+ array( 'description' => __('An improved version of the meta widget', 'dnxup') )\r
+ );\r
+ }\r
+\r
+ /**\r
+ * How to display the widget on the public side of the site.\r
+ */\r
+ public function widget( $args, $instance ) {\r
+ extract( $args );\r
+ global $user_ID, $current_user;\r
+ $dnxup_options = get_option('dnxup_options');\r
+ extract( $dnxup_options );\r
+\r
+ // Let's use our title\r
+ if($user_ID != '') { // if user is logged in let's greet him good\r
+ $current_user = wp_get_current_user();\r
+ if( '' != $logged_in_heading ) {\r
+ $title = apply_filters('widget_title', str_replace('%username%',ucwords($current_user->display_name),$logged_in_heading));\r
+ } else {\r
+ $title = false;\r
+ }\r
+ } else { // user is not logged in, let's treat him as a guest\r
+ if( '' != $logged_out_heading ) {\r
+ $title = apply_filters('widget_title', str_replace('%username%',ucwords($current_user->display_name),$logged_out_heading));\r
+ } else {\r
+ $title = false;\r
+ }\r
+ }\r
+\r
+\r
+ /* Before widget (defined by themes). */\r
+ echo $before_widget;\r
+\r
+ /* Display the widget title if one was input (before and after defined by themes). */\r
+ if ( $title )\r
+ echo $before_title . $title . $after_title;\r
+\r
+ /**\r
+ * if user is logged in to your site\r
+ * @since 0.8\r
+ */\r
+ if( $user_ID != '' ) {\r
+ /* If show_gravatar was selected, show the User's Gravatar. */\r
+ if ( $show_gravatar ) {\r
+ echo get_avatar($user_ID, 75);\r
+ }\r
+ echo '<ul id="dnxup_login_links" class="user_logged_in">';\r
+ echo '<li id="dashboard"><a href="' . get_bloginfo('url') . '/wp-admin/">' . __('Dashboard', 'dnxup') . '</a></li>';\r
+ echo '<li id="profile"><a href="' . get_bloginfo('url') . '/wp-admin/profile.php">' . __('Profile and personal options', 'dnxup') . '</a></li>';\r
+\r
+ /**\r
+ * custom links functionality\r
+ * @since 1.1.4\r
+ */\r
+ $links = do_shortcode(trim($logged_in_links));\r
+ $links = explode("\n", $links);\r
+ if (sizeof($links)>0) {\r
+ foreach ($links as $l) {\r
+ $l = trim($l);\r
+ if (!empty($l)) {\r
+ $link = explode('|',$l);\r
+ if (isset($link[1])) {\r
+ $cap = strtolower(trim($link[1]));\r
+ if ($cap=='true') {\r
+ if (!current_user_can( 'manage_options' )) continue;\r
+ } else {\r
+ if (!current_user_can( $cap )) continue;\r
+ }\r
+ }\r
+ // Parse %USERNAME%\r
+ $link[0] = str_replace('%USERNAME%',$current_user->user_login,$link[0]);\r
+ $link[0] = str_replace('%username%',$current_user->user_login,$link[0]);\r
+ // Parse %USERID%\r
+ $link[0] = str_replace('%USERID%',$current_user->ID,$link[0]);\r
+ $link[0] = str_replace('%userid%',$current_user->ID,$link[0]);\r
+ echo '<li class="dnxup_custom_link">'.$link[0].'</li>';\r
+ }\r
+ }\r
+ }\r
+\r
+ echo('<li id="logout"><a href="' . wp_logout_url( dnxup_current_url() ) . '">' . __('Exit', 'dnxup') . '</a></li>');\r
+ echo '</ul>';\r
+ /**\r
+ * else if user is logged out and registration is disabled\r
+ * @since 0.8\r
+ */\r
+ } else {\r
+ if( ! get_option('users_can_register') ) {\r
+ echo '<ul id="dnxup_login_links" class="logged_out_noreg">';\r
+ echo '<li id="login"><a href="' . wp_login_url( dnxup_current_url() ) . '">' . __('Login', 'dnxup') . '</a></li>';\r
+ echo '<li id="lostpassword"><a href="' . wp_lostpassword_url( dnxup_current_url() ) . '">' . __('Forgot your password?', 'dnxup') . '</a></li>';\r
+ echo '</ul>';\r
+ /**\r
+ * or if user is still logged out but user registration is enabled\r
+ * @since 0.9\r
+ */\r
+ } else {\r
+ echo '<ul id="dnxup_login_links" class="logged_out_yesreg">';\r
+ echo '<li id="register"><a href="' . get_option('siteurl') . '/wp-register.php">' . __('Register', 'dnxup') . '</a></li>';\r
+ echo '<li id="login"><a href="' . wp_login_url( dnxup_current_url() ) . '">' . __('Login', 'dnxup') . '</a></li>';\r
+ echo '<li id="lostpassword"><a href="' . wp_lostpassword_url( dnxup_current_url() ) . '">' . __('Forgot your password?', 'dnxup') . '</a></li>';\r
+ echo '</ul>';\r
+ }\r
+ }\r
+ /* After widget (defined by themes). */\r
+ echo $after_widget;\r
+ }\r
+\r
+ /**\r
+ * Displays just a quick notice with a link to the Settings page\r
+ */\r
+ public function form( $instance ) {\r
+ ?>\r
+\r
+ <!-- No settings here, -->\r
+ <p>\r
+ <?php echo sprintf( __('Nothing to set here, already had a look at the <a href="%1$s">Settings Page</a>?', 'dnxup'),\r
+ admin_url('options-general.php?page=dnxup_options')\r
+ ); ?>\r
+ </p>\r
+ <?php\r
+ }\r
+}\r
+\r
+?>\r