Plugin Directory

Changeset 2652963


Ignore:
Timestamp:
01/05/2022 07:41:08 AM (4 years ago)
Author:
rulecom
Message:

Update to version 2.2 from GitHub

Location:
woorule
Files:
4 added
4 deleted
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woorule/tags/2.2/README.txt

    r2637385 r2652963  
    55Tested up to: 5.8.0
    66Requires PHP: 5.6+
    7 Stable tag: 2.1
     7Stable tag: 2.2
    88License: MIT
    99License URI: http://opensource.org/licenses/MIT
     
    4040You can embed a Newsletter sign-up form in your posts, or on any page with a simple shortcode `[woorule]`
    4141
    42 You can also customize the subscribe form with the shortcode options:
     42You can also customize the sign-up form with any of the following shortcode options:
    4343`
    44 [woorule text="This is a new title text" button="New submit button text!" success="New Success message"]
     44[woorule title="Custom Title" placeholder="Custom Placeholder Text" button="Custom Button Text" success="Custom Success Message" tag="Custom Tag"]
    4545`
     46The `tag` field will be applied to the subscriber when the form is submitted. If no tag field is used a `Newsletter` tag will be applied by default.
    4647
    4748== Frequently Asked Questions ==
     
    100101For more information, check out our [releases](https://github.com/rulecom/woorule/releases).
    101102
    102 = 0.0.1 =
    103 * Non-public release
     103= 2.2 =
     104* Bugfix affecting Newsletter tags on checkout form
     105* Added field: Order.Names
     106* Added "tag" field to WooRule shortcode
    104107
    105 = 0.2 =
    106 * New Version public release
    107 
    108 = 0.3 =
    109 * Bugfixes
    110 
    111 = 0.4 =
    112 * Fixed missing assets
    113 
    114 = 0.5 =
    115 * New features
    116 * Bugfixes
    117 
    118 = 0.6 =
    119 * New features
    120 * Bugfixes
    121 
    122 = 1.1 =
    123 * User\order meta fields
    124 * Default data improvements
    125 * Bugfixes
    126 * Visual Adjustments
    127 
    128 = 1.2 =
    129 * Bugfixes
    130 
    131 = 1.3 =
    132 * Bugfixes
    133 
    134 = 1.4 =
    135 * Bugfixes
     108= 2.1 =
     109* Bugfix affecting PHP 8.0
    136110
    137111= 2.0 =
     
    146120* Other small bug fixes
    147121
    148 = 2.1 =
    149 * Bugfix affecting PHP 8.0
     122= 1.4 =
     123* Bugfixes
     124
     125= 1.3 =
     126* Bugfixes
     127
     128= 1.2 =
     129* Bugfixes
     130
     131= 1.1 =
     132* User\order meta fields
     133* Default data improvements
     134* Bugfixes
     135* Visual Adjustments
     136
     137= 0.6 =
     138* New features
     139* Bugfixes
     140
     141= 0.5 =
     142* New features
     143* Bugfixes
     144
     145= 0.4 =
     146* Fixed missing assets
     147
     148= 0.3 =
     149* Bugfixes
     150
     151= 0.2 =
     152* New Version public release
     153
     154= 0.0.1 =
     155* Non-public release
  • woorule/tags/2.2/inc/class-wc-woorule.php

    r2637385 r2652963  
    2121        add_action('woocommerce_review_order_before_submit', array($this, 'custom_checkout_field'));
    2222        add_action('woocommerce_checkout_update_order_meta', array($this, 'custom_checkout_field_update_order_meta'));
     23
     24        // Shortcode
     25        add_action('wp_enqueue_scripts', array($this, 'register_assets'));
     26        add_shortcode('woorule',  array($this, 'woorule_func'));
     27        add_action('wp_ajax_woorule_subscribe_user', array($this, 'subscribe_user')); // Admins only
     28        add_action('wp_ajax_nopriv_woorule_subscribe_user', array($this, 'subscribe_user')); // Users only
     29    }
     30
     31    // Plugin Stylesheet
     32    public function register_assets()
     33    {
     34        wp_enqueue_style('woorule', plugin_dir_url(__FILE__) . '../assets/woorule.css', 10, '1.0');
     35        wp_register_script('woorule', plugin_dir_url(__FILE__) . '../assets/woorule.js');
     36        wp_enqueue_script('woorule', plugin_dir_url(__FILE__) . '../assets/woorule.js', array('woorule'));
     37
     38        wp_localize_script('woorule', 'ajax_var', array(
     39            'url' => admin_url('admin-ajax.php'),
     40            'nonce' => wp_create_nonce('woorule'),
     41        ));
     42    }
     43
     44    public function woorule_func($atts)
     45    {
     46        //print_r($atts);
     47        $title = (isset($atts['title'])) ? $atts['title'] : __('Newsletter subscribtion', 'woorule');
     48        $submit = (isset($atts['button'])) ? $atts['button'] : __('Submit', 'woorule');
     49        $success = (isset($atts['success'])) ? $atts['success'] : __('Thank you!', 'woorule');
     50        $placeholder = (isset($atts['placeholder'])) ? $atts['placeholder'] :  __('Your e-mail', 'woorule');
     51        $error = __('Oops, something is wrong..', 'woorule');
     52
     53        $return = '<div class="woorule-subscribe">';
     54        $return .= '<form>';
     55            $return .= '<label for="semail" class="form_elem">' . $title . '</label>';
     56            $return .= '<input type="text" id="semail" name="email" class="form_elem" placeholder="' . $placeholder . '">';
     57            $return .= '<input type="submit" value="' . $submit . '" class="form_elem">';
     58
     59            if(isset($atts['tag'])) $return .= '<input value="' . $atts['tag'] . '" name="tags" class="tag hidden form_elem">';
     60
     61            $return .= '<p class="hidden success">' . $success . '</p>';
     62            $return .= '<p class="hidden error">' . $error . '</p>';
     63        $return .= '</form>';
     64        $return .= '</div>';
     65
     66        return $return;
     67    }
     68
     69    public function subscribe_user()
     70    {
     71        // Check for nonce security
     72        if ((!wp_verify_nonce($_POST['nonce'], 'woorule')) || (!isset($_POST['email']))) {
     73            die('err');
     74        }
     75
     76        $email = $_POST['email'];
     77
     78        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
     79            die('err');
     80        }
     81
     82        // Default tag should exist. Otherwise there will be an error from RULE API.
     83        $tags = [];
     84        // Add custom tags if set
     85        if (isset($_POST['tags'])) foreach(explode(',', $_POST['tags']) as $tag ) array_push($tags, $tag);
     86
     87        $subscription = array(
     88            'apikey'              => get_option('woocommerce_rulemailer_settings')['woorule_api_key'],
     89            'update_on_duplicate' => true,
     90            'auto_create_tags'    => true,
     91            'auto_create_fields'  => true,
     92            'async'               => true,
     93            'tags'                => $tags,
     94            'subscribers'         => array(
     95                'email'           => $email
     96            )
     97        );
     98
     99        $api = WP_RuleMailer_API::get_instance();
     100        $api::subscribe($subscription);
     101        die('ok');
    23102    }
    24103
     
    127206        $order_data = $order->get_data();
    128207
     208        if ( get_post_meta($id,'woorule_opt_in') ) {
     209            array_push( $tags, 'Newsletter'); // Check for a newsletter (checkout) chekbox
     210        }
     211
    129212        $tags = array_unique($tags); // API will give an error on duplicate tags. Making sure there wont be any.
     213
    130214        if(empty($tags)) array_push( $tags, 'WooRule'); // Making sure the tags array will never be empty as the API will not like this.
    131215
     
    308392                'type'        => 'json'
    309393            );
     394
     395            $products_names = [];
     396
     397            foreach ($products as $product) {
     398                array_push($products_names, $product['name']);
     399            }
     400
     401            if (!empty($products_names)) {
     402                $subscription['subscribers']['fields'][] = array(
     403                    'key'   => 'Order.Names',
     404                    'value' =>  $products_names,
     405                    'type'  => 'multiple'
     406                );
     407            }
    310408        }
    311409
  • woorule/tags/2.2/woorule.php

    r2637385 r2652963  
    1010 * Plugin URI:      http://github.com/rulecom/woorule
    1111 * Description:     RuleMailer integration for WooCommerce
    12  * Version:         2.1
     12 * Version:         2.2
    1313 * Author:          RuleMailer
    1414 * Author URI:      http://rule.se
  • woorule/trunk/README.txt

    r2637385 r2652963  
    55Tested up to: 5.8.0
    66Requires PHP: 5.6+
    7 Stable tag: 2.1
     7Stable tag: 2.2
    88License: MIT
    99License URI: http://opensource.org/licenses/MIT
     
    4040You can embed a Newsletter sign-up form in your posts, or on any page with a simple shortcode `[woorule]`
    4141
    42 You can also customize the subscribe form with the shortcode options:
     42You can also customize the sign-up form with any of the following shortcode options:
    4343`
    44 [woorule text="This is a new title text" button="New submit button text!" success="New Success message"]
     44[woorule title="Custom Title" placeholder="Custom Placeholder Text" button="Custom Button Text" success="Custom Success Message" tag="Custom Tag"]
    4545`
     46The `tag` field will be applied to the subscriber when the form is submitted. If no tag field is used a `Newsletter` tag will be applied by default.
    4647
    4748== Frequently Asked Questions ==
     
    100101For more information, check out our [releases](https://github.com/rulecom/woorule/releases).
    101102
    102 = 0.0.1 =
    103 * Non-public release
     103= 2.2 =
     104* Bugfix affecting Newsletter tags on checkout form
     105* Added field: Order.Names
     106* Added "tag" field to WooRule shortcode
    104107
    105 = 0.2 =
    106 * New Version public release
    107 
    108 = 0.3 =
    109 * Bugfixes
    110 
    111 = 0.4 =
    112 * Fixed missing assets
    113 
    114 = 0.5 =
    115 * New features
    116 * Bugfixes
    117 
    118 = 0.6 =
    119 * New features
    120 * Bugfixes
    121 
    122 = 1.1 =
    123 * User\order meta fields
    124 * Default data improvements
    125 * Bugfixes
    126 * Visual Adjustments
    127 
    128 = 1.2 =
    129 * Bugfixes
    130 
    131 = 1.3 =
    132 * Bugfixes
    133 
    134 = 1.4 =
    135 * Bugfixes
     108= 2.1 =
     109* Bugfix affecting PHP 8.0
    136110
    137111= 2.0 =
     
    146120* Other small bug fixes
    147121
    148 = 2.1 =
    149 * Bugfix affecting PHP 8.0
     122= 1.4 =
     123* Bugfixes
     124
     125= 1.3 =
     126* Bugfixes
     127
     128= 1.2 =
     129* Bugfixes
     130
     131= 1.1 =
     132* User\order meta fields
     133* Default data improvements
     134* Bugfixes
     135* Visual Adjustments
     136
     137= 0.6 =
     138* New features
     139* Bugfixes
     140
     141= 0.5 =
     142* New features
     143* Bugfixes
     144
     145= 0.4 =
     146* Fixed missing assets
     147
     148= 0.3 =
     149* Bugfixes
     150
     151= 0.2 =
     152* New Version public release
     153
     154= 0.0.1 =
     155* Non-public release
  • woorule/trunk/inc/class-wc-woorule.php

    r2637385 r2652963  
    2121        add_action('woocommerce_review_order_before_submit', array($this, 'custom_checkout_field'));
    2222        add_action('woocommerce_checkout_update_order_meta', array($this, 'custom_checkout_field_update_order_meta'));
     23
     24        // Shortcode
     25        add_action('wp_enqueue_scripts', array($this, 'register_assets'));
     26        add_shortcode('woorule',  array($this, 'woorule_func'));
     27        add_action('wp_ajax_woorule_subscribe_user', array($this, 'subscribe_user')); // Admins only
     28        add_action('wp_ajax_nopriv_woorule_subscribe_user', array($this, 'subscribe_user')); // Users only
     29    }
     30
     31    // Plugin Stylesheet
     32    public function register_assets()
     33    {
     34        wp_enqueue_style('woorule', plugin_dir_url(__FILE__) . '../assets/woorule.css', 10, '1.0');
     35        wp_register_script('woorule', plugin_dir_url(__FILE__) . '../assets/woorule.js');
     36        wp_enqueue_script('woorule', plugin_dir_url(__FILE__) . '../assets/woorule.js', array('woorule'));
     37
     38        wp_localize_script('woorule', 'ajax_var', array(
     39            'url' => admin_url('admin-ajax.php'),
     40            'nonce' => wp_create_nonce('woorule'),
     41        ));
     42    }
     43
     44    public function woorule_func($atts)
     45    {
     46        //print_r($atts);
     47        $title = (isset($atts['title'])) ? $atts['title'] : __('Newsletter subscribtion', 'woorule');
     48        $submit = (isset($atts['button'])) ? $atts['button'] : __('Submit', 'woorule');
     49        $success = (isset($atts['success'])) ? $atts['success'] : __('Thank you!', 'woorule');
     50        $placeholder = (isset($atts['placeholder'])) ? $atts['placeholder'] :  __('Your e-mail', 'woorule');
     51        $error = __('Oops, something is wrong..', 'woorule');
     52
     53        $return = '<div class="woorule-subscribe">';
     54        $return .= '<form>';
     55            $return .= '<label for="semail" class="form_elem">' . $title . '</label>';
     56            $return .= '<input type="text" id="semail" name="email" class="form_elem" placeholder="' . $placeholder . '">';
     57            $return .= '<input type="submit" value="' . $submit . '" class="form_elem">';
     58
     59            if(isset($atts['tag'])) $return .= '<input value="' . $atts['tag'] . '" name="tags" class="tag hidden form_elem">';
     60
     61            $return .= '<p class="hidden success">' . $success . '</p>';
     62            $return .= '<p class="hidden error">' . $error . '</p>';
     63        $return .= '</form>';
     64        $return .= '</div>';
     65
     66        return $return;
     67    }
     68
     69    public function subscribe_user()
     70    {
     71        // Check for nonce security
     72        if ((!wp_verify_nonce($_POST['nonce'], 'woorule')) || (!isset($_POST['email']))) {
     73            die('err');
     74        }
     75
     76        $email = $_POST['email'];
     77
     78        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
     79            die('err');
     80        }
     81
     82        // Default tag should exist. Otherwise there will be an error from RULE API.
     83        $tags = [];
     84        // Add custom tags if set
     85        if (isset($_POST['tags'])) foreach(explode(',', $_POST['tags']) as $tag ) array_push($tags, $tag);
     86
     87        $subscription = array(
     88            'apikey'              => get_option('woocommerce_rulemailer_settings')['woorule_api_key'],
     89            'update_on_duplicate' => true,
     90            'auto_create_tags'    => true,
     91            'auto_create_fields'  => true,
     92            'async'               => true,
     93            'tags'                => $tags,
     94            'subscribers'         => array(
     95                'email'           => $email
     96            )
     97        );
     98
     99        $api = WP_RuleMailer_API::get_instance();
     100        $api::subscribe($subscription);
     101        die('ok');
    23102    }
    24103
     
    127206        $order_data = $order->get_data();
    128207
     208        if ( get_post_meta($id,'woorule_opt_in') ) {
     209            array_push( $tags, 'Newsletter'); // Check for a newsletter (checkout) chekbox
     210        }
     211
    129212        $tags = array_unique($tags); // API will give an error on duplicate tags. Making sure there wont be any.
     213
    130214        if(empty($tags)) array_push( $tags, 'WooRule'); // Making sure the tags array will never be empty as the API will not like this.
    131215
     
    308392                'type'        => 'json'
    309393            );
     394
     395            $products_names = [];
     396
     397            foreach ($products as $product) {
     398                array_push($products_names, $product['name']);
     399            }
     400
     401            if (!empty($products_names)) {
     402                $subscription['subscribers']['fields'][] = array(
     403                    'key'   => 'Order.Names',
     404                    'value' =>  $products_names,
     405                    'type'  => 'multiple'
     406                );
     407            }
    310408        }
    311409
  • woorule/trunk/woorule.php

    r2637385 r2652963  
    1010 * Plugin URI:      http://github.com/rulecom/woorule
    1111 * Description:     RuleMailer integration for WooCommerce
    12  * Version:         2.1
     12 * Version:         2.2
    1313 * Author:          RuleMailer
    1414 * Author URI:      http://rule.se
Note: See TracChangeset for help on using the changeset viewer.