Plugin Directory

Changeset 2558872


Ignore:
Timestamp:
07/05/2021 02:55:47 PM (4 years ago)
Author:
cmachu
Message:

General refactoring, ability to use custom templates via filters, minor bug fixes

Location:
multiple-external-product-urls-for-woocommerce/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • multiple-external-product-urls-for-woocommerce/trunk/README.txt

    r2428525 r2558872  
    44Tags: woocommerce, external product, woo, external, product, product url, woocommerce external product, multiple external products,
    55Requires at least: 3.0.1
    6 Tested up to: 5.5
    7 Stable tag: 1.2.0
     6Tested up to: 5.7.2
     7Stable tag: 1.3.0
    88License: GPLv2 or late
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2525
    2626*   Ability to create multiple buttons with external / affiliate URLs
    27 *   Ability to open external / affiliate URLs in new window
     27*   Ability to open external / affiliate URLs in new window - configuration per product
     28*   Ability to display additional external / affiliate URLs on shop/category page - configuration per product
     29*   Ability to change additional button templates by hooks - `mepu_woo_product_page_template` and `mepu_woo_shop_page_template`
    2830
    2931== Installation ==
     
    3537
    3638== Changelog ==
     39
     40= 1.3.0 =
     41* MAINTENANCE: Clean code, general refactoring
     42* ADD: Dummy Template system and ability to use own templates via filters
     43* ADD: Added filter `mepu_woo_product_page_template`
     44* ADD: Added filter `mepu_woo_shop_page_template`
    3745
    3846= 1.2.0 =
  • multiple-external-product-urls-for-woocommerce/trunk/admin/class-mepu-woo-additional-fields.php

    r2042986 r2558872  
    22
    33/**
    4  * The admin-specific functionality of the plugin.
     4 * Class that define extra fields for WooCommerce external product metabox in wp-admin
    55 *
    66 * @link       http://cmachowski.com
     
    88 *
    99 * @package    Mepu_Woo
    10  * @subpackage Mepu_Woo/additional-fields
    11  */
    12 
    13 /**
    14  * The admin-specific functionality of the plugin.
    15  *
    16  * Defines extra fields for user create and update.
    17  *
    18  * @package    Mepu_Woo
    19  * @subpackage Mepu_Woo/additional-fields
     10 * @subpackage Mepu_Woo/admin
    2011 * @author     Paweł Ćmachowski <[email protected]>
    2112 */
    2213class Mepu_Woo_Additional_Fields
    2314{
     15    /**
     16     * Display extra fields container for clone, display serialized json array with label/url details
     17     *
     18     * @since   1.0.0
     19     */
     20    public function mepu_extra_fields()
     21    {
     22        global $post;
    2423
    25     /**
    26      * The ID of this plugin.
    27      *
    28      * @since    1.0.0
    29      * @access   private
    30      * @var      string $plugin_name The ID of this plugin.
    31      */
    32     private $plugin_name;
    33 
    34     /**
    35      * The version of this plugin.
    36      *
    37      * @since    1.0.0
    38      * @access   private
    39      * @var      string $version The current version of this plugin.
    40      */
    41     private $version;
    42 
    43     /**
    44      * Initialize the class and set its properties.
    45      *
    46      * @since    1.0.0
    47      * @param      string $plugin_name The name of this plugin.
    48      * @param      string $version The version of this plugin.
    49      */
    50     public function __construct($plugin_name, $version)
    51     {
    52         $this->plugin_name = $plugin_name;
    53         $this->version = $version;
     24        $data = Mepu_Woo_Datastore::getJSON($post);
     25        Mepu_Woo_Template::render(
     26            'admin/templates/woocommerce-external-fields.php',
     27            [
     28                'data' => $data
     29            ]
     30        );
    5431    }
    5532
    5633    /**
    57      * Register all hooks for custom fields in product edit area for creation and updating
     34     * Update product meta on save / update
    5835     *
    59      * @since    1.0.0
    60      */
    61     public function init_fields()
    62     {
    63         add_action('woocommerce_product_options_general_product_data', array($this, 'mepu_extra_fields') );
    64         add_action('woocommerce_process_product_meta', array($this, 'mepu_extra_fields_process') );
    65 
    66     }
    67 
    68     /**
    69      * Display extra fields clone container, display json array with multiple external details
    70      *
     36     * @param int $post_id - id of product
     37     * @return  bool
    7138     * @since   1.0.0
    7239     */
    73     function mepu_extra_fields(){
    74         global $post;
    75 
    76         $multiple_external_fields = get_post_meta($post->ID, '_multiple_external_');
    77         if(empty($multiple_external_fields) || !is_array($multiple_external_fields)){
    78             $multiple_external_fields = array();
    79         }
    80         echo "<input type='hidden' value='".json_encode($multiple_external_fields, JSON_HEX_APOS)."' id='mepu-woo-data'>";
    81 
    82     ?>
    83         <div class="options_group show_if_external mepu-woo-cont" style="padding:0px 10px;">
    84             <h4><?php _e('Multiple external product URLs','mepu-woo'); ?> - <a href="#mepu-woo-data" class="mepu-woo-add"><?php _e('Add new','mepu-woo'); ?></a></h4>
    85             <?php
    86             woocommerce_wp_checkbox(
    87                 array(
    88                     'id'          => '_external_target_blank',
    89                     'label'       => __( 'Open in new tab', 'mepu-woo' ),
    90                     'description' => __('Open external / affiliate URLs in new tab?', 'mepu-woo')
    91                 )
    92             );
    93 
    94             woocommerce_wp_checkbox(
    95                 array(
    96                     'id'          => '_external_show_in_cat',
    97                     'label'       => __( 'Category pages', 'mepu-woo' ),
    98                     'description' => __('Show all external product buttons on category pages', 'mepu-woo')
    99                 )
    100             );
    101             ?>
    102             <div class="hidden mepu-woo-only-for-clone" style="border-bottom:1px solid #efefef;">
    103                 <h5><?php _e('## External / Affiliate product details','mepu-woo'); ?> - <a href="#mepu-woo-data" class="mepu-woo-delete"><?php _e('Delete','mepu-woo'); ?></a></h5>
    104                 <?php
    105                     woocommerce_wp_text_input(
    106                         array(
    107                             'id'          => '_product_url_clone_[]',
    108                             'label'       => __( 'Product URL ##', 'mepu-woo' ),
    109                             'placeholder' => 'http://',
    110                         )
    111                     );
    112 
    113                     woocommerce_wp_text_input(
    114                         array(
    115                             'id'          => '_button_text_clone_[]',
    116                             'label'       => __( 'Button text ##', 'mepu-woo' ),
    117                             'placeholder' => _x( 'Buy product', 'placeholder', 'mepu-woo' ),
    118                         )
    119                     );
    120                ?>
    121             </div>
    122         </div>
    123     <?php
    124     }
    125 
    126 
    127     /**
    128      * Update product meta "_multiple_external_" on save
    129      *
    130      * @param   int     $post_id - id of product
    131      * @since   1.0.0
    132      *
    133      * @return  mixed
    134      */
    135     function mepu_extra_fields_process( $post_id )
     40    public function mepu_extra_fields_process($post_id)
    13641    {
    137         $fine_array = array();
    138 
    139         if ( ! ( isset( $_POST['woocommerce_meta_nonce'], $_POST[ '_external_target_blank' ], $_POST[ '_product_url_' ], $_POST[ '_button_text_' ] )
    140             || wp_verify_nonce( sanitize_key( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) ) {
     42        if (!wp_verify_nonce(sanitize_key($_POST['woocommerce_meta_nonce']), 'woocommerce_save_data')) {
     43            die('b');
    14144            return false;
    14245        }
    14346
    144         for($i = 0; $i < count($_POST['_product_url_']); $i++){
    145             if(isset($_POST['_product_url_'][$i], $_POST['_button_text_'][$i])) {
    146                 if(!empty($_POST['_product_url_'][$i]) && !empty($_POST['_button_text_'][$i])) {
    147                     array_push($fine_array, array($_POST['_product_url_'][$i], $_POST['_button_text_'][$i]));
     47        if (isset($_POST['_product_url_'], $_POST['_button_text_'])
     48            && is_array($_POST['_product_url_'])
     49            && is_array($_POST['_button_text_'])) {
     50
     51            $updateData = [];
     52            for ($i = 0; $i < count($_POST['_product_url_']); $i++) {
     53                if (!isset($_POST['_product_url_'][$i]) || !isset($_POST['_button_text_'][$i])) {
     54                    continue;
    14855                }
     56
     57                array_push(
     58                    $updateData,
     59                    [
     60                        sanitize_text_field($_POST['_product_url_'][$i]),
     61                        sanitize_text_field($_POST['_button_text_'][$i])
     62                    ]
     63                );
    14964            }
     65
     66            Mepu_Woo_Datastore::setData($post_id, $updateData);
    15067        }
    15168
    152         update_post_meta(
    153             $post_id,
    154             '_multiple_external_',
    155             $fine_array
    156         );
     69        Mepu_Woo_Datastore::setTargetValue($post_id, $_POST['_external_target_blank']);
     70        Mepu_Woo_Datastore::setCategoryVisibility($post_id, $_POST['_external_show_in_cat']);
    15771
    158         update_post_meta(
    159             $post_id,
    160             '_external_target_blank',
    161             esc_attr($_POST['_external_target_blank'])
    162         );
    163 
    164         update_post_meta(
    165             $post_id,
    166             '_external_show_in_cat',
    167             esc_attr($_POST['_external_show_in_cat'])
    168         );
    169 
     72        return true;
    17073    }
    171 
    17274}
  • multiple-external-product-urls-for-woocommerce/trunk/admin/class-mepu-woo-admin.php

    r2428525 r2558872  
    99 * @package    Mepu_Woo
    1010 * @subpackage Mepu_Woo/admin
    11  */
    12 
    13 /**
    14  * The admin-specific functionality of the plugin.
    15  *
    16  * Defines the plugin name, version, and two examples hooks for how to
    17  * enqueue the admin-specific stylesheet and JavaScript.
    18  *
    19  * @package    Mepu_Woo
    20  * @subpackage Mepu_Woo/admin
    2111 * @author     Paweł Ćmachowski <[email protected]>
    2212 */
    2313class Mepu_Woo_Admin
    2414{
    25 
    26     /**
    27      * The ID of this plugin.
    28      *
    29      * @since    1.0.0
    30      * @access   private
    31      * @var      string $plugin_name The ID of this plugin.
    32      */
    33     private $plugin_name;
    34 
    35     /**
    36      * The version of this plugin.
    37      *
    38      * @since    1.0.0
    39      * @access   private
    40      * @var      string $version The current version of this plugin.
    41      */
    42     private $version;
    43 
    44 
    45     /**
    46      * Initialize the class and set its properties.
    47      *
    48      * @since    1.0.0
    49      * @param      string $plugin_name The name of this plugin.
    50      * @param      string $version The version of this plugin.
    51      */
    52     public function __construct($plugin_name, $version)
    53     {
    54         $this->plugin_name = $plugin_name;
    55         $this->version = $version;
    56     }
    57 
    5815    /**
    5916     * Register the JavaScript for the admin area.
     
    6320    public function enqueue_scripts()
    6421    {
    65         wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/mepu-woo-admin.js', array('jquery'), $this->version, false);
     22        wp_enqueue_script(
     23            MEPU_WOO_SLUG,
     24            MEPU_WOO_PLUGIN_URL . 'admin/js/mepu-woo-admin.js',
     25            ['jquery'],
     26            MEPU_WOO_VERSION
     27        );
    6628    }
    67 
    6829}
  • multiple-external-product-urls-for-woocommerce/trunk/admin/js/mepu-woo-admin.js

    r1933588 r2558872  
    33
    44    $('#woocommerce-product-data').ready(function (event) {
    5         if ($('.mepu-woo-cont').length) {
    65
    7             if ($('#mepu-woo-data').val() != '') {
    8                 var data = $.parseJSON($('#mepu-woo-data').val());
    9                 if (data[0] != undefined) {
    10                     for (var i = 0; i < data[0].length; i++) {
    11                         mepu_woo_clone_block(i, data[0][i]);
    12                     }
    13                 }
    14             }
     6        if ($('.mepu-woo-cont').length === 0) {
     7            return false;
     8        }
    159
    16             $('.mepu-woo-add').bind('click', function () {
    17                 mepu_woo_clone_block($('.mepu-woo-cont-item').length, ['', '']);
    18             });
     10        let woo_data = $.parseJSON($('#mepu-woo-data').val());
     11        if (woo_data === '' || woo_data[0] === undefined) {
     12            woo_data = [[]];
     13        }
    1914
     15
     16        for (let i = 0; i < woo_data[0].length; i++) {
     17            mepu_woo_clone_block(i, woo_data[0][i]);
    2018        }
     19
     20        $('.mepu-woo-add').bind('click', function () {
     21            mepu_woo_clone_block($('.mepu-woo-cont-item').length, ['', '']);
     22        });
     23
    2124    });
    2225
    2326    function mepu_woo_clone_block(i, data) {
    24         var new_block = $('.mepu-woo-only-for-clone').clone();
     27        let new_block = $('.mepu-woo-only-for-clone').clone();
    2528        new_block.removeClass('hidden').removeClass('mepu-woo-only-for-clone').addClass('mepu-woo-cont-item');
    2629        new_block.find('h5').html(new_block.find('h5').html().replace('##', '#' + (i + 1)));
     30
    2731        new_block.find('label').each(function () {
    28             $(this).html($(this).html().replace('##', '#' + (i + 1)));
     32            $(this).html($(this).html().replace('##', '#' + (i + 1))); // replace all numbering
    2933        });
    3034
    31         var input_iterator = 0;
    32         new_block.find('input').each(function () {
    33             $(this).val(data[input_iterator++]);
    34             if ($(this).attr('id') == '_product_url_clone_[]') {
     35        new_block.find('input').each(function (index, item) {
     36
     37            $(this).val(data[index]);
     38
     39            if ($(this).attr('id') === '_product_url_clone_[]') {
    3540                $(this).attr('id', '_product_url_[]');
    3641                $(this).attr('name', '_product_url_[]');
    3742            }
    38             if ($(this).attr('id') == '_button_text_clone_[]') {
     43
     44            if ($(this).attr('id') === '_button_text_clone_[]') {
    3945                $(this).attr('id', '_button_text_[]');
    4046                $(this).attr('name', '_button_text_[]');
    4147            }
    4248        });
     49
    4350        $('.mepu-woo-cont').append(new_block);
    4451        mepu_bind_block_actions();
  • multiple-external-product-urls-for-woocommerce/trunk/frontend/class-mepu-woo-frontend.php

    r2428525 r2558872  
    22
    33/**
    4  * The admin-specific functionality of the plugin.
     4 * Front-end features of the plugin - display multiple external product url on shop/category/product-page
    55 *
    66 * @link       http://cmachowski.com
    77 * @since      1.0.0
    8  *
    9  * @package    Mepu_Woo
    10  * @subpackage Mepu_Woo/admin
    11  */
    12 
    13 /**
    14  * The admin-specific functionality of the plugin.
    15  *
    16  * Defines the plugin name, version, and two examples hooks for how to
    17  * enqueue the admin-specific stylesheet and JavaScript.
    188 *
    199 * @package    Mepu_Woo
     
    2313class Mepu_Woo_Frontend
    2414{
    25 
    2615    /**
    27      * The ID of this plugin.
     16     * Render multiple external product buttons on product page
    2817     *
    29      * @since    1.0.0
    30      * @access   private
    31      * @var      string $plugin_name The ID of this plugin.
    32      */
    33     private $plugin_name;
    34 
    35     /**
    36      * The version of this plugin.
    37      *
    38      * @since    1.0.0
    39      * @access   private
    40      * @var      string $version The current version of this plugin.
    41      */
    42     private $version;
    43 
    44 
    45     /**
    46      * Initialize the class and set its properties.
    47      *
    48      * @param string $plugin_name The name of this plugin.
    49      * @param string $version The version of this plugin.
    50      * @since    1.0.0
    51      */
    52     public function __construct($plugin_name, $version)
    53     {
    54         $this->plugin_name = $plugin_name;
    55         $this->version = $version;
    56     }
    57 
    58     /**
    59      * Render all buttons to external shops on product page
    6018     * @since   1.0.0
    6119     */
     
    6321    {
    6422        global $product;
    65         if ($product && ('external' == $product->get_type())) {
    66             $mepu_data = get_post_meta($product->get_id(), '_multiple_external_');
    67             if (is_array($mepu_data[0])) {
    68                 foreach ($mepu_data[0] as $mepu_item) {
    69                     ?>
    70                     <form class="cart" action="<?php echo esc_url($mepu_item[0]); ?>" method="get">
    71                         <?php do_action('woocommerce_before_add_to_cart_button'); ?>
    7223
    73                         <button type="submit"
    74                                 class="single_add_to_cart_button button alt"><?php echo esc_html($mepu_item[1]); ?></button>
     24        if (!Mepu_Woo_Datastore::isExternal($product)) {
     25            return;
     26        }
    7527
    76                         <?php wc_query_string_form_fields($mepu_item[0]); ?>
     28        $mepu_data = Mepu_Woo_Datastore::get($product);
     29        if ($mepu_data === null) {
     30            return;
     31        }
    7732
    78                         <?php do_action('woocommerce_after_add_to_cart_button'); ?>
    79                     </form>
    80                     <?php
    81                 }
    82             }
     33        foreach ($mepu_data[0] as $mepu_item) {
     34            $dataPack = [
     35                'url' => $mepu_item[0],
     36                'label' => $mepu_item[1]
     37            ];
     38
     39            echo apply_filters(
     40                'mepu_woo_product_page_template',
     41                Mepu_Woo_Template::get("frontend/templates/product-page-template.php", $dataPack),
     42                $dataPack
     43            );
    8344        }
     45
     46        return;
    8447    }
    8548
    8649    /**
    87      * Add multiple external buttons to loop in category
     50     * Render multiple external buttons to loop in category / shop
     51     *
    8852     * @param $buttons
    8953     * @param $product
     
    9458    public function render_mepu_buttons_loop($buttons, $product, $args = [])
    9559    {
    96         if (get_post_meta($product->get_id(), '_external_show_in_cat', true) && ('external' == $product->get_type())) {
    97             $mepu_data = get_post_meta($product->get_id(), '_multiple_external_');
    98             if (is_array($mepu_data[0])) {
    99                 foreach ($mepu_data[0] as $mepu_item) {
    100                     $buttons .= sprintf('<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
    101                         esc_url($mepu_item[0]),
    102                         esc_attr(isset($args['quantity']) ? $args['quantity'] : 1),
    103                         esc_attr(isset($args['class']) ? $args['class'] : 'button'),
    104                         isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
    105                         esc_html($mepu_item[1]));
    106                 }
    107             }
     60        if (!Mepu_Woo_Datastore::isExternal($product)) {
     61            return $buttons;
     62        }
     63
     64        if (!Mepu_Woo_Datastore::isOnCategory($product)) {
     65            return $buttons;
     66        }
     67
     68        $mepu_data = Mepu_Woo_Datastore::get($product);
     69        if ($mepu_data === null) {
     70            return $buttons;
     71        }
     72
     73        $shopPageButtonTemplate = apply_filters(
     74            'mepu_woo_shop_page_template',
     75            Mepu_Woo_Template::get('frontend/templates/shop-page-template.php')
     76        );
     77
     78        foreach ($mepu_data[0] as $mepu_item) {
     79            $buttons .= sprintf(
     80                $shopPageButtonTemplate,
     81                esc_url($mepu_item[0]),
     82                esc_attr(isset($args['quantity']) ? $args['quantity'] : 1),
     83                esc_attr(isset($args['class']) ? $args['class'] : 'button'),
     84                isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
     85                esc_html($mepu_item[1]));
    10886        }
    10987
     
    11290
    11391    /**
    114      * Adjust cart form details
     92     * Adjust cart form details - ability to open in new tab/window
     93     *
    11594     * @since   1.0.0
    11695     */
     
    11897    {
    11998        global $product;
    120         if ($product && $product->get_type() == 'external') {
    121             $mepu_data = get_post_meta($product->get_id(), '_external_target_blank', true);
    122             if ($mepu_data) {
    123                 ?>
    124                 <script>
    125                     if (jQuery('.cart')) {
    126                         jQuery('.cart').attr('target', '_blank');
    127                     }
    128                 </script>
    129                 <?php
    130             }
     99        if (Mepu_Woo_Datastore::isExternal($product) && Mepu_Woo_Datastore::isTargetBlank($product)) {
     100            Mepu_Woo_Template::render('frontend/templates/script-target-blank.php');
    131101        }
    132 
    133102    }
    134103
    135104    /**
    136      * Adjust external product buttons on category loop
     105     * Adjust external product buttons on category loop - ability to open in new tab/window
     106     *
    137107     * @param $args
    138108     * @param $product
     
    142112    public function adjust_cart_form_details_loop($args, $product)
    143113    {
    144         if(isset($args['attributes'])) {
    145             if (get_post_meta($product->get_id(), '_external_show_in_cat', true) && get_post_meta($product->get_id(), '_external_target_blank', true)) {
    146                 $args['attributes']['target'] = '_blank';
    147             }
     114        if (!Mepu_Woo_Datastore::isExternal($product)) {
     115            return $args;
     116        }
     117
     118        if (!isset($args['attributes'])) {
     119            return $args;
     120        }
     121
     122        if (Mepu_Woo_Datastore::isTargetBlank($product) && Mepu_Woo_Datastore::isOnCategory($product)) {
     123            $args['attributes']['target'] = '_blank';
    148124        }
    149125
    150126        return $args;
    151127    }
    152 
    153128}
  • multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-activator.php

    r1933588 r2558872  
    22
    33/**
    4  * Fired during plugin activation
     4 * Fired during plugin activation.
    55 *
    66 * @link       http://cmachowski.com
    77 * @since      1.0.0
    88 *
    9  * @package    Mepu_Woo
    10  * @subpackage Mepu_Woo/includes
    11  */
    12 
    13 /**
    14  * Fired during plugin activation.
    15  *
    16  * This class defines all code necessary to run during the plugin's activation.
    17  *
    18  * @since      1.0.0
    199 * @package    Mepu_Woo
    2010 * @subpackage Mepu_Woo/includes
     
    2515class Mepu_Woo_Activator
    2616{
    27 
    2817    /**
    2918     * Fires, when plugin is installed
     
    3322    public static function activate()
    3423    {
    35 
    3624        if (!is_plugin_active("woocommerce/woocommerce.php")) {
    3725            die(__('Please install and activate WooCommerce plugin first.', 'mepu-woo'));
    3826        }
    39 
    4027    }
    41 
    42 
    4328}
  • multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-deactivator.php

    r1933588 r2558872  
    22
    33/**
    4  * Fired during plugin deactivation
     4 * Fired during plugin deactivation.
    55 *
    66 * @link       http://cmachowski.com
     
    99 * @package    Mepu_Woo
    1010 * @subpackage Mepu_Woo/includes
    11  */
    12 
    13 /**
    14  * Fired during plugin deactivation.
    15  *
    16  * This class defines all code necessary to run during the plugin's deactivation.
    17  *
    18  * @since      1.0.0
    19  * @package    Mepu_Woo
    20  * @subpackage Mepu_Woo/includes
    2111 * @author     Paweł Ćmachowski <[email protected]>
    2212 */
    2313class Mepu_Woo_Deactivator
    2414{
    25 
    2615    /**
    27      * Short Description. (use period)
     16     * Remove all post_meta related to plugin
    2817     *
    29      * Long Description.
    30      *
    31      * @since    1.0.0
     18     * @since    1.3.0
    3219     */
    3320    public static function deactivate()
    3421    {
    35 
     22        // TODO - Should we really do this?
     23        //delete_post_meta_by_key('_multiple_external_');
     24        //delete_post_meta_by_key('_external_target_blank');
     25        //delete_post_meta_by_key('_external_show_in_cat');
    3626    }
    37 
    3827}
  • multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-i18n.php

    r1933588 r2558872  
    22
    33/**
    4  * Define the internationalization functionality
    5  *
    6  * Loads and defines the internationalization files for this plugin
    7  * so that it is ready for translation.
     4 * Define the internationalization functionality.
    85 *
    96 * @link       http://cmachowski.com
     
    129 * @package    Mepu_Woo
    1310 * @subpackage Mepu_Woo/includes
    14  */
    15 
    16 /**
    17  * Define the internationalization functionality.
    18  *
    19  * Loads and defines the internationalization files for this plugin
    20  * so that it is ready for translation.
    21  *
    22  * @since      1.0.0
    23  * @package    Mepu_Woo
    24  * @subpackage Mepu_Woo/includes
    2511 * @author     Paweł Ćmachowski <[email protected]>
    2612 */
    2713class Mepu_Woo_i18n
    2814{
    29 
    30 
    3115    /**
    3216     * Load the plugin text domain for translation.
     
    3620    public function load_plugin_textdomain()
    3721    {
    38 
    3922        load_plugin_textdomain(
    40             'mepu-woo',
     23            MEPU_WOO_SLUG,
    4124            false,
    42             dirname(dirname(plugin_basename(__FILE__))) . '/languages/'
     25            MEPU_WOO_DIR_NAME . '/languages/'
    4326        );
    44 
    4527    }
    46 
    47 
    4828}
  • multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-loader.php

    r1933588 r2558872  
    22
    33/**
    4  * Register all actions and filters for the plugin
    5  *
    6  * @link       http://cmachowski.com
    7  * @since      1.0.0
    8  *
    9  * @package    Mepu_Woo
    10  * @subpackage Mepu_Woo/includes
    11  */
    12 
    13 /**
     4 * Package from plugin starter
    145 * Register all actions and filters for the plugin.
    156 *
     
    178 * the plugin, and register them with the WordPress API. Call the
    189 * run function to execute the list of actions and filters.
     10 *
     11 * @link       http://cmachowski.com
     12 * @since      1.0.0
    1913 *
    2014 * @package    Mepu_Woo
     
    2418class Mepu_Woo_Loader
    2519{
    26 
    2720    /**
    2821     * The array of actions registered with WordPress.
     
    5043    public function __construct()
    5144    {
    52 
    53         $this->actions = array();
    54         $this->filters = array();
    55 
     45        $this->actions = [];
     46        $this->filters = [];
    5647    }
    5748
     
    5950     * Add a new action to the collection to be registered with WordPress.
    6051     *
     52     * @param string $hook The name of the WordPress action that is being registered.
     53     * @param object $component A reference to the instance of the object on which the action is defined.
     54     * @param string $callback The name of the function definition on the $component.
     55     * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
     56     * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
    6157     * @since    1.0.0
    62      * @param    string $hook The name of the WordPress action that is being registered.
    63      * @param    object $component A reference to the instance of the object on which the action is defined.
    64      * @param    string $callback The name of the function definition on the $component.
    65      * @param    int $priority Optional. The priority at which the function should be fired. Default is 10.
    66      * @param    int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
    6758     */
    6859    public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1)
     
    7465     * Add a new filter to the collection to be registered with WordPress.
    7566     *
     67     * @param string $hook The name of the WordPress filter that is being registered.
     68     * @param object $component A reference to the instance of the object on which the filter is defined.
     69     * @param string $callback The name of the function definition on the $component.
     70     * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
     71     * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
    7672     * @since    1.0.0
    77      * @param    string $hook The name of the WordPress filter that is being registered.
    78      * @param    object $component A reference to the instance of the object on which the filter is defined.
    79      * @param    string $callback The name of the function definition on the $component.
    80      * @param    int $priority Optional. The priority at which the function should be fired. Default is 10.
    81      * @param    int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
    8273     */
    8374    public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1)
     
    9081     * collection.
    9182     *
     83     * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
     84     * @param string $hook The name of the WordPress filter that is being registered.
     85     * @param object $component A reference to the instance of the object on which the filter is defined.
     86     * @param string $callback The name of the function definition on the $component.
     87     * @param int $priority The priority at which the function should be fired.
     88     * @param int $accepted_args The number of arguments that should be passed to the $callback.
     89     * @return   array                                  The collection of actions and filters registered with WordPress.
    9290     * @since    1.0.0
    9391     * @access   private
    94      * @param    array $hooks The collection of hooks that is being registered (that is, actions or filters).
    95      * @param    string $hook The name of the WordPress filter that is being registered.
    96      * @param    object $component A reference to the instance of the object on which the filter is defined.
    97      * @param    string $callback The name of the function definition on the $component.
    98      * @param    int $priority The priority at which the function should be fired.
    99      * @param    int $accepted_args The number of arguments that should be passed to the $callback.
    100      * @return   array                                  The collection of actions and filters registered with WordPress.
    10192     */
    10293    private function add($hooks, $hook, $component, $callback, $priority, $accepted_args)
    10394    {
    104 
    105         $hooks[] = array(
     95        $hooks[] = [
    10696            'hook' => $hook,
    10797            'component' => $component,
     
    10999            'priority' => $priority,
    110100            'accepted_args' => $accepted_args
    111         );
     101        ];
    112102
    113103        return $hooks;
    114 
    115104    }
    116105
     
    122111    public function run()
    123112    {
    124 
    125113        foreach ($this->filters as $hook) {
    126             add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
     114            add_filter($hook['hook'], [$hook['component'], $hook['callback']], $hook['priority'], $hook['accepted_args']);
    127115        }
    128116
    129117        foreach ($this->actions as $hook) {
    130             add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
     118            add_action($hook['hook'], [$hook['component'], $hook['callback']], $hook['priority'], $hook['accepted_args']);
    131119        }
    132 
    133120    }
    134 
    135121}
  • multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo.php

    r2042986 r2558872  
    11<?php
    2 
    3 /**
    4  * The file that defines the core plugin class
    5  *
    6  * A class definition that includes attributes and functions used across both the
    7  * public-facing side of the site and the admin area.
    8  *
    9  * @link       http://cmachowski.com
    10  * @since      1.0.0
    11  *
    12  * @package    Mepu_Woo
    13  * @subpackage Mepu_Woo/includes
    14  */
    152
    163/**
     
    207 * public-facing site hooks.
    218 *
    22  * Also maintains the unique identifier of this plugin as well as the current
    23  * version of the plugin.
     9 * @link       http://cmachowski.com
     10 * @since      1.0.0
    2411 *
    25  * @since      1.0.0
    2612 * @package    Mepu_Woo
    2713 * @subpackage Mepu_Woo/includes
     
    3016class Mepu_Woo
    3117{
     18    /**
     19     * Defines all plugin dependency files
     20     *
     21     * @since 1.3.0
     22     * @var array
     23     */
     24    protected $dependencies = [
     25        //helpers files
     26        'helpers/class-mepu-woo-datastore.php',
     27        'helpers/class-mepu-woo-template.php',
     28
     29        //core files
     30        'includes/class-mepu-woo-loader.php',
     31        'includes/class-mepu-woo-i18n.php',
     32
     33        //admin dependecy files
     34        'admin/class-mepu-woo-admin.php',
     35        'admin/class-mepu-woo-additional-fields.php',
     36
     37        //frontend dependency files
     38        'frontend/class-mepu-woo-frontend.php',
     39    ];
    3240
    3341    /**
     
    3543     * the plugin.
    3644     *
    37      * @since    1.0.0
    38      * @access   protected
    39      * @var      Mepu_Woo_Loader $loader Maintains and registers all hooks for the plugin.
     45     * @since 1.0.0
     46     * @var Mepu_Woo_Loader $loader
    4047     */
    4148    protected $loader;
    4249
    4350    /**
    44      * The unique identifier of this plugin.
    45      *
    46      * @since    1.0.0
    47      * @access   protected
    48      * @var      string $plugin_name The string used to uniquely identify this plugin.
    49      */
    50     protected $plugin_name;
    51 
    52     /**
    53      * The current version of the plugin.
    54      *
    55      * @since    1.0.0
    56      * @access   protected
    57      * @var      string $version The current version of the plugin.
    58      */
    59     protected $version;
    60 
    61     /**
    6251     * Define the core functionality of the plugin.
    63      *
    64      * Set the plugin name and the plugin version that can be used throughout the plugin.
    65      * Load the dependencies, define the locale, and set the hooks for the admin area and
    66      * the public-facing side of the site.
    6752     *
    6853     * @since    1.0.0
     
    7055    public function __construct()
    7156    {
    72         if (defined('MEPU_WOO_VERSION')) {
    73             $this->version = MEPU_WOO_VERSION;
    74         } else {
    75             $this->version = '1.0.0';
    76         }
    77         $this->plugin_name = 'mepu-woo';
    78 
    7957        $this->load_dependencies();
    8058        $this->set_locale();
     
    8260        $this->define_admin_hooks();
    8361        $this->define_frontend_hooks();
    84 
    8562    }
    8663
    8764    /**
    8865     * Load the required dependencies for this plugin.
    89      *
    90      * Include the following files that make up the plugin:
    91      *
    92      * - Mepu_Woo_Loader. Orchestrates the hooks of the plugin.
    93      * - Mepu_Woo_i18n. Defines internationalization functionality.
    94      * - Mepu_Woo_Admin. Defines all hooks for the admin area.
    95      * - Mepu_Woo_Public. Defines all hooks for the public side of the site.
    96      *
    9766     * Create an instance of the loader which will be used to register the hooks
    9867     * with WordPress.
    9968     *
    10069     * @since    1.0.0
    101      * @access   private
    10270     */
    10371    private function load_dependencies()
    10472    {
    105 
    106         /**
    107          * The class responsible for orchestrating the actions and filters of the
    108          * core plugin.
    109          */
    110         require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-mepu-woo-loader.php';
    111 
    112         /**
    113          * The class responsible for defining internationalization functionality
    114          * of the plugin.
    115          */
    116         require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-mepu-woo-i18n.php';
    117 
    118         /**
    119          * The class responsible for defining all actions that occur in the admin area.
    120          */
    121         require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-mepu-woo-admin.php';
    122 
    123         /**
    124          * The class responsible for defining all additional fields for user in the admin area.
    125          */
    126         require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-mepu-woo-additional-fields.php';
    127         /**
    128          * The class responsible for defining all front-end features
    129          */
    130         require_once plugin_dir_path(dirname(__FILE__)) . 'frontend/class-mepu-woo-frontend.php';
     73        foreach($this->dependencies as $dependency){
     74            require_once MEPU_WOO_PLUGIN_DIR . $dependency;
     75        }
    13176
    13277        $this->loader = new Mepu_Woo_Loader();
    133 
    13478    }
    13579
     
    13781     * Define the locale for this plugin for internationalization.
    13882     *
    139      * Uses the Mepu_Woo_i18n class in order to set the domain and to register the hook
    140      * with WordPress.
    141      *
    14283     * @since    1.0.0
    143      * @access   private
    14484     */
    14585    private function set_locale()
    14686    {
    147 
    14887        $plugin_i18n = new Mepu_Woo_i18n();
    149 
    15088        $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
    151 
    15289    }
    15390
     
    15794     *
    15895     * @since    1.0.0
    159      * @access   private
    16096     */
    16197    private function define_admin_hooks()
    16298    {
    163         $plugin_admin = new Mepu_Woo_Admin($this->get_plugin_name(), $this->get_version());
    164         $plugin_admin_additional_fields = new Mepu_Woo_Additional_Fields($this->get_plugin_name(), $this->get_version());
     99        $plugin_admin = new Mepu_Woo_Admin();
     100        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
    165101
    166         $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
    167         $plugin_admin_additional_fields->init_fields();
     102        $plugin_admin_additional_fields = new Mepu_Woo_Additional_Fields();
     103        $this->loader->add_action('woocommerce_product_options_general_product_data', $plugin_admin_additional_fields, 'mepu_extra_fields');
     104        $this->loader->add_action('woocommerce_process_product_meta', $plugin_admin_additional_fields, 'mepu_extra_fields_process');
    168105    }
    169106
     
    172109     *
    173110     * @since    1.0.0
    174      * @access   private
    175111     */
    176112    private function define_frontend_hooks()
    177113    {
    178         $plugin = new Mepu_Woo_Frontend($this->get_plugin_name(), $this->get_version());
     114        $plugin = new Mepu_Woo_Frontend();
    179115        $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'render_mepu_buttons');
    180116        $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'adjust_cart_form_details');
     
    183119        $this->loader->add_filter('woocommerce_loop_add_to_cart_args', $plugin, 'adjust_cart_form_details_loop', 10, 3);
    184120    }
    185 
    186121
    187122    /**
     
    194129        $this->loader->run();
    195130    }
    196 
    197     /**
    198      * The name of the plugin used to uniquely identify it within the context of
    199      * WordPress and to define internationalization functionality.
    200      *
    201      * @since     1.0.0
    202      * @return    string    The name of the plugin.
    203      */
    204     public function get_plugin_name()
    205     {
    206         return $this->plugin_name;
    207     }
    208 
    209     /**
    210      * The reference to the class that orchestrates the hooks with the plugin.
    211      *
    212      * @since     1.0.0
    213      * @return    Mepu_Woo_Loader    Orchestrates the hooks of the plugin.
    214      */
    215     public function get_loader()
    216     {
    217         return $this->loader;
    218     }
    219 
    220     /**
    221      * Retrieve the version number of the plugin.
    222      *
    223      * @since     1.0.0
    224      * @return    string    The version number of the plugin.
    225      */
    226     public function get_version()
    227     {
    228         return $this->version;
    229     }
    230 
    231131}
  • multiple-external-product-urls-for-woocommerce/trunk/languages/mepu-woo.pot

    r1933588 r2558872  
    1 # Copyright (C) 2018 Mepu_Woo
     1# Copyright (C) 2021 Mepu_Woo
    22# This file is distributed under the same license as the Mepu_Woo package.
    33msgid ""
     
    1414"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    1515
    16 #: ../admin/class-mepu-woo-additional-fields.php:84
     16#: ../admin/templates/woocommerce-external-fields.php:3
    1717msgid "Multiple external product URLs"
    1818msgstr ""
    1919
    20 #: ../admin/class-mepu-woo-additional-fields.php:84
     20#: ../admin/class-mepu-woo-additional-fields.php:4
    2121msgid "Add new"
    2222msgstr ""
    2323
    24 #: ../admin/class-mepu-woo-additional-fields.php:89
     24#: ../admin/class-mepu-woo-additional-fields.php:10
    2525msgid "Open in new tab"
    2626msgstr ""
    2727
    28 #: ../admin/class-mepu-woo-additional-fields.php:90
     28#: ../admin/class-mepu-woo-additional-fields.php:11
    2929msgid "Open external / affiliate URLs in new tab?"
    3030msgstr ""
    3131
    32 #: ../admin/class-mepu-woo-additional-fields.php:95
     32#: ../admin/class-mepu-woo-additional-fields.php:18
     33msgid "Category pages"
     34msgstr ""
     35
     36#: ../admin/class-mepu-woo-additional-fields.php:19
     37msgid "Show all external product buttons on category pages"
     38msgstr ""
     39
     40#: ../admin/class-mepu-woo-additional-fields.php:24
    3341msgid "## External / Affiliate product details"
    3442msgstr ""
    3543
    36 #: ../admin/class-mepu-woo-additional-fields.php:95
     44#: ../admin/class-mepu-woo-additional-fields.php:25
    3745msgid "Delete"
    3846msgstr ""
    3947
    40 #: ../admin/class-mepu-woo-additional-fields.php:100
     48#: ../admin/class-mepu-woo-additional-fields.php:31
    4149msgid "Product URL ##"
    4250msgstr ""
    4351
    44 #: ../admin/class-mepu-woo-additional-fields.php:108
     52#: ../admin/class-mepu-woo-additional-fields.php:39
    4553msgid "Button text ##"
    4654msgstr ""
    4755
    48 #: ../admin/class-mepu-woo-additional-fields.php:109
     56#: ../admin/class-mepu-woo-additional-fields.php:40
    4957msgctxt "placeholder"
    5058msgid "Buy product"
    5159msgstr ""
    5260
    53 #: ../includes/class-mepu-woo-activator.php:37
     61#: ../includes/class-mepu-woo-activator.php:25
    5462msgid "Please install and activate WooCommerce plugin first."
    5563msgstr ""
  • multiple-external-product-urls-for-woocommerce/trunk/mepu-woo.php

    r2428525 r2558872  
    11<?php
    2 
    32/**
    43 * @link              http://cmachowski.com
     
    98 * Plugin Name:       Multiple external product URLs for WooCommerce
    109 * Description:       Plugins gives you ability to add multiple external product URLs on WooCommerce product edit page.
    11  * Version:           1.1.1
     10 * Version:           1.3.0
    1211 * Author:            Paweł Ćmachowski
    13  * Author URI:        http://cmachowski.com
     12 * Author URI:        https://cmachowski.com
    1413 * License:           GPL-2.0+
    1514 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     
    1817 */
    1918
    20 // If this file is called directly, abort.
    2119if (!defined('WPINC')) {
    2220    die;
     
    2422
    2523/**
    26  * Currently plugin version.
    27  * Start at version 1.0.0 and use SemVer - https://semver.org
    28  * Rename this for your plugin and update it as you release new versions.
     24 * Plugin CONST values
    2925 */
    30 define('MEPU_WOO_VERSION', '1.2.0');
     26define('MEPU_WOO_VERSION', '1.3.0');
     27define('MEPU_WOO_SLUG', 'mepu-woo');
     28define('MEPU_WOO_DIR_NAME', 'multiple-external-product-urls-for-woocommerce');
     29define('MEPU_WOO_PLUGIN_DIR', plugin_dir_path(dirname(__FILE__)) . MEPU_WOO_DIR_NAME . '/');
     30define('MEPU_WOO_PLUGIN_URL', plugin_dir_url(dirname(__FILE__)) . MEPU_WOO_DIR_NAME . '/');
     31
    3132
    3233/**
    3334 * The code that runs during plugin activation.
    34  * This action is documented in includes/class-mepu-woo-activator.php
    3535 */
     36register_activation_hook(__FILE__, 'mepu_woo_activate');
    3637function mepu_woo_activate()
    3738{
     
    4243/**
    4344 * The code that runs during plugin deactivation.
    44  * This action is documented in includes/class-mepu-woo-deactivator.php
    4545 */
     46register_deactivation_hook(__FILE__, 'mepu_woo_deactivate');
    4647function mepu_woo_deactivate()
    4748{
     
    5051}
    5152
    52 register_activation_hook(__FILE__, 'mepu_woo_activate');
    53 register_deactivation_hook(__FILE__, 'mepu_woo_deactivate');
    54 
    5553/**
    56  * The core plugin class that is used to define internationalization,
    57  * admin-specific hooks, and public-facing site hooks.
     54 * Execution of the plugin.
     55 * @since    1.0.0
    5856 */
    5957require plugin_dir_path(__FILE__) . 'includes/class-mepu-woo.php';
    60 
    61 /**
    62  * Begins execution of the plugin.
    63  *
    64  * Since everything within the plugin is registered via hooks,
    65  * then kicking off the plugin from this point in the file does
    66  * not affect the page life cycle.
    67  *
    68  * @since    1.0.0
    69  */
    7058function mepu_woo_run()
    7159{
    72 
    7360    $plugin = new Mepu_Woo();
    7461    $plugin->run();
    75 
    7662}
    77 
    7863mepu_woo_run();
  • multiple-external-product-urls-for-woocommerce/trunk/uninstall.php

    r1933588 r2558872  
    33/**
    44 * Fired when the plugin is uninstalled.
    5  *
    6  * When populating this file, consider the following flow
    7  * of control:
    8  *
    9  * - This method should be static
    10  * - Check if the $_REQUEST content actually is the plugin name
    11  * - Run an admin referrer check to make sure it goes through authentication
    12  * - Verify the output of $_GET makes sense
    13  * - Repeat with other user roles. Best directly by using the links/query string parameters.
    14  * - Repeat things for multisite. Once for a single site in the network, once sitewide.
    15  *
    16  * This file may be updated more in future version of the Boilerplate; however, this is the
    17  * general skeleton and outline for how the file should work.
    18  *
    19  * For more information, see the following discussion:
    20  * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
    215 *
    226 * @link       http://cmachowski.com
Note: See TracChangeset for help on using the changeset viewer.