Forum Replies Created
-
AuthorPosts
-
Alex KladovParticipantHi @mcmaster,
Thanks for the suggestion. It’s a handy little extractor function for sure. However, when would it ever be a nested array in this scenario? Just seems like an overkill for this simple scenario..
Plus, I don’t like that it adds a level of uncertainty to the expected functionality. Instead of checking, if it
is_array(), and then looping through that array until you hit a simple value, I would much rather check foris_int()and abort in all other cases. Because I can’t know what the hell Piklist added into those nested arrays (since they shouldn’t even be arrays to begin with), so even the first values can’t be fully trusted. What if it decides to return an Object or basically anything else, that’s not an int. I can’t trust any of those values.But for now, given that I know the exact problem, I am just trusting that Piklist will add the right value in the first position, even if it’s in an array, and then I grab that value, after checking with a simple inline
! is_array( $app_settings['max_past_orders_to_show'] ) ? '' : $app_settings['max_past_orders_to_show']before I use it. But it’s definitely a bug that should be fixed, since there is no reason it should be saved as an array in this situation. It’s just bound to cause problems down the road, when this will be fixed one day.
Alex KladovParticipantI knew that had something to do with it! Because it was one of the only configuration differences between the two..
Please let me know here if/when you will release a patch for it. Because right now I was forced to use a workaround for it and request that value like this:
$app_settings = get_option('app_settings'); $max_past_orders_to_show = $app_settings['max_past_orders_to_show'][0];So if you would fix this bug, and field like this would revert to being a regular
int, that will break my plugin’s functionality (plus I might not be the only one who had to resort to this “hackery”).
Alex KladovParticipantHi @Steve,
Piklist settings are saved using the WordPress settings api, which saves all data as an array.
I understand that. My settings page looks something like this:
<?php /** * Title: General * Tab: General * Setting: app_settings * Flow: App Workflow **/ piklist( 'field', array( 'type' => 'number', 'field' => 'sync_frequency', 'label' => __( 'Sync Frequency', 'app_domain' ), 'help' => __( 'How often do you want to pull data from XYZ Service?', 'app_domain' ), 'description' => __( 'Set data sync frequency (in minutes). A lower value will lead to a more frequent synchronisation sycle & therefore might use more server resources. If you notice a significant performance impact, try increasing this value.', 'app_domain' ), 'value' => 1, 'columns' => 3, 'required' => true, 'attributes' => array( 'min' => 1, 'step' => 1, ), 'attributes' => array( 'required' => 'required', // HTML 5 validation ), 'validate' => array( array( 'type' => 'limit', 'options' => array( 'min' => 1, ), ), ), ) ); piklist( 'field', array( 'type' => 'number', 'field' => 'max_past_orders_to_show', 'label' => __( 'Past Orders to Display', 'app_domain' ), 'help' => __( 'Maximum number of Past Orders to display by default.', 'app_domain' ), 'description' => __( 'Set to 0 to always show all past orders right away. This will also permanently hide "Show All Past Orders" button. ', 'app_domain' ), 'value' => 20, 'columns' => 3, 'required' => true, 'attributes' => array( 'min' => 0, 'step' => 5, 'required' => 'required', // HTML 5 validation ), 'validate' => array( array( 'type' => 'limit', 'options' => array( 'min' => 0, ), ), ), ) );However, when I run
var_export( get_option( 'app_settings' ) );I get:array ( 'sync_frequency' => '1', 'max_past_orders_to_show' => array ( 0 => '10', ), )Why is
sync_frequencysaved as astring(which could be casted to aninteasily, so it’s ok), yetmax_past_orders_to_show, which is setup exactly the same way, is saved as anarrayofstrings? It’s so strange. I didn’t set it up to be a repeater field, why is Piklist doing it?
Alex KladovParticipantI see, fair enough. It’s definitely possible that it’s an actual bug.
Can you paste your
piklist( 'field', array(...) );code here? Maybe I’ll be able to find something.
Alex KladovParticipantHi @devr51! I was just working on File field myself, so thought I’d chime in.
In Piklist’s Developer Documentation for File (Upload) Field, they state that you need to omit
'basic' => trueunderoptions, if you want to use “WordPress media uploader”, otherwise it will use the “basic uploader”.So if you have something like this:
piklist( 'field', array( 'type' => 'file', 'field' => 'my_upload_field', 'label' => 'Upload Field', 'options' => array( 'basic' => true, // <=== REMOVE THIS, if you want to use WordPress media uploader 'button' => 'Add Image', 'preview_size' => 'medium', ), ) );Change it to this:
piklist( 'field', array( 'type' => 'file', 'field' => 'my_upload_field', 'label' => 'Upload Field', 'options' => array( 'button' => 'Add Image', 'preview_size' => 'medium', ), ) );And it should switch to using “WordPress media uploader”.
Alex KladovParticipant@Steve Sorry to bump an old thread, didn’t want to create one, since this discussion already exists.
Is this still in the works 4 years later? Or is there a single file select feature already available (i.e. like WordPress Featured Image field), but just not documented?
I am not talking about back-end validation, I already use that one and it works great. Just would be a nice from UI/usability perspective to disallow multi-file selection on the front-end as well, as to not confuse the users with unnecessary errors.
December 26, 2018 at 10:04 pm in reply to: Piklist + Divi are crashing the admin Pages in WP dashboard #9266
Alex KladovParticipantHi Steve,
Thanks so much for the quick fix (I believe the latest v1.0.2 has addressed this bug):
Merry Christmas,
AlexDecember 19, 2018 at 8:34 am in reply to: Piklist + Divi are crashing the admin Pages in WP dashboard #9253
Alex KladovParticipantHi Steve,
Thank you for your response.
Yes, I have logged a ticket with them regarding this issue and they have found a fix. Apparently Piklist was modifying the
$post_statesarray and turning it into aNULLvariable and they weren’t checking it, before trying to iterate through it to add their own status to pages, which was causing a fatal crash. Now they’ve implemented a fix, the issue is gone.If anyone is experiencing this issue, and wants to fix it before they will include this bug fix into their official release, you need to modify this file
/wp-content/themes/Divi/includes/builder/feature/BlockEditorIntegration.php. You need to find functiondisplay_post_states(right it’s starting on line 288) and replace all of it with:/** * Add 'Divi' to post states when builder is enabled for it. * * @param array $post_states Existing post states. * @param object $post Current post object. * * @return array */ public function display_post_states( $post_states, $post ) { // Make sure that $post_states is an array. Third party plugin might modify $post_states and makes it null // which create various issue (i.e. Piklist + Having a page configured as a static page) if ( ! is_array( $post_states ) ) { $post_states = array(); } if ( et_pb_is_pagebuilder_used( $post->ID ) ) { // Remove Gutenberg if existing $key = array_search( 'Gutenberg', $post_states ); if ( false !== $key ) { unset( $post_states[ $key ] ); } // GB devs didn't allow this to be translated so why should we ? $post_states[] = 'Divi'; } return $post_states; }However, I think there is still a general issue with Piklist. Why is it modifying the
$post_statesarray and making itNULL? I do not believe that’s an intentional behaviour. So what ends up happening is that Piklist strips all post statuses from pages, which I am pretty sure is a bug. For example, Piklist will cause the “Front Page” post state to not display on the All Pages section in WP Dashboard.Regards,
AlexSeptember 23, 2018 at 8:02 am in reply to: Validation rule or required parameter on a hidden field #9218
Alex KladovParticipantHi Steve,
The bug is still here almost 2 years later. Is there an expected bug fix release date for this?
Cheers,
Alex
Alex KladovParticipantHi Steve,
Thanks for pointing that out! That seems to be what I was looking for so far. Do you perhaps have a code snippet that does what I am looking for (i.e. hide tabs based on Piklist settings page value)?
Also, what about the dependency on hidden fields? Is this expected behaviour or did I stumble onto a bug?
Regards,
Alex -
AuthorPosts