Changeset 1957373
- Timestamp:
- 10/16/2018 09:47:48 AM (7 years ago)
- Location:
- storespot
- Files:
-
- 9 edited
- 9 copied
-
tags/1.0.7 (copied) (copied from storespot/trunk)
-
tags/1.0.7/admin/class-storespot-api.php (copied) (copied from storespot/trunk/admin/class-storespot-api.php) (3 diffs)
-
tags/1.0.7/admin/class-storespot-messages.php (copied) (copied from storespot/trunk/admin/class-storespot-messages.php)
-
tags/1.0.7/admin/class-storespot-product-feed.php (copied) (copied from storespot/trunk/admin/class-storespot-product-feed.php) (5 diffs)
-
tags/1.0.7/img (copied) (copied from storespot/trunk/img)
-
tags/1.0.7/includes/class-storespot-activator.php (copied) (copied from storespot/trunk/includes/class-storespot-activator.php) (1 diff)
-
tags/1.0.7/includes/class-storespot.php (copied) (copied from storespot/trunk/includes/class-storespot.php) (2 diffs)
-
tags/1.0.7/public/class-storespot-events.php (modified) (6 diffs)
-
tags/1.0.7/public/class-storespot-facebook-pixel.php (modified) (1 diff)
-
tags/1.0.7/readme.txt (copied) (copied from storespot/trunk/readme.txt) (2 diffs)
-
tags/1.0.7/storespot.php (copied) (copied from storespot/trunk/storespot.php) (2 diffs)
-
trunk/admin/class-storespot-product-feed.php (modified) (2 diffs)
-
trunk/includes/class-storespot-activator.php (modified) (1 diff)
-
trunk/includes/class-storespot.php (modified) (1 diff)
-
trunk/public/class-storespot-events.php (modified) (6 diffs)
-
trunk/public/class-storespot-facebook-pixel.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/storespot.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
storespot/tags/1.0.7/admin/class-storespot-api.php
r1945614 r1957373 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/tags/1.0.7/admin/class-storespot-product-feed.php
r1953043 r1957373 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 … … 112 140 113 141 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 ); 115 147 $item->appendChild( $child ); 116 148 return $item; … … 246 278 247 279 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 249 287 $child = $xml->createElement( 'g:google_product_category', $category ); 250 288 $item->appendChild( $child ); -
storespot/tags/1.0.7/includes/class-storespot-activator.php
r1946605 r1957373 5 5 public static function activate() { 6 6 7 $options = [ 8 'pixel_id' => '', 9 'product_feed' => 'yes', 10 'product_category' => '' 11 ]; 7 $stsp_settings = get_option('storespot_settings'); 12 8 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 14 24 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 }19 25 20 26 } -
storespot/tags/1.0.7/includes/class-storespot.php
r1946608 r1957373 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' ); … … 76 75 private function fb_integration_installed($pixel_id) { 77 76 $fb_option = get_option('facebook_config'); 77 $fb_integration_option_set = false; 78 78 if ( $fb_option && array_key_exists( 'pixel_id', $fb_option ) ) { 79 79 if ( $fb_option['pixel_id'] == $pixel_id) { 80 returntrue;80 $fb_integration_option_set = true; 81 81 } 82 82 } 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; 85 86 } 86 87 -
storespot/tags/1.0.7/public/class-storespot-events.php
r1939129 r1957373 16 16 } 17 17 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 18 24 public function render_product_view_event() { 19 25 global $post; … … 26 32 $params['content_type'] = ($product->get_type() == 'variable' ? 'product_group' : 'product'); 27 33 $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 ) ); 32 35 33 36 $this->facebook_pixel->event_code( 'ViewContent', $params ); … … 55 58 $product_ids = array(); 56 59 foreach ( $products as $item ) { 57 $product_ids[] = $ item['data']->get_id();60 $product_ids[] = $this->get_facebook_content_id( $item['data'] ); 58 61 } 59 62 60 63 $params = array(); 61 $params['content_ids'] = json_encode( $product_ids);64 $params['content_ids'] = json_encode( $product_ids ); 62 65 $params['content_type'] = 'product'; 63 66 $params['value'] = $woocommerce->cart->total; … … 78 81 $product_ids = array(); 79 82 foreach ( $products as $item ) { 80 $product_ids[] = $ item['data']->get_id();83 $product_ids[] = $this->get_facebook_content_id( $item['data'] ); 81 84 } 82 85 $params = array(); … … 99 102 $product_ids = array(); 100 103 foreach ( $products as $item ) { 101 $product_ids[] = $ item['data']->get_id();104 $product_ids[] = $this->get_facebook_content_id( $item['data'] ); 102 105 } 103 106 … … 120 123 $product_ids = array(); 121 124 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 ); 123 127 } 124 128 -
storespot/tags/1.0.7/public/class-storespot-facebook-pixel.php
r1939129 r1957373 37 37 38 38 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; 40 44 } 41 45 -
storespot/tags/1.0.7/readme.txt
r1953043 r1957373 5 5 Tested up to: 4.9 6 6 Requires PHP: 5.6 7 Stable tag: 1.0. 57 Stable tag: 1.0.7 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.7 = 53 * Compatibility with Facebook for WooCommerce plugin 54 55 = 1.0.6 = 56 * Use pagination on feed generation 57 52 58 = 1.0.5 = 53 59 * Add registration button to welcome message -
storespot/tags/1.0.7/storespot.php
r1953043 r1957373 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.7 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.7' ); 14 14 15 15 function activate_storespot() { -
storespot/trunk/admin/class-storespot-product-feed.php
r1955784 r1957373 140 140 141 141 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 ); 143 147 $item->appendChild( $child ); 144 148 return $item; … … 274 278 275 279 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 277 287 $child = $xml->createElement( 'g:google_product_category', $category ); 278 288 $item->appendChild( $child ); -
storespot/trunk/includes/class-storespot-activator.php
r1955784 r1957373 5 5 public static function activate() { 6 6 7 $options = [ 8 'pixel_id' => '', 9 'product_feed' => 'no', 10 'product_category' => '' 11 ]; 7 $stsp_settings = get_option('storespot_settings'); 12 8 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 14 24 set_transient( 'stsp-admin-activation-notice', true, 5 ); 15 25 -
storespot/trunk/includes/class-storespot.php
r1955784 r1957373 75 75 private function fb_integration_installed($pixel_id) { 76 76 $fb_option = get_option('facebook_config'); 77 $fb_integration_option_set = false; 77 78 if ( $fb_option && array_key_exists( 'pixel_id', $fb_option ) ) { 78 79 if ( $fb_option['pixel_id'] == $pixel_id) { 79 returntrue;80 $fb_integration_option_set = true; 80 81 } 81 82 } 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; 84 86 } 85 87 -
storespot/trunk/public/class-storespot-events.php
r1939129 r1957373 16 16 } 17 17 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 18 24 public function render_product_view_event() { 19 25 global $post; … … 26 32 $params['content_type'] = ($product->get_type() == 'variable' ? 'product_group' : 'product'); 27 33 $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 ) ); 32 35 33 36 $this->facebook_pixel->event_code( 'ViewContent', $params ); … … 55 58 $product_ids = array(); 56 59 foreach ( $products as $item ) { 57 $product_ids[] = $ item['data']->get_id();60 $product_ids[] = $this->get_facebook_content_id( $item['data'] ); 58 61 } 59 62 60 63 $params = array(); 61 $params['content_ids'] = json_encode( $product_ids);64 $params['content_ids'] = json_encode( $product_ids ); 62 65 $params['content_type'] = 'product'; 63 66 $params['value'] = $woocommerce->cart->total; … … 78 81 $product_ids = array(); 79 82 foreach ( $products as $item ) { 80 $product_ids[] = $ item['data']->get_id();83 $product_ids[] = $this->get_facebook_content_id( $item['data'] ); 81 84 } 82 85 $params = array(); … … 99 102 $product_ids = array(); 100 103 foreach ( $products as $item ) { 101 $product_ids[] = $ item['data']->get_id();104 $product_ids[] = $this->get_facebook_content_id( $item['data'] ); 102 105 } 103 106 … … 120 123 $product_ids = array(); 121 124 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 ); 123 127 } 124 128 -
storespot/trunk/public/class-storespot-facebook-pixel.php
r1939129 r1957373 37 37 38 38 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; 40 44 } 41 45 -
storespot/trunk/readme.txt
r1955784 r1957373 5 5 Tested up to: 4.9 6 6 Requires PHP: 5.6 7 Stable tag: 1.0. 67 Stable tag: 1.0.7 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.7 = 53 * Compatibility with Facebook for WooCommerce plugin 54 52 55 = 1.0.6 = 53 56 * Use pagination on feed generation -
storespot/trunk/storespot.php
r1955784 r1957373 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. 66 * Version: 1.0.7 7 7 * Author: StoreSpot 8 8 **/ … … 11 11 if ( ! defined( 'WPINC' ) ) { die; } 12 12 13 define( 'STORESPOT_VERSION', '1.0. 6' );13 define( 'STORESPOT_VERSION', '1.0.7' ); 14 14 15 15 function activate_storespot() {
Note: See TracChangeset
for help on using the changeset viewer.