简体   繁体   中英

How to get proper WordPress admin url in wordpress

I have the plugin with folder/files and I am using the plugin in admin dashboard.

Folder: views
       actions.php
       client_register.php

And I created one menu like this

add_submenu_page("custom", "Client Registration", "New Client Site",'manage_options', "client_register", 'page_client_register');

if ( ! function_exists( 'page_client_register' ) ) {
    function page_client_register(){
        render_page_client_register();
    }
}

And I am able to call the page_client_register function (which is actually a independent php file) like this. http://127.0.0.1/wp-admin/admin.php?page=client_register This is possible because I created the menu.

How can I access other files similar to that way? using wp-admin/admin.php url

If I directly call the files like http://127.0.0.1/wp-content/plugins/<pluginname>/views/actions.php it says Direct PHP ACCESS is not allowed in some cloud sites.

How can I access these files using wp-admin/admin.php ?

You get the concrete URL to admin.php by using the admin_url function:

admin_url('admin.php'); # http(s)://localhost/wp-admin/admin.php

And in your concrete example you add the page query-info part:

$url = admin_url('admin.php?page=client_register');
wp_redirect($url); 
exit;

OR

admin_url( "client_reg_action.php?page=client_register"] )
admin_url( "admin.php?page=".$_GET["page"] )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM