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

Add new function eligible_to_save #500

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 24 additions & 1 deletion includes/CMB2.php
Expand Up @@ -500,10 +500,33 @@ public function process_fields() {
$this->updated = array();

foreach ( $this->prop( 'fields' ) as $field_args ) {
$this->process_field( $field_args );
if ( $this->eligible_to_save( $field_args ) ) {
$this->process_field( $field_args );
}
}
}

/**
* Determine if field is eligible to be saved
* @since 2.1.3
* @param array $field_args Array of field arguments
*/
private function eligible_to_save( $field_args ) {
$eligible = true;

if ( isset( $field_args[ 'attributes' ] ) ) {
$attributes = $field_args[ 'attributes' ];
if ( isset( $attributes[ 'readonly' ] ) && 'readonly' === $attributes[ 'readonly' ] ) {
$eligible = false;
} elseif ( isset( $attributes[ 'disabled' ] ) && 'disabled' === $attributes[ 'disabled' ] ) {
$eligible = false;
}
}

// Add filter here to allow override?
return $eligible;
}

/**
* Process and save a field
* @since 2.0.0
Expand Down