theme = wp_get_theme(); $this->slug = $this->theme->template; add_action( 'admin_menu', array( $this, 'add_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_init', array( $this, 'redirect' ) ); } /** * Add theme dashboard page. */ public function add_menu() { add_theme_page( $this->theme->name, $this->theme->name, 'edit_theme_options', $this->slug, array( $this, 'render' ) ); } /** * Show dashboard page. */ public function render() { ?>
slug}" !== $hook ) { return; } wp_enqueue_style( "{$this->slug}-dashboard-style", get_template_directory_uri() . '/inc/dashboard/css/dashboard-style.css' ); wp_enqueue_script( "{$this->slug}-dashboard-script", get_template_directory_uri() . '/inc/dashboard/js/script.js', array( 'jquery' ), '', true ); } /** * Redirect to dashboard page after theme activation. */ public function redirect() { global $pagenow; if ( is_admin() && isset( $_GET['activated'] ) && 'themes.php' === $pagenow ) { wp_safe_redirect( admin_url( "themes.php?page={$this->slug}" ) ); exit; } } }