file = $file; self::$instance->version = get_plugin_data( self::$instance->file, false, false )['Version'] ?? ''; self::$instance->setup_constants(); 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__, esc_html__( '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__, esc_html__( 'Cheatin’ huh?', 'affiliatewp-leaderboard' ), '1.0' ); } /** * Setup plugin constants. * * @access private * @since 1.2 * @return void */ private function setup_constants() { // Plugin version. if ( ! defined( 'AFFWP_LB_VERSION' ) ) { define( 'AFFWP_LB_VERSION', $this->version ); } // Plugin Folder Path. if ( ! defined( 'AFFWP_LB_PLUGIN_DIR' ) ) { define( 'AFFWP_LB_PLUGIN_DIR', plugin_dir_path( $this->file ) ); } // Plugin Folder URL. if ( ! defined( 'AFFWP_LB_PLUGIN_URL' ) ) { define( 'AFFWP_LB_PLUGIN_URL', plugin_dir_url( $this->file ) ); } // Plugin Root File. if ( ! defined( 'AFFWP_LB_PLUGIN_FILE' ) ) { define( 'AFFWP_LB_PLUGIN_FILE', $this->file ); } } /** * 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( $this->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 AFFWP_LB_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 * @param array $atts Shortcode attributes. * @param string $content Shortcode content. * @return string */ public function affiliate_leaderboard( $atts, $content = null ) { $atts = shortcode_atts( array( 'number' => 10, // show 10 by default. 'referrals' => '', 'earnings' => '', 'visits' => '', 'orderby' => 'referrals', ), $atts, 'affiliate_leaderboard' ); // Return the rendered leaderboard as-is. Re-parsing it as shortcode input would execute // any shortcode (or markup) an affiliate planted in their display name. return $this->show_leaderboard( $atts ); } /** * Get referrals * * @since 1.0 * * @param array $args Shortcode attributes. * @return string */ public function show_leaderboard( $args = array() ) { $defaults = apply_filters( 'affwp_leaderboard_defaults', array( 'number' => isset( $args['number'] ) ? (int) $args['number'] : 10, // < 1 means all, as in get_affiliates(). 'orderby' => isset( $args['orderby'] ) ? $args['orderby'] : 'referrals', 'status' => 'active', // never publish pending/rejected applicants. ) ); $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 ) : ?>
' . wp_kses_post( $output ) . '
'; } ?>