Plugin Directory

Changeset 2309641


Ignore:
Timestamp:
05/21/2020 05:44:45 PM (6 years ago)
Author:
xevibrainity
Message:

Imported changes from Git repository

Location:
brainity-boost-ads/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • brainity-boost-ads/trunk/brainity.php

    r2296756 r2309641  
    99Author: Brainity
    1010Author URI: https://www.brainity.co
    11 Version: 1.0.4
     11Version: 1.0.5
    1212*/
    1313
     
    6666            ));
    6767        });
     68
     69        add_action('rest_api_init', function () {
     70            register_rest_route('brainity/v1', '/settings', array(
     71                'methods' => 'GET',
     72                'callback' => array(__CLASS__, 'get_settings'),
     73            ));
     74
     75            register_rest_route('brainity/v1', '/settings', array(
     76                'methods' => 'POST',
     77                'callback' => array(__CLASS__, 'set_settings'),
     78            ));
     79        });
    6880    }
    6981
     
    96108
    97109        echo($csv);
     110        exit;
     111    }
     112
     113    public static function get_settings($data)
     114    {
     115        header('Content-type: application/json');
     116
     117        $token = $data->get_param('token');
     118
     119        if (empty($token)) {
     120            return new WP_REST_Response('Not found', 404);
     121        }
     122
     123        global $wpdb;
     124
     125        $table_name = $wpdb->prefix . 'brainity';
     126
     127        $config = $wpdb->get_results("SELECT * FROM  $table_name ");
     128
     129        if ($config[0]->token !== $token) {
     130            return new WP_REST_Response('Not found', 404);
     131        }
     132
     133        if (count($config) === 0) {
     134            return new WP_REST_Response('Not found', 404);
     135        }
     136
     137        if ($config[0]->token !== $token) {
     138            return new WP_REST_Response('Not found', 404);
     139        }
     140
     141        $config[0]->facebook_for_woocomerce = get_option(
     142            'facebook_config',
     143                array(
     144                    'pixel_id' => '0'
     145                )
     146            );
     147
     148        echo(json_encode($config[0]));
     149        exit;
     150    }
     151
     152    public static function set_settings($data)
     153    {
     154        header('Content-type: application/json');
     155
     156        $token = $data->get_param('token');
     157
     158        if (empty($token)) {
     159            return new WP_REST_Response('Not found', 404);
     160        }
     161
     162        $pixel = $data->get_param('pixel_id');
     163
     164        $setPixelFacebookForWoocomer = $data->get_param('set_facebook_for_woocomerce');
     165        if (!empty($setPixelFacebookForWoocomer) && $setPixelFacebookForWoocomer) {
     166            $pixelFacebookForWoocomer = $data->get_param('facebook_for_woocomerce');
     167
     168            $options = get_option(
     169                'facebook_config',
     170                    array(
     171                        'pixel_id' => '0'
     172                    )
     173                );
     174           
     175            $options['pixel_id'] = $pixelFacebookForWoocomer;
     176            update_option('facebook_config', $options);
     177        }
     178
     179        global $wpdb;
     180
     181        $table_name = $wpdb->prefix . 'brainity';
     182       
     183        $config = $wpdb->get_results("SELECT * FROM  $table_name ");
     184        if ($config[0]->token !== $token) {
     185            return new WP_REST_Response('Not found', 404);
     186        }
     187
     188        if (empty($pixel)) {
     189            $wpdb->query(
     190                $wpdb->prepare("UPDATE $table_name SET pixel_id = NULL")
     191            );
     192        } else {
     193            $wpdb->query(
     194                $wpdb->prepare("UPDATE $table_name SET pixel_id = %s", $pixel)
     195            );
     196        }
     197       
     198        $config = $wpdb->get_results("SELECT * FROM  $table_name ");
     199        if (count($config) === 0) {
     200            return new WP_REST_Response('Not found', 404);
     201        }
     202
     203        if ($config[0]->token !== $token) {
     204            return new WP_REST_Response('Not found', 404);
     205        }
     206
     207        $config[0]->facebook_for_woocomerce = get_option(
     208            'facebook_config',
     209                array(
     210                    'pixel_id' => '0'
     211                )
     212            );
     213        echo(json_encode($config[0]));
    98214        exit;
    99215    }
  • brainity-boost-ads/trunk/pixel/FacebookWordpressPixelInjection.php

    r2243986 r2309641  
    3333        /*add_action('pre_get_posts',
    3434            array($this, 'inject_search_event'));*/
    35         add_action('woocommerce_after_cart',
    36             array($this, 'inject_add_to_cart_redirect_event'));
    37         add_action('woocommerce_add_to_cart',
    38             array($this, 'inject_add_to_cart_event'), self::FB_PRIORITY_HIGH);
    39         add_action('wc_ajax_fb_inject_add_to_cart_event',
    40             array($this, 'inject_ajax_add_to_cart_event'), self::FB_PRIORITY_HIGH);
     35
     36        // AddToCart events
     37        add_action( 'woocommerce_add_to_cart', [ $this, 'inject_add_to_cart_event' ], 40, 4 );
     38        // AddToCart while AJAX is enabled
     39        add_action( 'woocommerce_ajax_added_to_cart', [ $this, 'add_filter_for_add_to_cart_fragments' ] );
     40        // AddToCart while using redirect to cart page
     41        if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
     42            add_filter( 'woocommerce_add_to_cart_redirect', [ $this, 'set_last_product_added_to_cart_upon_redirect' ], 10, 2 );
     43            add_action( 'woocommerce_ajax_added_to_cart',   [ $this, 'set_last_product_added_to_cart_upon_ajax_redirect' ] );
     44            add_action( 'woocommerce_after_cart',           [ $this, 'inject_add_to_cart_redirect_event' ], 10, 2 );
     45        }
     46
    4147        add_action('woocommerce_after_checkout_form',
    4248            array($this, 'inject_initiate_checkout_event'));
     
    5056    public function injectPixelCode()
    5157    {
    52 
    53         if (
    54             (isset(self::$renderCache[0]) &&
    55                 self::$renderCache[0] === true) ||
     58        if (
    5659            empty(FacebookPixel::getPixelId())
    5760        ) {
     
    6770    public function injectPixelNoscriptCode()
    6871    {
    69         if (
    70             (isset(self::$renderCache[0]) &&
    71                 self::$renderCache[0] === true) ||
     72        if (           
    7273            empty(FacebookPixel::getPixelId())
    7374        ) {
     
    8283    public function inject_view_content_event()
    8384    {
    84         if (
    85             (isset(self::$renderCache[0]) &&
    86                 self::$renderCache[0] === true) ||
    87             empty(FacebookPixel::getPixelId())
    88         ) {
    89             return;
    90         }
    91         global $post;
     85        global $post;       
     86        if (
     87            empty(FacebookPixel::getPixelId() || !isset($post->ID))
     88        ) {
     89            return;
     90        }
     91       
    9292        $product = wc_get_product($post->ID);
    9393        $content_type = 'product_group';
     
    119119    {
    120120        if (
    121             (isset(self::$renderCache[0]) &&
    122                 self::$renderCache[0] === true) ||
    123121            empty(FacebookPixel::getPixelId())
    124122        ) {
     
    170168    {
    171169        if (
    172             (isset(self::$renderCache[0]) &&
    173                 self::$renderCache[0] === true) ||
    174170            empty(FacebookPixel::getPixelId())
    175171        ) {
     
    188184    {
    189185        if (
    190             (isset(self::$renderCache[0]) &&
    191                 self::$renderCache[0] === true) ||
    192186            empty(FacebookPixel::getPixelId())
    193187        ) {
     
    207201
    208202    /**
     203     * Setups a filter to add an add to cart fragment whenever a product is added to the cart through Ajax.
     204     *
     205     * @see \WC_Facebookcommerce_EventsTracker::add_add_to_cart_event_fragment
     206     *
     207     * @internal
     208     *
     209     * @since 1.10.2
     210     */
     211    public function add_filter_for_add_to_cart_fragments() {
     212
     213        if ( 'no' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
     214            add_filter( 'woocommerce_add_to_cart_fragments', [ $this, 'add_add_to_cart_event_fragment' ] );
     215        }
     216    }
     217
     218
     219    /**
     220     * Adds an add to cart fragment to trigger an AddToCart event.
     221     *
     222     * @internal
     223     *
     224     * @since 1.10.2
     225     *
     226     * @param array $fragments add to cart fragments
     227     * @return array
     228     */
     229    public function add_add_to_cart_event_fragment( $fragments ) {
     230
     231        if ( !empty(FacebookPixel::getPixelId()) ) {
     232
     233            $script = $this->pixel->get_event_script( 'AddToCart', [
     234                'content_ids'  => $this->get_cart_content_ids(),
     235                'content_type' => 'product',
     236                'contents'     => $this->get_cart_contents(),
     237                'value'        => $this->get_cart_total(),
     238                'currency'     => get_woocommerce_currency(),
     239            ] );
     240
     241            $fragments['div.wc-facebook-pixel-event-placeholder'] = '<div class="wc-facebook-pixel-event-placeholder">' . $script . '</div>';
     242        }
     243
     244        return $fragments;
     245    }
     246
     247    /**
     248     * Sets last product added to cart to session when adding to cart a product and redirection to cart is enabled.
     249     *
     250     * @internal
     251     *
     252     * @since 1.10.2
     253     *
     254     * @param string $redirect URL redirecting to (usually cart)
     255     * @param null|\WC_Product $product the product just added to the cart
     256     * @return string
     257     */
     258    public function set_last_product_added_to_cart_upon_redirect( $redirect, $product = null ) {
     259
     260        if ( $product instanceof \WC_Product ) {
     261            WC()->session->set( 'facebook_for_woocommerce_last_product_added_to_cart', $product->get_id() );
     262        } else {
     263           
     264        }
     265
     266        return $redirect;
     267    }
     268
     269    /**
    209270     * Triggers Purchase for thank you page for COD, BACS CHEQUE payment
    210271     * which won't invoke woocommerce_payment_complete.
     
    213274    {
    214275        if (
    215             (isset(self::$renderCache[0]) &&
    216                 self::$renderCache[0] === true) ||
    217276            empty(FacebookPixel::getPixelId())
    218277        ) {
     
    236295    {
    237296        if (
    238             (isset(self::$renderCache[0]) &&
    239                 self::$renderCache[0] === true) ||
    240297            empty(FacebookPixel::getPixelId())
    241298        ) {
     
    277334    {
    278335        if (
    279             (isset(self::$renderCache[0]) &&
    280                 self::$renderCache[0] === true) ||
    281336            empty(FacebookPixel::getPixelId())
    282337        ) {
     
    307362    {
    308363        if (
    309             (isset(self::$renderCache[0]) &&
    310                 self::$renderCache[0] === true) ||
    311364            empty(FacebookPixel::getPixelId())
    312365        ) {
  • brainity-boost-ads/trunk/readme.txt

    r2296756 r2309641  
    44Requires at least: 5.2.1
    55Tested up to: 5.2.1
    6 Stable tag: 1.0.4
     6Stable tag: 1.0.5
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    6565== Changelog ==
    6666
    67 = Brainity 1.0.4 =
     67= Brainity 1.0.5 =
    6868
    6969* Fix bug with virtual products.
Note: See TracChangeset for help on using the changeset viewer.