page_slug = $page_slug;
$this->folder = $folder;
if ( ! $parent_page ) {
$this->page_id = add_menu_page(
$page_title,
$menu_title,
forminator_get_permission( $page_slug ),
$page_slug,
$render ? array( $this, 'render' ) : null,
$this->get_menu_icon()
);
} else {
$this->page_id = add_submenu_page(
$parent_page,
$page_title,
$menu_title,
forminator_get_permission( $page_slug ),
$page_slug,
$render ? array( $this, 'render' ) : null
);
}
if ( $render ) {
$this->render_page_hooks();
}
$this->init();
add_filter( 'removable_query_args', array( $this, 'remove_notice_params' ) );
}
/**
* Use that method instead of __construct
*
* @todo : deperecate this, since its not correct way to execute action on page,
* instead this function will executed everywhere on all pages,
* unless you are really wanna do that?!
*
* @since 1.0
*/
public function init() {
}
/**
* Hooks before content render
*
* @since 1.0
*/
public function render_page_hooks() {
add_action( 'load-' . $this->page_id, array( $this, 'before_render' ) );
add_action( 'load-' . $this->page_id, array( $this, 'trigger_before_render_action' ) );
add_filter( 'load-' . $this->page_id, array( $this, 'add_page_hooks' ) );
if ( $this->is_edit_page() ) {
add_filter( 'forminator_data', array( $this, 'add_forminator_data' ) );
// Suppress admin notices on edit page.
add_action( 'in_admin_header', array( $this, 'suppress_wp_admin_notices' ), PHP_INT_MAX );
}
}
/**
* Suppress WP admin notices.
*
* @return void
*/
public function suppress_wp_admin_notices() {
remove_all_actions( 'admin_notices' );
remove_all_actions( 'all_admin_notices' );
remove_all_actions( 'user_admin_notices' );
remove_all_actions( 'network_admin_notices' );
}
/**
* Check if current page is edit page
*
* @return bool
*/
public function is_edit_page() {
global $plugin_page;
return ! empty( $plugin_page ) && $this->page_slug === $plugin_page &&
in_array( $this->page_slug, array( 'forminator-cform-wizard', 'forminator-poll-wizard', 'forminator-knowledge-wizard', 'forminator-nowrong-wizard' ), true );
}
/**
* Add logo info in Forminator data.
*
* @param array $data Data.
*
* @return array
*/
public function add_forminator_data( $data ) {
$data['statusBarLogoClass'] = $this->get_box_summary_classes();
return $data;
}
/**
* Return page slug
*
* @since 1.0
* @return string
*/
public function get_the_slug() {
return $this->page_slug;
}
/**
* Called when page is loaded and content not rendered yet
*
* @since 1.0
*/
public function before_render() {
}
/**
* Trigger an action before this screen is rendered
*
* @since 1.0
*/
public function trigger_before_render_action() {
do_action( 'forminator_loaded_admin_page_' . $this->get_the_slug() );
}
/**
* Add page screen hooks
*
* @since 1.0
*/
public function add_page_hooks() {
$page_action = filter_input( INPUT_GET, 'page_action' );
if ( ! forminator_cloud_templates_disabled() && 'hub_connection' === $page_action
&& ! Forminator_Hub_Connector::hub_connector_connected() ) {
return;
}
add_filter( 'user_can_richedit', '__return_true' ); // Confirms wp editor script is loaded on Forminator admin pages.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ) );
add_action( 'init', array( $this, 'init_scripts' ) );
}
/**
* Remove Get parameters for Forminator notices
*
* @param string[] $vars An array of query variables to remove from a URL.
* @return array
*/
public function remove_notice_params( $vars ) {
$vars[] = 'forminator_notice';
$vars[] = 'forminator_text_notice';
$vars[] = 'forminator_error_notice';
$vars[] = 'forminator_open_addon';
$vars[] = 'forminator_install_addon';
$vars[] = 'page_referral';
$vars[] = 'forminator_cache_bust';
if ( Forminator_Hub_Connector::hub_connector_connected() ) {
$vars[] = 'page_action';
$vars[] = 'feature';
}
return $vars;
}
/**
* Add page screen hooks
*
* @since 1.0
*
* @param string $hook Hook name.
*/
public function enqueue_scripts( $hook ) {
// Load admin scripts.
wp_register_script(
'forminator-admin',
forminator_plugin_url() . 'requirejs/main.js',
array(
'backbone',
'underscore',
'jquery',
'wp-color-picker',
),
FORMINATOR_VERSION,
true
);
forminator_common_admin_enqueue_scripts();
}
/**
* Init Admin scripts
*
* @since 1.0
*
* @param string $hook Hook name.
*/
public function init_scripts( $hook ) {
// Init jquery ui.
forminator_admin_jquery_ui_init();
}
/**
* Render page header
*
* @since 1.0
*/
protected function render_header() {
$this->show_css_warning();
$this->show_stripe_migration_notice();
if ( $this->template_exists( $this->folder . '/header' ) ) {
$this->template( $this->folder . '/header' );
} else {
?>
'
);
$hide_footer = apply_filters( 'wpmudev_branding_change_footer', $hide_footer );
$footer_text = apply_filters( 'wpmudev_branding_footer_text', $footer_text );
if ( $this->template_exists( $this->folder . '/footer' ) ) {
$this->template( $this->folder . '/footer' );
}
?>
is_edit_page() ) {
$this->render_header();
}
$this->render_page_content();
if ( ! $this->is_edit_page() ) {
$this->render_footer();
}
if ( $hub_connecting && Forminator_Hub_Connector::hub_connector_connected() ) {
self::hub_connected_successfully_modal();
}
}
?>
template( $this->folder . '/content' );
}
/**
* Load an admin template
*
* @since 1.0
*
* @param string $path Template path.
* @param array $args Arguments.
* @param bool $echo_content Echo.
*
* @return string
*/
public function template( $path, $args = array(), $echo_content = true ) {
$file = forminator_plugin_dir() . "admin/views/$path.php";
$content = '';
if ( is_file( $file ) ) {
ob_start();
if ( isset( $args['id'] ) ) {
$template_class = $args['class'];
$template_id = $args['id'];
$title = $args['title'];
$header_callback = $args['header_callback'];
$main_callback = $args['main_callback'];
$footer_callback = $args['footer_callback'];
}
include $file;
$content = ob_get_clean();
}
if ( $echo_content ) {
echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
return $content;
}
/**
* Check if template exist
*
* @since 1.0
*
* @param string $path Template path.
*
* @return bool
*/
protected function template_exists( $path ) {
$file = forminator_plugin_dir() . "admin/views/$path.php";
return is_file( $file );
}
/**
* Generates the admin body class required for WPMU DEV Shared UI
*
* @since 1.0.2
* @return string $sui_body_class
*/
public function get_sui_body_class() {
$sanitize_version = str_replace( '.', '-', FORMINATOR_SUI_VERSION );
$sui_body_class = "sui-$sanitize_version";
return $sui_body_class;
}
/**
* Add admin body classes
*
* @since 1.0.2
*
* @param string $classes Classes.
*
* @return string $classes
*/
public function admin_body_classes( $classes ) {
$screen = get_current_screen();
// Do nothing if not a forminator page.
if ( strpos( $screen->base, '_page_forminator' ) === false ) {
return $classes;
}
$classes = $this->get_sui_body_class();
// if accessibility enabled add sui select accessible class.
if ( get_option( 'forminator_enable_accessibility', false ) ) {
$classes .= ' sui-elements-accessible';
}
return $classes;
}
/**
* Get admin page param
*
* @since 1.5.4
* @return string
*/
protected function get_admin_page() {
return Forminator_Core::sanitize_text_field( 'page' );
}
/**
* Redirect to referer if available
*
* @since 1.6
*
* @param string $fallback_redirect url if referer not found.
* @param bool $to_referer Referer.
*/
protected function maybe_redirect_to_referer( $fallback_redirect = '', $to_referer = true ) {
$referer = wp_get_referer();
$referer = ! empty( $referer ) ? $referer : wp_get_raw_referer();
$referer = remove_query_arg( array( 'export', 'delete', 'forminator_notice', 'forminator_text_notice', 'forminator_error_notice' ), $referer );
if ( $referer && $to_referer ) {
wp_safe_redirect( $referer );
} elseif ( $fallback_redirect ) {
wp_safe_redirect( $fallback_redirect );
} else {
$admin_url = admin_url( 'admin.php' );
$admin_url = add_query_arg(
array(
'page' => $this->get_admin_page(),
),
$admin_url
);
wp_safe_redirect( $admin_url );
}
exit();
}
/**
* Get css class used for box summary on admin page
*
* @since 1.6
* @return string
*/
public function get_box_summary_classes() {
$classes = '';
if ( Forminator::is_wpmudev_member() ) {
$hide_branding = false;
$hide_branding = apply_filters( 'wpmudev_branding_hide_branding', $hide_branding );
$custom_branding_image = '';
$custom_branding_image = apply_filters( 'wpmudev_branding_hero_image', $custom_branding_image );
if ( $hide_branding && ! empty( $custom_branding_image ) ) {
$classes .= ' sui-rebranded';
} elseif ( $hide_branding && empty( $custom_branding_image ) ) {
$classes .= ' sui-unbranded';
}
}
return $classes;
}
/**
* Get image url for summary box
*
* @since 1.6
* @return string
*/
public function get_box_summary_image_url() {
$image_url = '';
if ( Forminator::is_wpmudev_member() ) {
$image_url = apply_filters( 'wpmudev_branding_hero_image', $image_url );
}
return $image_url;
}
/**
* Get inline style for box summary-image div
*
* @since 1.6
* @return string
*/
public function get_box_summary_image_style() {
$image_url = $this->get_box_summary_image_url();
if ( ! empty( $image_url ) ) {
return 'background-image:url(' . esc_url( $image_url ) . ')';
}
return '';
}
/**
* Show migration notice for stripe
*
* @return void
*/
public function show_stripe_migration_notice() {
$active_forms = Forminator_Form_Model::model()->get_models_with_old_stripe();
if ( ! $active_forms ) {
return;
}
?>
' . esc_html__( 'Learn more.', 'forminator' ) . ' '
: ''
);
?>
esc_html__( 'Forms', 'forminator' ),
'model' => Forminator_Form_Model::model(),
'slug' => 'form',
);
$modules[] = array(
'name' => esc_html__( 'Polls', 'forminator' ),
'model' => Forminator_Poll_Model::model(),
'slug' => 'poll',
);
$modules[] = array(
'name' => esc_html__( 'Quizzes', 'forminator' ),
'model' => Forminator_Quiz_Model::model(),
'slug' => 'quiz',
);
return $modules;
}
/**
* Modules form type
*
* @return array
*/
public function modules_form_type() {
$form_types = array();
$modules = $this->populate_modules();
foreach ( $modules as $module ) {
/**
* Forminator_Base_Form_Model
*
* @var Forminator_Base_Form_Model $model */
$model = $module['model'];
$name = $module['name'];
$form_types[ $model->get_post_type() ] = $name;
}
return $form_types;
}
/**
* Get Form Model if current requested form_id available and matched form_type
*
* @return bool|Forminator_Base_Form_Model|null
*/
public function get_form_model() {
if ( $this->get_current_form_id() ) {
$form_model = forminator_get_model_from_id( $this->get_current_form_id() );
if ( ! $form_model instanceof Forminator_Base_Form_Model ) {
return null;
}
if ( $form_model->get_post_type() !== $this->get_current_form_type() ) {
return null;
}
return $form_model;
}
return null;
}
}