Forum Replies Created
-
AuthorPosts
-
JasonKeymasterHahah! Yeah.. I hear that. Piklist is super awesome.. but still in beta. 😉
I think what I would do is make my own little function for handling this issue personally:
function get_single_post_meta($id, $key) { $meta = get_post_meta($id, $key, true); return ( is_array($meta) && count($meta) == 1 ) ? $meta[0] : $meta; }That will at least save you a line of code wherever you have the issue. 🙂
JasonKeymasterWhoops! Never noticed that. Thanks, Steve!
JasonKeymasterCheck this out on how to create custom validations: https://piklist.com/user-guide/
You can also see an example of a date validation I made in my PiklistHelper class (free to use): https://gist.github.com/JasonTheAdams/4a9fc4b2ad0104ab219f (search for “check_date_range).
What you’ll need to do is use the strtotime() function with something like strtotime(‘-2 weeks’), then compare the user date to that date.
Hope this helps! 🙂
JasonKeymasterThat’s definitely a thought. I’ve run into that one before. I’m not sure I’d agree that single should always return a single, though. Technically, it does return a single database row, it’s just serialized. Groups, for example, ought to be retrieved as a single row, but certainly aren’t a single value.
I’ve mentioned this to Steve in the past, but I feel the proper solution would be to provide field qualifiers (implicitly, one called “multiple” is already used). This would also help build a foundation for custom fields down the road.
Maybe I’m over-complicating, but I’d be leery to return a string every time an array had a single value (even in the circumstance that $single === true). I think it’d be better to handle this sort of thing on insertion, rather than retrieval.
September 4, 2014 at 3:46 pm in reply to: Do admin page setting changes require manage_options permission? #2374
JasonKeymasterI just tested this.. and the hook name {option_page} is misleading. Don’t use the menu slug, as that doesn’t work. Use the setting. The following works:
add_filter('piklist_post_types', 'add_program_post_type'); function add_program_post_type( $post_types ) { $post_types[PROGRAM_TYPE] = array( 'labels' => piklist('post_type_labels', 'Program'), 'title' => __('Title'), 'supports' => array( 'title' ), 'public' => true, 'has_archive' => true, 'rewrite' => array( 'slug' => 'does' ), 'capability_type' => 'post', 'hide_meta_box' => array( 'slug' ), 'post_states' => false ); return $post_types; } add_filter('piklist_admin_pages', 'add_program_admin_pages'); function add_program_admin_pages($pages) { $pages[] = array( 'page_title' => __('Archive Settings'), 'menu_title' => __('Archive Settings'), 'sub_menu' => 'edit.php?post_type=' . PROGRAM_TYPE, 'capability' => 'edit_others_posts', 'menu_slug' => 'program-archive-settings', 'setting' => 'program-settings' ); return $pages; } add_filter('option_page_capability_program-settings', 'set_program_archive_capability'); function set_program_archive_capability() { return 'edit_others_posts'; }Notice that I’m using “program-settings” in the hook, not “program-archive-settings”.
September 4, 2014 at 3:16 pm in reply to: Do admin page setting changes require manage_options permission? #2373
JasonKeymasterWow, that’s one of those annoying, undocumented hooks: http://wphooks.info/filters/option_page_capability_%7B$option_page%7D/
@Steve, it’d probably be a publicly spirited move to include information about this hook in the settings doc.
September 4, 2014 at 2:32 pm in reply to: Do admin page setting changes require manage_options permission? #2371
JasonKeymasterAh, I see what you’re saying. Well.. that does make sense. The capability provided simply determines whether or not the capability necessary for the page to show up. But it would seem like a WordPress limit that only users with “manage_options” can actually.. manage options. 🙂
I assume Piklist is only passing that parameter along since it’s there in add_menu_page. In that context, though, you might make a page for displaying data, etc., so you’re not always saving settings. I guess the benefit here is that at least users without said capability can at least view the settings.
September 4, 2014 at 2:18 pm in reply to: Do admin page setting changes require manage_options permission? #2369
JasonKeymasterThe “capability” element is simply a way to limit what level of capabilities the user has to have in order to save. You can use any of the capabilities listed here: http://codex.wordpress.org/Roles_and_Capabilities
If you don’t want “manage_options” (administrator capability) level necessary, then select a capability from a lower role. For example, “edit_other_posts” would require them to be at least an Editor.
Hope this helps!
JasonKeymasterI made some revisions to PiklistHelper:
- Consolidated piklist_validation_rules hooks to a single function.
- Added further docblock information to indicate when functions were added.
- Added a new validation, ‘group-mismatch’ that checks every field in a group to make sure no two fields have the same value.
Happy coding!
August 29, 2014 at 2:52 pm in reply to: Taxonomies inside add more advanced fields in custom post types #2347
JasonKeymasterI wouldn’t say it’s a limitation of the select field in Piklist, as much as in general. Outside of a fields that provides options as you search, I can’t think of a UI element that provides options while simultaneously being changeable. Sort of defeats the purpose.
If I really want fields, in Piklist, to be definable, and they don’t come from a post type, taxonomy, etc., then I often make a “Settings” section somewhere and provide the ability to define stuff there. So, for example, I’d have a “Programs” repeatable text field. I’d then pull the options when making the meta-box and use those for the list.
Hope this helps!
August 29, 2014 at 2:25 pm in reply to: Taxonomies inside add more advanced fields in custom post types #2344
JasonKeymasterAh, I think I see what you’re saying. So you want the Program select to be an adjustable list of items. A combobox is what’s coming to mind: http://jsfiddle.net/ivkremer/yq2TD/
Is that along what you’re thinking? Otherwise you can’t have a disassociated taxonomy; it has to belong to a post type. You could always create a post type that’s publicly invisible or create an admin page and have the list generated from an add_more there.
Help me to know if I’m thinking in the right direction.
August 29, 2014 at 2:02 pm in reply to: Taxonomies inside add more advanced fields in custom post types #2341
JasonKeymasterThanks for posting the code and picture! That helps!
I’m still a bit unclear as to where the taxonomy fits in all this. Are you saying you want to list taxonomies into a select? or are you trying to list all the terms of a specific taxonomy into a select?
We’ll get there! 😉
August 29, 2014 at 1:34 pm in reply to: Taxonomies inside add more advanced fields in custom post types #2339
JasonKeymasterI’m sorry, can you please try explaining that differently? I follow that you have an add_more group and want to do something with it concerning taxonomies, but that’s as much as I’m understanding. Have you tried doing what your explaining? Do you have any code (even not working) that you could show?
JasonKeymasterThe only reason I don’t think so, is because admin-pages can’t be included as tabs of a setting.. can they?
August 26, 2014 at 8:01 pm in reply to: Pulling data from custom field and use it in place of Title of Custom Post Type #2325
JasonKeymasterAhhh.. We’re talking in the wrong direction, then. What you want to do is change where that column is getting it’s value. That’s a totally different route. Checkout what I put here:
https://piklist.com/support/topic/can-piklist-enable-significant-customizing-of-list-tables/
Hope this helps!
-
AuthorPosts