Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Field Hook #475

Merged
merged 1 commit into from
Oct 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions includes/CMB2_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ public function save_field( $meta_value ) {
$new_value = $this->sanitization_cb( $meta_value );
$old = $this->get_data();
$updated = false;
$action = '';

if ( $this->args( 'multiple' ) && ! $this->args( 'repeatable' ) && ! $this->group ) {

Expand All @@ -462,13 +463,45 @@ public function save_field( $meta_value ) {
}

$updated = $count ? $count : false;
$action = 'repeatable';

} elseif ( ! cmb2_utils()->isempty( $new_value ) && $new_value !== $old ) {
$updated = $this->update_data( $new_value );
$action = 'updated';
} elseif ( cmb2_utils()->isempty( $new_value ) ) {
$updated = $this->remove_data();
$action = 'removed';
}

$field_args = $this->args();

/**
* Hooks after save field action.
*
* @since 2.2.0
*
* @param bool $updated Whether the metadata update action occurred.
* @param string $action Action performed. Could be "repeatable", "updated", or "removed".
* @param array $field_args All field arguments
* @param CMB2_Field object $field This field object
*/
do_action( 'cmb2_save_field', $updated, $action, $field_args, $this );

/**
* Hooks after save field action.
*
* The dynamic portion of the hook, $field_args['field_id'], refers to the current
* field id paramater.
*
* @since 2.2.0
*
* @param bool $updated Whether the metadata update action occurred.
* @param string $action Action performed. Could be "repeatable", "updated", or "removed".
* @param array $field_args All field arguments
* @param CMB2_Field object $field This field object
*/
do_action( 'cmb2_save_field_' . $field_args['field_id'], $updated, $action, $field_args, $this );

return $updated;
}

Expand Down