Changeset 3311711
- Timestamp:
- 06/14/2025 10:32:06 PM (10 months ago)
- Location:
- filterflex
- Files:
-
- 10 edited
- 10 copied
-
tags/1.1.0 (copied) (copied from filterflex/trunk)
-
tags/1.1.0/LICENSE (copied) (copied from filterflex/trunk/LICENSE)
-
tags/1.1.0/README.md (copied) (copied from filterflex/trunk/README.md)
-
tags/1.1.0/admin (copied) (copied from filterflex/trunk/admin)
-
tags/1.1.0/admin/css/filterflex-admin.css (modified) (2 diffs)
-
tags/1.1.0/admin/js/filterflex-admin.js (modified) (5 diffs)
-
tags/1.1.0/filterflex.php (copied) (copied from filterflex/trunk/filterflex.php) (1 diff)
-
tags/1.1.0/includes (copied) (copied from filterflex/trunk/includes)
-
tags/1.1.0/includes/class-filterflex-filter-application.php (modified) (8 diffs)
-
tags/1.1.0/includes/class-filterflex.php (modified) (6 diffs)
-
tags/1.1.0/languages (copied) (copied from filterflex/trunk/languages)
-
tags/1.1.0/readme.txt (copied) (copied from filterflex/trunk/readme.txt) (1 diff)
-
tags/1.1.0/static (copied) (copied from filterflex/trunk/static)
-
tags/1.1.0/uninstall.php (copied) (copied from filterflex/trunk/uninstall.php)
-
trunk/admin/css/filterflex-admin.css (modified) (2 diffs)
-
trunk/admin/js/filterflex-admin.js (modified) (5 diffs)
-
trunk/filterflex.php (modified) (1 diff)
-
trunk/includes/class-filterflex-filter-application.php (modified) (8 diffs)
-
trunk/includes/class-filterflex.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
filterflex/tags/1.1.0/admin/css/filterflex-admin.css
r3311280 r3311711 703 703 border-color: #7ad0f5; 704 704 } 705 .filterflex-tag-date { 706 background-color: #e0f2f7; /* Light blue */ 707 border-color: #81d4fa; /* Slightly darker blue */ 708 } 709 710 /* Ensure date format select adjusts width dynamically */ 711 .date-format-select { 712 white-space: nowrap; 713 overflow: hidden; 714 text-overflow: ellipsis; 715 box-sizing: border-box; /* Include padding and border in the element's total width */ 716 width: auto; /* Allow JS to control width */ 717 } 705 718 706 719 /* Hide the postbox header for the FilterFlex settings metabox */ … … 880 893 padding-top: 0; 881 894 } 895 896 /* Styles for the "Add Your First Filter" splash screen */ 897 .filterflex-no-filters-message { 898 margin: 20px auto; /* Center the box and add vertical margin */ 899 text-align: center; 900 padding: 40px 20px; /* Increased padding for better look */ 901 border-radius: 8px; /* Rounded corners for the box */ 902 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); /* Subtle shadow */ 903 max-width: 600px; /* Limit width for better presentation */ 904 background: linear-gradient(to bottom, #f2d092 0%, #ffffff 100%); /* User-specified yellow to white gradient */ 905 color: #333; /* Darker text for contrast */ 906 border: 1px solid #ffcc80; /* Soft border matching gradient */ 907 } 908 909 .filterflex-no-filters-message h2 { 910 font-size: 2em; /* Larger heading */ 911 color: #4a4a4a; 912 margin-top: 20px; /* Space after logo */ 913 margin-bottom: 10px; 914 } 915 916 .filterflex-no-filters-message p { 917 font-size: 1.1em; 918 line-height: 1.6; 919 margin-bottom: 25px; 920 color: #555; 921 } 922 923 .filterflex-no-filters-message .button-hero { 924 padding: 12px 25px; 925 font-size: 1.2em; 926 border-radius: 5px; 927 } 928 929 .filterflex-splash-logo { 930 max-width: 250px; /* Adjust size as needed */ 931 height: auto; 932 display: block; /* Center the image */ 933 margin: 0 auto; /* Center the image */ 934 margin-bottom: 20px; /* Space between logo and heading */ 935 } -
filterflex/tags/1.1.0/admin/js/filterflex-admin.js
r3311280 r3311711 1 1 // admin/js/filterflex-admin.js 2 2 jQuery(document).ready(function($) { 3 4 // Function to dynamically adjust the width of a select element based on its selected option's text 5 function adjustSelectWidth($selectElement) { 6 // Create a temporary span to measure text width 7 const $tempSpan = $('<span>').css({ 8 'position': 'absolute', 9 'visibility': 'hidden', 10 'white-space': 'nowrap', 11 'font-family': $selectElement.css('font-family'), 12 'font-size': $selectElement.css('font-size'), 13 'font-weight': $selectElement.css('font-weight'), 14 'letter-spacing': $selectElement.css('letter-spacing'), 15 'text-transform': $selectElement.css('text-transform'), 16 'padding': $selectElement.css('padding'), 17 'border': $selectElement.css('border') 18 }).appendTo('body'); 19 20 // Get the text of the selected option 21 const selectedText = $selectElement.find('option:selected').text(); 22 $tempSpan.text(selectedText); 23 24 // Calculate the width and add a buffer for the dropdown arrow and padding 25 // A buffer of 30-40px is usually sufficient for the custom arrow and internal padding 26 const calculatedWidth = $tempSpan.width() + 35; // Adjust buffer as needed 27 28 // Apply the calculated width to the select element 29 $selectElement.width(calculatedWidth); 30 31 // Remove the temporary span 32 $tempSpan.remove(); 33 } 3 34 4 35 // Add console log to check available tags … … 252 283 253 284 $itemWrapper.append($labelSpan).append($metaInput); 285 } else if (value === '{date}') { 286 $itemWrapper.attr('data-tag', '{date}'); // Store the tag value 287 const $labelSpan = $('<span>').addClass('tag-label').text('Date Format: '); 288 const $formatSelect = $('<select>').addClass('date-format-select'); 289 290 // Define date format options 291 const dateFormats = { 292 '': 'WordPress Default', // Default option 293 'Y-m-d': 'YYYY-MM-DD', 294 'm/d/Y': 'MM/DD/YYYY', 295 'd/m/Y': 'DD/MM/YYYY', 296 'F j, Y': 'Month D, YYYY', 297 'M j, y': 'Mon D, YY', 298 'H:i:s': 'HH:MM:SS (24 hour)', 299 'g:i a': 'HH:MM AM/PM' 300 }; 301 302 // Populate the select options 303 $.each(dateFormats, function(formatVal, formatText) { 304 $formatSelect.append($('<option>', { value: formatVal, text: formatText })); 305 }); 306 307 // Set a default selected format if needed, e.g., WordPress Default 308 $formatSelect.val(''); // WordPress Default selected by default 309 310 $itemWrapper.append($labelSpan).append($formatSelect); 311 // Adjust width immediately after creation 312 adjustSelectWidth($formatSelect); 313 // No remove item span here, it's added later for all tags except {filtered_element} 254 314 } else { 255 315 $itemWrapper.text(label); … … 319 379 console.log('Tag data with meta:', tagData); // Debug log 320 380 } 381 } else if (tagValue === '{date}') { 382 const formatVal = $item.find('.date-format-select').val(); 383 // Only add meta if a specific format is chosen (not the default WP one which is empty string) 384 if (formatVal !== '') { 385 tagData.meta = { format: formatVal }; 386 } 387 // If formatVal is '', no meta.format is added, PHP will use default. 321 388 } 322 389 … … 366 433 // Set the meta key value in the input 367 434 $newElement.find('.custom-field-meta-input').val(metaKey); 435 } else if (tagValue === '{date}') { 436 const baseLabel = filterFlexData.available_tags['{date}']?.label || 'Date'; 437 $newElement = createBuilderElement('tag', tagValue, baseLabel); // createBuilderElement will now add the select 438 const savedFormat = item.meta?.format || ''; // Default to empty string (WP Default) if not set 439 $newElement.find('.date-format-select').val(savedFormat); 368 440 } else { 369 441 // For other tags … … 637 709 }); 638 710 711 // Add event handler for date format select changes 712 $builderVisualInput.on('change', '.date-format-select', function() { 713 adjustSelectWidth($(this)); // Adjust width on change 714 updateHiddenPatternInput(); 715 }); 716 717 // Initial adjustment for all existing date format selects on page load 718 $('.date-format-select').each(function() { 719 adjustSelectWidth($(this)); 720 }); 721 639 722 // --- Status Toggle --- 640 723 if ($('.filterflex-status-toggle').length) { -
filterflex/tags/1.1.0/filterflex.php
r3311280 r3311711 4 4 * Plugin URI: https://wordpress.org/plugins/filterflex 5 5 * Description: A powerful plugin for applying filters to various WordPress elements with custom field support and dynamic tag replacement. 6 * Version: 1. 0.06 * Version: 1.1.0 7 7 * Requires at least: 5.0 8 8 * Requires PHP: 7.4 -
filterflex/tags/1.1.0/includes/class-filterflex-filter-application.php
r3311280 r3311711 555 555 556 556 // Check if the tag (e.g., "{categories}") is registered in our $available_tags (for default tags) 557 if ( isset( $this->available_tags[ $tag_placeholder ] ) && is _callable( $this->available_tags[ $tag_placeholder ]['callback'] ) ) {558 // Call the registered callback for this tag559 return call_user_func( $this->available_tags[ $tag_placeholder ]['callback'], $original_content, $post_id );557 if ( isset( $this->available_tags[ $tag_placeholder ] ) && isset( $this->available_tags[ $tag_placeholder ]['callback'] ) && is_callable( $this->available_tags[ $tag_placeholder ]['callback'] ) ) { 558 // Pass the original content, post ID, and the full tag item (which includes meta) to the callback 559 return call_user_func( $this->available_tags[ $tag_placeholder ]['callback'], $original_content, $post_id, $tag_item ); 560 560 } 561 561 … … 570 570 * @param string $original_content The original content. 571 571 * @param int $post_id The post ID. 572 * @param array $tag_item The tag item from the pattern, including meta. 572 573 * @return string The processed tag. 573 574 */ 574 public function process_filtered_element_tag( $original_content, $post_id ) {575 public function process_filtered_element_tag( $original_content, $post_id, $tag_item = [] ) { 575 576 return $original_content; 576 577 } … … 581 582 * @param string $original_content The original content. 582 583 * @param int $post_id The post ID. 584 * @param array $tag_item The tag item from the pattern, including meta. 583 585 * @return string The processed tag. 584 586 */ 585 public function process_categories_tag( $original_content, $post_id ) {587 public function process_categories_tag( $original_content, $post_id, $tag_item = [] ) { 586 588 $categories = get_the_category( $post_id ); 587 589 if ( empty( $categories ) ) { … … 598 600 * @param string $original_content The original content. 599 601 * @param int $post_id The post ID. 602 * @param array $tag_item The tag item from the pattern, including meta. 600 603 * @return string The processed tag. 601 604 */ 602 public function process_tags_tag( $original_content, $post_id ) {605 public function process_tags_tag( $original_content, $post_id, $tag_item = [] ) { 603 606 $tags = get_the_tags( $post_id ); 604 607 if ( empty( $tags ) ) { … … 615 618 * @param string $original_content The original content. 616 619 * @param int $post_id The post ID. 620 * @param array $tag_item The tag item from the pattern, including meta. 617 621 * @return string The processed tag. 618 622 */ 619 public function process_author_tag( $original_content, $post_id ) {623 public function process_author_tag( $original_content, $post_id, $tag_item = [] ) { 620 624 $post = get_post( $post_id ); 621 625 if ( ! $post ) { … … 632 636 * @param string $original_content The original content. 633 637 * @param int $post_id The post ID. 638 * @param array $tag_item The tag item from the pattern, including meta. 634 639 * @return string The processed tag. 635 640 */ 636 public function process_date_tag( $original_content, $post_id ) {641 public function process_date_tag( $original_content, $post_id, $tag_item = [] ) { 637 642 $post = get_post( $post_id ); 638 643 if ( ! $post ) { … … 640 645 } 641 646 642 return get_the_date( '', $post_id ); 647 // Determine the date format 648 $date_format_to_use = ''; // Default to WordPress setting 649 if ( isset( $tag_item['meta']['format'] ) && is_string( $tag_item['meta']['format'] ) && ! empty( $tag_item['meta']['format'] ) ) { 650 $date_format_to_use = $tag_item['meta']['format']; 651 } 652 653 return get_the_date( $date_format_to_use, $post_id ); 643 654 } 644 655 … … 648 659 * @param string $original_content The original content. 649 660 * @param int $post_id The post ID. 661 * @param array $tag_item The tag item from the pattern, including meta. 650 662 * @return string The processed tag. 651 663 */ 652 public function process_post_id_tag( $original_content, $post_id ) {664 public function process_post_id_tag( $original_content, $post_id, $tag_item = [] ) { 653 665 return (string) $post_id; 654 666 } -
filterflex/tags/1.1.0/includes/class-filterflex.php
r3311280 r3311711 260 260 '{tags}' => [ 'label' => __( 'Tags (Post Tags)', 'filterflex' ), 'type' => 'tag' ], 261 261 '{custom_field}' => [ 'label' => __( 'Custom Field', 'filterflex' ), 'type' => 'tag', 'meta_prompt' => 'custom_field_key' ], 262 '{date}' => [ 'label' => __( 'Date', 'filterflex' ), 'type' => 'tag' ],262 '{date}' => [ 'label' => __( 'Date', 'filterflex' ), 'type' => 'tag', 'has_options' => 'date_format' ], 263 263 '{author}' => [ 'label' => __( 'Author', 'filterflex' ), 'type' => 'tag' ], 264 264 '[static_text]' => [ 'label' => __( 'Static Text', 'filterflex' ), 'type' => 'text' ], … … 468 468 $icon_html = '<span class="filterflex-tag-icon dashicons dashicons-edit"></span>'; 469 469 $extra_class = ' filterflex-tag-static-text'; 470 } elseif ( $tag_placeholder === '{date}' ) { 471 $icon_html = '<span class="filterflex-tag-icon dashicons dashicons-calendar"></span>'; 472 $extra_class = ' filterflex-tag-date'; 470 473 } 471 474 ?> … … 678 681 'key' => sanitize_text_field($item_data['meta']['key']) 679 682 ]; 683 } 684 685 // Handle date tag meta data 686 if ($type === 'tag' && $value === '{date}' && isset($item_data['meta']['format'])) { 687 // Ensure 'format' is a string and not empty. 688 if (is_string($item_data['meta']['format']) && !empty(trim($item_data['meta']['format']))) { 689 // Initialize 'meta' if it wasn't set by a previous condition (e.g. custom_field) 690 if (!isset($sanitized_item['meta'])) { 691 $sanitized_item['meta'] = []; 692 } 693 $sanitized_item['meta']['format'] = sanitize_text_field(trim($item_data['meta']['format'])); 694 } 680 695 } 681 696 … … 962 977 '{tags}' => 'Tag1, Tag2', 963 978 '{custom_field}' => 'Some Custom Value', 964 '{date}' => gmdate( get_option( 'date_format' ) ),979 // '{date}' is now handled dynamically in the loop 965 980 '{author}' => 'Admin User', 966 981 // Add sample data for other tags if necessary … … 976 991 } else { 977 992 // For other tags, use sample data if available, otherwise the tag value itself. 978 $preview_string .= $sample_data[ $item['value'] ] ?? $item['value']; 993 if ( $item['value'] === '{date}' ) { 994 $date_preview_format = get_option( 'date_format' ); // Default WordPress format 995 if ( isset( $item['meta']['format'] ) && ! empty( $item['meta']['format'] ) && is_string($item['meta']['format']) ) { 996 $date_preview_format = $item['meta']['format']; 997 } 998 // Use current time for preview, date_i18n for consistency if server times vary. 999 $preview_string .= date_i18n( $date_preview_format ); 1000 } else { 1001 // For all other tags, use the existing sample_data lookup 1002 $preview_string .= $sample_data[ $item['value'] ] ?? $item['value']; 1003 } 979 1004 } 980 1005 } elseif ( $item['type'] === 'text' ) { … … 1209 1234 $add_new_url = admin_url( 'post-new.php?post_type=filterflex_filter' ); 1210 1235 ?> 1211 <div class='filterflex-no-filters-message' style='margin: 10px 0; text-align: center; padding: 20px; background-color: #fff; border: 1px solid #ccd0d4;'> 1236 <div class='filterflex-no-filters-message'> 1237 <img src='<?php echo esc_url( FILTERFLEX_PLUGIN_URL . 'static/img/filterflex-logo.png' ); ?>' alt='FilterFlex Logo' class='filterflex-splash-logo'> 1212 1238 <h2><?php esc_html_e( 'Add Your First Filter', 'filterflex' ); ?></h2> 1213 1239 <p><?php esc_html_e( "It looks like you haven't created any filters yet. Get started by adding your first one!", 'filterflex' ); ?></p> -
filterflex/tags/1.1.0/readme.txt
r3311282 r3311711 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 1. 0.16 Stable tag: 1.1.0 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later -
filterflex/trunk/admin/css/filterflex-admin.css
r3311280 r3311711 703 703 border-color: #7ad0f5; 704 704 } 705 .filterflex-tag-date { 706 background-color: #e0f2f7; /* Light blue */ 707 border-color: #81d4fa; /* Slightly darker blue */ 708 } 709 710 /* Ensure date format select adjusts width dynamically */ 711 .date-format-select { 712 white-space: nowrap; 713 overflow: hidden; 714 text-overflow: ellipsis; 715 box-sizing: border-box; /* Include padding and border in the element's total width */ 716 width: auto; /* Allow JS to control width */ 717 } 705 718 706 719 /* Hide the postbox header for the FilterFlex settings metabox */ … … 880 893 padding-top: 0; 881 894 } 895 896 /* Styles for the "Add Your First Filter" splash screen */ 897 .filterflex-no-filters-message { 898 margin: 20px auto; /* Center the box and add vertical margin */ 899 text-align: center; 900 padding: 40px 20px; /* Increased padding for better look */ 901 border-radius: 8px; /* Rounded corners for the box */ 902 box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); /* Subtle shadow */ 903 max-width: 600px; /* Limit width for better presentation */ 904 background: linear-gradient(to bottom, #f2d092 0%, #ffffff 100%); /* User-specified yellow to white gradient */ 905 color: #333; /* Darker text for contrast */ 906 border: 1px solid #ffcc80; /* Soft border matching gradient */ 907 } 908 909 .filterflex-no-filters-message h2 { 910 font-size: 2em; /* Larger heading */ 911 color: #4a4a4a; 912 margin-top: 20px; /* Space after logo */ 913 margin-bottom: 10px; 914 } 915 916 .filterflex-no-filters-message p { 917 font-size: 1.1em; 918 line-height: 1.6; 919 margin-bottom: 25px; 920 color: #555; 921 } 922 923 .filterflex-no-filters-message .button-hero { 924 padding: 12px 25px; 925 font-size: 1.2em; 926 border-radius: 5px; 927 } 928 929 .filterflex-splash-logo { 930 max-width: 250px; /* Adjust size as needed */ 931 height: auto; 932 display: block; /* Center the image */ 933 margin: 0 auto; /* Center the image */ 934 margin-bottom: 20px; /* Space between logo and heading */ 935 } -
filterflex/trunk/admin/js/filterflex-admin.js
r3311280 r3311711 1 1 // admin/js/filterflex-admin.js 2 2 jQuery(document).ready(function($) { 3 4 // Function to dynamically adjust the width of a select element based on its selected option's text 5 function adjustSelectWidth($selectElement) { 6 // Create a temporary span to measure text width 7 const $tempSpan = $('<span>').css({ 8 'position': 'absolute', 9 'visibility': 'hidden', 10 'white-space': 'nowrap', 11 'font-family': $selectElement.css('font-family'), 12 'font-size': $selectElement.css('font-size'), 13 'font-weight': $selectElement.css('font-weight'), 14 'letter-spacing': $selectElement.css('letter-spacing'), 15 'text-transform': $selectElement.css('text-transform'), 16 'padding': $selectElement.css('padding'), 17 'border': $selectElement.css('border') 18 }).appendTo('body'); 19 20 // Get the text of the selected option 21 const selectedText = $selectElement.find('option:selected').text(); 22 $tempSpan.text(selectedText); 23 24 // Calculate the width and add a buffer for the dropdown arrow and padding 25 // A buffer of 30-40px is usually sufficient for the custom arrow and internal padding 26 const calculatedWidth = $tempSpan.width() + 35; // Adjust buffer as needed 27 28 // Apply the calculated width to the select element 29 $selectElement.width(calculatedWidth); 30 31 // Remove the temporary span 32 $tempSpan.remove(); 33 } 3 34 4 35 // Add console log to check available tags … … 252 283 253 284 $itemWrapper.append($labelSpan).append($metaInput); 285 } else if (value === '{date}') { 286 $itemWrapper.attr('data-tag', '{date}'); // Store the tag value 287 const $labelSpan = $('<span>').addClass('tag-label').text('Date Format: '); 288 const $formatSelect = $('<select>').addClass('date-format-select'); 289 290 // Define date format options 291 const dateFormats = { 292 '': 'WordPress Default', // Default option 293 'Y-m-d': 'YYYY-MM-DD', 294 'm/d/Y': 'MM/DD/YYYY', 295 'd/m/Y': 'DD/MM/YYYY', 296 'F j, Y': 'Month D, YYYY', 297 'M j, y': 'Mon D, YY', 298 'H:i:s': 'HH:MM:SS (24 hour)', 299 'g:i a': 'HH:MM AM/PM' 300 }; 301 302 // Populate the select options 303 $.each(dateFormats, function(formatVal, formatText) { 304 $formatSelect.append($('<option>', { value: formatVal, text: formatText })); 305 }); 306 307 // Set a default selected format if needed, e.g., WordPress Default 308 $formatSelect.val(''); // WordPress Default selected by default 309 310 $itemWrapper.append($labelSpan).append($formatSelect); 311 // Adjust width immediately after creation 312 adjustSelectWidth($formatSelect); 313 // No remove item span here, it's added later for all tags except {filtered_element} 254 314 } else { 255 315 $itemWrapper.text(label); … … 319 379 console.log('Tag data with meta:', tagData); // Debug log 320 380 } 381 } else if (tagValue === '{date}') { 382 const formatVal = $item.find('.date-format-select').val(); 383 // Only add meta if a specific format is chosen (not the default WP one which is empty string) 384 if (formatVal !== '') { 385 tagData.meta = { format: formatVal }; 386 } 387 // If formatVal is '', no meta.format is added, PHP will use default. 321 388 } 322 389 … … 366 433 // Set the meta key value in the input 367 434 $newElement.find('.custom-field-meta-input').val(metaKey); 435 } else if (tagValue === '{date}') { 436 const baseLabel = filterFlexData.available_tags['{date}']?.label || 'Date'; 437 $newElement = createBuilderElement('tag', tagValue, baseLabel); // createBuilderElement will now add the select 438 const savedFormat = item.meta?.format || ''; // Default to empty string (WP Default) if not set 439 $newElement.find('.date-format-select').val(savedFormat); 368 440 } else { 369 441 // For other tags … … 637 709 }); 638 710 711 // Add event handler for date format select changes 712 $builderVisualInput.on('change', '.date-format-select', function() { 713 adjustSelectWidth($(this)); // Adjust width on change 714 updateHiddenPatternInput(); 715 }); 716 717 // Initial adjustment for all existing date format selects on page load 718 $('.date-format-select').each(function() { 719 adjustSelectWidth($(this)); 720 }); 721 639 722 // --- Status Toggle --- 640 723 if ($('.filterflex-status-toggle').length) { -
filterflex/trunk/filterflex.php
r3311280 r3311711 4 4 * Plugin URI: https://wordpress.org/plugins/filterflex 5 5 * Description: A powerful plugin for applying filters to various WordPress elements with custom field support and dynamic tag replacement. 6 * Version: 1. 0.06 * Version: 1.1.0 7 7 * Requires at least: 5.0 8 8 * Requires PHP: 7.4 -
filterflex/trunk/includes/class-filterflex-filter-application.php
r3311280 r3311711 555 555 556 556 // Check if the tag (e.g., "{categories}") is registered in our $available_tags (for default tags) 557 if ( isset( $this->available_tags[ $tag_placeholder ] ) && is _callable( $this->available_tags[ $tag_placeholder ]['callback'] ) ) {558 // Call the registered callback for this tag559 return call_user_func( $this->available_tags[ $tag_placeholder ]['callback'], $original_content, $post_id );557 if ( isset( $this->available_tags[ $tag_placeholder ] ) && isset( $this->available_tags[ $tag_placeholder ]['callback'] ) && is_callable( $this->available_tags[ $tag_placeholder ]['callback'] ) ) { 558 // Pass the original content, post ID, and the full tag item (which includes meta) to the callback 559 return call_user_func( $this->available_tags[ $tag_placeholder ]['callback'], $original_content, $post_id, $tag_item ); 560 560 } 561 561 … … 570 570 * @param string $original_content The original content. 571 571 * @param int $post_id The post ID. 572 * @param array $tag_item The tag item from the pattern, including meta. 572 573 * @return string The processed tag. 573 574 */ 574 public function process_filtered_element_tag( $original_content, $post_id ) {575 public function process_filtered_element_tag( $original_content, $post_id, $tag_item = [] ) { 575 576 return $original_content; 576 577 } … … 581 582 * @param string $original_content The original content. 582 583 * @param int $post_id The post ID. 584 * @param array $tag_item The tag item from the pattern, including meta. 583 585 * @return string The processed tag. 584 586 */ 585 public function process_categories_tag( $original_content, $post_id ) {587 public function process_categories_tag( $original_content, $post_id, $tag_item = [] ) { 586 588 $categories = get_the_category( $post_id ); 587 589 if ( empty( $categories ) ) { … … 598 600 * @param string $original_content The original content. 599 601 * @param int $post_id The post ID. 602 * @param array $tag_item The tag item from the pattern, including meta. 600 603 * @return string The processed tag. 601 604 */ 602 public function process_tags_tag( $original_content, $post_id ) {605 public function process_tags_tag( $original_content, $post_id, $tag_item = [] ) { 603 606 $tags = get_the_tags( $post_id ); 604 607 if ( empty( $tags ) ) { … … 615 618 * @param string $original_content The original content. 616 619 * @param int $post_id The post ID. 620 * @param array $tag_item The tag item from the pattern, including meta. 617 621 * @return string The processed tag. 618 622 */ 619 public function process_author_tag( $original_content, $post_id ) {623 public function process_author_tag( $original_content, $post_id, $tag_item = [] ) { 620 624 $post = get_post( $post_id ); 621 625 if ( ! $post ) { … … 632 636 * @param string $original_content The original content. 633 637 * @param int $post_id The post ID. 638 * @param array $tag_item The tag item from the pattern, including meta. 634 639 * @return string The processed tag. 635 640 */ 636 public function process_date_tag( $original_content, $post_id ) {641 public function process_date_tag( $original_content, $post_id, $tag_item = [] ) { 637 642 $post = get_post( $post_id ); 638 643 if ( ! $post ) { … … 640 645 } 641 646 642 return get_the_date( '', $post_id ); 647 // Determine the date format 648 $date_format_to_use = ''; // Default to WordPress setting 649 if ( isset( $tag_item['meta']['format'] ) && is_string( $tag_item['meta']['format'] ) && ! empty( $tag_item['meta']['format'] ) ) { 650 $date_format_to_use = $tag_item['meta']['format']; 651 } 652 653 return get_the_date( $date_format_to_use, $post_id ); 643 654 } 644 655 … … 648 659 * @param string $original_content The original content. 649 660 * @param int $post_id The post ID. 661 * @param array $tag_item The tag item from the pattern, including meta. 650 662 * @return string The processed tag. 651 663 */ 652 public function process_post_id_tag( $original_content, $post_id ) {664 public function process_post_id_tag( $original_content, $post_id, $tag_item = [] ) { 653 665 return (string) $post_id; 654 666 } -
filterflex/trunk/includes/class-filterflex.php
r3311280 r3311711 260 260 '{tags}' => [ 'label' => __( 'Tags (Post Tags)', 'filterflex' ), 'type' => 'tag' ], 261 261 '{custom_field}' => [ 'label' => __( 'Custom Field', 'filterflex' ), 'type' => 'tag', 'meta_prompt' => 'custom_field_key' ], 262 '{date}' => [ 'label' => __( 'Date', 'filterflex' ), 'type' => 'tag' ],262 '{date}' => [ 'label' => __( 'Date', 'filterflex' ), 'type' => 'tag', 'has_options' => 'date_format' ], 263 263 '{author}' => [ 'label' => __( 'Author', 'filterflex' ), 'type' => 'tag' ], 264 264 '[static_text]' => [ 'label' => __( 'Static Text', 'filterflex' ), 'type' => 'text' ], … … 468 468 $icon_html = '<span class="filterflex-tag-icon dashicons dashicons-edit"></span>'; 469 469 $extra_class = ' filterflex-tag-static-text'; 470 } elseif ( $tag_placeholder === '{date}' ) { 471 $icon_html = '<span class="filterflex-tag-icon dashicons dashicons-calendar"></span>'; 472 $extra_class = ' filterflex-tag-date'; 470 473 } 471 474 ?> … … 678 681 'key' => sanitize_text_field($item_data['meta']['key']) 679 682 ]; 683 } 684 685 // Handle date tag meta data 686 if ($type === 'tag' && $value === '{date}' && isset($item_data['meta']['format'])) { 687 // Ensure 'format' is a string and not empty. 688 if (is_string($item_data['meta']['format']) && !empty(trim($item_data['meta']['format']))) { 689 // Initialize 'meta' if it wasn't set by a previous condition (e.g. custom_field) 690 if (!isset($sanitized_item['meta'])) { 691 $sanitized_item['meta'] = []; 692 } 693 $sanitized_item['meta']['format'] = sanitize_text_field(trim($item_data['meta']['format'])); 694 } 680 695 } 681 696 … … 962 977 '{tags}' => 'Tag1, Tag2', 963 978 '{custom_field}' => 'Some Custom Value', 964 '{date}' => gmdate( get_option( 'date_format' ) ),979 // '{date}' is now handled dynamically in the loop 965 980 '{author}' => 'Admin User', 966 981 // Add sample data for other tags if necessary … … 976 991 } else { 977 992 // For other tags, use sample data if available, otherwise the tag value itself. 978 $preview_string .= $sample_data[ $item['value'] ] ?? $item['value']; 993 if ( $item['value'] === '{date}' ) { 994 $date_preview_format = get_option( 'date_format' ); // Default WordPress format 995 if ( isset( $item['meta']['format'] ) && ! empty( $item['meta']['format'] ) && is_string($item['meta']['format']) ) { 996 $date_preview_format = $item['meta']['format']; 997 } 998 // Use current time for preview, date_i18n for consistency if server times vary. 999 $preview_string .= date_i18n( $date_preview_format ); 1000 } else { 1001 // For all other tags, use the existing sample_data lookup 1002 $preview_string .= $sample_data[ $item['value'] ] ?? $item['value']; 1003 } 979 1004 } 980 1005 } elseif ( $item['type'] === 'text' ) { … … 1209 1234 $add_new_url = admin_url( 'post-new.php?post_type=filterflex_filter' ); 1210 1235 ?> 1211 <div class='filterflex-no-filters-message' style='margin: 10px 0; text-align: center; padding: 20px; background-color: #fff; border: 1px solid #ccd0d4;'> 1236 <div class='filterflex-no-filters-message'> 1237 <img src='<?php echo esc_url( FILTERFLEX_PLUGIN_URL . 'static/img/filterflex-logo.png' ); ?>' alt='FilterFlex Logo' class='filterflex-splash-logo'> 1212 1238 <h2><?php esc_html_e( 'Add Your First Filter', 'filterflex' ); ?></h2> 1213 1239 <p><?php esc_html_e( "It looks like you haven't created any filters yet. Get started by adding your first one!", 'filterflex' ); ?></p> -
filterflex/trunk/readme.txt
r3311282 r3311711 4 4 Requires at least: 5.0 5 5 Tested up to: 6.8 6 Stable tag: 1. 0.16 Stable tag: 1.1.0 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.