0

I'm trying to create a menu and a submenu in wordpress, here is the code:

<?php
require_once(ABSPATH.'wp-config.php');
require_once(ABSPATH.'wp-includes/pluggable.php');
require_once(ABSPATH.'wp-admin/includes/plugin.php ');

require_once ABSPATH.'wp-content/plugins/acesso-rapido/layouts/admin-layout.php';
    class Menu{
        
        // Propriedades (variáveis de classe)
        private $PageTitle;
        private $MenuTitle;
        private $Capability;
        private $MenuSlug;
        private $Function;
        private $IconUrl;
        private $Position;

        // Método construtor
        public function __construct($Capability, $MenuSlug) {
            $this->Capability = $Capability;
            $this->MenuSlug = $MenuSlug;

            $this->PageTitle = "Acesso Rapido";
            $this->MenuTitle = "Acesso Rapido";
            $this->Function = 'LayoutPageAdmin';
            $this->IconUrl = 'dashicons-store';
            $this->Position = 7;
            
            
            wp_enqueue_style('bootstrap-css', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css');
            wp_enqueue_script('bootstrap-js', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js', array('jquery'), '4.5.2', true);

            do_action('wp_enqueue_scripts', 'carregar_bootstrap');
        }

        public function CallAdminMenu(){
            add_action('admin_menu',
            add_menu_page(
                $this->PageTitle,
                $this->MenuTitle,
                $this->Capability,
                $this->MenuSlug,
                $this->Function,
                $this->IconUrl,
                $this->Position,
            ));
        }

        public function CallAdminSubMenu($page_title, $menu_title, $parent_slug, $menu_slug, $callback, $position){
            add_action('admin_menu', add_submenu_page(
                
                $this->MenuSlug,
                $page_title,
                $menu_title,
                'manage_options',
                $menu_slug,
                $callback,
                $position,
            ), 99);
        }
        
        public function RenderAdminPage(){
            // include_once '../layouts/admin-layout.php';          
        }   
    }

?>
<?php
/**
 * Plugin Name: Acesso Rápido
 * Author: Bruno Lima
 **/
require_once(ABSPATH.'wp-config.php');

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

if ( is_admin() ) {
    // we are in admin mode
    
    require_once(ABSPATH.'wp-content/plugins/acesso-rapido/componentes/menu-admin.php');
    
    $MenuAdmin = new Menu('manage_options', 'layouts/admin-layout.php');

    add_action('admin-menu',$MenuAdmin->CallAdminMenu());

    $MenuAdmin->CallAdminSubMenu('Adicionar Link Acesso Rápido',
                                    'Adicionar Link',
                                    'layouts/admin-layout.php',
                                    'layouts/admin-edit-acesso-rapido.php',
                                    'EditAcessoRapidoPage',
                                    1);
}

?>

But somehow, the submenu is redirecting to http://localhost/wordpress/wp-admin/layouts/admin-edit-acesso-rapido.php and not to a page into the administrative panel. I noticed that the url in the ul list is:

<a href="layouts/admin-edit-acesso-rapido.php">Adicionar Link</a>

Once in a menu that is working is:

<a href="admin.php?page=layouts/admin-layout.php" class="wp-first-item current" aria-current="page">Acesso Rapido</a>

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.