sallow field preview "Duplicate" button.
*
* @since 1.9.4
*
* @param bool|mixed $display Display switch.
* @param array $field Field settings.
*
* @return bool
* @noinspection PhpMissingParamTypeInspection
*/
public function filter_field_preview_display_duplicate_button( $display, $field ): bool {
if ( $field['type'] !== $this->type || empty( $this->is_disabled_field ) ) {
return (bool) $display;
}
return false;
}
/**
* Add a class to the field preview container.
*
* @since 1.9.4
*
* @param string|mixed $css_class CSS class.
* @param array $field Field settings.
*
* @return string
* @noinspection PhpMissingParamTypeInspection
*/
public function filter_field_preview_class( $css_class, $field ): string {
$css_class = (string) $css_class;
if ( $field['type'] !== $this->type || empty( $this->is_disabled_field ) ) {
return $css_class;
}
return trim( $css_class . ' wpforms-field-is-pro' );
}
/**
* Filter entry save data.
*
* @since 1.9.5
*
* @param array|mixed $fields Entry fields data.
* @param array $entry Entry data.
* @param array $form_data Form data.
*
* @return array
* @noinspection PhpUnusedParameterInspection
*/
public function filter_entry_save_data( $fields, array $entry, array $form_data ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$fields = (array) $fields;
// If it's not a disabled Pro field, return the fields as is.
if ( empty( $this->is_disabled_field ) ) {
return $fields;
}
// Remove disabled Pro fields from the entry fields.
foreach ( $fields as $field_id => $field ) {
if ( isset( $field['type'] ) && $field['type'] === $this->type ) {
unset( $fields[ $field_id ] );
}
}
return $fields;
}
/**
* Filter forbidden columns on the Form Entries page.
*
* @since 1.9.5
*
* @param array|mixed $forbidden_fields Entry fields data.
* @param int|string $form_id Form ID.
*
* @return array
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUnusedLocalVariableInspection
*/
public function filter_field_columns_forbidden_fields( $forbidden_fields, $form_id ): array {
$forbidden_fields = (array) $forbidden_fields;
if ( empty( $this->is_disabled_field ) ) {
return $forbidden_fields;
}
$form_data = $this->get_form_data( (int) $form_id );
if ( ! $form_data ) {
return $forbidden_fields;
}
$fields = $form_data['fields'] ?? [];
foreach ( $fields as $field_id => $field ) {
if ( isset( $field['type'] ) && $field['type'] === $this->type ) {
$forbidden_fields[] = $field['type'];
}
}
return $forbidden_fields;
}
/**
* Get form data by form ID and cache it.
*
* @since 1.9.5
*
* @param int $form_id Form ID.
*
* @return array
*/
private function get_form_data( int $form_id ): array {
$form_obj = wpforms()->obj( 'form' );
if ( ! $form_obj ) {
return [];
}
// Cache the form data into static variable.
static $cached_form_data = [];
if ( isset( $cached_form_data[ $form_id ] ) ) {
return $cached_form_data[ $form_id ];
}
$cached_form_data[ $form_id ] = (array) $form_obj->get( $form_id, [ 'content_only' => true ] );
return $cached_form_data[ $form_id ];
}
/**
* Filter entries export configuration.
*
* @since 1.9.5
*
* @param array $config Export configuration.
*
* @return array
* @noinspection PhpMissingParamTypeInspection
*/
public function filter_entries_export_configuration( $config ): array {
$config = (array) $config;
// If it's not a disabled Pro field, return the config as is.
if ( empty( $this->is_disabled_field ) ) {
return $config;
}
if ( empty( $this->type ) ) {
return $config;
}
$config['disallowed_fields'] = ! empty( $config['disallowed_fields'] ) ? (array) $config['disallowed_fields'] : [];
// Add the disabled Pro field type to `disallowed_fields` if not already there.
if ( ! in_array( $this->type, $config['disallowed_fields'], true ) ) {
$config['disallowed_fields'][] = $this->type;
}
return $config;
}
/**
* Filter if field is displayable in the Entry Edit page.
*
* @since 1.9.5
*
* @param bool|mixed $displayable Whether the field is displayable.
* @param array $field Field data.
* @param array $form_data Form data.
*
* @return bool
* @noinspection PhpUnusedParameterInspection
*/
public function filter_is_field_displayable( $displayable, array $field, array $form_data ): bool { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
if ( ! $this->is_disabled_field ) {
return (bool) $displayable;
}
return false;
}
}
Fatal error: Trait 'WPForms\Forms\Fields\Traits\ProField' not found in /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Forms/Fields/Address/Field.php on line 13