mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 18:05:45 +03:00
Keep data-related code together
This commit is contained in:
parent
1909870e92
commit
a7a8a37019
1 changed files with 37 additions and 37 deletions
|
@ -156,43 +156,6 @@ function render_meta_boxes( $pledge, $box ) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that an array contains values for all required keys.
|
||||
*
|
||||
* @return bool|WP_Error True if all required values are present. Otherwise WP_Error.
|
||||
*/
|
||||
function has_required_pledge_meta( array $submission ) {
|
||||
$error = new WP_Error();
|
||||
|
||||
$required = array_keys( get_pledge_meta_config( 'user_input' ) );
|
||||
|
||||
foreach ( $required as $key ) {
|
||||
if ( ! isset( $submission[ $key ] ) || is_null( $submission[ $key ] ) ) {
|
||||
$error->add(
|
||||
'required_field_empty',
|
||||
sprintf(
|
||||
__( 'The <code>%s</code> field does not have a value.', 'wporg' ),
|
||||
sanitize_key( $key )
|
||||
)
|
||||
);
|
||||
} elseif ( false === $submission[ $key ] ) {
|
||||
$error->add(
|
||||
'required_field_invalid',
|
||||
sprintf(
|
||||
__( 'The <code>%s</code> field has an invalid value.', 'wporg' ),
|
||||
sanitize_key( $key )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $error->get_error_messages() ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the pledge data.
|
||||
*
|
||||
|
@ -279,6 +242,43 @@ function update_generated_meta( $meta_id, $object_id, $meta_key, $_meta_value )
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that an array contains values for all required keys.
|
||||
*
|
||||
* @return bool|WP_Error True if all required values are present. Otherwise WP_Error.
|
||||
*/
|
||||
function has_required_pledge_meta( array $submission ) {
|
||||
$error = new WP_Error();
|
||||
|
||||
$required = array_keys( get_pledge_meta_config( 'user_input' ) );
|
||||
|
||||
foreach ( $required as $key ) {
|
||||
if ( ! isset( $submission[ $key ] ) || is_null( $submission[ $key ] ) ) {
|
||||
$error->add(
|
||||
'required_field_empty',
|
||||
sprintf(
|
||||
__( 'The <code>%s</code> field does not have a value.', 'wporg' ),
|
||||
sanitize_key( $key )
|
||||
)
|
||||
);
|
||||
} elseif ( false === $submission[ $key ] ) {
|
||||
$error->add(
|
||||
'required_field_invalid',
|
||||
sprintf(
|
||||
__( 'The <code>%s</code> field has an invalid value.', 'wporg' ),
|
||||
sanitize_key( $key )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $error->get_error_messages() ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the input filters for submitted content.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue