Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Created February 4, 2016 04:08
Show Gist options
  • Save bentasm1/058fb9c5591e2545e97d to your computer and use it in GitHub Desktop.
Save bentasm1/058fb9c5591e2545e97d to your computer and use it in GitHub Desktop.
WC Vendors Pro & BuddyPress Widget
<?php
/**
* Plugin Name: WC Vendors Pro Widgets
* Plugin URI: https://www.wcvendors.com
* Description: Does Widget Stuff
* Author: WC Vendors
* Author URI: https://www.wcvendors.com
*
* Version: 1.0.0
* Requires at least: 4.0.0
* Tested up to: 4.0.0
*
* Text Domain: wc_vendors_widgets
*
* @category Private
* @copyright Copyright © WC Vendors - This code is not GPL. You may eat a dick if you think you can repackage and resell it. :)
* @author WC Vendors
* @package WooCommerce
*/
/* Widgets for WC Vendors Pro in its own plugin for development purposes. We'll add these to WC Vendors Pro core once Jamie is pleased with Ben's work. */
/* For a border use this CSS
* div.wcv-pro-widget {
* border: 2px solid gray;
* }
*/
/* The Widget Class */
class WCV_Pro_Widget_Name extends WP_Widget {
public function __construct() {
parent::__construct(
'wcv_pro_widget_name',
'WC Vendors Pro Widget', // Name of widget in wp-admin
array( 'description' => 'Displays links to Vendor Dashboard for Vendors, quick links to private messages, and account controls.' ) // Description of widget in wp-admin
);
}
// widget function responsible for displaying code on the page
public function widget( $args, $instance ) {
extract( $args );
//print_r( $args ); // Will show array of things available with $args
// Show the Widget Title
$title = apply_filters( 'widget_title', $instance['title'] );
// Get the logged in users data so we can do stuff
$wcv_userid = get_current_user_id();
$wcv_userdata = get_userdata( $wcv_username );
$wcv_profiledata = wp_get_current_user();
$wcv_unread = bp_get_total_unread_messages_count();
$wcv_dashboard_url = get_permalink(WCVendors_Pro::get_option( 'dashboard_page_id' ));
echo $before_widget;
?>
<div class='wcv-pro-widget'>
<h3 class='widget-title'><center><?php echo $title ?><center></h3>
<?php
if ( $wcv_userid == 0 ) {
// User is not logged in
echo '<br><center><a class="button" href="' . get_site_url() . '/my-account/">Login/Register</a></center>';
echo '<br><br>Creating your account is <strong>free</strong>! Join Your Next Deal for the best deals on the Internet!';
} elseif (in_array( 'vendor', (array) $wcv_profiledata->roles ) ) {
// Logged in user is a vendor.
echo '<center><a href="' . get_site_url() . '/members/' . $wcv_profiledata->user_login . '/profile/change-avatar/">' . get_avatar( $wcv_userid, 100 ) . '</a></center><br>';
echo '<br><center><a class="button" href="' . get_site_url() . '/my-account/">My Account</a></center>';
echo '<br><br><center><a class="button" href="' . $wcv_dashboard_url . '">Vendor Dashboard</a></center>';
if ( $wcv_unread > 0 ) {
echo '<br><br><center><a class="button" href="' . get_site_url() . '/members/' . $wcv_profiledata->user_login . '/messages/">' .$wcv_unread. ' Unread Messages</a></center>';
} else {
echo '<br><br><center><a class="button" href="' . get_site_url() . '/members/' . $wcv_profiledata->user_login . '/messages/">No new messages</a></center>';
}
//echo '<br>You are a vendor!'; // Handy for testing
} else {
// Logged in user is not a vendor, but is logged in (customer)
echo '<center><a href="' . get_site_url() . '/members/' . $wcv_profiledata->user_login . '/profile/change-avatar/">' . get_avatar( $wcv_userid, 100 ) . '</a></center><br>';
echo '<br><center><a class="button" href="' . get_site_url() . '/my-account/">My Account</a></center>';
if ( $wcv_unread > 0 ) {
echo '<br><br><center><a class="button" href="' . get_site_url() . '/members/' . $wcv_profiledata->user_login . '/messages/">' .$wcv_unread. ' Unread Messages</a></center>';
} else {
echo '<br><br><center><a class="button" href="' . get_site_url() . '/members/' . $wcv_profiledata->user_login . '/messages/">No new messages</a></center>';
}
//echo '<br>You are NOT a vendor!'; // Handy for testing
}
?>
</div>
<?php
echo $after_widget;
}
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
// form function responsible for the wp-admin form
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
} else {
$title = 'New title';
}
//print_r($instance); // Will show the array of things available with $this
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
}
function wcv_pro_widgets_init(){
register_widget( 'WCV_Pro_Widget_Name' );
}
add_action( 'widgets_init', 'wcv_pro_widgets_init' );
/* The End */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment