Plugin Directory

Changeset 1955784


Ignore:
Timestamp:
10/12/2018 01:46:27 PM (7 years ago)
Author:
storespot
Message:

Release 1.0.6

Location:
storespot/trunk
Files:
6 edited

Legend:

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

    r1945614 r1955784  
    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/trunk/admin/class-storespot-product-feed.php

    r1953043 r1955784  
    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
  • storespot/trunk/includes/class-storespot-activator.php

    r1946605 r1955784  
    77        $options = [
    88            'pixel_id' => '',
    9             'product_feed' => 'yes',
     9            'product_feed' => 'no',
    1010            'product_category' => ''
    1111        ];
     
    1414        set_transient( 'stsp-admin-activation-notice', true, 5 );
    1515
    16         if ( ! wp_next_scheduled( 'stsp_product_feed_update' ) ) {
    17             wp_schedule_event( time(), 'hourly', 'stsp_product_feed_update' );
    18         }
    19 
    2016    }
    2117
  • storespot/trunk/includes/class-storespot.php

    r1946608 r1955784  
    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' );
  • storespot/trunk/readme.txt

    r1953043 r1955784  
    55Tested up to: 4.9
    66Requires PHP: 5.6
    7 Stable tag: 1.0.5
     7Stable tag: 1.0.6
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050== Changelog ==
    5151
     52= 1.0.6 =
     53* Use pagination on feed generation
     54
    5255= 1.0.5 =
    5356* Add registration button to welcome message
  • storespot/trunk/storespot.php

    r1953043 r1955784  
    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.6
    77 * Author:       StoreSpot
    88**/
     
    1111if ( ! defined( 'WPINC' ) ) { die; }
    1212
    13 define( 'STORESPOT_VERSION', '1.0.4' );
     13define( 'STORESPOT_VERSION', '1.0.6' );
    1414
    1515function activate_storespot() {
Note: See TracChangeset for help on using the changeset viewer.