Forum Replies Created
-
AuthorPosts
-
February 12, 2019 at 9:36 PM in reply to: ✅Only auto populate neighborhood field if not empty #13277
pluginoven
ParticipantTwo weeks and crickets... The following changes would need to be made to include the
'bind_if_empty' => false, //default true
idea described above.File: js/mp-geo.js
Line: 85var $this = $( this ), dataBinding = $this.data( 'binding' ), dataBindEmpty = $this.data( 'bind_if_empty' ), addressField = $this.data( 'address_field' ), fieldValue = that.getFieldData( dataBinding, place );File: inc/class-meta-box-geolocation.php
Line: 97$binding = isset( $field['binding'] ) ? $field['binding'] : $this->guessBindingField( $field['id'] ); $bind_if_empty = isset( $field['bind_if_empty'] ) ? $field['bind_if_empty'] : 1; $address_field = isset( $field['address_field'] ) ? $field['address_field'] : ''; if ( $binding ) { $begin .= '<script type="html/template" class="rwmb-geo-binding" data-binding="' . esc_attr( $binding ) . '" data-bind_if_empty="' . esc_attr( $bind_if_empty ) . '" data-address_field="' . esc_attr( $address_field ) ...Would be fantastically 2019 if there was a magical way to submit a pull request.
pluginoven
ParticipantUpdate: I have added a working bind_if_empty. Please me know how best to submit a pull request.
pluginoven
ParticipantIt turns out the values can be easily filtered using the ´rwmb_value´ filter like so:
add_filter( 'rwmb_value', array( $this, 'uncheck_thruthiness' ), 20, 3 ); public function uncheck_thruthiness ( $new, $field, $old ) { if($field['id'] == 'truthiness' && !empty( $field['attributes']['mod_lock'] ) ){ $new = ''; } return $new; }I have a different issue now... This can be marked as resolved. I'll open a new thread.
March 29, 2018 at 3:01 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #9003pluginoven
ParticipantIssue can be marked as resolved.
March 26, 2018 at 10:06 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #8966pluginoven
ParticipantHere are the full selectomatic custom field extended classes based on the Select field:
if ( class_exists( 'RWMB_Field' ) ) { class RWMB_Selectomatic_Field extends RWMB_Select_Field { public static function walk( $field, $options, $db_fields, $meta ) { $attributes = self::call( 'get_attributes', $field, $meta ); $walker = new RWMB_Walker_Selectomatic( $db_fields, $field, $meta ); $output = sprintf( '<select %s>', self::render_attributes( $attributes ) ); if ( false === $field['multiple'] ) { $output .= $field['placeholder'] ? '<option value="">' . esc_html( $field['placeholder'] ) . '</option>' : ''; } $output .= $walker->walk( $options, $field['flatten'] ? - 1 : 0 ); $output .= '</select>'; $output .= self::get_select_all_html( $field ); return $output; } } class RWMB_Walker_Selectomatic extends RWMB_Walker_Select { public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { $label = $this->db_fields['label']; $id = $this->db_fields['id']; $meta = $this->meta; if($depth){ $output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $object->$id ), selected( in_array( $object->$id, $meta ), true, false ), esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object ) ) ); } else{ $output .= sprintf( '<optgroup label="%s">', esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object ) ) ); } } public function rwmb_end_html_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { if(!$depth){ $output .= '</optgroup>'; } } } }March 26, 2018 at 9:27 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #8965pluginoven
ParticipantUggg... again with the markdown. Please wrap that last code in proper backticks.
March 26, 2018 at 9:26 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #8964pluginoven
ParticipantI was able to achieve something building off of the standard select field. I created a new field type called: 'selectomatic' which is defined as so:
array( 'type' => 'selectomatic', 'id' => 'animal_select', 'name' => 'Animals', 'options' => array( array( 'value' => 'monkey', 'label' => 'Monkeys' ), array( 'value' => 'king_kong', 'label' => 'King Kong', 'parent' => 'monkey' ), array( 'value' => 'curious_george', 'label' => 'Curious George', 'parent' => 'monkey' ), array( 'value' => 'donkey', 'label' => 'Donkeys' ), array( 'value' => 'eeyore', 'label' => 'Eeyore', 'parent' => 'donkey' ), array( 'value' => 'guss', 'label' => 'Gus', 'parent' => 'donkey' ), ), 'flatten' => false ),Then I extended the Select Field Class and Select Walker Class like so:
class RWMB_Walker_Selectomatic extends RWMB_Walker_Select { public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { $label = $this->db_fields['label']; $id = $this->db_fields['id']; $meta = $this->meta; if($depth){ $output .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $object->$id ), selected( in_array( $object->$id, $meta ), true, false ), esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object ) ) ); } else{ $output .= sprintf( '<optgroup label="%s">', esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object ) ) ); } } public function rwmb_end_html_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { if(!$depth){ $output .= '</optgroup>'; } } }It's not beautiful, but it's a work-around that... works!
March 24, 2018 at 9:34 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #8948pluginoven
ParticipantUpdate: there seems to be a special field type (not in the documentation, by the way) called a 'select-tree' that was brought up in this thread: https://support.metabox.io/topic/custom-select-tree/
Seems like a better starting point then the standard select field....
March 24, 2018 at 7:30 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #8947pluginoven
ParticipantThank you for fixing the link in the initial post. Should read:
There is currently no support for the<optgroup>tag in theSelectandSelect-Advancedfield types...March 23, 2018 at 7:30 PM in reply to: ✅Option Group support for Select/Select Advanced Field Types #8933pluginoven
ParticipantLooks like I missed the closing a tag on the link to optgroup. Sorry, wish I could edit, but that's not possible.
March 23, 2018 at 3:20 PM in reply to: Using Custom Attributes from rwmb_before_save_post action #8929pluginoven
ParticipantAnh, that worked perfectly! Thank you, thank you, thank you. You can close this issue as resolved. But please don't forget to add this to the documentation... it will save the next person some grey hairs :D.
March 23, 2018 at 3:01 PM in reply to: Using Custom Attributes from rwmb_before_save_post action #8927pluginoven
ParticipantHA! I was actually just in the process of modifying filter.php in a similar way.
Does it make sense to also add a rwmb_before_save_field?
It looks like the values would have already been saved to the default meta_keys in the dB by the time this filter is triggered.Regardless, thank you! I was sure I had missed something.
March 23, 2018 at 2:07 PM in reply to: Using Custom Attributes from rwmb_before_save_post action #8925pluginoven
ParticipantAt this point it seems the only way currently to 'filter' the save process using a fields custom attributes would be to create a series of new custom fields types. These new 'extended' field types would only serve to overwrite the static save method as shown above. There must be a better way to do this.
March 23, 2018 at 12:56 AM in reply to: Using Custom Attributes from rwmb_before_save_post action #8921pluginoven
ParticipantUpdate!
A little deeper and some progress.
I have been able to extend a certain field type like so:if ( class_exists( 'RWMB_Field' ) ) { class RWMB_Monkey_Field extends RWMB_Text_Field { public static function save( $new, $old, $post_id, $field ) { $pre = ''; if(!empty($field['attributes']['mod_lock'])){ $pre = 'pending_'; } if($new !== $old){ $storage->update( $post_id, $pre.$field['id'], $new); } if( empty($new) ){ $storage->delete( $post_id, $pre.$field['id'] ); } } } }However this would require extending every single field type that is in use. Is there not a way to extend the base RWMB_Field class to use a special save function?
Any clue is greatly appreciated...
March 31, 2016 at 11:59 PM in reply to: Suppress Error Message before Meta-Box-Groups is Activated #2636pluginoven
ParticipantThis is what I ended up doing:
I include the meta-box file only if the plugin is activated like so:if ( is_plugin_active( 'tmeta-box-group/meta-box-group.php' ) ){ include ('inc/config-meta-boxes.php'); }NOTE: the folder is now
tmeta-box-group(not sure when this changed) and NOT meta-box-group. -
AuthorPosts