Forum Replies Created

Viewing 15 posts - 1 through 15 (of 28 total)
  • Author
    Posts
  • in reply to: Project abandoned? #8454
    Mehdi Salem
    Member

    Thanks Steve!

    The beta on Github fixed the php warning I got after the WP 4.9 update, cool!

    All good.
    The truth is that I would rather try to patch piklist my self moving forward rather than having to use ACF or CMB2 again, they are both great but once you play with piklist, moving to less power is difficult…

    Long life to the king, cause it ain’t dead yet!

    Cheers!

    in reply to: Project abandoned? #8446
    Mehdi Salem
    Member

    And indeed, the forum looks spammed for sure, hmmmm….
    These things can happen from time to time ok but no cleanup is not a good sign…
    This is worrying I admit but is everything happening only on Github now? WordPress does not allow new Frameworks on the repo… is this related? is WordPress not allowing framework devs to update their plugins anymore?

    in reply to: Project abandoned? #8445
    Mehdi Salem
    Member

    Yes, we need to know guys…
    I would pay a yearly fee with no hesitation to get dev going on this project because it is so awesome to let it die.

    Mehdi Salem
    Member

    Thanks @Jason for transmitting and for your prompt answer!

    Yes, I faced the user experience issue as soon as my client started adding stuff. So it pushed me to find a more creative solution, in this case, getting rid of the add_more and let the user add multiple files in the same uploader field. I had to do some more work though to hook into the media uploader ajax light box and stick my other fields in there instead… and write a conversion script for the data already saved in the database. So far it is a way nicer user experience for this particular project but it did cost me a lot to make the switch at the last minute.

    And I’m happy that we all agree it is not a valid excuse… making Piklist more efficient and match other platforms performances out there is a must. While I could figure out an alternative in this case, other more ambitious projects might suffer.

    I’ll be happy if you keep me in the loop in case this moves to another topic.

    Mehdi Salem
    Member

    Ok, here is the issue with Piklist admin Javascript and there are 2 major issue scenarios.

    Tested on default Twenty Sixteen WP theme with default post type “Post” and also custom post types on powerful Macbook Pro (all major browsers)

    1. In first scenario we have a meta box “Gallery” containing an add_more field group with file upload and simple stuff (code bellow): First time post is created, you can add as many add_more as you want. As soon as you save the post, the more you have add_mores, the slower the browser responds. if you reach 40 add_mores then 2 issues: takes 15 seconds and more for the page to load – if a new add_more is added or removed when “minus” or “plus” buttons are clicked same thing, 15 seconds or more delay…

    2. In second scenario we have the same previous meta box “Gallery” containing add_more folder_content_group field group COUPLED with another meta box “Gallery Folder Display Setting” containing file upload field and some conditionals with NO add_more: Same behavior on first save, no problem with as many add_mores as you want but gets very slow if you pass 25 add_mores and when you reach 40 and up, browser becomes unresponsive and Firefox even prompts to kill the script. Can take 60 seconds for browser to respond on page load and same amount of time just to add an add_more or remove it… Oh, yes, and some HEATING AND SUPER HIGH CPU usage on MacBook Pro (Retina, 15-inch, Mid 2015) – 2.5 GHz Intel Core i7 – 16 GB 1600 MHz DDR3

    I’ve seen that some tickets have been opened regarding performance issues with Javascript with and field combination… I was not satisfied by the solutions offered which basically asked to simplify the fields and that it was a lot to handle by for the scripts…

    This is for me a major Javascript optimization issue (and maybe also an architectural issue in the way JS has to prepare the html form input fields for PHP handling???)

    Because Piklist is meant for developers I do think this needs to be addressed seriously and before the release of the stable version.

    Many page builders handle add_mores efficiently, on WordPress or on many many other platforms.

    Personally this is an issue because on of my future projects was to create a Bootstrap and Curb Foundation page builder for WordPress using piklist, but I see this is not an option at this time…

    Thank you Jason for looking at this. Here are the two different meta boxes. Coupling them on the same post type will certainly allow to duplicate all this.

    Let me know if you want me to transfer this to another topic.
    Cheers!

    Gallery meta box:

    <?php
    /*
    Title: <h3>Gallery</h3>
    Post Type: post
    Order: 20
    */
    
    piklist('field', array(
        'type' => 'group'
    ,'field' => 'folder_content_group'
    ,'label' => __('Gallery Photo','stopping-the-world-admin')
    ,'description' => __('Add photos to this folder.', 'stopping-the-world-admin')
    ,'help' => __('Adds a new photo to this gallery folder and sets its availability on the store.','stopping-the-world-admin')
    ,'add_more' => true
    ,'fields' => array(
            array(
                'type' => 'file'
            ,'field' => 'single_photo'
            ,'label' => __('Photo','stopping-the-world-admin')
            ,'options' => array(
                'modal_title' => __('Add photo','stopping-the-world-admin')
            ,'button' => __('Add','stopping-the-world-admin')
            )
            ,'required' => true
            ,'columns' => 6
            ,'validate' => array(
                array(
                    'type' => 'limit',
                    'options' => array(
                        'min' => 1,
                        'max' => 1
                    )
                )
            ,array(
                    'type' => 'image'
                )
            )
            )
        ,array(
                'type' => 'text'
            ,'field' => 'photo_title'
            ,'label' => __('Title','stopping-the-world-admin')
            ,'help' => __('Sets the photo title. This will appear bellow the photo and above the description on the Gallery Foolder post.','stopping-the-world-admin')
            ,'columns' => 6
            ,'attributes' => array(
                    'placeholder' => __('Enter photo title here...', 'stopping-the-world-admin')
                )
            )
        ,array(
                'type' => 'checkbox'
            ,'field' => 'store_availability'
            ,'label' => __('Store Availability','stopping-the-world-admin')
            ,'help' => __('(Leave unchecked if you do not want to sell this photo.)','stopping-the-world-admin')
            ,'columns' => 6
            ,'choices' => array(
                    'option1' => 'Stock'
                ,'option2' => 'Print'
                )
            )
        ,array(
                'type' => 'textarea'
            ,'field' => 'photo_description'
            ,'label' => __('Description','stopping-the-world-admin')
            ,'help' => __('Sets the photo description. This will appear bellow the photo and its title on the Gallery Folder post.','stopping-the-world-admin')
            ,'columns' => 6
            ,'attributes' => array(
                    'rows' => 5
                ,'cols' => 60
                ,'placeholder' => __('Describe this photo...', 'stopping-the-world-admin')
                ,'maxlength' => '320'
                )
            )
        )
    ));

    Gallery Folder Display Setting meta box:

    <?php
    /*
    Title: <h3>Gallery Folder Display Setting</h3>
    Post Type: post
    Order: 10
    */
    
    piklist('field', array(
        'type' => 'file'
    ,'field' => 'folder_cover_photo'
    ,'label' => __('Folder Cover Photo','stopping-the-world-admin')
    ,'help' => __('Sets the folder folder cover photo of the folder next to the folder title & description on the Galleries Menu page.','stopping-the-world-admin')
    ,'options' => array(
            'modal_title' => __('Set folder cover photo','stopping-the-world-admin')
        ,'button' => __('Set','stopping-the-world-admin')
        )
    ,'required' => true
    ,'columns' => 12
    ,'validate' => array(
            array(
                'type' => 'limit',
                'options' => array(
                    'min' => 1,
                    'max' => 1
                )
            )
        ,array(
                'type' => 'image'
            )
        )
    ));
    
    piklist('field', array(
        'type' => 'text'
    ,'field' => 'folder_title'
    ,'label' => __('Folder Title','stopping-the-world-admin')
    ,'description' => __('(Max 60 characters.)', 'stopping-the-world-admin')
    ,'help' => __('Sets the folder title. This will appear above the folder description and next to the folder cover photo on the Gallery page.','stopping-the-world-admin')
    ,'required' => true
    ,'columns' => 12
    ,'attributes' => array(
            'rows' => 4
        ,'cols' => 20
        ,'placeholder' => 'Enter folder title here...'
        ,'maxlength' => '60'
        ,'class' => 'centered-text'
        )
    ));
    
    piklist('field', array(
        'type' => 'textarea'
    ,'field' => 'folder_description'
    ,'label' => __('Folder Description','stopping-the-world-admin')
    ,'description' => __('(Max 220 characters.)', 'stopping-the-world-admin')
    ,'help' => __('Sets the folder description. This will appear bellow the folder title and next to the folder cover photo on the Gallery page.','stopping-the-world-admin')
    ,'columns' => 12
    ,'attributes' => array(
            'rows' => 5
        ,'cols' => 50
        ,'placeholder' => __('Describe this gallery folder...', 'stopping-the-world-admin')
        ,'maxlength' => '220'
        )
    ));
    
    // Register checkbox that will control conditionally the displaying of the CSS settings options below
    piklist('field', array(
        'type' => 'radio'
    ,'field' => 'custom_css'
    ,'label' => 'Customize CSS'
    ,'help' => __('Check this box to adjust some styling parameters on the folder\'s title, description and containing box.', 'stopping-the-world-admin')
    ,'columns' => 12
    ,'attributes' => array(
            'class' => 'text custom-folder-info'
        )
    ,'choices' => array(
            'no' => __('No', 'stopping-the-world-admin')
        ,'yes' => __('Yes', 'stopping-the-world-admin')
        )
    ,'value' => 'no'
    ));
    
    // Register the folder info box field group
    piklist('field', array(
        'type' => 'group'
    ,'field' => 'folder_info_box_css'
    ,'label' => '<span class="mnl-setting-tab-inner-title">' . __('Folder Info Box CSS','stopping-the-world-admin') . '</span>'
    ,'fields' => array(
            array( // Register the info spacing field
                'type' => 'text'
            ,'field' => 'folder_info_spacing'
            ,'label' => __('Spacing between the Title and the Description', 'stopping-the-world-admin')
            ,'help' => __('Sets the space between the Folder Title and its Description which appear next to the folder\'s Cover Photo on the Galleries Menu pages. The margin CSS unit used here will be a percentage of the width of the containing box to ensure mobile responsiveness.', 'stopping-the-world-admin')
            ,'attributes' => array(
                'class' => 'number'
            ,'placeholder' => '1.3'
            )
            ,'validate' => array(
                array(
                    'type' => 'range'
                ,'options' => array(
                    'min' => 0
                ,'max' => 25
                )
                )
            )
            )
        )
    ,'conditions' => array(
            array(
                'field' => 'custom_css'
            ,'value' => 'yes'
            )
        )
    ));
    
    // Register the folder title field group
    piklist('field', array(
        'type' => 'group'
    ,'field' => 'folder_title_css'
    ,'label' => '<span class="mnl-setting-tab-inner-title">' . __('Folder Title CSS','stopping-the-world-admin') . '</span>'
    ,'fields' => array(
            array( // Register the title font size field
                'type' => 'text'
            ,'field' => 'font_size'
            ,'label' => __('Font Size <span class="mnl-label-comment">(4 decimals max.)</span>', 'stopping-the-world-admin')
            ,'help' => 'Sets the font size of the Folder Title which appear next to the folder\'s Cover Photo on the Galleries Menu pages. The CSS unit used here will be in \'em\' and thus will depend on the parent element font size.'
            ,'columns' => 12
            ,'attributes' => array(
                'class' => 'number'
            ,'placeholder' => '1.525'
            )
            ,'validate' => array(
                array(
                    'type' => 'range'
                ,'options' => array(
                    'min' => 0
                ,'max' => 25
                )
                )
            )
            )
        ,array( // Register the title line height field
                'type' => 'text'
            ,'field' => 'line_height'
            ,'label' => __('Line Height <span class="mnl-label-comment">(3 decimals max.)</span>', 'stopping-the-world-admin')
            ,'help' => 'Sets the line height of the Folder Title which appear next to the folder\'s Cover Photo on the Galleries Menu pages. No CSS unit is used here.'
            ,'columns' => 12
            ,'attributes' => array(
                    'class' => 'number'
                ,'placeholder' => '1.5'
                )
            ,'validate' => array(
                    array(
                        'type' => 'range'
                    ,'options' => array(
                        'min' => 0
                    ,'max' => 25
                    )
                    )
                )
            )
        ,array( // Register the title letter spacing field
                'type' => 'text'
            ,'field' => 'letter_spacing'
            ,'label' => __('Letter spacing <span class="mnl-label-comment">(3 decimals max.)</span>', 'stopping-the-world-admin')
            ,'help' => 'Sets the letter spacing of the Folder Title which appear next to the folder\'s Cover Photo on the Galleries Menu pages. The CSS unit used here will be in \'em\' and thus will depend on the parent element font size.'
            ,'columns' => 12
            ,'attributes' => array(
                    'class' => 'number'
                ,'placeholder' => '.1'
                )
            ,'validate' => array(
                    array(
                        'type' => 'range'
                    ,'options' => array(
                        'min' => 0
                    ,'max' => 10
                    )
                    )
                )
            )
        )
    ,'conditions' => array(
            array(
                'field' => 'custom_css'
            ,'value' => 'yes'
            )
        )
    ));
    
    // Register the folder description field group
    piklist('field', array(
        'type' => 'group'
    ,'field' => 'folder_desc_css'
    ,'label' => '<span class="mnl-setting-tab-inner-title">' . __('Folder Description CSS','stopping-the-world-admin') . '</span>'
    ,'fields' => array(
            array( // Register the description font size field
                'type' => 'text'
            ,'field' => 'font_size'
            ,'label' => __('Font Size <span class="mnl-label-comment">(4 decimals max.)</span>', 'stopping-the-world-admin')
            ,'help' => 'Sets the font size of the Folder description which appear next to the folder\'s Cover Photo on the Galleries Menu pages. The CSS unit used here will be in \'em\' and thus will depend on the parent element font size.'
            ,'columns' => 12
            ,'attributes' => array(
                'class' => 'number'
            ,'placeholder' => '.08'
            )
            ,'validate' => array(
                array(
                    'type' => 'range'
                ,'options' => array(
                    'min' => 0
                ,'max' => 25
                )
                )
            )
            )
        ,array( // Register the description line height field
                'type' => 'text'
            ,'field' => 'line_height'
            ,'label' => __('Line Height <span class="mnl-label-comment">(3 decimals max.)</span>', 'stopping-the-world-admin')
            ,'help' => 'Sets the line height of the Folder description which appear next to the folder\'s Cover Photo on the Galleries Menu pages. No CSS unit is used here.'
            ,'columns' => 12
            ,'attributes' => array(
                    'class' => 'number'
                ,'placeholder' => '1.5'
                )
            ,'validate' => array(
                    array(
                        'type' => 'range'
                    ,'options' => array(
                        'min' => 0
                    ,'max' => 25
                    )
                    )
                )
            )
        ,array( // Register the description letter spacing field
                'type' => 'text'
            ,'field' => 'letter_spacing'
            ,'label' => __('Letter spacing <span class="mnl-label-comment">(3 decimals max.)</span>', 'stopping-the-world-admin')
            ,'help' => 'Sets the letter spacing of the Folder description which appear next to the folder\'s Cover Photo on the Galleries Menu pages. The CSS unit used here will be in \'em\' and thus will depend on the parent element font size.'
            ,'columns' => 12
            ,'attributes' => array(
                    'class' => 'number'
                ,'placeholder' => '.1'
                )
            ,'validate' => array(
                    array(
                        'type' => 'range'
                    ,'options' => array(
                        'min' => 0
                    ,'max' => 10
                    )
                    )
                )
            )
        )
    ,'conditions' => array(
            array(
                'field' => 'custom_css'
            ,'value' => 'yes'
            )
        )
    ));
    
    Mehdi Salem
    Member

    Thanks Jason! I will elaborate asap a little later today, I have to run to an appointment right now

    in reply to: Is it true that Piklist is dead? #7515
    Mehdi Salem
    Member

    Thanks for the update!

    Mehdi Salem
    Member

    BIG OOOOOPS!!! What I described above is not a bug…

    In fact, I had the same meta box group set as an add_more before. Since I had issues with Javascript performance when I passing 15 add_more boxes, I changed the structure of the group, dropping the add_more feature but kept the same name and since I had some updated_post_meta action that was necessary ti fix a bug with the add_more group, I did completely forgot about it and it was messing the metadata with the new field structure because it is using the array_values php function…

    I will open a new ticket about add_more bug when I’ll have time

    My sincere apologies guys!!!

    in reply to: Is it true that Piklist is dead? #7511
    Mehdi Salem
    Member

    As far as I can see, Steve’s last answer is dated of Nov 07, right before the election day… I hope he did not move to Canada hahaha…

    I apologize for the joke and the bellow, this is not a forum I know but if we will be supporting Piklist in the future, we need to have a clear vision.

    Let’s give the support team some time to react and see, maybe they are on a break or there is a personal matter going on, they have a small team and this is all free for now.

    On the other hand, I noticed that the WordPress repository policy will start to be enforced more severely and will not be allowing frameworks there anymore… and recommend to include frameworks in plugins instead. (https://wptavern.com/the-wordpress-plugin-directory-will-no-longer-accept-frameworks)

    Previously allowed frameworks like Piklist do not seem to be affected by this new resolution for now though.

    When you’ll get a chance Steve please, could you let us know what to expect from Piklist on the long run and if there will be repercussions on Piklist due to the new WordPress repo resolutions? Will Piklist have to pivot?

    As a developer who relies currently on Piklist I’m admitting today that I will eminently have to make a choice… I may have to switch towards the old way and write my own classes instead of depending on somebody else’s code.

    I love Piklist and I add my voice to dameer’s to say that I would gladly pay for a long term support version. What about a yearly fee?

    How can we move forward safely?

    Regards

    Mehdi Salem
    Member

    Thanks for your feedback and I respect your point of view.

    I’m not affiliated to Piklist in any way, however, I believe that Piklist coding standards are high and that it can be a great tool for developers if the community starts supporting it.

    This is just my point of view and keep in mind that Piklist is still in beta and mostly targeting developers for now 😉

    Best regards

    Mehdi Salem
    Member

    Here is a temporary ugly fix I made in case somebody needs it while you guys are hopefully trying to fix this in core:

    Replace of course the value of the MY_CORRUPTED_METADATA_META constant according to your fields

    if( ! function_exists( 'hdev_filter_piklist_corrupted_metadata' ) )
    {
       /**
        * Define field group fields constant and apply filter
        */
       function hdev_filter_piklist_corrupted_metadata()
       {
          // Define all the meta keys we want to process here as an array constant [string META_KEY => array FIELDS] (make sure to include all the groups fields in the right order)
          define( 'MY_CORRUPTED_METADATA_META', array( 'folder_content_group' => array( 'folder_title', 'single_photo' ) ) );
    
          // Hook filter
          add_filter( 'update_post_metadata', 'hdev_overwrite_piklist_corrupted_metabox_fields', 10, 5 );
       }
    }
    add_action( 'init', 'hdev_filter_piklist_corrupted_metadata' );
    
    if( ! function_exists( 'hdev_overwrite_piklist_corrupted_metabox_fields' ) )
    {
       /**
        * Overwrite Piklist corrupted post metadata with correct value before it is added to the database
        *
        * @param $null
        * @param $object_id
        * @param $meta_key
        * @param $meta_value
        * @param $prev_value
        * @return bool|null
        */
       function hdev_overwrite_piklist_corrupted_metabox_fields( $null, $object_id, $meta_key, $meta_value, $prev_value ) {
    
          // Loop through meta keys associated with potential corruptible metadata
          foreach( MY_CORRUPTED_METADATA_META as $corrupted_meta_key => $corrupted_metadata_fields )
          {
             // Possible correct data if processing potential corruptible metadata
             if ( $corrupted_meta_key == $meta_key )
             {
                // do nothing and continue normal execution if new value is empty
                if (  empty( $meta_value ) ) {
                   return null;
                }
    
                // Initialize new meta value var
                $corrected_meta_value = array();
    
                // Initialize key count
                $key = 0;
    
                // Loop through all the filed group fields defined earlier in the constant
                foreach( $corrupted_metadata_fields as $corrupted_metadata_field )
                {
                   // Make sure the new meta value is corrupted, correct if necessary
                   if ( ! array_key_exists( $corrupted_metadata_field, $meta_value ) )
                   {
                      // Correct
                      $corrected_meta_value[$corrupted_metadata_field] = $meta_value[$key];
                      $key++;
                   }
                   else
                   {
                      // Do not correct
                      $corrected_meta_value[$corrupted_metadata_field] = $meta_value[$corrupted_metadata_field];
                      $key++;
                   }
                }
    
                // continue normal execution if meta value was not corrupted
                if( $corrected_meta_value == $meta_key ) {
                   return null;
                }
    
                // Unhook just in case
                remove_filter( 'update_post_metadata', 'hdev_overwrite_piklist_corrupted_metabox_fields', 10 );
    
                update_post_meta( $object_id, $corrupted_meta_key, $corrected_meta_value );
    
                // Reapply hook
                add_filter( 'update_post_metadata', 'hdev_overwrite_piklist_corrupted_metabox_fields', 10, 5 );
    
                return true; // Stop normal execution
             }
          }
    
          return null; // continue normal execution
       }
    }
    Mehdi Salem
    Member

    Here is something weird worth noticing:
    I’m hooking into the update_post_metadata filter to correct the issue on the fly. I tested trying to grab what’s in the $prev_value variable and guess what, IT IS ALWAYS EMPTY… even if a previous value for the postmeta was already set

    in reply to: Advice for sorting by date (with Date Picker) #4640
    Mehdi Salem
    Member

    Hello Guys, I just remembered that I wrote a complete stable solution just with WordPress action hooks for this that works really well. You can include this in your plugin or theme’s function.php, just replace my field names and post types with yours. This module will insure that your date picker fields will be saved in timestamp format in the database so your plugins will be able to compare dates directly. It will also make sure that this data will be displayed as a clear date format wherever you want to display it, front & admin. Here is the code:

    <?php
    
    if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    /**
     * START PIKLIST DATE PICKER ACTIONS & FILTERS: SAVE AS TIMESTAMP BUT DISPLAY AS DATE IN ADMIN EDIT
     */
    
    // Change the meta data after a post is saved
    add_action( 'save_post', 'hdev_update_meta_data' );
    function hdev_update_meta_data( $post_id ) {
    
       // If this is just a revision, don't do anything.
       if ( wp_is_post_revision( $post_id ) )
          return;
    
       global $post;
       $post_type = $post->post_type;
    
       /* ******* Change piklist date picker saved date to timestamp format for easy date comparison when needed **** */
    
       // Make sure any date will be saved in PDT LA Time timestamp format
       date_default_timezone_set('America/Los_Angeles'); /** USE YOUR DESIRED TIMEZONE HERE -- IMPORTANT TO AVOID YOUR DATE FROM BEING CHANGED TO A SLIGHTLY DIFFERENT ONE EACH TIME TIME YOU SAVE YOUR POST */
    
       if($post_type =='new') // Apply changes only to desired post_types metadata
       {
          $listing_start_date_stamp = strtotime(get_post_meta($post_id, 'YOUR_listing-start-date', true));
          $listing_end_date_stamp = strtotime(get_post_meta($post_id, 'YOUR_listing-end-date', true));
          update_post_meta($post_id, 'YOUR_listing-start-date', $listing_start_date_stamp);
          update_post_meta($post_id, 'YOUR_listing-end-date', $listing_end_date_stamp);
       }
       if(in_array($post_type, array('page', 'post', 'YOUR_OTHER_POST_TYPES_HERE'))) // Apply changes only to desired post_types metadata
       {
          $event_listing_start_date_stamp = strtotime(get_post_meta($post_id, 'YOUR_event-listing-start-date', true));
          $event_listing_end_date_stamp = strtotime(get_post_meta($post_id, 'YOUR_event-listing-end-date', true));
          update_post_meta($post_id, 'YOUR_event-listing-start-date', $event_listing_start_date_stamp);
          update_post_meta($post_id, 'YOUR_event-listing-end-date', $event_listing_end_date_stamp);
       }
    
       /* *************************************************** */
    
    }
    
    // Change the meta data just when displaying it on the admin edit page but keep it unchanged in the database
    add_filter( 'get_post_metadata', 'hdev_convert_timestamp_to_date', 99, 4 );
    function hdev_convert_timestamp_to_date($metadata, $object_id, $meta_key, $single){
    
       if(is_admin() && isset( $meta_key ) && in_array($meta_key, array('YOUR_listing-start-date', 'YOUR_listing-end-date', 'YOUR_event-listing-start-date', 'YOUR_event-listing-end-date')))
       {
          //  Remove this very same filter to avoid infinite loop
          remove_filter( 'get_post_metadata', 'hdev_convert_timestamp_to_date', 99 );
          $meta_value = get_post_meta( $object_id, $meta_key, TRUE );
          add_filter('get_post_metadata', 'hdev_convert_timestamp_to_date', 99, 4);
    
          // Convert meta value from timestamp to readable (MM d, yy) date format and return it
          if(hdev_is_timestamp($meta_value)) // Check to avoid passing a date to date() instead of a timestamp - case happens during above save_post hook on get_post_meta call while date not converted yet to timestamp...
          {
             return date("F d, Y", $meta_value);
          }
       }
    
       // Return original if the check does not pass
       return $metadata;
    
    }
    
    /**
     * Checks if a string is a valid timestamp.
     *
     * @param  string $timestamp Timestamp to validate.
     *
     * @return bool
     */
    function hdev_is_timestamp($timestamp)
    {
       $check = (is_int($timestamp) OR is_float($timestamp))
             ? $timestamp
             : (string) (int) $timestamp;
       return  ($check === $timestamp)
               AND ( (int) $timestamp <=  PHP_INT_MAX)
                   AND ( (int) $timestamp >= ~PHP_INT_MAX);
    }
    
    /** END PIKLIST DATE PICKER CUSTOM **********************************************/
    
    
    in reply to: Limit validation broken with add_more #4570
    Mehdi Salem
    Member

    Hello Steve,

    In addition to the problem described above, I discovered another important hidden issue with the limit validation process.

    Here is the case:

    1. I set the limit to 1 file upload in my file upload meta-box field (set to required)
    2. Then I edit my post and upload 1 image file to the field & save the post
    3. I go to the media library and delete the image I just uploaded (simulating a real case where for some reason the uploaded file is missing from the server or got deleted Inadvertently)
    4. I go back to editing my post and obviously the file preview is gone (for now it still seems okay)
    5. I click the “Set” button to upload another image file (still working okay here)
    6. The if I try to update the post and save my changes with the freshly added image I get the following validation error message: “Folder Cover Photo must have exactly 1 items added.2
    7. Another issue is that if I do not try to add the image back and save the post it will update without throwing a validation error even though the file upload field is required and seems empty!

    So basically if for some reason the file or image gets deleted from the media Library, the post is stuck in that state as my file upload field is a required one… Only intervention in the database can unlock this
    ps: not also the typo in the error message… the dot should be after ‘items’ 😉

    Thank you guys for looking at all this and here is a sample code to reproduce the issue:

    <?php
    /*
    Title: Gallery Folders Listing
    Post Type: post
    Order: 10
    */
    
    piklist('field', array(
          'type' => 'file'
    ,'field' => 'folder_cover_photo'
    ,'label' => __('Folder Cover Photo','stopping-the-world-admin')
    ,'description' => __('Give a taste of the folder\'s content.', 'stopping-the-world-admin')
    ,'help' => __('Sets the folder folder cover photo of the folder next to the folder title & description on the Gallery page.','stopping-the-world-admin')
    ,'options' => array(
                'modal_title' => __('Set folder cover photo','stopping-the-world-admin')
          ,'button' => __('Set','stopping-the-world-admin')
          )
    ,'required' => true
    ,'columns' => 12
    ,'validate' => array(
                array(
                      'type' => 'limit',
                      'options' => array(
                            'min' => 1,
                            'max' => 1
                      )
                )
          ,array(
                      'type' => 'image'
                )
          )
    ));
    
    in reply to: Nested group fields containing add_more: BUG on save #4542
    Mehdi Salem
    Member

    I noticed this bug while testing Piklist 0.9.9.2 by the way, did not test on other versions

Viewing 15 posts - 1 through 15 (of 28 total)