WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
Custom fields conditions (4 posts)

  1. sophos
    Member
    Posted 1 year ago #

    There is new conditions checking in 1.2 and it seems to work wrong. In /wp-content/plugins/types/embedded/classes/conditional/evaluate.php you do a check for all the conditions in function "evulate". Variable $passed is originally false

    /*
     *
     * Since Types 1.2
     * We force initial value to be FALSE.
     * Better to have restricted than allowed because of sensitive data.
     * If conditional is set on field and it goes wrong - better to abort
     * so user can report bug without exposing his content.
     */
    $passed = false;

    Most of times code go to check if all or one condition is passed operating vars $passed_all and $passed_one. After that you check if not all the conditions passed and logic is and or if no one passed and logic is or.

    if ( $count > 1 ) {
    	if ( !$passed_all && $field['data']['conditional_display']['relation'] == 'AND' ) {
    		$passed = false;
    	}
    	if ( !$passed_one && $field['data']['conditional_display']['relation'] == 'OR' ) {
    		$passed = false;
    	}
    }

    And you make $passed "falser" then before. So when it is gonna be true? Isn't better to use instead:

    if ( $count > 1 ) {
    	$passed = !(!$passed_all && $field['data']['conditional_display']['relation'] == 'AND' || !$passed_one && $field['data']['conditional_display']['relation'] == 'OR');
    }

    It help me in most of cases I use conditions of types plugin.

    http://wordpress.org/extend/plugins/types/

  2. sophos
    Member
    Posted 1 year ago #

    Another issue I found: titles of some fields are displayed even if field is hidden. Seems like header goes before div, that has classes "wpcf-wrap wpcf-repetitive-wrapper". (/wp-content/plugins/types/embedded/classes/repeater.php:line 316).
    I moved title just after div. It could make more bugs, but for now working fine :)
    Finished code is:

    // Set title
    // $form[$unique_id . '_main_title'] = array(
    	// '#type' => 'markup',
    	// '#markup' => '<strong>' . $this->title . '</strong><br/>',
    // );
    
    /*
     *
     *
     * Start wrapper
     */
    $form[$unique_id . '_repetitive_wrapper_open'] = array(
    	'#type' => 'markup',
    	'#markup' => ''
    	. '<div id="wpcf_'
    	. $form_id
    	. '_repetitive_wrapper_' . $unique_id
    		. '" class="wpcf-wrap wpcf-repetitive-wrapper" style="' . $css_cd . '"><strong>' . $this->title . '</strong><br/>',
    	);
  3. Srdjan
    Member
    Plugin Author

    Posted 1 year ago #

    Hi sophos,
    about first comment - look for code:

    $passed = wpcf_cd_admin_compare( $condition['operation'],
    $value, $condition['value'] );

    That's where $passed is possibly set to TRUE.

  4. Srdjan
    Member
    Plugin Author

    Posted 1 year ago #

    About second one - you're right and fix is added.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic