0

Is it against the WordPress guidelines to create a separate Administration section for my plugin? For example, Elementor opens a separate page for building pages but I'd like to create a similar administration section but do more stuff as WordPress itself does. Like items listing, editing, etc. You could say it might end up being somewhat like a whole different website inside another website I guess if I am to keep adding more features.

Please ask if more information is needed :)

Edit 1:

When an admin clicks on my plugin's admin menu, I will hide everything belonging to WordPress, like the top bar menu, sidebar, notices, etc. Or maybe I will start with a blank page and show it to only admins to avoid extra work. Would my plugin get accepted if I were to do this?

0

So, As we discussed in comments, the better approach is to do something on Frontend.

It adds unnecessary wait to the page, and therefore it isnt viable to have it on backend. If you are building plugin for your own use, then the approach of having backend filters removed on that page could be useful, but I cant recommend it for a plugin to be published in wordpress repository.

So, what you need to do is have a page on frontend, that uses a completely blank page template, and then in it do whatever you want.

So, first of all in the event for plugin activation, create a page, something like this.

When the plugin activates, you need to check if the page already exists, if it does no need to create a new page

register_activation_hook( __FILE__, 'myplugin_activate' );
    function myplugin_activate() {
    // I have set page Title as admin, because I hope thats what you would probably call it
    $new_page_title     = __('Admin','text-domain'); // Page's title
    $new_page_content   = '';               // Leave it empty, Template does the trick
    $new_page_template  = plugin_dir_path( __FILE__ ) . 'page-custom-page.php';       // The template to use for Admin Stuff
    $page_check = get_page_by_title($new_page_title);   // Why make something which exists
    // Store the above data in an array
    $new_page = array(
            'post_type'     => 'page', 
            'post_title'    => $new_page_title,
            'post_content'  => $new_page_content,
            'post_status'   => 'publish',
            'post_author'   => 1,
            'post_name'     => 'admin'
    );
    // If the page doesn't already exist, create it
    if(!isset($page_check->ID)){
        $new_page_id = wp_insert_post($new_page);
        if(!empty($new_page_template)){
            update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
        }
    }
}

So we now have a page, but we need to make it empty as vacuum, because that is what you wanted.

Remember you are making a plugin, and the directory path included in answer is for plugin director, so create a file page-custom-page.php in your plugin.

Note: You wanted empty page, so there is no point of we telling you what to include in header, as you would not like to include it for your own purpose, therefore based on the info you provided template shall remain empty, and I am not showing any code for it.

One thing I would recommend is to restrict its access to non admin people, It's simple, but I still include it.

if(is_user_logged_in()){
    global $current_user;
    $Current_User = get_current_user_id();
    if(user_can( $Current_User, 'administrator' )){
        // Your Code should come somewhat here
    }
}

Now as far as admin is concerned.

Let's Again make an Admin Menu item.

function wpse_374104(){
    add_menu_page( 
        __( 'Admin', 'textdomain' ),
        'custom menu',
        'manage_options',
        'Admin',
        'Plugin_Admin_Page',
        plugins_url( 'wpse374104/images/icon.png' ),
        5
    ); 
}
add_action( 'admin_menu', 'wpse374104' );

This code is same as the last version of my answer, I just changed the Page Title.

So, now we created an arbitrary slug to which your admin menu page would link.

Now, We need a redirect.

function Plugin_Admin_Page() {

    global $pagenow;

    # Check current admin page.
    if ( $pagenow == 'Plugin_Admin_Page') {
        wp_redirect( site_url( '/admin' ) );
        exit;

    }
}

add_action('admin_init', 'Plugin_Admin_Page');

It does the trick in my opinion, I think I have answer everything needed by you, I have put a lot of effort, hope it works good for you. I am always there in comments to help further.

PSA: Incase someone else other than the person who asked question is reading this, I do not recommend putting admin stuff in frontend, as it is not a good practice, but if you do, please include link back to the admin page, or the page from the user got referred, because otherwise it becomes tough(relatively) to navigate back to admin.

| improve this answer | |
  • Thanks for the great explanation but I'm still a bit confused. I want to customize the admin section to the extent where I will not show the WordPress's default top bar and sidebar, no notices. Just my plugin's content, when an admin clicks on my plugin's admin menu. Would WordPress really allow that? And I'd also add my plugin logo at a corner. – Krishna Suwal Sep 1 at 13:36
  • Okay i get it not very tough imo, just confirm that you want to build an admin page, like I did in my answer, but just that page should be relatively blank, like no sidebar and top menu. right? – Aditya Agarwal Sep 1 at 13:54
  • @KrishnaSuwal not showing the admin menu and the top bar is a separate problem that you did not ask about, you should ask about that in a separate question, however, if you're totally replacing the pages in the admin then perhaps WP Admin is not the appropriate place to do that, but rather the frontend – Tom J Nowell Sep 1 at 13:56
  • @TomJNowell I think U are right, I on my own site, maintain stats and data of over 300 users, WordPress can be messy, In my opinion the better approach is to create a frontend page, and then restrict for logged in users or may be admins, though the admin alternative is still possible in my opinion. What u suggest should be backend approack? – Aditya Agarwal Sep 1 at 14:14
  • 1
    What you're wanting to build is not a WP Admin page. I would not build an admin page then hide everything in the admin, just build an area of the frontend visible only to logged in users. You can always link to it from the admin menu. – Tom J Nowell Sep 1 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.