processRequest();
}
/**
* Trigger before render
*/
public function before_render() {
wp_enqueue_script( 'forminator-chart', forminator_plugin_url() . 'assets/js/library/Chart.bundle.min.js', array( 'jquery' ), '2.9.4', false );
}
/**
* Count modules
*
* @param string $status Modules status.
* @since 1.0
* @return int
*/
public function countModules( $status = '' ) {
$class_name = 'Forminator_' . forminator_get_prefix( static::$module_slug, '', true ) . '_Model';
return $class_name::model()->count_all( $status );
}
/**
* Get modules
*
* @since 1.0
* @return array
*/
public function getModules() {
$modules = array();
$limit = null;
$const = 'FORMINATOR_' . strtoupper( static::$module_slug ) . '_LIST_LIMIT';
if ( defined( $const ) && constant( $const ) ) {
$limit = constant( $const );
}
$data = self::get_models( $limit );
$form_view = Forminator_Form_Views_Model::get_instance();
// Fallback.
if ( ! isset( $data['models'] ) || empty( $data['models'] ) ) {
return $modules;
}
foreach ( $data['models'] as $model ) {
$form_name = $model->name;
if ( isset( $model->settings['formName'] ) && ! empty( $model->settings['formName'] ) ) {
$form_name = $model->settings['formName'];
}
$modules[] = static::module_array(
$model->id,
$form_name,
$form_view->count_views( $model->id ),
gmdate( get_option( 'date_format' ), strtotime( $model->raw->post_date ) ),
$model->status,
$model
);
}
return $modules;
}
/**
* Get modules for search
*
* @param null|string $search_keyword Search Keyword.
* @param null|int $page_number Optional page number. Added in 1.52.
*
* @since 1.14.12
* @return array
*/
public static function get_searched_modules( $search_keyword = null, $page_number = 1 ) {
$modules = array();
self::$page_number = max( 1, $page_number );
$data = self::get_models( null, $search_keyword );
// Fallback.
if ( ! isset( $data['models'] ) || empty( $data['models'] ) ) {
return $modules;
}
// Search.
if ( ! is_null( $search_keyword ) ) {
$form_view = Forminator_Form_Views_Model::get_instance();
$module_slug = self::get_slug_ajax( true );
$class_name = 'Forminator_' . $module_slug . '_Page';
foreach ( $data['models'] as $model ) {
$modules[] = $class_name::module_array(
$model->id,
$model->settings['formName'],
$form_view->count_views( $model->id ),
gmdate( get_option( 'date_format' ), strtotime( $model->raw->post_date ) ),
$model->status,
$model
);
}
}
return array(
'modules' => $modules,
'total_modules' => $data['foundPosts'],
);
}
/**
* Get slug for ajax search
*
* @param string|bool $slug Module slug.
*
* @since 1.14.12
* @return array
*/
public static function get_slug_ajax( $slug = false ) {
$page = Forminator_Core::sanitize_text_field( 'page' );
if ( ! $page ) {
return '';
}
switch ( $page ) {
case 'forminator-poll':
$module_slug = $slug ? 'Poll' : 'poll';
break;
case 'forminator-quiz':
$module_slug = $slug ? 'Quiz' : 'quiz';
break;
default:
$module_slug = $slug ? 'CForm' : 'form';
break;
}
return $module_slug;
}
/**
* Has error on payment field
*
* @param mixed $module Module.
* @return bool
*/
public static function has_payment_field_error( $module ) {
if ( ! empty( $module['model'] ) && method_exists( $module['model'], 'has_stripe_field' ) ) {
$stripe_field = $module['model']->has_stripe_field();
if ( ! empty( $stripe_field ) ) {
$stripe_mode = $stripe_field->mode;
$stripe_payments = $stripe_field->payments;
if ( empty( $stripe_mode ) || ! in_array( $stripe_mode, array( 'test', 'live' ), true ) ) {
$stripe_mode = 'test';
}
$test_ready = forminator_is_stripe_mode_ready( 'test' );
$live_ready = forminator_is_stripe_mode_ready( 'live' );
if ( ! $test_ready && ! $live_ready ) {
return true;
}
$selected_mode_ready = ( 'live' === $stripe_mode ) ? $live_ready : $test_ready;
if ( ! $selected_mode_ready ) {
return true;
}
$plan_id_key = 'live' === $stripe_mode ? 'live_plan_id' : 'test_plan_id';
if ( ! empty( $stripe_payments ) ) {
foreach ( $stripe_payments as $plan ) {
if ( 'subscription' === $plan['payment_method'] && empty( $plan[ $plan_id_key ] ) ) {
return true;
}
}
}
}
}
if ( ! empty( $module['model'] ) && method_exists( $module['model'], 'has_paypal_field' ) ) {
$paypal_field = $module['model']->has_paypal_field();
if ( ! empty( $paypal_field ) ) {
if ( false === forminator_has_paypal_settings() ) {
return true;
}
}
}
return false;
}
/**
* Check if has error on registration form
*
* @param mixed $module Module.
* @return bool
*/
public static function has_error_on_registration_form( $module ) {
if ( ! empty( $module['model']->settings['form-type'] ) && 'registration' === $module['model']->settings['form-type'] ) {
$settings = $module['model']->settings;
if ( 'manual' === forminator_get_property( $settings, 'activation-method' ) ) {
return false;
}
if ( ! forminator_is_user_registration_enabled() ) {
return true;
}
$option_create_site = forminator_get_property( $settings, 'site-registration' );
if ( forminator_is_main_site() && 'enable' === $option_create_site && ! forminator_is_site_registration_enabled() ) {
return true;
}
}
return false;
}
/**
* Check if module is editable by the current user.
*
* @since 1.52.0
*
* @param array $module Module data array (may contain 'model' object or flat 'settings' array).
* @return bool
*/
public static function is_module_editable( $module ) {
if ( ! empty( $module['model'] ) && is_object( $module['model'] ) ) {
$settings = $module['model']->settings;
} elseif ( ! empty( $module['settings'] ) && is_array( $module['settings'] ) ) {
$settings = $module['settings'];
} else {
return true;
}
return true === forminator_check_registration_form_permissions( $settings );
}
/**
* Show the modules
*
* @param array $modules Modules.
* @param string $module_slug Module slug.
* @param string $preview_dialog Preview dialog.
* @param string $preview_title Preview title.
* @param string $export_dialog Export dialog.
* @param string $post_type Post type.
* @param string $soon Soon.
* @param string $sql_month_start_date Start date.
* @param string $wizard_page Wizard page.
* @param string $search_keyword Search Keyword.
*
* @since 1.14.12
* @return mixed
*/
public static function show_modules( $modules, $module_slug, $preview_dialog, $preview_title, $export_dialog, $post_type, $soon, $sql_month_start_date, $wizard_page, $search_keyword = null ) {
if ( empty( $modules ) ) {
$is_search = true;
require_once forminator_plugin_dir() . 'admin/views/common/list/empty_content.php';
}
$page = $module_slug;
if ( 'form' === $page ) {
$page = 'cform';
}
foreach ( $modules as $module ) {
$module_entries_from_last_month = 0 !== $module['entries'] ? count( Forminator_Form_Entry_Model::get_newer_entry_ids_of_form_id( $module['id'], $sql_month_start_date ) ) : 0;
$opened_class = '';
$opened_chart = '';
$has_leads = isset( $module['has_leads'] ) ? $module['has_leads'] : false;
$leads_id = isset( $module['leads_id'] ) ? $module['leads_id'] : 0;
if ( ! is_null( $wizard_page ) && ! isset( $module['type'] ) ) {
$edit_url = admin_url( 'admin.php?page=' . $wizard_page . '&id=' . $module['id'] );
} else {
// For quizzes.
$edit_url = admin_url( 'admin.php?page=forminator-' . ( 'nowrong' === $module['type'] ? $module['type'] : 'knowledge' ) . '-wizard&id=' . $module['id'] );
}
$view_stats = filter_input( INPUT_GET, 'view-stats', FILTER_VALIDATE_INT );
if ( $view_stats && intval( $module['id'] ) === $view_stats ) {
$opened_class = ' sui-accordion-item--open forminator-scroll-to';
$opened_chart = ' sui-chartjs-loaded';
}
$display_warning_icon = self::has_payment_field_error( $module );
$display_registration_warning = self::has_error_on_registration_form( $module );
$is_module_editable = self::is_module_editable( $module );
if ( $display_warning_icon || $display_registration_warning ) {
$opened_class .= ' forminator-notice-yellow';
}
?>
0 ) {
$rate = round( ( $module['entries'] * 100 ) / $module['views'], 1 );
} else {
$rate = 0;
}
return $rate;
}
/**
* Pagination
*
* @param bool $is_search Is search.
* @param int $count Count.
*
* @since 1.0
*/
public function pagination( $is_search, $count ) {
echo '';
if ( $is_search ) {
return;
}
forminator_list_pagination( $count );
}
/**
* Get models
*
* @since 1.0
* @since 1.6 add $limit
* @param int $limit Limit.
* @param null|string $search_keyword Optional Search Keyword.Added in 1.52.
*
* @return array
*/
public static function get_models( $limit = null, $search_keyword = null ) {
if ( ! isset( static::$module_slug ) ) {
$module_slug = self::get_slug_for_search();
} else {
$module_slug = static::$module_slug;
}
$class_name = 'Forminator_' . forminator_get_prefix( $module_slug, '', true ) . '_Model';
$data = $class_name::model()->get_all_paged( self::$page_number, $limit, '', null, $search_keyword );
return $data;
}
/**
* Get slug when in search
*
* @since 1.14.12
*
* @return string
*/
public static function get_slug_for_search() {
$page = Forminator_Core::sanitize_text_field( 'page' );
switch ( $page ) {
case 'forminator-poll':
$module_slug = 'poll';
break;
case 'forminator-quiz':
$module_slug = 'quiz';
break;
default:
$module_slug = 'form';
break;
}
return $module_slug;
}
/**
* Clone Module
*
* @since 1.6
*
* @param int $id Module Id.
*/
public function clone_module( $id ) {
// check if this id is valid and the record is exists.
$model = Forminator_Base_Form_Model::get_model( $id );
if ( is_object( $model ) ) {
// create one.
// reset id.
$model->id = null;
// update title.
if ( isset( $model->settings['formName'] ) ) {
$model->settings['formName'] = /* translators: %s: Form name */ sprintf( esc_html__( 'Copy of %s', 'forminator' ), esc_html( $model->settings['formName'] ) );
}
// save it to create new record.
$new_id = $model->save( true );
if ( is_wp_error( $new_id ) ) {
return $new_id;
}
/**
* Action called after module cloned
*
* @since 1.11
*
* @param int $new_id - module id.
* @param object $model - module model.
*
* @since 1.39
* @param int $id - Old module id.
*/
do_action( 'forminator_' . static::$module_slug . '_action_clone', $new_id, $model, $id );
$function = 'forminator_clone_' . static::$module_slug . '_submissions_retention';
if ( function_exists( $function ) ) {
$function( $id, $new_id );
}
// Purge count forms cache.
$cache_prefix = 'forminator_' . static::$module_slug . '_total_entries';
wp_cache_delete( $cache_prefix, $cache_prefix );
wp_cache_delete( $cache_prefix . '_publish', $cache_prefix . '_publish' );
wp_cache_delete( $cache_prefix . '_draft', $cache_prefix . '_draft' );
// Call do action after create duplicate module.
Forminator_Base_Form_Model::module_update_do_action( static::$module_slug, $new_id, $model );
}
}
/**
* Delete module
*
* @since 1.6
*
* @param int $id Module Id.
*/
public static function delete_module( $id ) {
// check if this id is valid and the record is exists.
$model = Forminator_Base_Form_Model::get_model( $id );
if ( is_object( $model ) ) {
$validate = forminator_check_registration_form_permissions( $model->settings );
if ( is_wp_error( $validate ) ) {
return $validate;
}
// For Quizzes with Leads.
if ( isset( $model->settings['hasLeads'] ) && isset( $model->settings['leadsId'] ) && $model->settings['hasLeads'] ) {
$leads_id = $model->settings['leadsId'];
$leads_model = Forminator_Base_Form_Model::get_model( $leads_id );
if ( is_object( $leads_model ) ) {
wp_delete_post( $leads_id );
self::delete_css( $leads_id );
}
}
Forminator_Form_Entry_Model::delete_by_form( $id );
$form_view = Forminator_Form_Views_Model::get_instance();
$form_view->delete_by_form( $id );
$post_status = get_post_status( $id );
if ( 'pdf_form' === $post_status ) {
$model::$module_slug = 'pdf';
}
$function = 'forminator_update_' . $model::$module_slug . '_submissions_retention';
if ( function_exists( $function ) ) {
$function( $id, null, null );
}
wp_delete_post( $id );
self::delete_css( $id );
// Purge count forms cache.
$cache_prefix = 'forminator_' . $model::$module_slug . '_total_entries';
wp_cache_delete( $cache_prefix, $cache_prefix );
wp_cache_delete( $cache_prefix . '_publish', $cache_prefix . '_publish' );
wp_cache_delete( $cache_prefix . '_draft', $cache_prefix . '_draft' );
/**
* Action called after module deleted
*
* @since 1.11
*
* @param int $id - module id.
*/
do_action( 'forminator_' . $model::$module_slug . '_action_delete', $id );
}
}
/**
* Delete module CSS file
*
* @param int $id Module ID.
*/
private static function delete_css( $id ) {
$css_file = Forminator_Assets_Enqueue::get_css_upload( $id, 'dir' );
if ( file_exists( $css_file ) ) {
// delete CSS file.
wp_delete_file( $css_file );
}
$css_dir = dirname( $css_file );
$index_file = $css_dir . DIRECTORY_SEPARATOR . 'index.php';
if ( file_exists( $index_file ) ) {
// Delete index.php file inside `css` folder.
wp_delete_file( $index_file );
}
// Ensure the WP_Filesystem is initialized.
if ( ! function_exists( 'wp_filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
WP_Filesystem();
// Global $wp_filesystem should be available now.
global $wp_filesystem;
// remove `css` folder.
if ( $wp_filesystem->is_dir( $css_dir ) ) {
$wp_filesystem->rmdir( $css_dir );
}
$module_dir = dirname( $css_dir );
$files = array_diff( scandir( $module_dir ), array( '.', '..', 'index.php' ) );
// Completely remove module folder if there are no other files.
if ( ! $files ) {
$index_file = $module_dir . DIRECTORY_SEPARATOR . 'index.php';
if ( file_exists( $index_file ) ) {
// Delete index.php file inside module folder.
wp_delete_file( $index_file );
}
// remove module folder.
if ( $wp_filesystem->is_dir( $module_dir ) ) {
$wp_filesystem->rmdir( $module_dir );
}
}
}
/**
* Delete module entries
*
* @since 1.6
*
* @param int $id Module Id.
*/
public function delete_module_entries( $id ) {
// check if this id is valid and the record is exists.
$model = Forminator_Base_Form_Model::get_model( $id );
if ( is_object( $model ) ) {
Forminator_Form_Entry_Model::delete_by_form( $id );
}
}
/**
* Export module
*
* @since 1.6
*
* @param int $id Module Id.
*/
public function export_module( $id ) {
$exportable = array();
$model_name = '';
$model = Forminator_Base_Form_Model::get_model( $id );
if ( $model instanceof Forminator_Base_Form_Model ) {
$model_name = $model->name;
$exportable = $model->to_exportable_data();
}
$encoded = wp_json_encode( $exportable );
$fp = fopen( 'php://memory', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
fwrite( $fp, $encoded ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
fseek( $fp, 0 );
$filename = esc_html__( 'forminator', 'forminator' ) . '-' . sanitize_title( $model_name ) . '-' . static::$module_slug . '-export.txt';
header( 'Content-Description: File Transfer' );
header( 'Content-Type: text/plain' );
header( 'Content-Disposition: attachment; filename="' . basename( $filename ) . '"' );
header( 'Cache-Control: must-revalidate' );
header( 'Content-Length: ' . strlen( $encoded ) );
// make php send the generated csv lines to the browser.
ob_clean();
fpassthru( $fp );
}
/**
* Override scripts to be loaded
*
* @since 1.11
*
* @param string $hook Hook name.
*/
public function enqueue_scripts( $hook ) {
parent::enqueue_scripts( $hook );
forminator_print_front_styles();
forminator_print_front_scripts();
}
/**
* Process request
*
* @since 1.0
*/
public function processRequest() {
$action = Forminator_Core::sanitize_text_field( 'forminator_action' );
if ( ! $action ) {
return;
}
if ( 'pdf-preview' === $action ) {
$this->process_pdf_actions( $action );
return;
}
$page = Forminator_Core::sanitize_text_field( 'page' );
// Check if the page is not the relevant module type page and not forminator dashboard page.
if ( 'forminator-' . forminator_get_prefix( static::$module_slug, 'c' ) !== $page && 'forminator' !== $page ) {
return;
}
$form_type = Forminator_Core::sanitize_text_field( 'form_type' );
// In forminator dashboard, check if form type is not the relevant module type.
if ( 'forminator' === $page && $form_type && forminator_get_prefix( static::$module_slug, 'custom-' ) !== $form_type ) {
return;
}
$id = filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT );
// Set nonce names first for verification.
switch ( $action ) {
case 'clone':
$nonce_name = 'forminatorNonce';
$nonce_action = 'forminator-nonce-clone-' . $id;
break;
case 'reset-views':
$nonce_name = 'forminatorNonce';
$nonce_action = 'forminator-nonce-reset-views-' . $id;
break;
case 'update-status':
$nonce_name = 'forminator-nonce-update-status-' . $id;
$nonce_action = $nonce_name;
break;
default:
$nonce_name = 'forminatorNonce';
$nonce_action = 'forminator_' . static::$module_slug . '_request';
break;
}
$slug = 'forminator-cform';
if ( 'poll' === static::$module_slug ) {
$slug = 'forminator-poll';
} elseif ( 'quiz' === static::$module_slug ) {
$slug = 'forminator-quiz';
}
// Verify nonce.
$nonce = Forminator_Core::sanitize_text_field( $nonce_name );
if ( ! $nonce || ! wp_verify_nonce( $nonce, $nonce_action )
|| ! forminator_is_user_allowed( $slug ) ) {
return;
}
$plural_slug = forminator_get_prefix( static::$module_slug, '', false, true );
$is_redirect = true;
$ids = Forminator_Core::sanitize_text_field( 'ids' );
$module_ids = ! empty( $ids ) ? explode( ',', $ids ) : array();
$has_access_error = 0;
$has_form_error = 0;
switch ( $action ) {
case 'delete':
if ( ! empty( $id ) ) {
$result = static::delete_module( $id );
if ( is_wp_error( $result ) ) {
$error_message = $result->get_error_message();
} else {
$notice = static::$module_slug . '_deleted';
}
}
break;
case 'clone':
if ( ! empty( $id ) ) {
$result = $this->clone_module( $id );
if ( is_wp_error( $result ) ) {
$error_message = $result->get_error_message();
} else {
$notice = static::$module_slug . '_duplicated';
}
}
break;
case 'reset-views':
if ( ! empty( $id ) ) {
self::reset_module_views( $id );
$notice = static::$module_slug . '_reset';
}
break;
case 'delete-votes':
case 'delete-entries':
if ( ! empty( $id ) ) {
$this->delete_module_entries( $id );
}
break;
case 'export':
if ( ! empty( $id ) ) {
$this->export_module( $id );
}
$is_redirect = false;
break;
case 'delete-' . $plural_slug:
foreach ( $module_ids as $id ) {
$result = static::delete_module( $id );
if ( is_wp_error( $result ) && ( in_array( $result->get_error_code(), array( 'invalid_access', 'invalid_user_role' ), true ) ) ) {
++$has_access_error;
}
}
if ( $has_access_error ) {
$text_message = __( 'The selected form(s) have been deleted. Note: This action cannot be performed on forms without sufficient permissions.', 'forminator' );
}
break;
case 'delete-votes-polls':
case 'delete-entries-' . $plural_slug:
foreach ( $module_ids as $id ) {
$this->delete_module_entries( $id );
}
break;
case 'clone-' . $plural_slug:
foreach ( $module_ids as $id ) {
$result = $this->clone_module( $id );
if ( is_wp_error( $result ) && ( in_array( $result->get_error_code(), array( 'invalid_access', 'invalid_user_role' ), true ) ) ) {
++$has_access_error;
}
}
if ( $has_access_error ) {
$text_message = esc_html__( 'The selected form(s) have been duplicated. Note: This action cannot be performed on forms without sufficient permissions.', 'forminator' );
}
break;
case 'reset-views-' . $plural_slug:
foreach ( $module_ids as $id ) {
self::reset_module_views( $id );
}
break;
case 'update-status':
$status = Forminator_Core::sanitize_text_field( 'status' );
if ( ! empty( $id ) && ! empty( $status ) ) {
$result = $this->update_module_status( $id, $status );
if ( is_wp_error( $result ) ) {
$error_message = $result->get_error_message();
}
}
break;
case 'update-statuses':
$status = Forminator_Core::sanitize_text_field( 'status' );
// only publish and draft status avail.
if ( ! empty( $status ) && in_array( $status, array( 'publish', 'draft' ), true ) ) {
foreach ( $module_ids as $id ) {
$model = Forminator_Base_Form_Model::get_model( $id );
if ( $model instanceof Forminator_Base_Form_Model ) {
$model->status = $status;
$result = $model->save();
if ( is_wp_error( $result ) && ( in_array( $result->get_error_code(), array( 'invalid_access', 'invalid_user_role' ), true ) ) ) {
++$has_access_error;
} else {
// Call module update do action on status update.
Forminator_Base_Form_Model::module_update_do_action( static::$module_slug, $id, $model );
}
}
}
if ( $has_access_error ) {
$text_message = esc_html__( 'The selected form(s) have been updated. Note: This action cannot be performed on forms without sufficient permissions.', 'forminator' );
}
}
break;
case 'draft-' . $plural_slug:
foreach ( $module_ids as $form_id ) {
$result = $this->update_module_status( $form_id, 'draft' );
if ( is_wp_error( $result ) && ( in_array( $result->get_error_code(), array( 'invalid_access', 'invalid_user_role' ), true ) ) ) {
++$has_access_error;
}
}
if ( $has_access_error ) {
$text_message = esc_html__( 'The selected form(s) have been updated. Note: This action cannot be performed on forms without sufficient permissions.', 'forminator' );
}
break;
case 'publish-' . $plural_slug:
foreach ( $module_ids as $form_id ) {
$result = $this->update_module_status( $form_id, 'publish' );
if ( is_wp_error( $result ) ) {
if ( in_array( $result->get_error_code(), array( 'invalid_access', 'invalid_user_role' ), true ) ) {
++$has_access_error;
} elseif ( 'form_error' === $result->get_error_code() ) {
++$has_form_error;
}
}
}
if ( $has_access_error ) {
$text_message = esc_html__( 'The selected form(s) have been updated. Note: This action cannot be performed on forms without sufficient permissions.', 'forminator' );
} elseif ( $has_form_error ) {
$text_message = esc_html__( 'The selected form(s) have been updated. Note: Some forms could not be published due to validation errors.', 'forminator' );
}
break;
default:
break;
}
if ( $is_redirect ) {
$to_referer = true;
if ( isset( $_POST['forminatorRedirect'] ) && 'false' === $_POST['forminatorRedirect'] ) {
$to_referer = false;
}
$args = array(
'page' => $this->get_admin_page(),
);
$search = Forminator_Core::sanitize_text_field( 'msearch' );
if ( $search ) {
$args['module-search'] = $search;
$to_referer = false;
}
if ( ! empty( $notice ) ) {
$args['forminator_notice'] = $notice;
$to_referer = false;
}
if ( ! empty( $error_message ) ) {
$args['forminator_error_notice'] = $error_message;
$to_referer = false;
}
if ( ! empty( $text_message ) ) {
$args['forminator_text_notice'] = $text_message;
$to_referer = false;
}
$fallback_redirect = add_query_arg(
$args,
admin_url( 'admin.php' )
);
$this->maybe_redirect_to_referer( $fallback_redirect, $to_referer );
}
exit;
}
/**
* Process PDF actions
*
* @param string $action PDF action.
*
* @since 1.25
*/
public function process_pdf_actions( $action ) {
$page = Forminator_Core::sanitize_text_field( 'page' );
$form_type = Forminator_Core::sanitize_text_field( 'form_type' );
if ( 'forminator-cform-wizard' !== $page && 'pdf-form' !== $form_type ) {
return;
}
$nonce = Forminator_Core::sanitize_text_field( 'preview_nonce' );
if ( ! $nonce || ! wp_verify_nonce( $nonce, 'forminator_load_module_preview' ) ) {
return;
}
if ( ! current_user_can( forminator_get_permission( 'forminator-cform' ) ) ) {
return;
}
$pdf_id = Forminator_Core::sanitize_text_field( 'pdf_id' );
if ( empty( $pdf_id ) ) {
$pdf_id = Forminator_Core::sanitize_text_field( 'id' );
}
if ( ! is_numeric( $pdf_id ) ) {
return;
}
if ( class_exists( 'Forminator_PDF_Form_Actions' ) ) {
$pdf_action = new Forminator_PDF_Form_Actions();
$pdf = Forminator_API::get_module( $pdf_id );
if ( 'pdf-preview' === $action ) {
$pdf_action->process_pdf_download(
$pdf,
'preview',
esc_html( $pdf->name . '_' . wp_date( 'M-j-y' ) . '.pdf' ),
'I'
);
exit; // Do not remove.
}
}
}
/**
* Update Module Status
*
* @since 1.6
*
* @param int $id Module Id.
* @param string $status Module status.
*/
public function update_module_status( $id, $status ) {
// only publish and draft status avail.
if ( in_array( $status, array( 'publish', 'draft' ), true ) ) {
$model = Forminator_Base_Form_Model::get_model( $id );
if ( $model instanceof Forminator_Base_Form_Model ) {
$is_publishable = $model->is_publishable();
if ( 'publish' === $status && is_wp_error( $is_publishable ) ) {
return $is_publishable;
}
$model->status = $status;
$result = $model->save();
if ( is_wp_error( $result ) ) {
return $result;
} else {
// Call module update do action on status update.
Forminator_Base_Form_Model::module_update_do_action( static::$module_slug, $id, $model );
}
}
}
}
/**
* Reset views data
*
* @since 1.6
*
* @param int $id Module ID.
*/
public static function reset_module_views( $id ) {
$form_types = forminator_form_types();
$module = get_post( $id );
if ( ! empty( $module->post_type ) && in_array( $module->post_type, $form_types, true ) ) {
$form_view = Forminator_Form_Views_Model::get_instance();
$form_view->delete_by_form( $id );
}
}
}