Changeset 1955784
- Timestamp:
- 10/12/2018 01:46:27 PM (7 years ago)
- Location:
- storespot/trunk
- Files:
-
- 6 edited
-
admin/class-storespot-api.php (modified) (3 diffs)
-
admin/class-storespot-product-feed.php (modified) (3 diffs)
-
includes/class-storespot-activator.php (modified) (2 diffs)
-
includes/class-storespot.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
storespot.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
storespot/trunk/admin/class-storespot-api.php
r1945614 r1955784 10 10 'permission_callback' => array( $this, 'update_settings_permission_check' ), 11 11 ) ); 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 )); 12 18 } 13 19 … … 27 33 $settings = $request['settings']; 28 34 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 } 29 38 30 39 $data = array( 'updated' => true, 'settings' => get_option( 'storespot_settings' ) ); … … 34 43 return $response; 35 44 } 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 36 76 } -
storespot/trunk/admin/class-storespot-product-feed.php
r1953043 r1955784 45 45 } 46 46 47 private function log_file() { 48 return $this->upload_directory()['dir_path'] . 'debug.log'; 49 } 50 47 51 public function generate_xml_feed( $url ) { 52 error_log("\n" . date('Y-m-d h:i:s'). " :: starting feed write", 3, $this->log_file()); 48 53 $xml = new DOMDocument(); 49 54 $xml->version = "1.0"; … … 62 67 $feed->appendChild( $link ); 63 68 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 ) { 70 91 foreach ( $products as $id ) { 71 92 $product = wc_get_product( $id ); … … 75 96 } 76 97 } 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; 81 109 } 82 110 -
storespot/trunk/includes/class-storespot-activator.php
r1946605 r1955784 7 7 $options = [ 8 8 'pixel_id' => '', 9 'product_feed' => ' yes',9 'product_feed' => 'no', 10 10 'product_category' => '' 11 11 ]; … … 14 14 set_transient( 'stsp-admin-activation-notice', true, 5 ); 15 15 16 if ( ! wp_next_scheduled( 'stsp_product_feed_update' ) ) {17 wp_schedule_event( time(), 'hourly', 'stsp_product_feed_update' );18 }19 20 16 } 21 17 -
storespot/trunk/includes/class-storespot.php
r1946608 r1955784 52 52 $product_feed = new StoreSpot_Product_Feed(); 53 53 $admin_message = new StoreSpot_Messages(); 54 $this->loader->add_action( 'update_option_storespot_settings', $product_feed, 'write_product_feed' );55 54 $this->loader->add_action( 'stsp_product_feed_update', $product_feed, 'write_product_feed' ); 56 55 $this->loader->add_action( 'admin_notices', $admin_message, 'activation_notice' ); -
storespot/trunk/readme.txt
r1953043 r1955784 5 5 Tested up to: 4.9 6 6 Requires PHP: 5.6 7 Stable tag: 1.0. 57 Stable tag: 1.0.6 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 50 50 == Changelog == 51 51 52 = 1.0.6 = 53 * Use pagination on feed generation 54 52 55 = 1.0.5 = 53 56 * Add registration button to welcome message -
storespot/trunk/storespot.php
r1953043 r1955784 4 4 * Plugin URI: https://storespot.io/ 5 5 * Description: Stop leaving money on the table. Automate your retargeting ads with StoreSpot. 6 * Version: 1.0. 56 * Version: 1.0.6 7 7 * Author: StoreSpot 8 8 **/ … … 11 11 if ( ! defined( 'WPINC' ) ) { die; } 12 12 13 define( 'STORESPOT_VERSION', '1.0. 4' );13 define( 'STORESPOT_VERSION', '1.0.6' ); 14 14 15 15 function activate_storespot() {
Note: See TracChangeset
for help on using the changeset viewer.