Plugin Directory

Changeset 1957373


Ignore:
Timestamp:
10/16/2018 09:47:48 AM (7 years ago)
Author:
storespot
Message:

Release 1.0.7

Location:
storespot
Files:
9 edited
9 copied

Legend:

Unmodified
Added
Removed
  • storespot/tags/1.0.7/admin/class-storespot-api.php

    r1945614 r1957373  
    1010            'permission_callback' => array( $this, 'update_settings_permission_check' ),
    1111        ) );
     12
     13        register_rest_route( $this->namespace, '/storespot/', array(
     14            'methods'                       => WP_REST_SERVER::READABLE,
     15            'callback'                      => array( $this, 'get_storespot_settings' ),
     16            'permission_callback' => array( $this, 'get_settings_permission_check' ),
     17        ));
    1218    }
    1319
     
    2733        $settings = $request['settings'];
    2834        update_option( 'storespot_settings', $settings );
     35        if ( ! wp_next_scheduled( 'stsp_product_feed_update' ) ) {
     36            wp_schedule_event( time(), 'hourly', 'stsp_product_feed_update' );
     37        }
    2938
    3039        $data = array( 'updated' => true, 'settings' => get_option( 'storespot_settings' ) );
     
    3443        return $response;
    3544    }
     45
     46    public function get_settings_permission_check() {
     47        if ( !wc_rest_check_user_permissions('read') ) {
     48            return new WP_Error(
     49                'woocommerce_rest_cannot_read',
     50                __( 'Woops, it seems you are not allowed to do this.', 'storespot' ),
     51                array( 'status' => rest_authorization_required_code() )
     52            );
     53        }
     54
     55        return true;
     56    }
     57
     58    public function get_storespot_settings($request) {
     59        if ( wp_next_scheduled( 'stsp_product_feed_update' ) ) {
     60            $cronjob = wp_next_scheduled( 'stsp_product_feed_update' );
     61        } else {
     62            $cronjob = false;
     63        }
     64
     65        $data = array(
     66            'cronjob' => $cronjob,
     67            'plugin_version' => STORESPOT_VERSION,
     68            'settings' => get_option( ' storespot_settings' ),
     69        );
     70        $response = rest_ensure_response($data);
     71        $response->set_status(200);
     72
     73        return $response;
     74    }
     75
    3676}
  • storespot/tags/1.0.7/admin/class-storespot-product-feed.php

    r1953043 r1957373  
    4545        }
    4646
     47        private function log_file() {
     48            return $this->upload_directory()['dir_path'] . 'debug.log';
     49        }
     50
    4751        public function generate_xml_feed( $url ) {
     52            error_log("\n" . date('Y-m-d h:i:s'). " :: starting feed write", 3, $this->log_file());
    4853            $xml = new DOMDocument();
    4954            $xml->version = "1.0";
     
    6267            $feed->appendChild( $link );
    6368
    64             $args = array(
    65                 'limit' => -1,
    66                 'return' => 'ids',
    67                 'status' => 'publish'
    68             );
    69             $products = wc_get_products( $args );
     69            $page = 1;
     70            $limit = $this->get_page_limit();
     71            do {
     72                $args = array(
     73                    'page' => $page,
     74                    'limit' => $limit,
     75                    'paginate' => true,
     76                    'return' => 'ids',
     77                    'status' => 'publish'
     78                );
     79                $products = wc_get_products( $args );
     80                $this->append_products_to_feed( $xml, $feed, $products->products );
     81                $page += 1;
     82            } while ( $page <= $products->max_num_pages);
     83
     84            $xml->appendChild( $feed );
     85            error_log("\n" . date('Y-m-d h:i:s'). " :: completed feed write", 3, $this->log_file());
     86
     87            return $xml->saveXML();
     88        }
     89
     90        private function append_products_to_feed( $xml, $feed, $products ) {
    7091            foreach ( $products as $id ) {
    7192                $product = wc_get_product( $id );
     
    7596                }
    7697            }
    77 
    78             $xml->appendChild( $feed );
    79 
    80             return $xml->saveXML();
     98        }
     99
     100        private function get_page_limit() {
     101            if (version_compare(phpversion(), '5.6', '<')) {
     102                $products_per_page = 50;
     103            } elseif (version_compare(phpversion(), '5.6', '=')) {
     104                $products_per_page = 250;
     105            } else {
     106                $products_per_page = 1000;
     107            }
     108            return $products_per_page;
    81109        }
    82110
     
    112140
    113141        private function set_id_field( $xml, $item, $product ) {
    114             $child = $xml->createElement( 'g:id', $product->get_id() );
     142            $product_id = $product->get_id();
     143            $product_sku = $product->get_sku();
     144            $id = $product_sku ? $product_sku . '_' . $product_id : 'wc_post_id_' . $product_id;
     145
     146            $child = $xml->createElement( 'g:id', $id );
    115147            $item->appendChild( $child );
    116148            return $item;
     
    246278
    247279        private function set_google_product_category_field( $xml, $item ) {
    248             $category = get_option('storespot_settings')['product_category'];
     280            $stsp_settings = get_option( 'storespot_settings' );
     281            if( $stsp_settings && array_key_exists( 'product_category', $stsp_settings )) {
     282                $category = $stsp_settings['product_category'];
     283            } else {
     284                $category = 0;
     285            }
     286
    249287            $child = $xml->createElement( 'g:google_product_category', $category );
    250288            $item->appendChild( $child );
  • storespot/tags/1.0.7/includes/class-storespot-activator.php

    r1946605 r1957373  
    55    public static function activate() {
    66
    7         $options = [
    8             'pixel_id' => '',
    9             'product_feed' => 'yes',
    10             'product_category' => ''
    11         ];
     7        $stsp_settings = get_option('storespot_settings');
    128
    13         add_option( 'storespot_settings', $options );
     9        if( $stsp_settings && array_key_exists( 'product_feed', $stsp_settings )) {
     10            $feed = $stsp_settings['product_feed'];
     11            if ( $feed && !wp_next_scheduled( 'stsp_product_feed_update' ) ) {
     12                wp_schedule_event( time(), 'hourly', 'stsp_product_feed_update' );
     13            }
     14        } else {
     15            $options = [
     16                'pixel_id' => '',
     17                'product_feed' => 'no',
     18                'product_category' => ''
     19            ];
     20
     21            add_option( 'storespot_settings', $options );
     22        }
     23
    1424        set_transient( 'stsp-admin-activation-notice', true, 5 );
    15 
    16         if ( ! wp_next_scheduled( 'stsp_product_feed_update' ) ) {
    17             wp_schedule_event( time(), 'hourly', 'stsp_product_feed_update' );
    18         }
    1925
    2026    }
  • storespot/tags/1.0.7/includes/class-storespot.php

    r1946608 r1957373  
    5252            $product_feed = new StoreSpot_Product_Feed();
    5353            $admin_message = new StoreSpot_Messages();
    54             $this->loader->add_action( 'update_option_storespot_settings', $product_feed, 'write_product_feed' );
    5554            $this->loader->add_action( 'stsp_product_feed_update', $product_feed, 'write_product_feed' );
    5655            $this->loader->add_action( 'admin_notices', $admin_message, 'activation_notice' );
     
    7675    private function fb_integration_installed($pixel_id) {
    7776        $fb_option = get_option('facebook_config');
     77        $fb_integration_option_set = false;
    7878        if ( $fb_option && array_key_exists( 'pixel_id', $fb_option ) ) {
    7979            if ( $fb_option['pixel_id'] == $pixel_id) {
    80                 return true;
     80                $fb_integration_option_set = true;
    8181            }
    8282        }
    83 
    84         return false;
     83        include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     84        $fb_integration_activated = class_exists('WC_Facebookcommerce');
     85        return $fb_integration_activated && $fb_integration_option_set;
    8586    }
    8687
  • storespot/tags/1.0.7/public/class-storespot-events.php

    r1939129 r1957373  
    1616    }
    1717
     18    public function get_facebook_content_id($product) {
     19        $product_id = $product->get_id();
     20        $product_sku = $product->get_sku();
     21        return $product_sku ? $product_sku . '_' . $product_id : 'wc_post_id_' . $product_id;
     22    }
     23
    1824    public function render_product_view_event() {
    1925        global $post;
     
    2632            $params['content_type'] = ($product->get_type() == 'variable' ? 'product_group' : 'product');
    2733            $params['currency'] = get_woocommerce_currency();
    28 
    29             $content_id = $product->get_id();
    30 
    31             $params['content_ids'] = json_encode( $content_id );
     34            $params['content_ids'] = json_encode( $this->get_facebook_content_id( $product ) );
    3235
    3336            $this->facebook_pixel->event_code( 'ViewContent', $params );
     
    5558        $product_ids = array();
    5659        foreach ( $products as $item ) {
    57             $product_ids[] = $item['data']->get_id();
     60            $product_ids[] = $this->get_facebook_content_id( $item['data'] );
    5861        }
    5962
    6063        $params = array();
    61         $params['content_ids'] = json_encode($product_ids);
     64        $params['content_ids'] = json_encode( $product_ids );
    6265        $params['content_type'] = 'product';
    6366        $params['value'] = $woocommerce->cart->total;
     
    7881        $product_ids = array();
    7982        foreach ( $products as $item ) {
    80             $product_ids[] = $item['data']->get_id();
     83            $product_ids[] = $this->get_facebook_content_id( $item['data'] );
    8184        }
    8285        $params = array();
     
    99102        $product_ids = array();
    100103        foreach ( $products as $item ) {
    101             $product_ids[] = $item['data']->get_id();
     104            $product_ids[] = $this->get_facebook_content_id( $item['data'] );
    102105        }
    103106
     
    120123        $product_ids = array();
    121124        foreach ( $order->get_items() as $item ) {
    122             $product_ids[] = $item['product_id'];
     125            $product = $item->get_product();
     126            $product_ids[] = $this->get_facebook_content_id( $product );
    123127        }
    124128
  • storespot/tags/1.0.7/public/class-storespot-facebook-pixel.php

    r1939129 r1957373  
    3737
    3838    public function get_pixel_id() {
    39         return get_option( 'storespot_settings' )['pixel_id'];
     39        $stsp_settings = get_option( 'storespot_settings' );
     40        if( $stsp_settings && array_key_exists( 'pixel_id', $stsp_settings )) {
     41            return $stsp_settings['pixel_id'];
     42        }
     43        return false;
    4044    }
    4145
  • storespot/tags/1.0.7/readme.txt

    r1953043 r1957373  
    55Tested up to: 4.9
    66Requires PHP: 5.6
    7 Stable tag: 1.0.5
     7Stable tag: 1.0.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050== Changelog ==
    5151
     52= 1.0.7 =
     53* Compatibility with Facebook for WooCommerce plugin
     54
     55= 1.0.6 =
     56* Use pagination on feed generation
     57
    5258= 1.0.5 =
    5359* Add registration button to welcome message
  • storespot/tags/1.0.7/storespot.php

    r1953043 r1957373  
    44 * Plugin URI:   https://storespot.io/
    55 * Description:  Stop leaving money on the table. Automate your retargeting ads with StoreSpot.
    6  * Version:      1.0.5
     6 * Version:      1.0.7
    77 * Author:       StoreSpot
    88**/
     
    1111if ( ! defined( 'WPINC' ) ) { die; }
    1212
    13 define( 'STORESPOT_VERSION', '1.0.4' );
     13define( 'STORESPOT_VERSION', '1.0.7' );
    1414
    1515function activate_storespot() {
  • storespot/trunk/admin/class-storespot-product-feed.php

    r1955784 r1957373  
    140140
    141141        private function set_id_field( $xml, $item, $product ) {
    142             $child = $xml->createElement( 'g:id', $product->get_id() );
     142            $product_id = $product->get_id();
     143            $product_sku = $product->get_sku();
     144            $id = $product_sku ? $product_sku . '_' . $product_id : 'wc_post_id_' . $product_id;
     145
     146            $child = $xml->createElement( 'g:id', $id );
    143147            $item->appendChild( $child );
    144148            return $item;
     
    274278
    275279        private function set_google_product_category_field( $xml, $item ) {
    276             $category = get_option('storespot_settings')['product_category'];
     280            $stsp_settings = get_option( 'storespot_settings' );
     281            if( $stsp_settings && array_key_exists( 'product_category', $stsp_settings )) {
     282                $category = $stsp_settings['product_category'];
     283            } else {
     284                $category = 0;
     285            }
     286
    277287            $child = $xml->createElement( 'g:google_product_category', $category );
    278288            $item->appendChild( $child );
  • storespot/trunk/includes/class-storespot-activator.php

    r1955784 r1957373  
    55    public static function activate() {
    66
    7         $options = [
    8             'pixel_id' => '',
    9             'product_feed' => 'no',
    10             'product_category' => ''
    11         ];
     7        $stsp_settings = get_option('storespot_settings');
    128
    13         add_option( 'storespot_settings', $options );
     9        if( $stsp_settings && array_key_exists( 'product_feed', $stsp_settings )) {
     10            $feed = $stsp_settings['product_feed'];
     11            if ( $feed && !wp_next_scheduled( 'stsp_product_feed_update' ) ) {
     12                wp_schedule_event( time(), 'hourly', 'stsp_product_feed_update' );
     13            }
     14        } else {
     15            $options = [
     16                'pixel_id' => '',
     17                'product_feed' => 'no',
     18                'product_category' => ''
     19            ];
     20
     21            add_option( 'storespot_settings', $options );
     22        }
     23
    1424        set_transient( 'stsp-admin-activation-notice', true, 5 );
    1525
  • storespot/trunk/includes/class-storespot.php

    r1955784 r1957373  
    7575    private function fb_integration_installed($pixel_id) {
    7676        $fb_option = get_option('facebook_config');
     77        $fb_integration_option_set = false;
    7778        if ( $fb_option && array_key_exists( 'pixel_id', $fb_option ) ) {
    7879            if ( $fb_option['pixel_id'] == $pixel_id) {
    79                 return true;
     80                $fb_integration_option_set = true;
    8081            }
    8182        }
    82 
    83         return false;
     83        include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
     84        $fb_integration_activated = class_exists('WC_Facebookcommerce');
     85        return $fb_integration_activated && $fb_integration_option_set;
    8486    }
    8587
  • storespot/trunk/public/class-storespot-events.php

    r1939129 r1957373  
    1616    }
    1717
     18    public function get_facebook_content_id($product) {
     19        $product_id = $product->get_id();
     20        $product_sku = $product->get_sku();
     21        return $product_sku ? $product_sku . '_' . $product_id : 'wc_post_id_' . $product_id;
     22    }
     23
    1824    public function render_product_view_event() {
    1925        global $post;
     
    2632            $params['content_type'] = ($product->get_type() == 'variable' ? 'product_group' : 'product');
    2733            $params['currency'] = get_woocommerce_currency();
    28 
    29             $content_id = $product->get_id();
    30 
    31             $params['content_ids'] = json_encode( $content_id );
     34            $params['content_ids'] = json_encode( $this->get_facebook_content_id( $product ) );
    3235
    3336            $this->facebook_pixel->event_code( 'ViewContent', $params );
     
    5558        $product_ids = array();
    5659        foreach ( $products as $item ) {
    57             $product_ids[] = $item['data']->get_id();
     60            $product_ids[] = $this->get_facebook_content_id( $item['data'] );
    5861        }
    5962
    6063        $params = array();
    61         $params['content_ids'] = json_encode($product_ids);
     64        $params['content_ids'] = json_encode( $product_ids );
    6265        $params['content_type'] = 'product';
    6366        $params['value'] = $woocommerce->cart->total;
     
    7881        $product_ids = array();
    7982        foreach ( $products as $item ) {
    80             $product_ids[] = $item['data']->get_id();
     83            $product_ids[] = $this->get_facebook_content_id( $item['data'] );
    8184        }
    8285        $params = array();
     
    99102        $product_ids = array();
    100103        foreach ( $products as $item ) {
    101             $product_ids[] = $item['data']->get_id();
     104            $product_ids[] = $this->get_facebook_content_id( $item['data'] );
    102105        }
    103106
     
    120123        $product_ids = array();
    121124        foreach ( $order->get_items() as $item ) {
    122             $product_ids[] = $item['product_id'];
     125            $product = $item->get_product();
     126            $product_ids[] = $this->get_facebook_content_id( $product );
    123127        }
    124128
  • storespot/trunk/public/class-storespot-facebook-pixel.php

    r1939129 r1957373  
    3737
    3838    public function get_pixel_id() {
    39         return get_option( 'storespot_settings' )['pixel_id'];
     39        $stsp_settings = get_option( 'storespot_settings' );
     40        if( $stsp_settings && array_key_exists( 'pixel_id', $stsp_settings )) {
     41            return $stsp_settings['pixel_id'];
     42        }
     43        return false;
    4044    }
    4145
  • storespot/trunk/readme.txt

    r1955784 r1957373  
    55Tested up to: 4.9
    66Requires PHP: 5.6
    7 Stable tag: 1.0.6
     7Stable tag: 1.0.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050== Changelog ==
    5151
     52= 1.0.7 =
     53* Compatibility with Facebook for WooCommerce plugin
     54
    5255= 1.0.6 =
    5356* Use pagination on feed generation
  • storespot/trunk/storespot.php

    r1955784 r1957373  
    44 * Plugin URI:   https://storespot.io/
    55 * Description:  Stop leaving money on the table. Automate your retargeting ads with StoreSpot.
    6  * Version:      1.0.6
     6 * Version:      1.0.7
    77 * Author:       StoreSpot
    88**/
     
    1111if ( ! defined( 'WPINC' ) ) { die; }
    1212
    13 define( 'STORESPOT_VERSION', '1.0.6' );
     13define( 'STORESPOT_VERSION', '1.0.7' );
    1414
    1515function activate_storespot() {
Note: See TracChangeset for help on using the changeset viewer.