/home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Admin/Education/Builder
Edit: /home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Admin/Education/Builder/Calculations.php (8248B)
form_id ?? 0;
$dismiss_section = "builder-form-$form_id-field-options-calculations-notice";
// Check whether it is dismissed.
if ( ! empty( $dismissed[ 'edu-' . $dismiss_section ] ) ) {
return;
}
// Display notice only if Calculations addon is released (available in the `addons.json` file).
$addon = $this->addons->get_addon( 'calculations' );
if ( ! $addon ) {
return;
}
if (
AIHelpers::is_disabled() ||
(
wpforms_version_compare(
$addon['version'] ?? '1.5.0',
'1.5.0',
'<='
)
)
) {
$this->print_standard_education( $dismiss_section );
return;
}
$badge = esc_html__( 'NEW FEATURE', 'wpforms-lite' );
$notice_header = esc_html__( 'AI Calculations Are Here!', 'wpforms-lite' );
$notice = sprintf(
wp_kses( /* translators: %1$s - link to the WPForms.com doc article. */
__( 'Easily create advanced calculations with WPForms AI. Head over to the
Advanced Tab to get started or read
our documentation to learn more.', 'wpforms-lite' ),
[
'a' => [
'href' => [],
'rel' => [],
'target' => [],
],
]
),
esc_url( wpforms_utm_link( 'https://wpforms.com/docs/generating-calculation-formulas-with-wpforms-ai/', 'Calculations Education', 'Calculations Documentation' ) )
);
printf(
'
',
esc_html__( 'Dismiss this notice.', 'wpforms-lite' ),
esc_attr( $dismiss_section ),
$notice, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$notice_header, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$badge // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
/**
* Print standard education notice.
*
* @since 1.9.4
*
* @param string $dismiss_section Dismiss section.
*
* @noinspection HtmlUnknownAnchorTarget
* @noinspection HtmlUnknownTarget
*/
private function print_standard_education( string $dismiss_section ): void {
$notice = sprintf(
wp_kses( /* translators: %1$s - link to the WPForms.com doc article. */
__( 'Easily perform calculations based on user input. Head over to the
Advanced Tab to get started or read
our documentation to learn more.', 'wpforms-lite' ),
[
'a' => [
'href' => [],
'rel' => [],
'target' => [],
],
]
),
esc_url( wpforms_utm_link( 'https://wpforms.com/docs/calculations-addon/', 'Calculations Education', 'Calculations Documentation' ) )
);
printf(
'
',
esc_html__( 'Dismiss this notice.', 'wpforms-lite' ),
esc_attr( $dismiss_section ),
$notice // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
/**
* Display advanced options.
*
* @since 1.8.4.1
*
* @param array $field Field data.
* @param object $instance Builder instance.
*
* @noinspection ReturnTypeCanBeDeclaredInspection
* @noinspection PhpMissingParamTypeInspection
*/
public function advanced_options( $field, $instance ) {
if ( ! in_array( $field['type'], self::ALLOWED_FIELD_TYPES, true ) ) {
return;
}
$addon = $this->addons->get_addon( 'calculations' );
if ( ! $this->is_edu_required_by_status( $addon ) ) {
return;
}
$row_args = $this->get_row_attributes( $addon );
$row_args['content'] = $instance->field_element(
'toggle',
$field,
$this->get_field_attributes( $addon ),
false
);
$instance->field_element( 'row', $field, $row_args );
}
/**
* Get row attributes.
*
* @since 1.8.4.1
*
* @param array $addon Addon data.
*
* @return array
*/
private function get_row_attributes( array $addon ): array {
$data = $this->prepare_field_action_data( $addon );
$default = [
'slug' => 'calculation_is_enabled',
];
if ( ! empty( $data ) ) {
return wp_parse_args( $data, $default );
}
return wp_parse_args(
[
'data' => [
'action' => 'upgrade',
'name' => esc_html__( 'Calculations', 'wpforms-lite' ),
'utm-content' => 'Enable Calculations',
'license' => $addon['license_level'],
],
'class' => 'education-modal',
],
$default
);
}
/**
* Get attributes for the Enable Calculation field.
*
* @since 1.8.4.1
*
* @param array $addon Addon data.
*
* @return array
*/
private function get_field_attributes( array $addon ): array {
$default = [
'slug' => 'calculation_is_enabled',
'value' => '0',
'desc' => esc_html__( 'Enable Calculation', 'wpforms-lite' ),
];
if ( $addon['plugin_allow'] ) {
return $default;
}
return wp_parse_args(
[
'desc' => sprintf(
'%1$s%2$s',
esc_html__( 'Enable Calculation', 'wpforms-lite' ),
Helpers::get_badge( $addon['license_level'], 'sm', 'inline', 'slate' )
),
'attrs' => [
'disabled' => 'disabled',
],
],
$default
);
}
/**
* Determine if we require displaying educational items according to the addon status.
*
* @since 1.8.4.1
*
* @param array $addon Addon data.
*
* @return bool
*/
private function is_edu_required_by_status( array $addon ): bool {
return ! (
empty( $addon ) ||
empty( $addon['action'] ) ||
empty( $addon['status'] ) || (
$addon['status'] === 'active' && $addon['action'] !== 'upgrade'
)
);
}
}