$conditions ) : $match_condition_group = true; foreach ( $conditions as $condition ) : $condition = apply_filters( 'wp-conditions\condition', $condition ); // BC helper $wpc_condition = wpc_get_condition( $condition['condition'] ); // Match the condition - pass any custom ($)args as parameters. $match = call_user_func_array( array( $wpc_condition, 'match' ), array( false, $condition['operator'], $condition['value'], $args ) ); // Filter the matched result - BC helper $parameters = array( 'wp-conditions\condition\match', $match, $condition['condition'], $condition['operator'], $condition['value'], $args ); $match = call_user_func_array( 'apply_filters', $parameters ); // Original - simple - way // $match = $wpc_condition->match( false, $condition['operator'], $condition['value'] ); // $match = apply_filters( 'wp-conditions\condition\match', $match, $condition['condition'], $condition['operator'], $condition['value'] ); if ( false == $match ) : $match_condition_group = false; endif; endforeach; // return true if one condition group matches if ( true == $match_condition_group ) : return true; endif; endforeach; return false; } } if ( ! function_exists( 'wpc_sanitize_conditions' ) ) { /** * Sanitize conditions. * * Go over all the conditions and sanitize them. Used when the conditions are being saved. * * @since 1.0.0 * * @param array $conditions The list of conditions. * @return array */ function wpc_sanitize_conditions( $conditions ) { $sanitized_conditions = array(); foreach ( $conditions as $group_key => $condition_group ) : if ( $group_key == '9999' ) continue; // Template group foreach ( $condition_group as $condition_id => $condition_values ) : if ( $condition_id == '9999' ) continue; // Template condition if ( ! isset( $condition_values['value'] ) ) $condition_values['value'] = ''; foreach ( $condition_values as $condition_key => $condition_value ) : switch ( $condition_key ) : default : $condition_value = sanitize_text_field( $condition_value ); break; case 'condition' : $condition_value = sanitize_key( $condition_value ); break; case 'operator' : $condition_value = in_array( $condition_value, array( '==', '!=', '>=', '<=' ) ) ? $condition_value : '=='; break; case 'value' : if ( is_array( $condition_value ) ) : $condition_value = array_map( 'sanitize_text_field', $condition_value ); elseif ( is_string( $condition_value ) ) : $condition_value = sanitize_text_field( $condition_value ); endif; break; endswitch; $sanitized_conditions[ $group_key ][ $condition_id ][ $condition_key ] = $condition_value; endforeach; endforeach; endforeach; return $sanitized_conditions; } } if ( ! function_exists( 'wpc_condition_operators' ) ) { /** * Get all condition operators. * * Get a list of the available operators for all the conditions. * Mainly used to determine which operators to show per condition. * * @since 1.0.0 * * @return array List of condition operators. */ function wpc_condition_operators() { $condition_operators = array( // Add default for when a custom condition doesn't properly add the available operators 'default' => array( '==' => __( 'Equal to', 'wpc-conditions' ), '!=' => __( 'Not equal to', 'wpc-conditions' ), '>=' => __( 'Greater or equal to', 'wpc-conditions' ), '<=' => __( 'Less or equal to ', 'wpc-conditions' ), ), ); foreach ( wpc_get_registered_conditions() as $condition ) { $condition_operators[ $condition->get_slug() ] = $condition->get_available_operators(); } return apply_filters( 'wp-conditions\condition_operators', $condition_operators ); } } if ( ! function_exists( 'wpc_condition_descriptions' ) ) { /** * Get all condition operators. * * Get a list of the available operators for all the conditions. * Mainly used to determine which operators to show per condition. * * @since 1.0.0 * * @return array List of condition operators. */ function wpc_condition_descriptions() { $condition_descriptions = array(); foreach ( wpc_get_registered_conditions() as $condition ) { $condition_descriptions[ $condition->get_slug() ] = $condition->get_description(); } return apply_filters( 'wp-conditions\condition_descriptions', $condition_descriptions ); } }