diff options
Diffstat (limited to 'danixland-user-panel.php')
| -rw-r--r-- | danixland-user-panel.php | 378 |
1 files changed, 378 insertions, 0 deletions
diff --git a/danixland-user-panel.php b/danixland-user-panel.php new file mode 100644 index 0000000..aded94a --- /dev/null +++ b/danixland-user-panel.php @@ -0,0 +1,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
+ }
+}
+
+?>
|
