Changeset 2315109
- Timestamp:
- 05/30/2020 05:07:56 PM (6 years ago)
- Location:
- woo-sale-product-date-info
- Files:
-
- 4 added
- 4 deleted
- 14 edited
- 1 copied
-
tags/1.0.9 (copied) (copied from woo-sale-product-date-info/trunk)
-
tags/1.0.9/css/admin.css (modified) (2 diffs)
-
tags/1.0.9/css/website.php (modified) (1 diff)
-
tags/1.0.9/html/admin.php (modified) (4 diffs)
-
tags/1.0.9/html/website.php (modified) (1 diff)
-
tags/1.0.9/js/admin.js (modified) (8 diffs)
-
tags/1.0.9/languages/motpr355_woo_sale_product_info-fr_FR.mo (deleted)
-
tags/1.0.9/languages/motpr355_woo_sale_product_info-fr_FR.po (deleted)
-
tags/1.0.9/languages/woo-sale-product-date-info-fr_FR.mo (added)
-
tags/1.0.9/languages/woo-sale-product-date-info-fr_FR.po (added)
-
tags/1.0.9/readme.txt (modified) (4 diffs)
-
tags/1.0.9/woo-sale-product-date-info.php (modified) (18 diffs)
-
trunk/css/admin.css (modified) (2 diffs)
-
trunk/css/website.php (modified) (1 diff)
-
trunk/html/admin.php (modified) (4 diffs)
-
trunk/html/website.php (modified) (1 diff)
-
trunk/js/admin.js (modified) (8 diffs)
-
trunk/languages/motpr355_woo_sale_product_info-fr_FR.mo (deleted)
-
trunk/languages/motpr355_woo_sale_product_info-fr_FR.po (deleted)
-
trunk/languages/woo-sale-product-date-info-fr_FR.mo (added)
-
trunk/languages/woo-sale-product-date-info-fr_FR.po (added)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/woo-sale-product-date-info.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-sale-product-date-info/tags/1.0.9/css/admin.css
r1917801 r2315109 1 #motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic { 2 background: black;color: white;border-radius: 25px;padding: 4px 10px;display: inline-block; 1 #motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic { 2 background: black; 3 color: white; 4 border-radius: 25px; 5 padding: 4px 10px; 6 display: inline-block; 7 margin-bottom: 3px; 3 8 } 4 9 … … 25 30 position: relative; 26 31 display: none; 32 animation: motpr355_woo_sale_product_date_info_activate_arrow_blink 1s infinite; 33 } 34 35 @keyframes motpr355_woo_sale_product_date_info_activate_arrow_blink { 36 0% { opacity:0; } 37 50% { opacity:1; } 38 100% { opacity:0; } 27 39 } 28 40 -
woo-sale-product-date-info/tags/1.0.9/css/website.php
r1917801 r2315109 13 13 font-weight: <?php echo esc_html( $this->settings->{$this->settings_enum->font_weight} ) ?>; 14 14 text-transform: <?php echo esc_html( $this->settings->{$this->settings_enum->text_transform} ) ?>; 15 text-align: center; 15 16 border-radius: 25px; 16 17 padding: 4px 10px; 17 display: inline-block; 18 display: inline-block; 18 19 } 19 20 </style> -
woo-sale-product-date-info/tags/1.0.9/html/admin.php
r2019865 r2315109 3 3 exit; 4 4 } 5 $example_start_date = date_i18n( get_option( 'date_format' ), time() - 432000 ); 6 $example_end_date = date_i18n( get_option( 'date_format' ), time() + 432000 ); 5 7 ?> 6 8 <div class="wrap" id="motpr355_woo_sale_product_date_info"> … … 10 12 </h1> 11 13 12 <h3><?php _e( 'Display WooCommerce products sale enddate.', 'woo-sale-product-date-info' ) ?></h3>14 <h3><?php _e( 'Display WooCommerce sale product date.', 'woo-sale-product-date-info' ) ?></h3> 13 15 14 16 <noscript> … … 121 123 </span> 122 124 </p> 125 <p> 126 <span> 127 <?php _e( 'Display:', 'woo-sale-product-date-info' ) ?> 128 </span> 129 <span> 130 <label> 131 <input type="radio" 132 name="<?php echo $this->settings_enum->display ?>" 133 value="<?php echo $this->display_enum->start_date ?>"> 134 <span><?php _e( 'Only sale start date', 'woo-sale-product-date-info' ) ?></span> 135 </label> 136 <label> 137 <input type="radio" 138 name="<?php echo $this->settings_enum->display ?>" 139 value="<?php echo $this->display_enum->end_date ?>"> 140 <span><?php _e( 'Only sale end date', 'woo-sale-product-date-info' ) ?></span> 141 </label> 142 <label> 143 <input type="radio" 144 name="<?php echo $this->settings_enum->display ?>" 145 value="<?php echo $this->display_enum->start_end_date ?>"> 146 <span><?php _e( 'Sale start and end date', 'woo-sale-product-date-info' ) ?></span> 147 </label> 148 </span> 149 </p> 123 150 <hr/> 124 151 <p> … … 127 154 </span> 128 155 <span> 129 <span id="motpr355_woo_sale_product_date_info_classic"> 130 <?php printf( __( "Until %s", 'woo-sale-product-date-info' ), date_i18n( get_option( 'date_format' ), time() ) ) ?> 156 <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start"> 157 <?php printf( __( "On sale from %s", 'woo-sale-product-date-info' ), $example_start_date ) ?> 158 </span> 159 <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_end"> 160 <?php printf( __( "On sale until %s", 'woo-sale-product-date-info' ), $example_end_date ) ?> 161 </span> 162 <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start_end"> 163 <?php printf( __( "On sale from %s to %s", 'woo-sale-product-date-info' ), $example_start_date, $example_end_date ) ?> 131 164 </span> 132 165 </span> -
woo-sale-product-date-info/tags/1.0.9/html/website.php
r2019865 r2315109 6 6 <div class="motpr355_woo_sale_product_date_info_div"> 7 7 <span class="motpr355_woo_sale_product_date_info_span"> 8 <?php _e( "On sale until %s", 'woo-sale-product-date-info' ) ?>8 CONTENT 9 9 </span> 10 10 </div> -
woo-sale-product-date-info/tags/1.0.9/js/admin.js
r1917801 r2315109 10 10 init_font_weight(); 11 11 init_text_transform(); 12 init_display(); 12 13 init_preview(); 13 14 }; … … 36 37 }; 37 38 39 var init_display = function() { 40 init_value( 'display' ); 41 }; 42 38 43 var init_preview = function() { 39 44 set_preview( … … 41 46 settings.color, 42 47 settings.font_weight, 43 settings.text_transform 48 settings.text_transform, 49 settings.display 44 50 ); 45 51 }; … … 61 67 }; 62 68 69 var get_display = function() { 70 return get_value( 'display' ); 71 }; 72 63 73 var refresh_preview = function() { 64 74 set_preview( … … 66 76 get_color(), 67 77 get_font_weight(), 68 get_text_transform() 78 get_text_transform(), 79 get_display() 69 80 ); 70 81 }; … … 72 83 var get_value = function( id ) { 73 84 var text_values = [ 'background_color', 'color' ]; 74 var radio_values = [ 'font_weight', 'text_transform' ];85 var radio_values = [ 'font_weight', 'text_transform', 'display' ]; 75 86 var element = '#motpr355_woo_sale_product_date_info input[name="' + id + '"]'; 76 87 if ( radio_values.indexOf( id ) !== -1 ) { … … 84 95 var init_value = function( id ) { 85 96 var text_values = [ 'background_color', 'color' ]; 86 var radio_values = [ 'activation', 'font_weight', 'text_transform' ];97 var radio_values = [ 'activation', 'font_weight', 'text_transform', 'display' ]; 87 98 var element = '#motpr355_woo_sale_product_date_info [name="' + id + '"]'; 88 99 if ( radio_values.indexOf( id ) !== -1 ) { … … 94 105 }; 95 106 96 var set_preview = function( background_color, color, font_weight, text_transform ) { 107 var set_preview = function( background_color, color, font_weight, text_transform, display ) { 108 var start = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start'; 109 var end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_end'; 110 var start_end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start_end'; 111 var show = ''; 112 var hide = ''; 113 if (display === 'start_date') { 114 show = start; 115 hide = end + ',' + start_end; 116 } else if (display === 'end_date') { 117 show = end; 118 hide = start + ',' + start_end; 119 } else { 120 show = end + ',' + start + ',' + start_end; 121 hide = ''; 122 } 123 $( show ).show(); 124 $( hide ).hide(); 97 125 if ( check_color_format( background_color ) && check_color_format( color ) ) { 98 var element = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic';126 var element = '#motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic'; 99 127 $( element ).css( { 100 128 backgroundColor: background_color, -
woo-sale-product-date-info/tags/1.0.9/readme.txt
r2090705 r2315109 3 3 Tags: WooCommerce, E-commerce, product, sale date product, sale date product list, product list, sale date product tag, sale date product info, WooCommerce product 4 4 Requires at least: 4.0 5 Tested up to: 5. 25 Tested up to: 5.4 6 6 Requires PHP : 5.4 7 Stable tag: 1.0. 87 Stable tag: 1.0.9 8 8 License: GPLv2 or later 9 9 10 Display a customizable sale enddate tag for WooCommerce products.10 Display a customizable sale date tag for WooCommerce products. 11 11 12 12 … … 26 26 This plugin is fully free ; no hidden features, no premium features, no ads, no account creation... Just a **free plugin made with love by Motpr355**. 27 27 28 This plugin allow you to display a customizable customizable sale enddate tag for WooCommerce products.28 This plugin allow you to display a customizable sale date tag for WooCommerce products. 29 29 30 30 You can customize your tag in the plugin settings. … … 34 34 - Choose tag color with a color picker 35 35 - Choose font weight between normal and bold 36 - Choose text transform. Examples: "Until 2018-10-01", "until 2018-10-01", "UNTIL 2018-10-01". Date format is the one defined in WordPress Settings > General. 36 - Choose text transform. Examples: "On sale until 2018-10-01", "ON SALE UNTIL 2018-10-01"... Date format is the one defined in WordPress Settings > General. 37 - Choose if you want to display sale start date, end date, or both 37 38 - Preview the tag before save configuration 38 39 … … 60 61 == Changelog == 61 62 63 = 1.0.9 = 64 * Display product sale start date option 65 * Translations update 66 62 67 = 1.0.7 = 63 68 * Translations update -
woo-sale-product-date-info/tags/1.0.9/woo-sale-product-date-info.php
r2090705 r2315109 2 2 /* 3 3 Plugin Name: WooCommerce sale product date info 4 Description: Display a customizable sale enddate tag for WooCommerce products.5 Version: 1.0. 84 Description: Display a customizable sale date tag for WooCommerce products. 5 Version: 1.0.9 6 6 Author: Motpr355 7 7 Text Domain: woo-sale-product-date-info … … 18 18 private $font_weight_enum; 19 19 private $text_transform_enum; 20 private $display_enum; 20 21 21 22 public function __construct() { … … 53 54 54 55 private function init_data() { 55 $this->configuration_saved = false;56 $this->settings = $this->get_settings();57 56 $this->settings_enum = ( object ) array( 58 57 'nonce' => 'nonce', … … 61 60 'color' => 'color', 62 61 'font_weight' => 'font_weight', 63 'text_transform' => 'text_transform' 62 'text_transform' => 'text_transform', 63 'display' => 'display' 64 64 ); 65 65 $this->activation_enum = ( object ) array( … … 76 76 'uppercase' => 'uppercase' 77 77 ); 78 $this->display_enum = ( object ) array( 79 'start_date' => 'start_date', 80 'end_date' => 'end_date', 81 'start_end_date' => 'start_end_date' 82 ); 83 84 $this->configuration_saved = false; 85 $this->settings = $this->get_settings(); 78 86 } 79 87 … … 96 104 $this->settings->{$this->settings_enum->color}, 97 105 $this->settings->{$this->settings_enum->font_weight}, 98 $this->settings->{$this->settings_enum->text_transform} ) ) { 106 $this->settings->{$this->settings_enum->text_transform}, 107 $this->settings->{$this->settings_enum->display} ) ) { 99 108 include plugin_dir_path( __FILE__ ) . 'css/website.php'; 100 } 109 } 101 110 } 102 111 … … 106 115 if ( $product->is_on_sale() ) { 107 116 if ( function_exists( 'get_post_meta' ) && function_exists( 'get_the_ID' ) && function_exists( 'date_i18n' ) ) { 108 $date = get_post_meta( get_the_ID(), '_sale_price_dates_to', true ); 109 if ( $date && is_string( $date ) ) { 110 $date = date_i18n( get_option( 'date_format' ), $date ); 111 if ( isset ( $this->display_info_content ) ) { 112 return str_replace( '%s', $date, $this->display_info_content ); 113 } 114 if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) { 115 ob_start(); 116 include plugin_dir_path( __FILE__ ) . 'html/website.php'; 117 $this->display_info_content = ob_get_clean(); 118 return str_replace( '%s', $date, $this->display_info_content ); 117 $date_format = get_option( 'date_format' ); 118 if ( $date_format !== false ) { 119 if ( method_exists( $product, 'get_date_on_sale_from' ) && method_exists( $product, 'get_date_on_sale_to' ) ) { 120 $begin_date_display = false; 121 $begin_date = $product->get_date_on_sale_from( 'edit' ); 122 if ( $begin_date && method_exists( $begin_date, 'getOffsetTimestamp' ) ) { 123 $begin_date_display = date_i18n( $date_format, $begin_date->getOffsetTimestamp() ); 124 } 125 $end_date_display = false; 126 $end_date = $product->get_date_on_sale_to( 'edit' ); 127 if ( $end_date && method_exists( $end_date, 'getOffsetTimestamp' ) ) { 128 $end_date_display = date_i18n( $date_format, $end_date->getOffsetTimestamp() ); 129 } 130 if ( $begin_date_display || $end_date_display ) { 131 if ( isset ( $this->settings->{$this->settings_enum->background_color}, 132 $this->settings->{$this->settings_enum->color}, 133 $this->settings->{$this->settings_enum->font_weight}, 134 $this->settings->{$this->settings_enum->text_transform}, 135 $this->settings->{$this->settings_enum->display}) ) { 136 $display_option = $this->settings->{$this->settings_enum->display}; 137 $text = false; 138 if ( $begin_date_display && $end_date_display ) { 139 if ( $display_option === $this->display_enum->start_date ) { 140 $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display ); 141 } else if ( $display_option === $this->display_enum->end_date ) { 142 $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display ); 143 } else if ( $display_option === $this->display_enum->start_end_date ) { 144 $text = sprintf( __( 'On sale from %s to %s', 'woo-sale-product-date-info' ), $begin_date_display, $end_date_display ); 145 } 146 } else if ( $begin_date_display && ! $end_date_display ) { 147 if ( $display_option === $this->display_enum->start_date || $display_option === $this->display_enum->start_end_date ) { 148 $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display ); 149 } 150 } else if ( ! $begin_date_display && $end_date_display ) { 151 if ( $display_option === $this->display_enum->end_date || $display_option === $this->display_enum->start_end_date ) { 152 $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display ); 153 } 154 } 155 if ( $text !== false ) { 156 if ( isset ( $this->display_info_content ) ) { 157 return str_replace( 'CONTENT', $text, $this->display_info_content ); 158 } 159 if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) { 160 ob_start(); 161 include plugin_dir_path( __FILE__ ) . 'html/website.php'; 162 $this->display_info_content = ob_get_clean(); 163 return str_replace( 'CONTENT', $text, $this->display_info_content ); 164 } 165 } 166 } 167 } 119 168 } 120 169 } … … 143 192 'color' => '#ffffff', 144 193 'font_weight' => 'bold', 145 'text_transform' => 'none' 194 'text_transform' => 'none', 195 'display' => 'end_date' 146 196 ); 147 197 update_option( 'motpr355_woo_sale_product_date_info_settings', $settings ); … … 149 199 150 200 public function installed( $plugin ) { 151 if( $plugin === plugin_basename( __FILE__) ) {152 exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) );153 }201 if( $plugin === plugin_basename( __FILE__ ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) { 202 exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) ); 203 } 154 204 } 155 205 … … 201 251 plugins_url( 'js/admin.js', __FILE__ ), 202 252 array( 'wp-color-picker' ), 203 '1.0. 0',253 '1.0.9', 204 254 true 205 255 ); … … 214 264 plugins_url( 'js/admin-extensions.js', __FILE__ ), 215 265 array(), 216 '1.0. 0',266 '1.0.9', 217 267 true 218 268 ); … … 221 271 'motpr355_woo_sale_product_date_info_translations', 222 272 array( 223 'woo_inactive' => __( 273 'woo_inactive' => __( 224 274 'WooCommerce must be actived', 225 275 'woo-sale-product-date-info' … … 242 292 plugins_url( 'css/admin.css', __FILE__ ), 243 293 array(), 244 '1.0. 0'294 '1.0.9' 245 295 ); 246 296 wp_enqueue_style( 'motpr355_woo_sale_product_date_info_style' ); … … 268 318 private function save_configuration() { 269 319 if ( isset ( $_POST[ 'nonce' ], $_POST[ 'activation' ], $_POST[ 'background_color' ], 270 $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ] ) ) {320 $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ], $_POST[ 'display' ] ) ) { 271 321 $nonce = $this->get_cleaned_posted_data( $_POST[ 'nonce' ] ); 272 322 $saved_nonce = $this->settings->{$this->settings_enum->nonce}; … … 277 327 $font_weight = $this->get_cleaned_font_weight( $_POST[ 'font_weight' ] ); 278 328 $text_transform = $this->get_cleaned_text_transform( $_POST[ 'text_transform' ] ); 329 $display = $this->get_cleaned_display( $_POST[ 'display' ] ); 279 330 if ( $activation !== false && $background_color !== false && $color !== false 280 && $font_weight !== false && $text_transform !== false ) {331 && $font_weight !== false && $text_transform !== false && $display !== false ) { 281 332 $settings = array( 282 333 'nonce' => $saved_nonce, … … 285 336 'color' => $color, 286 337 'font_weight' => $font_weight, 287 'text_transform' => $text_transform 338 'text_transform' => $text_transform, 339 'display' => $display 288 340 ); 289 341 update_option( 'motpr355_woo_sale_product_date_info_settings', $settings ); … … 320 372 } 321 373 374 private function get_cleaned_display( $display ) { 375 $display = $this->get_cleaned_posted_data( $display ); 376 return in_array( $display, ( array ) $this->display_enum ) ? $display : false; 377 } 378 322 379 private function get_cleaned_posted_data( $data ) { 323 380 return stripslashes_deep( sanitize_text_field( $data ) ); … … 337 394 338 395 private function get_settings() { 339 return ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() ); 396 $settings = ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() ); 397 if ( ! isset ( $settings->display ) ) { 398 $settings->display = $this->display_enum->end_date; 399 } 400 return $settings; 340 401 } 341 402 -
woo-sale-product-date-info/trunk/css/admin.css
r1917801 r2315109 1 #motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic { 2 background: black;color: white;border-radius: 25px;padding: 4px 10px;display: inline-block; 1 #motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic { 2 background: black; 3 color: white; 4 border-radius: 25px; 5 padding: 4px 10px; 6 display: inline-block; 7 margin-bottom: 3px; 3 8 } 4 9 … … 25 30 position: relative; 26 31 display: none; 32 animation: motpr355_woo_sale_product_date_info_activate_arrow_blink 1s infinite; 33 } 34 35 @keyframes motpr355_woo_sale_product_date_info_activate_arrow_blink { 36 0% { opacity:0; } 37 50% { opacity:1; } 38 100% { opacity:0; } 27 39 } 28 40 -
woo-sale-product-date-info/trunk/css/website.php
r1917801 r2315109 13 13 font-weight: <?php echo esc_html( $this->settings->{$this->settings_enum->font_weight} ) ?>; 14 14 text-transform: <?php echo esc_html( $this->settings->{$this->settings_enum->text_transform} ) ?>; 15 text-align: center; 15 16 border-radius: 25px; 16 17 padding: 4px 10px; 17 display: inline-block; 18 display: inline-block; 18 19 } 19 20 </style> -
woo-sale-product-date-info/trunk/html/admin.php
r2019865 r2315109 3 3 exit; 4 4 } 5 $example_start_date = date_i18n( get_option( 'date_format' ), time() - 432000 ); 6 $example_end_date = date_i18n( get_option( 'date_format' ), time() + 432000 ); 5 7 ?> 6 8 <div class="wrap" id="motpr355_woo_sale_product_date_info"> … … 10 12 </h1> 11 13 12 <h3><?php _e( 'Display WooCommerce products sale enddate.', 'woo-sale-product-date-info' ) ?></h3>14 <h3><?php _e( 'Display WooCommerce sale product date.', 'woo-sale-product-date-info' ) ?></h3> 13 15 14 16 <noscript> … … 121 123 </span> 122 124 </p> 125 <p> 126 <span> 127 <?php _e( 'Display:', 'woo-sale-product-date-info' ) ?> 128 </span> 129 <span> 130 <label> 131 <input type="radio" 132 name="<?php echo $this->settings_enum->display ?>" 133 value="<?php echo $this->display_enum->start_date ?>"> 134 <span><?php _e( 'Only sale start date', 'woo-sale-product-date-info' ) ?></span> 135 </label> 136 <label> 137 <input type="radio" 138 name="<?php echo $this->settings_enum->display ?>" 139 value="<?php echo $this->display_enum->end_date ?>"> 140 <span><?php _e( 'Only sale end date', 'woo-sale-product-date-info' ) ?></span> 141 </label> 142 <label> 143 <input type="radio" 144 name="<?php echo $this->settings_enum->display ?>" 145 value="<?php echo $this->display_enum->start_end_date ?>"> 146 <span><?php _e( 'Sale start and end date', 'woo-sale-product-date-info' ) ?></span> 147 </label> 148 </span> 149 </p> 123 150 <hr/> 124 151 <p> … … 127 154 </span> 128 155 <span> 129 <span id="motpr355_woo_sale_product_date_info_classic"> 130 <?php printf( __( "Until %s", 'woo-sale-product-date-info' ), date_i18n( get_option( 'date_format' ), time() ) ) ?> 156 <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start"> 157 <?php printf( __( "On sale from %s", 'woo-sale-product-date-info' ), $example_start_date ) ?> 158 </span> 159 <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_end"> 160 <?php printf( __( "On sale until %s", 'woo-sale-product-date-info' ), $example_end_date ) ?> 161 </span> 162 <span class="motpr355_woo_sale_product_date_info_classic" id="motpr355_woo_sale_product_date_display_start_end"> 163 <?php printf( __( "On sale from %s to %s", 'woo-sale-product-date-info' ), $example_start_date, $example_end_date ) ?> 131 164 </span> 132 165 </span> -
woo-sale-product-date-info/trunk/html/website.php
r2019865 r2315109 6 6 <div class="motpr355_woo_sale_product_date_info_div"> 7 7 <span class="motpr355_woo_sale_product_date_info_span"> 8 <?php _e( "On sale until %s", 'woo-sale-product-date-info' ) ?>8 CONTENT 9 9 </span> 10 10 </div> -
woo-sale-product-date-info/trunk/js/admin.js
r1917801 r2315109 10 10 init_font_weight(); 11 11 init_text_transform(); 12 init_display(); 12 13 init_preview(); 13 14 }; … … 36 37 }; 37 38 39 var init_display = function() { 40 init_value( 'display' ); 41 }; 42 38 43 var init_preview = function() { 39 44 set_preview( … … 41 46 settings.color, 42 47 settings.font_weight, 43 settings.text_transform 48 settings.text_transform, 49 settings.display 44 50 ); 45 51 }; … … 61 67 }; 62 68 69 var get_display = function() { 70 return get_value( 'display' ); 71 }; 72 63 73 var refresh_preview = function() { 64 74 set_preview( … … 66 76 get_color(), 67 77 get_font_weight(), 68 get_text_transform() 78 get_text_transform(), 79 get_display() 69 80 ); 70 81 }; … … 72 83 var get_value = function( id ) { 73 84 var text_values = [ 'background_color', 'color' ]; 74 var radio_values = [ 'font_weight', 'text_transform' ];85 var radio_values = [ 'font_weight', 'text_transform', 'display' ]; 75 86 var element = '#motpr355_woo_sale_product_date_info input[name="' + id + '"]'; 76 87 if ( radio_values.indexOf( id ) !== -1 ) { … … 84 95 var init_value = function( id ) { 85 96 var text_values = [ 'background_color', 'color' ]; 86 var radio_values = [ 'activation', 'font_weight', 'text_transform' ];97 var radio_values = [ 'activation', 'font_weight', 'text_transform', 'display' ]; 87 98 var element = '#motpr355_woo_sale_product_date_info [name="' + id + '"]'; 88 99 if ( radio_values.indexOf( id ) !== -1 ) { … … 94 105 }; 95 106 96 var set_preview = function( background_color, color, font_weight, text_transform ) { 107 var set_preview = function( background_color, color, font_weight, text_transform, display ) { 108 var start = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start'; 109 var end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_end'; 110 var start_end = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_display_start_end'; 111 var show = ''; 112 var hide = ''; 113 if (display === 'start_date') { 114 show = start; 115 hide = end + ',' + start_end; 116 } else if (display === 'end_date') { 117 show = end; 118 hide = start + ',' + start_end; 119 } else { 120 show = end + ',' + start + ',' + start_end; 121 hide = ''; 122 } 123 $( show ).show(); 124 $( hide ).hide(); 97 125 if ( check_color_format( background_color ) && check_color_format( color ) ) { 98 var element = '#motpr355_woo_sale_product_date_info #motpr355_woo_sale_product_date_info_classic';126 var element = '#motpr355_woo_sale_product_date_info .motpr355_woo_sale_product_date_info_classic'; 99 127 $( element ).css( { 100 128 backgroundColor: background_color, -
woo-sale-product-date-info/trunk/readme.txt
r2090705 r2315109 3 3 Tags: WooCommerce, E-commerce, product, sale date product, sale date product list, product list, sale date product tag, sale date product info, WooCommerce product 4 4 Requires at least: 4.0 5 Tested up to: 5. 25 Tested up to: 5.4 6 6 Requires PHP : 5.4 7 Stable tag: 1.0. 87 Stable tag: 1.0.9 8 8 License: GPLv2 or later 9 9 10 Display a customizable sale enddate tag for WooCommerce products.10 Display a customizable sale date tag for WooCommerce products. 11 11 12 12 … … 26 26 This plugin is fully free ; no hidden features, no premium features, no ads, no account creation... Just a **free plugin made with love by Motpr355**. 27 27 28 This plugin allow you to display a customizable customizable sale enddate tag for WooCommerce products.28 This plugin allow you to display a customizable sale date tag for WooCommerce products. 29 29 30 30 You can customize your tag in the plugin settings. … … 34 34 - Choose tag color with a color picker 35 35 - Choose font weight between normal and bold 36 - Choose text transform. Examples: "Until 2018-10-01", "until 2018-10-01", "UNTIL 2018-10-01". Date format is the one defined in WordPress Settings > General. 36 - Choose text transform. Examples: "On sale until 2018-10-01", "ON SALE UNTIL 2018-10-01"... Date format is the one defined in WordPress Settings > General. 37 - Choose if you want to display sale start date, end date, or both 37 38 - Preview the tag before save configuration 38 39 … … 60 61 == Changelog == 61 62 63 = 1.0.9 = 64 * Display product sale start date option 65 * Translations update 66 62 67 = 1.0.7 = 63 68 * Translations update -
woo-sale-product-date-info/trunk/woo-sale-product-date-info.php
r2090705 r2315109 2 2 /* 3 3 Plugin Name: WooCommerce sale product date info 4 Description: Display a customizable sale enddate tag for WooCommerce products.5 Version: 1.0. 84 Description: Display a customizable sale date tag for WooCommerce products. 5 Version: 1.0.9 6 6 Author: Motpr355 7 7 Text Domain: woo-sale-product-date-info … … 18 18 private $font_weight_enum; 19 19 private $text_transform_enum; 20 private $display_enum; 20 21 21 22 public function __construct() { … … 53 54 54 55 private function init_data() { 55 $this->configuration_saved = false;56 $this->settings = $this->get_settings();57 56 $this->settings_enum = ( object ) array( 58 57 'nonce' => 'nonce', … … 61 60 'color' => 'color', 62 61 'font_weight' => 'font_weight', 63 'text_transform' => 'text_transform' 62 'text_transform' => 'text_transform', 63 'display' => 'display' 64 64 ); 65 65 $this->activation_enum = ( object ) array( … … 76 76 'uppercase' => 'uppercase' 77 77 ); 78 $this->display_enum = ( object ) array( 79 'start_date' => 'start_date', 80 'end_date' => 'end_date', 81 'start_end_date' => 'start_end_date' 82 ); 83 84 $this->configuration_saved = false; 85 $this->settings = $this->get_settings(); 78 86 } 79 87 … … 96 104 $this->settings->{$this->settings_enum->color}, 97 105 $this->settings->{$this->settings_enum->font_weight}, 98 $this->settings->{$this->settings_enum->text_transform} ) ) { 106 $this->settings->{$this->settings_enum->text_transform}, 107 $this->settings->{$this->settings_enum->display} ) ) { 99 108 include plugin_dir_path( __FILE__ ) . 'css/website.php'; 100 } 109 } 101 110 } 102 111 … … 106 115 if ( $product->is_on_sale() ) { 107 116 if ( function_exists( 'get_post_meta' ) && function_exists( 'get_the_ID' ) && function_exists( 'date_i18n' ) ) { 108 $date = get_post_meta( get_the_ID(), '_sale_price_dates_to', true ); 109 if ( $date && is_string( $date ) ) { 110 $date = date_i18n( get_option( 'date_format' ), $date ); 111 if ( isset ( $this->display_info_content ) ) { 112 return str_replace( '%s', $date, $this->display_info_content ); 113 } 114 if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) { 115 ob_start(); 116 include plugin_dir_path( __FILE__ ) . 'html/website.php'; 117 $this->display_info_content = ob_get_clean(); 118 return str_replace( '%s', $date, $this->display_info_content ); 117 $date_format = get_option( 'date_format' ); 118 if ( $date_format !== false ) { 119 if ( method_exists( $product, 'get_date_on_sale_from' ) && method_exists( $product, 'get_date_on_sale_to' ) ) { 120 $begin_date_display = false; 121 $begin_date = $product->get_date_on_sale_from( 'edit' ); 122 if ( $begin_date && method_exists( $begin_date, 'getOffsetTimestamp' ) ) { 123 $begin_date_display = date_i18n( $date_format, $begin_date->getOffsetTimestamp() ); 124 } 125 $end_date_display = false; 126 $end_date = $product->get_date_on_sale_to( 'edit' ); 127 if ( $end_date && method_exists( $end_date, 'getOffsetTimestamp' ) ) { 128 $end_date_display = date_i18n( $date_format, $end_date->getOffsetTimestamp() ); 129 } 130 if ( $begin_date_display || $end_date_display ) { 131 if ( isset ( $this->settings->{$this->settings_enum->background_color}, 132 $this->settings->{$this->settings_enum->color}, 133 $this->settings->{$this->settings_enum->font_weight}, 134 $this->settings->{$this->settings_enum->text_transform}, 135 $this->settings->{$this->settings_enum->display}) ) { 136 $display_option = $this->settings->{$this->settings_enum->display}; 137 $text = false; 138 if ( $begin_date_display && $end_date_display ) { 139 if ( $display_option === $this->display_enum->start_date ) { 140 $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display ); 141 } else if ( $display_option === $this->display_enum->end_date ) { 142 $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display ); 143 } else if ( $display_option === $this->display_enum->start_end_date ) { 144 $text = sprintf( __( 'On sale from %s to %s', 'woo-sale-product-date-info' ), $begin_date_display, $end_date_display ); 145 } 146 } else if ( $begin_date_display && ! $end_date_display ) { 147 if ( $display_option === $this->display_enum->start_date || $display_option === $this->display_enum->start_end_date ) { 148 $text = sprintf( __( 'On sale from %s', 'woo-sale-product-date-info' ), $begin_date_display ); 149 } 150 } else if ( ! $begin_date_display && $end_date_display ) { 151 if ( $display_option === $this->display_enum->end_date || $display_option === $this->display_enum->start_end_date ) { 152 $text = sprintf( __( 'On sale until %s', 'woo-sale-product-date-info' ), $end_date_display ); 153 } 154 } 155 if ( $text !== false ) { 156 if ( isset ( $this->display_info_content ) ) { 157 return str_replace( 'CONTENT', $text, $this->display_info_content ); 158 } 159 if ( function_exists( 'ob_start' ) && function_exists( 'ob_get_clean' ) ) { 160 ob_start(); 161 include plugin_dir_path( __FILE__ ) . 'html/website.php'; 162 $this->display_info_content = ob_get_clean(); 163 return str_replace( 'CONTENT', $text, $this->display_info_content ); 164 } 165 } 166 } 167 } 119 168 } 120 169 } … … 143 192 'color' => '#ffffff', 144 193 'font_weight' => 'bold', 145 'text_transform' => 'none' 194 'text_transform' => 'none', 195 'display' => 'end_date' 146 196 ); 147 197 update_option( 'motpr355_woo_sale_product_date_info_settings', $settings ); … … 149 199 150 200 public function installed( $plugin ) { 151 if( $plugin === plugin_basename( __FILE__) ) {152 exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) );153 }201 if( $plugin === plugin_basename( __FILE__ ) && is_plugin_active( 'woocommerce/woocommerce.php' ) ) { 202 exit( wp_redirect( admin_url( 'edit.php?post_type=product&page=motpr355_woo_sale_product_date_info' ) ) ); 203 } 154 204 } 155 205 … … 201 251 plugins_url( 'js/admin.js', __FILE__ ), 202 252 array( 'wp-color-picker' ), 203 '1.0. 0',253 '1.0.9', 204 254 true 205 255 ); … … 214 264 plugins_url( 'js/admin-extensions.js', __FILE__ ), 215 265 array(), 216 '1.0. 0',266 '1.0.9', 217 267 true 218 268 ); … … 221 271 'motpr355_woo_sale_product_date_info_translations', 222 272 array( 223 'woo_inactive' => __( 273 'woo_inactive' => __( 224 274 'WooCommerce must be actived', 225 275 'woo-sale-product-date-info' … … 242 292 plugins_url( 'css/admin.css', __FILE__ ), 243 293 array(), 244 '1.0. 0'294 '1.0.9' 245 295 ); 246 296 wp_enqueue_style( 'motpr355_woo_sale_product_date_info_style' ); … … 268 318 private function save_configuration() { 269 319 if ( isset ( $_POST[ 'nonce' ], $_POST[ 'activation' ], $_POST[ 'background_color' ], 270 $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ] ) ) {320 $_POST[ 'color' ], $_POST[ 'font_weight' ], $_POST[ 'text_transform' ], $_POST[ 'display' ] ) ) { 271 321 $nonce = $this->get_cleaned_posted_data( $_POST[ 'nonce' ] ); 272 322 $saved_nonce = $this->settings->{$this->settings_enum->nonce}; … … 277 327 $font_weight = $this->get_cleaned_font_weight( $_POST[ 'font_weight' ] ); 278 328 $text_transform = $this->get_cleaned_text_transform( $_POST[ 'text_transform' ] ); 329 $display = $this->get_cleaned_display( $_POST[ 'display' ] ); 279 330 if ( $activation !== false && $background_color !== false && $color !== false 280 && $font_weight !== false && $text_transform !== false ) {331 && $font_weight !== false && $text_transform !== false && $display !== false ) { 281 332 $settings = array( 282 333 'nonce' => $saved_nonce, … … 285 336 'color' => $color, 286 337 'font_weight' => $font_weight, 287 'text_transform' => $text_transform 338 'text_transform' => $text_transform, 339 'display' => $display 288 340 ); 289 341 update_option( 'motpr355_woo_sale_product_date_info_settings', $settings ); … … 320 372 } 321 373 374 private function get_cleaned_display( $display ) { 375 $display = $this->get_cleaned_posted_data( $display ); 376 return in_array( $display, ( array ) $this->display_enum ) ? $display : false; 377 } 378 322 379 private function get_cleaned_posted_data( $data ) { 323 380 return stripslashes_deep( sanitize_text_field( $data ) ); … … 337 394 338 395 private function get_settings() { 339 return ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() ); 396 $settings = ( object ) get_option( 'motpr355_woo_sale_product_date_info_settings', array() ); 397 if ( ! isset ( $settings->display ) ) { 398 $settings->display = $this->display_enum->end_date; 399 } 400 return $settings; 340 401 } 341 402
Note: See TracChangeset
for help on using the changeset viewer.