. * * @package Leaderboard * @category Core * @author Andrew Munro * @version 1.0 */ // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; final class AffiliateWP_Leaderboard { /** Singleton *************************************************************/ /** * @var AffiliateWP_Leaderboard The one true AffiliateWP_Leaderboard * @since 1.0 */ private static $instance; public static $plugin_dir; public static $plugin_url; private static $version; /** * Main AffiliateWP_Leaderboard Instance * * Insures that only one instance of AffiliateWP_Leaderboard exists in memory at any one * time. Also prevents needing to define globals all over the place. * * @since 1.0 * @static * @staticvar array $instance * @return The one true AffiliateWP_Leaderboard */ public static function instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AffiliateWP_Leaderboard ) ) { self::$instance = new AffiliateWP_Leaderboard; self::$plugin_dir = plugin_dir_path( __FILE__ ); self::$plugin_url = plugin_dir_url( __FILE__ ); self::$version = '1.0'; self::$instance->load_textdomain(); self::$instance->includes(); self::$instance->hooks(); } return self::$instance; } /** * Throw error on object clone * * The whole idea of the singleton design pattern is that there is a single * object therefore, we don't want the object to be cloned. * * @since 1.0 * @access protected * @return void */ public function __clone() { // Cloning instances of the class is forbidden _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliatewp-leaderboard' ), '1.0' ); } /** * Disable unserializing of the class * * @since 1.0 * @access protected * @return void */ public function __wakeup() { // Unserializing instances of the class is forbidden _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'affiliatewp-leaderboard' ), '1.0' ); } /** * Loads the plugin language files * * @access public * @since 1.0 * @return void */ public function load_textdomain() { // Set filter for plugin's languages directory $lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; $lang_dir = apply_filters( 'affiliatewp_leaderboard_languages_directory', $lang_dir ); // Traditional WordPress plugin locale filter $locale = apply_filters( 'plugin_locale', get_locale(), 'affiliatewp-leaderboard' ); $mofile = sprintf( '%1$s-%2$s.mo', 'affiliatewp-leaderboard', $locale ); // Setup paths to current locale file $mofile_local = $lang_dir . $mofile; $mofile_global = WP_LANG_DIR . '/affiliatewp-leaderboard/' . $mofile; if ( file_exists( $mofile_global ) ) { // Look in global /wp-content/languages/affiliatewp-leaderboard/ folder load_textdomain( 'affiliatewp-leaderboard', $mofile_global ); } elseif ( file_exists( $mofile_local ) ) { // Look in local /wp-content/plugins/affiliatewp-leaderboard/languages/ folder load_textdomain( 'affiliatewp-leaderboard', $mofile_local ); } else { // Load the default language files load_plugin_textdomain( 'affiliatewp-leaderboard', false, $lang_dir ); } } /** * Include necessary files * * @access private * @since 1.0.0 * @return void */ private function includes() { require_once self::$plugin_dir . 'includes/class-widget.php'; } /** * Setup the default hooks and actions * * @since 1.0 * * @return void */ private function hooks() { // shortcode add_shortcode( 'affiliate_leaderboard', array( $this, 'affiliate_leaderboard' ) ); // css add_action( 'wp_head', array( $this, 'css' ) ); // plugin meta add_filter( 'plugin_row_meta', array( $this, 'plugin_meta' ), null, 2 ); } /** * Affiliate leaderboard shortcode * * @since 1.0 * @return string */ public function affiliate_leaderboard( $atts, $content = null ) { shortcode_atts( array( 'number' => 10, // show 10 by default 'referrals' => '', 'earnings' => '', 'visits' => '', 'orderby' => 'referrals' ), $atts, 'affiliate_leaderboard' ); $content = $this->show_leaderboard( $atts ); return do_shortcode( $content ); } /** * Get referrals * * @since 1.0 * @return string */ public function show_leaderboard( $args = array() ) { $defaults = apply_filters( 'affwp_leaderboard_defaults', array( 'number' => isset( $args['number'] ) ? $args['number'] : 10, 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'earnings', 'order' => 'DESC' ) ); $args = wp_parse_args( $args, $defaults ); // show an affiliate's earnings $show_earnings = isset( $args['earnings'] ) && ( 'yes' == $args['earnings'] || 'on' == $args['earnings'] ) ? true : false; // show an affiliate's referrals $show_referrals = isset( $args['referrals'] ) && ( 'yes' == $args['referrals'] || 'on' == $args['referrals'] ) ? true : false; // show an affiliate's visits $show_visits = isset( $args['visits'] ) && ( 'yes' == $args['visits'] || 'on' == $args['visits'] ) ? true : false; // get affiliates $affiliates = affiliate_wp()->affiliates->get_affiliates( $defaults ); ob_start(); if ( $affiliates ) : ?>
' . $output . '
'; } ?>