| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
if( !class_exists('PieRegisterWidget') ){ |
| 5 |
class PieRegisterWidget{ |
| 6 |
function __construct() { //contructor |
| 7 |
// Add the widget to the dashboard |
| 8 |
add_action( 'wp_dashboard_setup', array($this, 'register_widget') ); |
| 9 |
add_filter( 'wp_dashboard_widgets', array($this, 'add_widget') ); |
| 10 |
} |
| 11 |
function register_widget() { |
| 12 |
$piereg = get_option(OPTION_PIE_REGISTER); |
| 13 |
if ( current_user_can('manage_options') ) |
| 14 |
wp_register_sidebar_widget( 'piereg_invite_tracking', __('Pie Register Invitation Code Tracking Dashboard', 'pie-register' ), array($this, 'widget'), array( 'settings' => 'options-general.php?page=pie-register' ) ); |
| 15 |
} |
| 16 |
// Modifies the array of dashboard widgets and adds this plugin's |
| 17 |
function add_widget( $widgets ) { |
| 18 |
global $wp_registered_widgets,$wp_registered_widget_controls; |
| 19 |
$wp_registered_widget_controls['piereg_invite_tracking']['callback'] = ''; |
| 20 |
|
| 21 |
if ( !isset($wp_registered_widgets['piereg_invite_tracking']) ) return $widgets; |
| 22 |
|
| 23 |
array_splice( $widgets, 2, 0, 'piereg_invite_tracking' ); |
| 24 |
|
| 25 |
return $widgets; |
| 26 |
|
| 27 |
} |
| 28 |
// Output the widget contents |
| 29 |
function widget( $args ) { |
| 30 |
|
| 31 |
global $wpdb; |
| 32 |
|
| 33 |
$users = $wpdb->get_results( $wpdb->prepare("SELECT COUNT(user_id) as total_users,`meta_value` FROM $wpdb->usermeta WHERE meta_key=%s GROUP BY BINARY `meta_value`", 'invite_code') ); |
| 34 |
|
| 35 |
$count = 0; |
| 36 |
echo '<div class="pieregister_dash_widget_style"> |
| 37 |
<style type="text/css"> |
| 38 |
table.piereg_dash_widget td h3{border:none;} |
| 39 |
table.piereg_dash_widget tr td a{display:none;} |
| 40 |
table.piereg_dash_widget tr:nth-child(even){background:#F9F9F9;} |
| 41 |
table.piereg_dash_widget tr:hover{background:#F3F3F3;} |
| 42 |
</style> |
| 43 |
</div>'; |
| 44 |
echo '<table width="100%" class="piereg_dash_widget" cellspacing="0" cellpaddinig="10">'; |
| 45 |
echo '<tr><td colspan="2" align="center"><em>'. esc_html__("Showing invitation code of currently registered users only","pie-register") .'</em></td></tr>'; |
| 46 |
foreach($users as $user){ |
| 47 |
$total_users = $user->total_users; |
| 48 |
$count++; |
| 49 |
$meta_value = $user->meta_value; |
| 50 |
if(!empty($meta_value)){ |
| 51 |
echo '<tr>'; |
| 52 |
echo '<td><h3>' . esc_html($meta_value) . '</h3></td>'; |
| 53 |
echo '<td>' . esc_html($total_users).' '; |
| 54 |
echo esc_html__("Users Registered","pie-register"); |
| 55 |
echo '</td>'; |
| 56 |
echo '</tr>'; |
| 57 |
} |
| 58 |
} |
| 59 |
echo '</table>'; |
| 60 |
} |
| 61 |
} |
| 62 |
} # End Class PieRegisterWidget |
| 63 |
|
| 64 |
|
| 65 |
// Start this plugin once all other plugins are fully loaded |
| 66 |
add_action( 'plugins_loaded', 'initialize_pr_dashwidget'); |
| 67 |
function initialize_pr_dashwidget(){ |
| 68 |
$piereg_widget = new PieRegisterWidget(); |
| 69 |
} |
| 70 |
?> |