Support Forum » User Profile

Forum Replies Created

Viewing 14 posts - 46 through 59 (of 59 total)
  • Author
    Posts
  • in reply to: Need a filter before save field #9005
    pluginovenpluginoven
    Participant

    It 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.

    pluginovenpluginoven
    Participant

    Issue can be marked as resolved.

    pluginovenpluginoven
    Participant

    Here 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>';
    			}
    		}
    	}
    }
    pluginovenpluginoven
    Participant

    Uggg... again with the markdown. Please wrap that last code in proper backticks.

    pluginovenpluginoven
    Participant

    I 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!

    pluginovenpluginoven
    Participant

    Update: 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....

    pluginovenpluginoven
    Participant

    Thank you for fixing the link in the initial post. Should read:
    There is currently no support for the <optgroup> tag in the Select and Select-Advanced field types...

    pluginovenpluginoven
    Participant

    Looks like I missed the closing a tag on the link to optgroup. Sorry, wish I could edit, but that's not possible.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8929
    pluginovenpluginoven
    Participant

    Anh, 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.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8927
    pluginovenpluginoven
    Participant

    HA! 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.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8925
    pluginovenpluginoven
    Participant

    At 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.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8921
    pluginovenpluginoven
    Participant

    Update!

    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...

    in reply to: Suppress Error Message before Meta-Box-Groups is Activated #2636
    pluginovenpluginoven
    Participant

    This 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.

    in reply to: Change clone buttontext #690
    pluginovenpluginoven
    Participant

    Thank you kindly! We have updated the plugin and our code and it is, in fact, working! However, we are getting the following php Warnings:

    First, with meta-box-group 1.01 installed and the filter added, the following warning is displayed on the edit page where the clone-able meta-boxes are installed:

    Warning: Missing argument 1 for RWMB_Group_Field::add_clone_button() in .../wp-content/plugins/meta-box-group/class-rwmb-group-field.php on line 140 Notice: Undefined variable: field in .../wp-content/plugins/meta-box-group/class-rwmb-group-field.php on line 142

    Fix:
    We fixed this by making the following change to the add_clone_button function:

    static function add_clone_button( $field = '' ){
    	$text = apply_filters( 'rwmb_group_add_clone_button_text', __( '+ Add more', 'meta-box-group' ), $field );
    	return "<a href='#'' class='rwmb-button button-primary add-clone'>".$text."</a>";
    }
    

    Next, with the meta-box-group plugin de-activated, we are seeing the following php warnings in all pages of the dashboard:

    Warning: call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in .../wp-content/plugins/meta-box/inc/meta-box.php on line 402 Warning: call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in .../wp-content/plugins/meta-box/inc/meta-box.php on line 80

    will we also need to update the meta-box plugin as well?

Viewing 14 posts - 46 through 59 (of 59 total)