WordPress.org

Ready to get started?Download WordPress

Forums

[closed] How to get URL of admin menu item? (3 posts)

  1. Mickey Kay
    Member
    Posted 8 months ago #

    Hi there,

    Is there a simple way to get the URL of admin menu items? I've grabbed the gobal $menu and $submenu arrays which contain quite a bit of info about each menu item, but digging into menu_header.php, it appears that there's quite a bit of conditional logic going on behind the scenes to generate basic urls (e.g. /wp-admin/options-general.php?page=easy-custom-templates, or /wp-admin/admin.php?page=wpcf-import-export). Some of the logic, for example, looks like this:

    if ( ! empty( $menu_hook ) || ( ( 'index.php' != $sub_item[2] ) && file_exists( WP_PLUGIN_DIR . "/$sub_file" ) && ! file_exists( ABSPATH . "/wp-admin/$sub_file" ) ) ) {
    	// If admin.php is the current page or if the parent exists as a file in the plugins or admin dir
    	if ( ( ! $admin_is_parent && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! is_dir( WP_PLUGIN_DIR . "/{$item[2]}" ) ) || file_exists( $menu_file ) )
    		$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), $item[2] );
    	else
    		$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), 'admin.php' );
    
    	$sub_item_url = esc_url( $sub_item_url );
    	echo "<li$class><a href='$sub_item_url'$class>$title</a></li>";
    } else {
    	echo "<li$class><a href='{$sub_item[2]}'$class>$title</a></li>";
    }

    Does anyone know of a simple, reliable way to get admin menu item URLs for use in plugins? Thanks!

  2. bcworkz
    Member
    Posted 8 months ago #

  3. WPyogi
    Volunteer Moderator
    Posted 8 months ago #

    Closed - @McGuive7 - please don't post duplicate threads.

Topic Closed

This topic has been closed to new replies.

About this Topic