Skip to content

Commit

Permalink
prevent required acf image fields on dev environments
Browse files Browse the repository at this point in the history
  • Loading branch information
crstauf authored Jan 2, 2024
1 parent a8cbfff commit 9d5f1fb
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/cssllc-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function __construct() {

add_action( 'acf/input/admin_head', array( $this, 'action__acf_input_admin_head' ) );

add_filter( 'acf/load_field/type=image', array( $this,'filter__acf_load_field_type_image' ) );
add_filter( 'acf/settings/enable_post_types', '__return_false' );
add_filter( 'acf/settings/enable_options_pages_ui', '__return_false' );
add_filter( 'acf/settings/save_json', array( $this, 'filter__acf_settings_save_json' ) );
Expand Down Expand Up @@ -97,6 +98,35 @@ public function action__acf_input_admin_head() : void {
echo '<style>.hide-label .acf-label { display: none; }</style>';
}

/**
* Filter: acf/load_field/type=image
*
* Remove requirement from image fields on development environments.
*
* @param array<string, mixed> $field
* @return array<string, mixed>
*/
public function filter__acf_load_field_type_image( array $field ) : array {
$screen = get_current_screen();

if ( 'acf-field-group' === $screen->id ) {
return $field;
}

if ( ! in_array( wp_get_environment_type(), array( 'local', 'development' ) ) ) {
return $field;
}

if ( empty( $field['required'] ) ) {
return $field;
}

$field['required'] = false;
$field['label'] .= ' <span class="acf-required" title="Required, but disabled in dev environment">*</span>';

return $field;
}

/**
* Filter: acf/settings/save_json
*
Expand Down

0 comments on commit 9d5f1fb

Please sign in to comment.