Created
July 23, 2018 05:40
-
-
Save mycred/e0cb74ded2d858843d0a3dc04b8d3311 to your computer and use it in GitHub Desktop.
Display the total current users myCRED awarded and lost points in front end.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: myCRED User Awarded | |
* Plugin URI: http://www.birminghamiu.co.uk | |
* Description: Display the total current users myCRED awarded and lost points in front end. | |
* Version: 1.0 | |
* Author: G. Lloyd | |
* Author URI: http://www.birminghamiu.co.uk | |
* License: Copyrighted | |
* | |
* Copyright © 2015 BirminghamIU | |
* | |
* Permission is hereby granted, to the licensed domain to install and run this | |
* software and associated documentation files (the "Software") for an unlimited | |
* time with the followning restrictions: | |
* | |
* - This software is only used under the domain name registered with the purchased | |
* license though the BirminghamIU website (www.birminghamiu.co.uk). Exception is given for localhost | |
* installations or test enviroments. | |
* | |
* - This software can not be copied and installed on a website not licensed. | |
* | |
* - This software is supported only if no changes are made to the software files | |
* or documentation. All support is voided as soon as any changes are made. | |
* | |
* - This software is not copied and re-sold under the current brand or any other | |
* branding in any medium or format. | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
function count_users_total_point_gains( $user_id ) { | |
global $wpdb; | |
$user_id = absint( $user_id ); | |
$mycred_log = $wpdb->prefix . 'myCRED_log'; | |
return $wpdb->get_var( " | |
SELECT SUM( creds ) | |
FROM {$mycred_log} | |
WHERE user_id = {$user_id} | |
AND creds > 0;" ); | |
} | |
function count_users_total_point_loses( $user_id ) { | |
global $wpdb; | |
$user_id = absint( $user_id ); | |
$mycred_log = $wpdb->prefix . 'myCRED_log'; | |
return $wpdb->get_var( " | |
SELECT SUM( creds ) | |
FROM {$mycred_log} | |
WHERE user_id = {$user_id} | |
AND creds < 0;" ); | |
} | |
// Function to add user awarded points total to frontend via shortcode | |
function total_user_shortcode() { | |
echo 'You have gained a total of: ' . count_users_total_point_gains( get_current_user_id() ) . ' points'; | |
echo 'You have lost a total of: ' . count_users_total_point_loses( get_current_user_id() ) . ' points'; | |
} | |
add_shortcode('myCREDtotal', 'total_user_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment