page_slug = $page_slug; $this->folder = $folder; if ( ! $parent ) { $this->page_id = add_menu_page( $page_title, $menu_title, ai_robot_get_admin_cap(), $page_slug, $render ? array( $this, 'render' ) : null, 'dashicons-buddicons-replies' ); } else { $this->page_id = add_submenu_page( $parent, $page_title, $menu_title, ai_robot_get_admin_cap(), $page_slug, $render ? array( $this, 'render' ) : null ); } if ( $render ) { $this->render_page_hooks(); } $this->init(); } /** * Use that method instead of __construct * * @since 1.0.0 */ public function init() { } /** * Hooks before content render * * @since 1.0.0 */ public function render_page_hooks() { add_filter( 'load-' . $this->page_id, array( $this, 'add_page_hooks' ) ); } /** * Render page container * * @since 1.0.0 */ public function render() { ?>
render_menu(); ?>
render_header(); $this->render_page_content(); $this->render_footer(); ?>
template_exists( 'menu/header' ) ) { $this->template( 'menu/header' ); } } /** * Render page header * * @since 1.0.0 */ protected function render_header() { ?>
template_exists( $this->folder . '/header' ) ) { $this->template( $this->folder . '/header' ); } else { ?>

template_exists( $this->folder . '/footer' ) ) { $this->template( $this->folder . '/footer' ); } ?> template( $this->folder . '/content' ); } /** * Load an admin template * * @since 1.0 * * @param $path * @param array $args * @param bool $echo * * @return string */ public function template( $path, $args = array(), $echo = true ) { $file = AI_ROBOT_DIR . "/admin/views/$path.php"; $content = ''; if ( is_file( $file ) ) { ob_start(); $settings = $args; include $file; $content = ob_get_clean(); } if ( $echo ) { echo $content;// phpcs:ignore } return $content; } /** * Check if template exist * * @since 1.0.0 * * @param $path * * @return bool */ protected function template_exists( $path ) { $file = AI_ROBOT_DIR . "admin/views/$path.php"; return is_file( $file ); } /** * Add page screen hooks * * @since 1.0.0 */ public function add_page_hooks() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'init', array( $this, 'init_scripts' ) ); } /** * Add page screen hooks * * @since 1.0.0 * * @param $hook */ public function enqueue_scripts( $hook ) { // Load admin fonts ai_robot_admin_enqueue_fonts( AI_ROBOT_VERSION ); // Load admin styles ai_robot_admin_enqueue_styles( AI_ROBOT_VERSION ); $ai_robot_data = new Ai_Robot_Admin_Data(); // Load admin scripts ai_robot_admin_enqueue_scripts( AI_ROBOT_VERSION, $ai_robot_data->get_options_data() ); } /** * Init Admin scripts * * @since 1.0.0 * * @param $hook */ public function init_scripts( $hook ) { // Init jquery ui ai_robot_admin_jquery_ui_init(); } /** * Redirect to referer if available * * @since 1.0.0 * * @param string $fallback_redirect url if referer not found */ protected function maybe_redirect_to_referer( $fallback_redirect = '' ) { $referer = wp_get_referer(); $referer = ! empty( $referer ) ? $referer : wp_get_raw_referer(); if ( $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 admin page param * * @since 1.0.0 * @return string */ protected function get_admin_page() { return ( isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '' ); } } endif;