/home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Admin/Tools/Export/Views/Templates
Edit: /home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Admin/Tools/Export/Views/Templates/Page.php (7654B)
hooks();
}
/**
* Register hooks.
*
* @since 1.10.1
*/
private function hooks(): void {
add_action( 'wpforms_tools_init', [ $this, 'process' ] );
}
/**
* Get the Tab label.
*
* @since 1.10.1
*
* @return string
*/
public function get_tab_label(): string {
return __( 'Export Templates', 'wpforms-lite' );
}
/**
* Check if the current user has the capability to view the page.
*
* @since 1.10.1
*
* @return bool
*/
public function current_user_can(): bool {
return wpforms_current_user_can( 'edit_forms' );
}
/**
* Export template process.
*
* @since 1.10.1
*/
public function process(): void {
// phpcs:disable WordPress.Security.NonceVerification
if (
empty( $_POST['action'] ) ||
$_POST['action'] !== 'export_template' ||
! isset( $_POST['submit-export'] ) ||
! $this->verify_nonce()
) {
return;
}
if ( empty( $_POST['form'] ) ) {
return;
}
// phpcs:enable WordPress.Security.NonceVerification
$this->process_template();
}
/**
* Page content.
*
* @since 1.10.1
*/
public function display(): void {
$this->forms = Form::get_all();
if ( empty( $this->forms ) ) {
echo wpforms_render( 'admin/empty-states/no-forms' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
?>
see our documentation.', 'wpforms-lite' ),
[
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
]
),
'https://wpforms.com/docs/how-to-create-a-custom-form-template/'
);
?>
Tools::SLUG,
'view' => 'export',
'tab' => $this->slug,
],
admin_url( 'admin.php' )
);
}
/**
* Forms selector HTML.
*
* @since 1.10.1
*/
private function forms_select_html(): void {
?>
obj( 'form' );
if ( ! $form_obj || ! $form_id ) {
return;
}
$form_data = $form_obj->get( $form_id, [ 'content_only' => true ] );
// Define basic data with strict validation.
$name = sanitize_text_field( $form_data['settings']['form_title'] ?? '' );
$desc = sanitize_text_field( $form_data['settings']['form_desc'] ?? '' );
$slug = sanitize_key( str_replace( [ ' ', '-' ], '_', trim( $name ) ) );
if ( ! $slug ) {
// Slug is always empty when the $form_data is not valid.
return;
}
$class = 'WPForms_Template_' . $slug;
$data = $this->get_template_data( $slug, $form_data );
// Build the final template string.
$this->template = <<
name = '$name';
// Template slug
\$this->slug = '$slug';
// Template description
\$this->description = '$desc';
// Template field and settings
\$this->data = $data;
}
}
new $class();
endif;
EOT;
}
/**
* Get template data.
*
* @since 1.10.1
*
* @param string $slug Template slug.
* @param array|mixed $form_data Form data.
*
* @return string
*/
private function get_template_data( string $slug, $form_data ): string {
// Format template field and settings data.
$data = [];
$data['meta']['template'] = $slug;
$data['fields'] = isset( $form_data['fields'] ) && is_array( $form_data['fields'] )
? wpforms_array_remove_empty_strings( $form_data['fields'] )
: [];
$data['settings'] = isset( $form_data['settings'] ) && is_array( $form_data['settings'] )
? wpforms_array_remove_empty_strings( $form_data['settings'] )
: [];
$template_data = (string) var_export( $data, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
$template_data = str_replace( ' ', "\t", $template_data );
return preg_replace( '/([\t\r\n]+?)array/', 'array', $template_data );
}
}