setup_constants(); self::$instance->includes(); self::$instance->load_textdomain(); } return self::$instance; } /** * Setup plugin constants * * @access private * @since 0.1 * @return void */ private function setup_constants() { // Plugin name define( 'AFFILIATE_PROMOTIONS_NAME', 'Affiliate Promotions' ); // Plugin domain plug define( 'AFFILIATE_PROMOTIONS_PLUG', 'aff-promotion' ); // Plugin affiliate AccessTrade prefix define( 'AFFILIATE_PROMOTIONS_AT_PREFIX', 'affpromos_accesstrade_' ); // Plugin version define( 'AFFILIATE_PROMOTIONS_VER', '0.1.6' ); // Plugin path define( 'AFFILIATE_PROMOTIONS_DIR', plugin_dir_path( __FILE__ ) ); // Plugin URL define( 'AFFILIATE_PROMOTIONS_URL', plugin_dir_url( __FILE__ ) ); // Plugin prefix define( 'AFFILIATE_PROMOTIONS_PREFIX', 'affpromos_' ); // Constant hours auto update (HOURS_PER_UPDATE) define( 'AFFILIATE_AUTO_UPDATE_HOURS_PER_UPDATE', 3 ); // Publisher homepage define( 'AFFILIATE_PROMOTIONS_HOMEPAGE', 'https://khuyenmaimuasam.com/affiliate/' ); // AccessTrade get key page define( 'AFFILIATE_PROMOTIONS_ACCESSTRADE_TOKEN_PAGE', 'https://pub.accesstrade.vn/accounts/profile' ); // APIs define( 'AFFILIATE_PROMOTIONS_ACCESSTRADE_GET_VENDOR_API', 'https://api.accesstrade.vn/v1/campaigns' ); define( 'AFFILIATE_PROMOTIONS_ACCESSTRADE_GET_PROMOTION_API', 'https://api.accesstrade.vn/v1/offers_informations' ); define( 'AFFILIATE_PROMOTIONS_ACCESSTRADE_GET_OFFER_API', 'https://api.accesstrade.vn/v1/datafeeds' ); // Logs table name define( 'AFFILIATE_ACTION_LOG_TABLE',AFFILIATE_PROMOTIONS_PREFIX.'action_log' ); // Cron for auto-update feature) // if (!defined('ALTERNATE_WP_CRON') || ALTERNATE_WP_CRON == false) { // define('ALTERNATE_WP_CRON', true); // } // Select2 libs in Shortcode UI define( 'SELECT2_NOCONFLICT', true ); } /** * Include necessary files * * @access private * @since 0.1.0 * @return void */ private function includes() { // Basic require_once AFFILIATE_PROMOTIONS_DIR . 'includes/helper.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/scripts.php'; // Dependencies require_once AFFILIATE_PROMOTIONS_DIR . 'includes/libs.php'; // Admin only if ( is_admin() ) { require_once AFFILIATE_PROMOTIONS_DIR . 'includes/admin/plugins.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/admin/class.settings.php'; } // Promotions require_once AFFILIATE_PROMOTIONS_DIR . 'includes/promotions/post-type.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/promotions/type-taxonomy.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/promotions/category-taxonomy.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/promotions/manage-promotions.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/promotions/metaboxes.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/promotion-functions.php'; // Vendors require_once AFFILIATE_PROMOTIONS_DIR . 'includes/vendors/post-type.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/vendors/manage-vendors.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/vendors/metaboxes.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/vendor-functions.php'; // Offers require_once AFFILIATE_PROMOTIONS_DIR . 'includes/offers/post-type.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/offers/manage-offers.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/offers/metaboxes.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/offers/shortcodes.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/offer-functions.php'; // Anything else require_once AFFILIATE_PROMOTIONS_DIR . 'includes/hooks.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/functions.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/shortcodes.php'; // Widget require_once AFFILIATE_PROMOTIONS_DIR . 'includes/widgets/latest_promotion.php'; require_once AFFILIATE_PROMOTIONS_DIR . 'includes/widgets/latest_offer.php'; // Auto update require_once AFFILIATE_PROMOTIONS_DIR . 'includes/admin/update.php'; // css scripts wp_register_style( AFFILIATE_PROMOTIONS_PREFIX.'custom_style', plugin_dir_url( __FILE__ ) . 'public/assets/css/admin.min.css' ); wp_enqueue_style( AFFILIATE_PROMOTIONS_PREFIX.'custom_style' ); // wp_enqueue_style( AFFILIATE_PROMOTIONS_PREFIX.'latest_promotions_widget', plugins_url('public/assets/css.css',dirname(__FILE__) )); wp_enqueue_script( AFFILIATE_PROMOTIONS_PREFIX.'custom_scrips', plugin_dir_url( __FILE__ ) . 'public/assets/js/affpromos_custom.js', array(), null, true ); } /** * Internationalization * * @access public * @since 0.1.0 * @return void */ public function load_textdomain() { // Set filter for language directory $lang_dir = AFFILIATE_PROMOTIONS_DIR . '/languages/'; $lang_dir = apply_filters( 'affiliate_promotions_languages_directory', $lang_dir ); // Traditional WordPress plugin locale filter $locale = apply_filters( 'plugin_locale', get_locale(), AFFILIATE_PROMOTIONS_PLUG ); $mofile = sprintf( '%1$s-%2$s.mo', AFFILIATE_PROMOTIONS_PLUG, $locale ); // Setup paths to current locale file $mofile_local = $lang_dir . $mofile; $mofile_global = WP_LANG_DIR . '/affiliate-promotions/' . $mofile; if( file_exists( $mofile_global ) ) { // Look in global /wp-content/languages/affiliate-promotions/ folder load_textdomain( AFFILIATE_PROMOTIONS_PLUG, $mofile_global ); } elseif( file_exists( $mofile_local ) ) { // Look in local /wp-content/plugins/affiliate-promotions/languages/ folder load_textdomain( AFFILIATE_PROMOTIONS_PLUG, $mofile_local ); } else { // Load the default language files load_plugin_textdomain( AFFILIATE_PROMOTIONS_PLUG, false, $lang_dir ); } } } } // End if class_exists check class AffiliatePromotionWidget { /** * Hook to wp_dashboard_setup to add the widget. */ public static function init() { wp_add_dashboard_widget( "id_promotion_dashboard_widget", __( 'Promotion Statistic', 'affiliate_promotion' ), array('AffiliatePromotionWidget', 'render_widget') ); } public static function get_count_promotion_of_vendor() { global $wpdb; $sql_count = 'SELECT meta_value as vendor_id, count(post_id) as count FROM wp_postmeta where (meta_key="'.AFFILIATE_PROMOTIONS_PREFIX.'promotion_vendor") group by meta_value order by count desc'; $sql = 'select post.guid as image_url, tab.count as count, tab.vendor_id as vendor_id from '.$wpdb->posts.' as post, ('.$sql_count.') as tab where (post.post_parent = tab.vendor_id and post.post_type="attachment") order by count desc limit 10;'; return $wpdb->get_results($sql); } public static function get_count_offer_of_vendor($vendor_id){ global $wpdb; $sql_count = 'SELECT count(post_id) as offers FROM wp_postmeta where (meta_key = "'.AFFILIATE_PROMOTIONS_PREFIX.'offer_vendor" and meta_value='.$vendor_id.'); '; return $wpdb->get_results($sql_count)[0]->offers; } public static function render_widget(){ if(!wp_script_is('affproms-widget.css', 'enqueued')) { wp_enqueue_style( 'affproms-widget.css', plugins_url('public/assets/css/affproms-widget.css', __FILE__), array(), false); } $stripe = true; $data = AffiliatePromotionWidget::get_count_promotion_of_vendor(); echo "
No records ! Please update in the Settings section or Add some items
We are highly recommand using Shortcode-UI plugin for better visualize shortcode in WP editor.
GET & ACTIVE NO