Plugin Directory

Changeset 2107071


Ignore:
Timestamp:
06/16/2019 09:56:43 PM (7 years ago)
Author:
ashour
Message:

test on latest

Location:
woo-affiliate-sort/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • woo-affiliate-sort/trunk/readme.txt

    r1843323 r2107071  
    22Donate link: https://www.paypal.me/ash0ur
    33Tags: Woocommerce, development, affiliate, external, sort, order, popularity, clicks
    4 Tested up to: 4.9.4
    5 Version: 1.0.0 
     4Tested up to: 5.2.1
     5Version: 1.0.0
    66Author: Abdelrahman Ashour
    77Author email: abdelrahman.ashour38@gmail.com
     
    1111
    1212== Description ==
    13 This plugin is for sites that promote affiliate or external products, It allows sorting the affiliate products by popularity using the users clicks on the product link.
    14 
    15 
     13This plugin is for sites that promote affiliate/external products, It allows sorting the affiliate/external products ascending by popularity using the users clicks on the product link.
  • woo-affiliate-sort/trunk/woocommerce-affiliate-sort.php

    r1843323 r2107071  
    1616 * License:      GPL2
    1717 * License URI:  https://www.gnu.org/licenses/gpl-2.0.html
    18 */
     18 */
    1919
    20 if(!defined('ABSPATH'))
     20if ( ! defined( 'ABSPATH' ) ) {
    2121        exit;
     22}
    2223
    2324
    24 if(!class_exists('WooCommerce_affiliate_sort')):
     25if ( ! class_exists( 'WooCommerce_affiliate_sort' ) ) :
    2526
    26 class WooCommerce_affiliate_sort{
     27    class WooCommerce_affiliate_sort {
    2728
    2829
    29     public static function init(){
    30         $theCalc = new self();
    31     }
     30        public static function init() {
     31            $theCalc = new self();
     32        }
    3233
    33     public function __construct(){
     34        public function __construct() {
    3435
    35         $this->define_constants();
    36         $this->setup_actions();
    37     }
     36            $this->define_constants();
     37            $this->setup_actions();
     38        }
    3839
    3940
    4041
    41     public function define_constants(){
     42        public function define_constants() {
    4243
    43            define('WOOAFFPRO_BASE_URL', trailingslashit( plugins_url('woocommerce-affiliate-sort') ));
    44            define('WOOAFFPRO_ASSETS_URL', trailingslashit( WOOAFFPRO_BASE_URL . 'assets') );
    45            define('WOOAFFPRO_PATH', plugin_dir_path(__FILE__ ));
    46     }
     44               define( 'WOOAFFPRO_BASE_URL', trailingslashit( plugins_url( 'woocommerce-affiliate-sort' ) ) );
     45               define( 'WOOAFFPRO_ASSETS_URL', trailingslashit( WOOAFFPRO_BASE_URL . 'assets' ) );
     46               define( 'WOOAFFPRO_PATH', plugin_dir_path( __FILE__ ) );
     47        }
    4748
    48     public static function plugin_activated(){
    49        
    50         if( !in_array('woocommerce/woocommerce.php',apply_filters('active_plugins',get_option('active_plugins')))  ){
    51             die('WooCommerce plugin must be active');
     49        public static function plugin_activated() {
     50
     51            if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
     52                die( 'WooCommerce plugin must be active' );
     53
     54            }
    5255
    5356        }
     57
     58
     59
     60        public function frontend_enqueue_global() {
     61
     62            if ( ! wp_script_is( 'jquery', 'registered' ) ) {
     63                wp_enqueue_script( 'jquery' );
     64            }
     65
     66            wp_enqueue_script( 'WOOAFFPRO_actions', WOOAFFPRO_ASSETS_URL . 'js/actions.js', array( 'jquery' ), WC_VERSION, true );
     67
     68            wp_localize_script(
     69                'WOOAFFPRO_actions',
     70                'WOOAFFPRO_ajax_data',
     71                array(
     72                    'ajaxUrl' => admin_url( 'admin-ajax.php' ),
     73                    'nonce'   => wp_create_nonce( 'WOOAFFPRO_ajax_nonce' ),
     74                )
     75            );
     76        }
     77
     78
     79        public function setup_actions() {
     80
     81            add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue_global' ) );
     82
     83            add_action( 'wp_ajax_nopriv_increase_external_populatiry', array( $this, 'increase_external_populatiry_func' ) );
     84
     85            add_action( 'wp_ajax_increase_external_populatiry', array( $this, 'increase_external_populatiry_func' ) );
     86        }
     87
     88
     89        public function increase_external_populatiry_func() {
     90
     91            check_ajax_referer( 'WOOAFFPRO_ajax_nonce', 'nonce' );
     92
     93            $product_id = absint( $_POST['product_id'] );
     94
     95            if ( $product_id && wc_get_product( $product_id )->get_type() == 'external' ) {
     96
     97                $lastCount = get_post_meta( $product_id, 'total_sales', true );
     98
     99                if ( ! empty( $lastCount ) ) {
     100
     101                    $updated = update_post_meta( $product_id, 'total_sales', $lastCount + 1 );
     102
     103                } else {
     104                    $updated = update_post_meta( $product_id, 'total_sales', 1 );
     105                }
     106            }
     107
     108            wp_die();
     109        }
     110
    54111
    55112    }
     
    57114
    58115
    59     public function frontend_enqueue_global(){
     116    add_action( 'plugins_loaded', array( 'WooCommerce_affiliate_sort', 'init' ), 10 );
    60117
    61         if(!wp_script_is( 'jquery', 'registered' ))
    62             wp_enqueue_script( 'jquery');
    63 
    64         wp_enqueue_script( 'WOOAFFPRO_actions',WOOAFFPRO_ASSETS_URL . 'js/actions.js',array('jquery'),WC_VERSION,true);
    65 
    66         wp_localize_script('WOOAFFPRO_actions','WOOAFFPRO_ajax_data',array('ajaxUrl'=>admin_url('admin-ajax.php'),'nonce'=>wp_create_nonce('WOOAFFPRO_ajax_nonce')) );
    67     }
    68 
    69 
    70     public function setup_actions(){
    71 
    72         add_action('wp_enqueue_scripts',array($this,'frontend_enqueue_global'));
    73 
    74         add_action('wp_ajax_nopriv_increase_external_populatiry',array($this,'increase_external_populatiry_func'));
    75            
    76         add_action('wp_ajax_increase_external_populatiry',array($this,'increase_external_populatiry_func'));
    77     }
    78 
    79 
    80     public function increase_external_populatiry_func(){
    81 
    82         check_ajax_referer( 'WOOAFFPRO_ajax_nonce','nonce' );
    83 
    84         $product_id = absint($_POST['product_id']);
    85 
    86         if( $product_id  && wc_get_product($product_id)->get_type() == 'external' ){
    87 
    88             $lastCount = get_post_meta($product_id,'total_sales',true);
    89 
    90             if(!empty($lastCount)){
    91 
    92                 $updated = update_post_meta($product_id,'total_sales',$lastCount+1);
    93 
    94             }else{
    95                 $updated = update_post_meta($product_id,'total_sales',1);
    96             }
    97 
    98         }
    99 
    100         wp_die();
    101     }
    102 
    103 
    104 }
    105 
    106 
    107 
    108 add_action('plugins_loaded',array('WooCommerce_affiliate_sort','init'),10);
    109 
    110 register_activation_hook( __FILE__,array('WooCommerce_affiliate_sort','plugin_activated') );
     118    register_activation_hook( __FILE__, array( 'WooCommerce_affiliate_sort', 'plugin_activated' ) );
    111119
    112120endif;
    113 
    114 
    115 
    116 
    117 
Note: See TracChangeset for help on using the changeset viewer.