Changeset 2558872
- Timestamp:
- 07/05/2021 02:55:47 PM (4 years ago)
- 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 4 4 Tags: woocommerce, external product, woo, external, product, product url, woocommerce external product, multiple external products, 5 5 Requires at least: 3.0.1 6 Tested up to: 5. 57 Stable tag: 1. 2.06 Tested up to: 5.7.2 7 Stable tag: 1.3.0 8 8 License: GPLv2 or late 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 25 25 26 26 * 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` 28 30 29 31 == Installation == … … 35 37 36 38 == 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` 37 45 38 46 = 1.2.0 = -
multiple-external-product-urls-for-woocommerce/trunk/admin/class-mepu-woo-additional-fields.php
r2042986 r2558872 2 2 3 3 /** 4 * The admin-specific functionality of the plugin.4 * Class that define extra fields for WooCommerce external product metabox in wp-admin 5 5 * 6 6 * @link http://cmachowski.com … … 8 8 * 9 9 * @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 20 11 * @author Paweł Ćmachowski <[email protected]> 21 12 */ 22 13 class Mepu_Woo_Additional_Fields 23 14 { 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; 24 23 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 ); 54 31 } 55 32 56 33 /** 57 * Register all hooks for custom fields in product edit area for creation and updating34 * Update product meta on save / update 58 35 * 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 71 38 * @since 1.0.0 72 39 */ 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) 136 41 { 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'); 141 44 return false; 142 45 } 143 46 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; 148 55 } 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 ); 149 64 } 65 66 Mepu_Woo_Datastore::setData($post_id, $updateData); 150 67 } 151 68 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']); 157 71 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; 170 73 } 171 172 74 } -
multiple-external-product-urls-for-woocommerce/trunk/admin/class-mepu-woo-admin.php
r2428525 r2558872 9 9 * @package Mepu_Woo 10 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 to17 * enqueue the admin-specific stylesheet and JavaScript.18 *19 * @package Mepu_Woo20 * @subpackage Mepu_Woo/admin21 11 * @author Paweł Ćmachowski <[email protected]> 22 12 */ 23 13 class Mepu_Woo_Admin 24 14 { 25 26 /**27 * The ID of this plugin.28 *29 * @since 1.0.030 * @access private31 * @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.039 * @access private40 * @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.049 * @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 58 15 /** 59 16 * Register the JavaScript for the admin area. … … 63 20 public function enqueue_scripts() 64 21 { 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 ); 66 28 } 67 68 29 } -
multiple-external-product-urls-for-woocommerce/trunk/admin/js/mepu-woo-admin.js
r1933588 r2558872 3 3 4 4 $('#woocommerce-product-data').ready(function (event) { 5 if ($('.mepu-woo-cont').length) {6 5 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 } 15 9 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 } 19 14 15 16 for (let i = 0; i < woo_data[0].length; i++) { 17 mepu_woo_clone_block(i, woo_data[0][i]); 20 18 } 19 20 $('.mepu-woo-add').bind('click', function () { 21 mepu_woo_clone_block($('.mepu-woo-cont-item').length, ['', '']); 22 }); 23 21 24 }); 22 25 23 26 function mepu_woo_clone_block(i, data) { 24 varnew_block = $('.mepu-woo-only-for-clone').clone();27 let new_block = $('.mepu-woo-only-for-clone').clone(); 25 28 new_block.removeClass('hidden').removeClass('mepu-woo-only-for-clone').addClass('mepu-woo-cont-item'); 26 29 new_block.find('h5').html(new_block.find('h5').html().replace('##', '#' + (i + 1))); 30 27 31 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 29 33 }); 30 34 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_[]') { 35 40 $(this).attr('id', '_product_url_[]'); 36 41 $(this).attr('name', '_product_url_[]'); 37 42 } 38 if ($(this).attr('id') == '_button_text_clone_[]') { 43 44 if ($(this).attr('id') === '_button_text_clone_[]') { 39 45 $(this).attr('id', '_button_text_[]'); 40 46 $(this).attr('name', '_button_text_[]'); 41 47 } 42 48 }); 49 43 50 $('.mepu-woo-cont').append(new_block); 44 51 mepu_bind_block_actions(); -
multiple-external-product-urls-for-woocommerce/trunk/frontend/class-mepu-woo-frontend.php
r2428525 r2558872 2 2 3 3 /** 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 5 5 * 6 6 * @link http://cmachowski.com 7 7 * @since 1.0.0 8 *9 * @package Mepu_Woo10 * @subpackage Mepu_Woo/admin11 */12 13 /**14 * The admin-specific functionality of the plugin.15 *16 * Defines the plugin name, version, and two examples hooks for how to17 * enqueue the admin-specific stylesheet and JavaScript.18 8 * 19 9 * @package Mepu_Woo … … 23 13 class Mepu_Woo_Frontend 24 14 { 25 26 15 /** 27 * The ID of this plugin.16 * Render multiple external product buttons on product page 28 17 * 29 * @since 1.0.030 * @access private31 * @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.039 * @access private40 * @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.051 */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 page60 18 * @since 1.0.0 61 19 */ … … 63 21 { 64 22 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'); ?>72 23 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 } 75 27 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 } 77 32 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 ); 83 44 } 45 46 return; 84 47 } 85 48 86 49 /** 87 * Add multiple external buttons to loop in category 50 * Render multiple external buttons to loop in category / shop 51 * 88 52 * @param $buttons 89 53 * @param $product … … 94 58 public function render_mepu_buttons_loop($buttons, $product, $args = []) 95 59 { 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])); 108 86 } 109 87 … … 112 90 113 91 /** 114 * Adjust cart form details 92 * Adjust cart form details - ability to open in new tab/window 93 * 115 94 * @since 1.0.0 116 95 */ … … 118 97 { 119 98 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'); 131 101 } 132 133 102 } 134 103 135 104 /** 136 * Adjust external product buttons on category loop 105 * Adjust external product buttons on category loop - ability to open in new tab/window 106 * 137 107 * @param $args 138 108 * @param $product … … 142 112 public function adjust_cart_form_details_loop($args, $product) 143 113 { 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'; 148 124 } 149 125 150 126 return $args; 151 127 } 152 153 128 } -
multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-activator.php
r1933588 r2558872 2 2 3 3 /** 4 * Fired during plugin activation 4 * Fired during plugin activation. 5 5 * 6 6 * @link http://cmachowski.com 7 7 * @since 1.0.0 8 8 * 9 * @package Mepu_Woo10 * @subpackage Mepu_Woo/includes11 */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.019 9 * @package Mepu_Woo 20 10 * @subpackage Mepu_Woo/includes … … 25 15 class Mepu_Woo_Activator 26 16 { 27 28 17 /** 29 18 * Fires, when plugin is installed … … 33 22 public static function activate() 34 23 { 35 36 24 if (!is_plugin_active("woocommerce/woocommerce.php")) { 37 25 die(__('Please install and activate WooCommerce plugin first.', 'mepu-woo')); 38 26 } 39 40 27 } 41 42 43 28 } -
multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-deactivator.php
r1933588 r2558872 2 2 3 3 /** 4 * Fired during plugin deactivation 4 * Fired during plugin deactivation. 5 5 * 6 6 * @link http://cmachowski.com … … 9 9 * @package Mepu_Woo 10 10 * @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.019 * @package Mepu_Woo20 * @subpackage Mepu_Woo/includes21 11 * @author Paweł Ćmachowski <[email protected]> 22 12 */ 23 13 class Mepu_Woo_Deactivator 24 14 { 25 26 15 /** 27 * Short Description. (use period)16 * Remove all post_meta related to plugin 28 17 * 29 * Long Description. 30 * 31 * @since 1.0.0 18 * @since 1.3.0 32 19 */ 33 20 public static function deactivate() 34 21 { 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'); 36 26 } 37 38 27 } -
multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-i18n.php
r1933588 r2558872 2 2 3 3 /** 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. 8 5 * 9 6 * @link http://cmachowski.com … … 12 9 * @package Mepu_Woo 13 10 * @subpackage Mepu_Woo/includes 14 */15 16 /**17 * Define the internationalization functionality.18 *19 * Loads and defines the internationalization files for this plugin20 * so that it is ready for translation.21 *22 * @since 1.0.023 * @package Mepu_Woo24 * @subpackage Mepu_Woo/includes25 11 * @author Paweł Ćmachowski <[email protected]> 26 12 */ 27 13 class Mepu_Woo_i18n 28 14 { 29 30 31 15 /** 32 16 * Load the plugin text domain for translation. … … 36 20 public function load_plugin_textdomain() 37 21 { 38 39 22 load_plugin_textdomain( 40 'mepu-woo',23 MEPU_WOO_SLUG, 41 24 false, 42 dirname(dirname(plugin_basename(__FILE__))). '/languages/'25 MEPU_WOO_DIR_NAME . '/languages/' 43 26 ); 44 45 27 } 46 47 48 28 } -
multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo-loader.php
r1933588 r2558872 2 2 3 3 /** 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 14 5 * Register all actions and filters for the plugin. 15 6 * … … 17 8 * the plugin, and register them with the WordPress API. Call the 18 9 * run function to execute the list of actions and filters. 10 * 11 * @link http://cmachowski.com 12 * @since 1.0.0 19 13 * 20 14 * @package Mepu_Woo … … 24 18 class Mepu_Woo_Loader 25 19 { 26 27 20 /** 28 21 * The array of actions registered with WordPress. … … 50 43 public function __construct() 51 44 { 52 53 $this->actions = array(); 54 $this->filters = array(); 55 45 $this->actions = []; 46 $this->filters = []; 56 47 } 57 48 … … 59 50 * Add a new action to the collection to be registered with WordPress. 60 51 * 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. 61 57 * @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.67 58 */ 68 59 public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) … … 74 65 * Add a new filter to the collection to be registered with WordPress. 75 66 * 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 76 72 * @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 182 73 */ 83 74 public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) … … 90 81 * collection. 91 82 * 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. 92 90 * @since 1.0.0 93 91 * @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.101 92 */ 102 93 private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) 103 94 { 104 105 $hooks[] = array( 95 $hooks[] = [ 106 96 'hook' => $hook, 107 97 'component' => $component, … … 109 99 'priority' => $priority, 110 100 'accepted_args' => $accepted_args 111 );101 ]; 112 102 113 103 return $hooks; 114 115 104 } 116 105 … … 122 111 public function run() 123 112 { 124 125 113 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']); 127 115 } 128 116 129 117 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']); 131 119 } 132 133 120 } 134 135 121 } -
multiple-external-product-urls-for-woocommerce/trunk/includes/class-mepu-woo.php
r2042986 r2558872 1 1 <?php 2 3 /**4 * The file that defines the core plugin class5 *6 * A class definition that includes attributes and functions used across both the7 * public-facing side of the site and the admin area.8 *9 * @link http://cmachowski.com10 * @since 1.0.011 *12 * @package Mepu_Woo13 * @subpackage Mepu_Woo/includes14 */15 2 16 3 /** … … 20 7 * public-facing site hooks. 21 8 * 22 * Also maintains the unique identifier of this plugin as well as the current23 * version of the plugin.9 * @link http://cmachowski.com 10 * @since 1.0.0 24 11 * 25 * @since 1.0.026 12 * @package Mepu_Woo 27 13 * @subpackage Mepu_Woo/includes … … 30 16 class Mepu_Woo 31 17 { 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 ]; 32 40 33 41 /** … … 35 43 * the plugin. 36 44 * 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 40 47 */ 41 48 protected $loader; 42 49 43 50 /** 44 * The unique identifier of this plugin.45 *46 * @since 1.0.047 * @access protected48 * @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.056 * @access protected57 * @var string $version The current version of the plugin.58 */59 protected $version;60 61 /**62 51 * 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 and66 * the public-facing side of the site.67 52 * 68 53 * @since 1.0.0 … … 70 55 public function __construct() 71 56 { 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 79 57 $this->load_dependencies(); 80 58 $this->set_locale(); … … 82 60 $this->define_admin_hooks(); 83 61 $this->define_frontend_hooks(); 84 85 62 } 86 63 87 64 /** 88 65 * 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 *97 66 * Create an instance of the loader which will be used to register the hooks 98 67 * with WordPress. 99 68 * 100 69 * @since 1.0.0 101 * @access private102 70 */ 103 71 private function load_dependencies() 104 72 { 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 } 131 76 132 77 $this->loader = new Mepu_Woo_Loader(); 133 134 78 } 135 79 … … 137 81 * Define the locale for this plugin for internationalization. 138 82 * 139 * Uses the Mepu_Woo_i18n class in order to set the domain and to register the hook140 * with WordPress.141 *142 83 * @since 1.0.0 143 * @access private144 84 */ 145 85 private function set_locale() 146 86 { 147 148 87 $plugin_i18n = new Mepu_Woo_i18n(); 149 150 88 $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); 151 152 89 } 153 90 … … 157 94 * 158 95 * @since 1.0.0 159 * @access private160 96 */ 161 97 private function define_admin_hooks() 162 98 { 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'); 165 101 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'); 168 105 } 169 106 … … 172 109 * 173 110 * @since 1.0.0 174 * @access private175 111 */ 176 112 private function define_frontend_hooks() 177 113 { 178 $plugin = new Mepu_Woo_Frontend( $this->get_plugin_name(), $this->get_version());114 $plugin = new Mepu_Woo_Frontend(); 179 115 $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'render_mepu_buttons'); 180 116 $this->loader->add_action('woocommerce_after_add_to_cart_form', $plugin, 'adjust_cart_form_details'); … … 183 119 $this->loader->add_filter('woocommerce_loop_add_to_cart_args', $plugin, 'adjust_cart_form_details_loop', 10, 3); 184 120 } 185 186 121 187 122 /** … … 194 129 $this->loader->run(); 195 130 } 196 197 /**198 * The name of the plugin used to uniquely identify it within the context of199 * WordPress and to define internationalization functionality.200 *201 * @since 1.0.0202 * @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.0213 * @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.0224 * @return string The version number of the plugin.225 */226 public function get_version()227 {228 return $this->version;229 }230 231 131 } -
multiple-external-product-urls-for-woocommerce/trunk/languages/mepu-woo.pot
r1933588 r2558872 1 # Copyright (C) 20 18Mepu_Woo1 # Copyright (C) 2021 Mepu_Woo 2 2 # This file is distributed under the same license as the Mepu_Woo package. 3 3 msgid "" … … 14 14 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 15 15 16 #: ../admin/ class-mepu-woo-additional-fields.php:8416 #: ../admin/templates/woocommerce-external-fields.php:3 17 17 msgid "Multiple external product URLs" 18 18 msgstr "" 19 19 20 #: ../admin/class-mepu-woo-additional-fields.php: 8420 #: ../admin/class-mepu-woo-additional-fields.php:4 21 21 msgid "Add new" 22 22 msgstr "" 23 23 24 #: ../admin/class-mepu-woo-additional-fields.php: 8924 #: ../admin/class-mepu-woo-additional-fields.php:10 25 25 msgid "Open in new tab" 26 26 msgstr "" 27 27 28 #: ../admin/class-mepu-woo-additional-fields.php: 9028 #: ../admin/class-mepu-woo-additional-fields.php:11 29 29 msgid "Open external / affiliate URLs in new tab?" 30 30 msgstr "" 31 31 32 #: ../admin/class-mepu-woo-additional-fields.php:95 32 #: ../admin/class-mepu-woo-additional-fields.php:18 33 msgid "Category pages" 34 msgstr "" 35 36 #: ../admin/class-mepu-woo-additional-fields.php:19 37 msgid "Show all external product buttons on category pages" 38 msgstr "" 39 40 #: ../admin/class-mepu-woo-additional-fields.php:24 33 41 msgid "## External / Affiliate product details" 34 42 msgstr "" 35 43 36 #: ../admin/class-mepu-woo-additional-fields.php: 9544 #: ../admin/class-mepu-woo-additional-fields.php:25 37 45 msgid "Delete" 38 46 msgstr "" 39 47 40 #: ../admin/class-mepu-woo-additional-fields.php: 10048 #: ../admin/class-mepu-woo-additional-fields.php:31 41 49 msgid "Product URL ##" 42 50 msgstr "" 43 51 44 #: ../admin/class-mepu-woo-additional-fields.php: 10852 #: ../admin/class-mepu-woo-additional-fields.php:39 45 53 msgid "Button text ##" 46 54 msgstr "" 47 55 48 #: ../admin/class-mepu-woo-additional-fields.php: 10956 #: ../admin/class-mepu-woo-additional-fields.php:40 49 57 msgctxt "placeholder" 50 58 msgid "Buy product" 51 59 msgstr "" 52 60 53 #: ../includes/class-mepu-woo-activator.php: 3761 #: ../includes/class-mepu-woo-activator.php:25 54 62 msgid "Please install and activate WooCommerce plugin first." 55 63 msgstr "" -
multiple-external-product-urls-for-woocommerce/trunk/mepu-woo.php
r2428525 r2558872 1 1 <?php 2 3 2 /** 4 3 * @link http://cmachowski.com … … 9 8 * Plugin Name: Multiple external product URLs for WooCommerce 10 9 * Description: Plugins gives you ability to add multiple external product URLs on WooCommerce product edit page. 11 * Version: 1. 1.110 * Version: 1.3.0 12 11 * Author: Paweł Ćmachowski 13 * Author URI: http ://cmachowski.com12 * Author URI: https://cmachowski.com 14 13 * License: GPL-2.0+ 15 14 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt … … 18 17 */ 19 18 20 // If this file is called directly, abort.21 19 if (!defined('WPINC')) { 22 20 die; … … 24 22 25 23 /** 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 29 25 */ 30 define('MEPU_WOO_VERSION', '1.2.0'); 26 define('MEPU_WOO_VERSION', '1.3.0'); 27 define('MEPU_WOO_SLUG', 'mepu-woo'); 28 define('MEPU_WOO_DIR_NAME', 'multiple-external-product-urls-for-woocommerce'); 29 define('MEPU_WOO_PLUGIN_DIR', plugin_dir_path(dirname(__FILE__)) . MEPU_WOO_DIR_NAME . '/'); 30 define('MEPU_WOO_PLUGIN_URL', plugin_dir_url(dirname(__FILE__)) . MEPU_WOO_DIR_NAME . '/'); 31 31 32 32 33 /** 33 34 * The code that runs during plugin activation. 34 * This action is documented in includes/class-mepu-woo-activator.php35 35 */ 36 register_activation_hook(__FILE__, 'mepu_woo_activate'); 36 37 function mepu_woo_activate() 37 38 { … … 42 43 /** 43 44 * The code that runs during plugin deactivation. 44 * This action is documented in includes/class-mepu-woo-deactivator.php45 45 */ 46 register_deactivation_hook(__FILE__, 'mepu_woo_deactivate'); 46 47 function mepu_woo_deactivate() 47 48 { … … 50 51 } 51 52 52 register_activation_hook(__FILE__, 'mepu_woo_activate');53 register_deactivation_hook(__FILE__, 'mepu_woo_deactivate');54 55 53 /** 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 58 56 */ 59 57 require 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 does66 * not affect the page life cycle.67 *68 * @since 1.0.069 */70 58 function mepu_woo_run() 71 59 { 72 73 60 $plugin = new Mepu_Woo(); 74 61 $plugin->run(); 75 76 62 } 77 78 63 mepu_woo_run(); -
multiple-external-product-urls-for-woocommerce/trunk/uninstall.php
r1933588 r2558872 3 3 /** 4 4 * Fired when the plugin is uninstalled. 5 *6 * When populating this file, consider the following flow7 * of control:8 *9 * - This method should be static10 * - Check if the $_REQUEST content actually is the plugin name11 * - Run an admin referrer check to make sure it goes through authentication12 * - Verify the output of $_GET makes sense13 * - 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 the17 * 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-2854191321 5 * 22 6 * @link http://cmachowski.com
Note: See TracChangeset
for help on using the changeset viewer.