Plugin Directory

Changeset 3311711


Ignore:
Timestamp:
06/14/2025 10:32:06 PM (10 months ago)
Author:
gpnagy
Message:

Custom date formats and styling for Add First Filter screen

Location:
filterflex
Files:
10 edited
10 copied

Legend:

Unmodified
Added
Removed
  • filterflex/tags/1.1.0/admin/css/filterflex-admin.css

    r3311280 r3311711  
    703703    border-color: #7ad0f5;
    704704}
     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}
    705718
    706719/* Hide the postbox header for the FilterFlex settings metabox */
     
    880893    padding-top: 0;
    881894}
     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  
    11// admin/js/filterflex-admin.js
    22jQuery(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    }
    334
    435    // Add console log to check available tags
     
    252283               
    253284                $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}
    254314            } else {
    255315                $itemWrapper.text(label);
     
    319379                        console.log('Tag data with meta:', tagData); // Debug log
    320380                    }
     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.
    321388                }
    322389               
     
    366433                    // Set the meta key value in the input
    367434                    $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);
    368440                } else {
    369441                    // For other tags
     
    637709    });
    638710
     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
    639722    // --- Status Toggle ---
    640723    if ($('.filterflex-status-toggle').length) {
  • filterflex/tags/1.1.0/filterflex.php

    r3311280 r3311711  
    44 * Plugin URI:        https://wordpress.org/plugins/filterflex
    55 * Description:       A powerful plugin for applying filters to various WordPress elements with custom field support and dynamic tag replacement.
    6  * Version:           1.0.0
     6 * Version:           1.1.0
    77 * Requires at least: 5.0
    88 * Requires PHP:      7.4
  • filterflex/tags/1.1.0/includes/class-filterflex-filter-application.php

    r3311280 r3311711  
    555555
    556556        // 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 tag
    559             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 );
    560560        }
    561561
     
    570570     * @param string $original_content The original content.
    571571     * @param int    $post_id The post ID.
     572     * @param array  $tag_item The tag item from the pattern, including meta.
    572573     * @return string The processed tag.
    573574     */
    574     public function process_filtered_element_tag( $original_content, $post_id ) {
     575    public function process_filtered_element_tag( $original_content, $post_id, $tag_item = [] ) {
    575576        return $original_content;
    576577    }
     
    581582     * @param string $original_content The original content.
    582583     * @param int    $post_id The post ID.
     584     * @param array  $tag_item The tag item from the pattern, including meta.
    583585     * @return string The processed tag.
    584586     */
    585     public function process_categories_tag( $original_content, $post_id ) {
     587    public function process_categories_tag( $original_content, $post_id, $tag_item = [] ) {
    586588        $categories = get_the_category( $post_id );
    587589        if ( empty( $categories ) ) {
     
    598600     * @param string $original_content The original content.
    599601     * @param int    $post_id The post ID.
     602     * @param array  $tag_item The tag item from the pattern, including meta.
    600603     * @return string The processed tag.
    601604     */
    602     public function process_tags_tag( $original_content, $post_id ) {
     605    public function process_tags_tag( $original_content, $post_id, $tag_item = [] ) {
    603606        $tags = get_the_tags( $post_id );
    604607        if ( empty( $tags ) ) {
     
    615618     * @param string $original_content The original content.
    616619     * @param int    $post_id The post ID.
     620     * @param array  $tag_item The tag item from the pattern, including meta.
    617621     * @return string The processed tag.
    618622     */
    619     public function process_author_tag( $original_content, $post_id ) {
     623    public function process_author_tag( $original_content, $post_id, $tag_item = [] ) {
    620624        $post = get_post( $post_id );
    621625        if ( ! $post ) {
     
    632636     * @param string $original_content The original content.
    633637     * @param int    $post_id The post ID.
     638     * @param array  $tag_item The tag item from the pattern, including meta.
    634639     * @return string The processed tag.
    635640     */
    636     public function process_date_tag( $original_content, $post_id ) {
     641    public function process_date_tag( $original_content, $post_id, $tag_item = [] ) {
    637642        $post = get_post( $post_id );
    638643        if ( ! $post ) {
     
    640645        }
    641646
    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 );
    643654    }
    644655
     
    648659     * @param string $original_content The original content.
    649660     * @param int    $post_id The post ID.
     661     * @param array  $tag_item The tag item from the pattern, including meta.
    650662     * @return string The processed tag.
    651663     */
    652     public function process_post_id_tag( $original_content, $post_id ) {
     664    public function process_post_id_tag( $original_content, $post_id, $tag_item = [] ) {
    653665        return (string) $post_id;
    654666    }
  • filterflex/tags/1.1.0/includes/class-filterflex.php

    r3311280 r3311711  
    260260            '{tags}'             => [ 'label' => __( 'Tags (Post Tags)', 'filterflex' ), 'type' => 'tag' ],
    261261            '{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' ],
    263263            '{author}'           => [ 'label' => __( 'Author', 'filterflex' ), 'type' => 'tag' ],
    264264            '[static_text]'      => [ 'label' => __( 'Static Text', 'filterflex' ), 'type' => 'text' ],
     
    468468                                    $icon_html = '<span class="filterflex-tag-icon dashicons dashicons-edit"></span>';
    469469                                    $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';
    470473                                }
    471474                            ?>
     
    678681                                'key' => sanitize_text_field($item_data['meta']['key'])
    679682                            ];
     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                            }
    680695                        }
    681696
     
    962977            '{tags}'             => 'Tag1, Tag2',
    963978            '{custom_field}'     => 'Some Custom Value',
    964             '{date}'             => gmdate( get_option( 'date_format' ) ),
     979            // '{date}' is now handled dynamically in the loop
    965980            '{author}'           => 'Admin User',
    966981            // Add sample data for other tags if necessary
     
    976991                } else {
    977992                    // 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                    }
    9791004                }
    9801005            } elseif ( $item['type'] === 'text' ) {
     
    12091234            $add_new_url = admin_url( 'post-new.php?post_type=filterflex_filter' );
    12101235            ?>
    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'>
    12121238                <h2><?php esc_html_e( 'Add Your First Filter', 'filterflex' ); ?></h2>
    12131239                <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  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.1
     6Stable tag: 1.1.0
    77Requires PHP: 7.4
    88License: GPLv2 or later
  • filterflex/trunk/admin/css/filterflex-admin.css

    r3311280 r3311711  
    703703    border-color: #7ad0f5;
    704704}
     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}
    705718
    706719/* Hide the postbox header for the FilterFlex settings metabox */
     
    880893    padding-top: 0;
    881894}
     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  
    11// admin/js/filterflex-admin.js
    22jQuery(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    }
    334
    435    // Add console log to check available tags
     
    252283               
    253284                $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}
    254314            } else {
    255315                $itemWrapper.text(label);
     
    319379                        console.log('Tag data with meta:', tagData); // Debug log
    320380                    }
     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.
    321388                }
    322389               
     
    366433                    // Set the meta key value in the input
    367434                    $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);
    368440                } else {
    369441                    // For other tags
     
    637709    });
    638710
     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
    639722    // --- Status Toggle ---
    640723    if ($('.filterflex-status-toggle').length) {
  • filterflex/trunk/filterflex.php

    r3311280 r3311711  
    44 * Plugin URI:        https://wordpress.org/plugins/filterflex
    55 * Description:       A powerful plugin for applying filters to various WordPress elements with custom field support and dynamic tag replacement.
    6  * Version:           1.0.0
     6 * Version:           1.1.0
    77 * Requires at least: 5.0
    88 * Requires PHP:      7.4
  • filterflex/trunk/includes/class-filterflex-filter-application.php

    r3311280 r3311711  
    555555
    556556        // 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 tag
    559             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 );
    560560        }
    561561
     
    570570     * @param string $original_content The original content.
    571571     * @param int    $post_id The post ID.
     572     * @param array  $tag_item The tag item from the pattern, including meta.
    572573     * @return string The processed tag.
    573574     */
    574     public function process_filtered_element_tag( $original_content, $post_id ) {
     575    public function process_filtered_element_tag( $original_content, $post_id, $tag_item = [] ) {
    575576        return $original_content;
    576577    }
     
    581582     * @param string $original_content The original content.
    582583     * @param int    $post_id The post ID.
     584     * @param array  $tag_item The tag item from the pattern, including meta.
    583585     * @return string The processed tag.
    584586     */
    585     public function process_categories_tag( $original_content, $post_id ) {
     587    public function process_categories_tag( $original_content, $post_id, $tag_item = [] ) {
    586588        $categories = get_the_category( $post_id );
    587589        if ( empty( $categories ) ) {
     
    598600     * @param string $original_content The original content.
    599601     * @param int    $post_id The post ID.
     602     * @param array  $tag_item The tag item from the pattern, including meta.
    600603     * @return string The processed tag.
    601604     */
    602     public function process_tags_tag( $original_content, $post_id ) {
     605    public function process_tags_tag( $original_content, $post_id, $tag_item = [] ) {
    603606        $tags = get_the_tags( $post_id );
    604607        if ( empty( $tags ) ) {
     
    615618     * @param string $original_content The original content.
    616619     * @param int    $post_id The post ID.
     620     * @param array  $tag_item The tag item from the pattern, including meta.
    617621     * @return string The processed tag.
    618622     */
    619     public function process_author_tag( $original_content, $post_id ) {
     623    public function process_author_tag( $original_content, $post_id, $tag_item = [] ) {
    620624        $post = get_post( $post_id );
    621625        if ( ! $post ) {
     
    632636     * @param string $original_content The original content.
    633637     * @param int    $post_id The post ID.
     638     * @param array  $tag_item The tag item from the pattern, including meta.
    634639     * @return string The processed tag.
    635640     */
    636     public function process_date_tag( $original_content, $post_id ) {
     641    public function process_date_tag( $original_content, $post_id, $tag_item = [] ) {
    637642        $post = get_post( $post_id );
    638643        if ( ! $post ) {
     
    640645        }
    641646
    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 );
    643654    }
    644655
     
    648659     * @param string $original_content The original content.
    649660     * @param int    $post_id The post ID.
     661     * @param array  $tag_item The tag item from the pattern, including meta.
    650662     * @return string The processed tag.
    651663     */
    652     public function process_post_id_tag( $original_content, $post_id ) {
     664    public function process_post_id_tag( $original_content, $post_id, $tag_item = [] ) {
    653665        return (string) $post_id;
    654666    }
  • filterflex/trunk/includes/class-filterflex.php

    r3311280 r3311711  
    260260            '{tags}'             => [ 'label' => __( 'Tags (Post Tags)', 'filterflex' ), 'type' => 'tag' ],
    261261            '{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' ],
    263263            '{author}'           => [ 'label' => __( 'Author', 'filterflex' ), 'type' => 'tag' ],
    264264            '[static_text]'      => [ 'label' => __( 'Static Text', 'filterflex' ), 'type' => 'text' ],
     
    468468                                    $icon_html = '<span class="filterflex-tag-icon dashicons dashicons-edit"></span>';
    469469                                    $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';
    470473                                }
    471474                            ?>
     
    678681                                'key' => sanitize_text_field($item_data['meta']['key'])
    679682                            ];
     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                            }
    680695                        }
    681696
     
    962977            '{tags}'             => 'Tag1, Tag2',
    963978            '{custom_field}'     => 'Some Custom Value',
    964             '{date}'             => gmdate( get_option( 'date_format' ) ),
     979            // '{date}' is now handled dynamically in the loop
    965980            '{author}'           => 'Admin User',
    966981            // Add sample data for other tags if necessary
     
    976991                } else {
    977992                    // 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                    }
    9791004                }
    9801005            } elseif ( $item['type'] === 'text' ) {
     
    12091234            $add_new_url = admin_url( 'post-new.php?post_type=filterflex_filter' );
    12101235            ?>
    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'>
    12121238                <h2><?php esc_html_e( 'Add Your First Filter', 'filterflex' ); ?></h2>
    12131239                <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  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.1
     6Stable tag: 1.1.0
    77Requires PHP: 7.4
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.