init_hooks(); } /** * Init hooks. * * @since 1.0.0 */ private function init_hooks() { add_action( 'admin_menu', array( $this, 'init_menus' ) ); add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 ); add_filter( 'update_footer', array( $this, 'admin_footer_version' ), 11 ); add_action( 'in_admin_header', array( $this, 'hide_admin_notices' ) ); add_action( 'admin_init', array( $this, 'admin_redirects' ) ); } /** * Init menus. * * @since 1.0.0 */ public function init_menus() { $blockart_page = add_menu_page( esc_html__( 'BlockArt', 'blockart' ), esc_html__( 'BlockArt', 'blockart' ), 'manage_options', 'blockart', array( $this, 'markup' ), 'data:image/svg+xml;base64,' . base64_encode( '' ) // phpcs:ignore ); add_submenu_page( 'blockart', esc_html__( 'Getting Started', 'blockart' ), esc_html__( 'Getting Started', 'blockart' ), 'manage_options', 'blockart#/getting-started', array( $this, 'markup' ) ); add_submenu_page( 'blockart', esc_html__( 'Settings', 'blockart' ), esc_html__( 'Settings', 'blockart' ), 'manage_options', 'blockart#/settings', array( $this, 'markup' ) ); add_action( "admin_print_scripts-$blockart_page", array( $this, 'enqueue' ) ); remove_submenu_page( 'blockart', 'blockart' ); } /** * Markup. * * @since 1.0.0 */ public function markup() { echo '
'; } /** * Enqueue. * * @since 1.0.0 */ public function enqueue() { wp_enqueue_script( 'blockart-admin' ); wp_enqueue_style( 'blockart-admin' ); } /** * Change admin footer text on BlockArt page. * * @param string $text Admin footer text. * @return string Admin footer text. */ public function admin_footer_text( $text ) { if ( 'toplevel_page_blockart' !== get_current_screen()->id ) { return $text; } if ( ! get_option( '_blockart_admin_footer_text_rated' ) ) { $text = sprintf( /* translators: 1: BlockArt, 2: Five stars */ esc_html__( 'Enjoyed %1$s? please leave us a %2$s rating. We really appreciate your support!', 'blockart' ), sprintf( '%s', esc_html__( 'BlockArt', 'blockart' ) ), '★★★★★' ); } else { $text = esc_html__( 'Thank you for creating with BlockArt.', 'blockart' ); } return $text; } /** * Override WordPress version with plugin version. * * @param string $version Version text. * @return string Version text. */ public function admin_footer_version( $version ) { return 'toplevel_page_blockart' !== get_current_screen()->id ? $version : __( 'Version ', 'blockart' ) . BLOCKART_VERSION; } /** * Redirecting user to dashboard page. */ public function admin_redirects() { if ( get_option( '_blockart_activation_redirect' ) && apply_filters( 'blockart_activation_redirect', true ) ) { update_option( '_blockart_activation_redirect', false ); wp_safe_redirect( admin_url( 'index.php?page=blockart#/getting-started' ) ); exit; } } /** * Hide admin notices from BlockArt admin pages. * * @since 1.0.0 */ public function hide_admin_notices() { // Bail if we're not on a BlockArt screen or page. if ( empty( $_REQUEST['page'] ) || false === strpos( sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ), 'blockart' ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } global $wp_filter; $ignore_notices = apply_filters( 'blockart_ignore_hide_admin_notices', array() ); foreach ( array( 'user_admin_notices', 'admin_notices', 'all_admin_notices' ) as $wp_notice ) { if ( empty( $wp_filter[ $wp_notice ] ) ) { continue; } $hook_callbacks = $wp_filter[ $wp_notice ]->callbacks; if ( empty( $hook_callbacks ) || ! is_array( $hook_callbacks ) ) { continue; } foreach ( $hook_callbacks as $priority => $hooks ) { foreach ( $hooks as $name => $callback ) { if ( ! empty( $name ) && in_array( $name, $ignore_notices, true ) ) { continue; } if ( ! empty( $callback['function'] ) && ! is_a( $callback['function'], '\Closure' ) && isset( $callback['function'][0], $callback['function'][1] ) && is_object( $callback['function'][0] ) && in_array( $callback['function'][1], $ignore_notices, true ) ) { continue; } unset( $wp_filter[ $wp_notice ]->callbacks[ $priority ][ $name ] ); } } } } }