Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
vvasilev- committed Oct 22, 2019
2 parents b52920b + 2b0ae66 commit a2b30cc
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 92 deletions.
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Define version constant
if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
define( __NAMESPACE__ . '\VERSION', '3.1.3' );
define( __NAMESPACE__ . '\VERSION', '3.1.6' );
}

# Define root directory
Expand Down
4 changes: 3 additions & 1 deletion core/Toolset/Key_Toolset.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public function get_storage_key_deleter_patterns( $is_complex_field, $is_simple_
* @return string
*/
public function storage_key_patterns_to_sql( $table_column, $patterns ) {
global $wpdb;

$sql = array();

foreach ( $patterns as $storage_key => $type ) {
Expand All @@ -257,7 +259,7 @@ public function storage_key_patterns_to_sql( $table_column, $patterns ) {
$comparison = $table_column . ' = "' . esc_sql( $storage_key ) . '"';
break;
case static::PATTERN_COMPARISON_STARTS_WITH:
$comparison = $table_column . ' LIKE "' . esc_sql( $storage_key ) . '%"';
$comparison = $table_column . ' LIKE "' . $wpdb->esc_like( $storage_key ) . '%"';
break;
default:
Incorrect_Syntax_Exception::raise( 'Unsupported storage key pattern type used: "' . $type . '"' );
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbon-fields",
"version": "3.1.3",
"version": "3.1.6",
"description": "WordPress developer-friendly custom fields for post types, taxonomy terms, users, comments, widgets, options, navigation menus and more.",
"directories": {
"test": "tests"
Expand Down Expand Up @@ -81,7 +81,7 @@
"callbag-start-with": "^3.1.0",
"classnames": "^2.2.6",
"immer": "^1.7.4",
"lodash": "^4.17.11",
"lodash": "^4.17.13",
"nanoid": "^2.0.0",
"observe-resize": "^1.1.3",
"react": "^16.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/fields/oembed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OembedField extends Component {
const { value } = this.props;

const i = setInterval( () => {
if ( this.node.current.getBoundingClientRect().width > 0 ) {
if ( this.node.current !== null && this.node.current.getBoundingClientRect().width > 0 ) {
clearInterval( i );

this.handleSearch( value );
Expand Down
7 changes: 7 additions & 0 deletions packages/core/hocs/with-conditional-logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { withEffects } from 'refract-callbag';
import { __, sprintf } from '@wordpress/i18n';
import {
has,
find,
some,
every,
isEmpty
Expand Down Expand Up @@ -51,6 +52,12 @@ export default function withConditionalLogic( input, output ) {
*/
function handler( props ) {
return function( effect ) {
const fieldExists = find( effect, [ 'id', props.id ] );

if ( ! fieldExists ) {
return;
}

const { relation, rules } = props.field.conditional_logic;
const data = output( props, effect );

Expand Down
3 changes: 2 additions & 1 deletion packages/core/utils/fetch-attachments-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default ( attachments ) => {
data: {
action: 'query-attachments',
query: {
post__in: attachments
post__in: attachments,
posts_per_page: attachments.length
}
}
} );
Expand Down
25 changes: 7 additions & 18 deletions packages/metaboxes/fields/complex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,14 @@ class ComplexField extends Component {
const {
id,
value,
removeFields,
onChange
} = this.props;

onChange( id, without( value, group ) );

// Delay removal of fields because React will complain
// about missing objects.
// TODO: Investigate why this is necessary.
setTimeout( () => {
const fieldIds = group.fields.map( ( groupField ) => groupField.id );

removeFields( fieldIds );
}, 1 );
onChange(
id,
without( value, group ),
group.fields.map( ( groupField ) => groupField.id )
);
}

/**
Expand Down Expand Up @@ -245,16 +239,11 @@ const applyWithSelect = withSelect( ( select, props ) => {
} );

const applyWithDispatch = withDispatch( ( dispatch ) => {
const {
addFields,
cloneFields,
removeFields
} = dispatch( 'carbon-fields/metaboxes' );
const { addFields, cloneFields } = dispatch( 'carbon-fields/metaboxes' );

return {
addFields,
cloneFields,
removeFields
cloneFields
};
} );

Expand Down
2 changes: 1 addition & 1 deletion packages/metaboxes/hocs/with-field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default createHigherOrderComponent( ( Component ) => {
const applyWithSelect = withSelect( ( select, props ) => {
const { compactInput, compactInputKey } = window.cf.config;
const field = select( 'carbon-fields/metaboxes' ).getFieldById( props.id );
const { value } = field;
const value = field && field.value;

let name = props.name || field.name;

Expand Down
11 changes: 7 additions & 4 deletions packages/metaboxes/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ export function updateState( containers, fields ) {
/**
* Returns an action object used to update the field's value.
*
* @param {string} fieldId
* @param {mixed} value
* @param {string} fieldId
* @param {mixed} value
* @param {string[]} fieldsToRemove It's used by the complex fields to remove the nested
* fields within a single action.
* @return {Object}
*/
export function updateFieldValue( fieldId, value ) {
export function updateFieldValue( fieldId, value, fieldsToRemove = [] ) {
return {
type: 'UPDATE_FIELD_VALUE',
payload: {
fieldId,
value
value,
fieldsToRemove
}
};
}
Expand Down
17 changes: 15 additions & 2 deletions packages/metaboxes/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
assign,
forEach,
cloneDeep,
values
values,
unset
} from 'lodash';

/**
Expand Down Expand Up @@ -124,9 +125,21 @@ export function fields( state = {}, action ) {

case 'UPDATE_FIELD_VALUE':
return produce( state, ( draft ) => {
const { fieldId, value } = action.payload;
const {
fieldId,
value,
fieldsToRemove
} = action.payload;

draft[ fieldId ].value = value;

const fieldIdsToRemove = fieldsToRemove.reduce( ( accumulator, fieldIdToRemove ) => {
return getFieldIdsByRootId( fieldIdToRemove, state, accumulator );
}, [] );

fieldIdsToRemove.forEach( ( fieldIdToRemove ) => {
unset( draft, fieldIdToRemove );
} );
} );

case 'ADD_FIELDS':
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/Key_Toolset/KeyToolsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function testStorageKeyPatternsToSql() {
'_field' => Key_Toolset::PATTERN_COMPARISON_EQUAL,
'_field|' => Key_Toolset::PATTERN_COMPARISON_STARTS_WITH,
);
$expected = ' ( `option_name` = "_field" OR `option_name` LIKE "_field|%" ) ';
$expected = ' ( `option_name` = "_field" OR `option_name` LIKE "\_field|%" ) ';
$received = $this->subject->storage_key_patterns_to_sql( $table_column, $patterns );
$this->assertSame( $expected, $received );
}
Expand Down
Loading

0 comments on commit a2b30cc

Please sign in to comment.