Skip to content

Instantly share code, notes, and snippets.

@raftaar1191
Last active March 3, 2017 13:13
Show Gist options
  • Save raftaar1191/7e29aae14148b5ec88af6cf8189cbb0c to your computer and use it in GitHub Desktop.
Save raftaar1191/7e29aae14148b5ec88af6cf8189cbb0c to your computer and use it in GitHub Desktop.
Add sub menu in media tab in admin menu
<?php
// check if function does not exists
if ( ! function_exists( 'rtmedia_add_admin_bar_media_sub_menu_for_upload' ) ) {
function rtmedia_add_admin_bar_media_sub_menu_for_upload() {
// Please change the page_slug if you want from here
$page_slug = 'file-upload';
// check if function does not exists and RTMEDIA_MEDIA_SLUG is alredy defined
if ( function_exists( 'get_page_by_path' ) && defined( 'RTMEDIA_MEDIA_SLUG' ) ) {
// get the page by slug
$page_data = get_page_by_path( $page_slug );
// check if the page exists.
if ( is_object( $page_data ) ) {
// check if the page id exists.
if ( isset( $page_data->ID ) ) {
global $wp_admin_bar;
global $rtmedia;
$page_id = $page_data->ID;
$wp_admin_bar->add_menu( array(
'parent' => 'my-account-' . RTMEDIA_MEDIA_SLUG,
'id' => 'my-account-media-' . $page_slug,
'title' => 'Upload',
'href' => get_permalink( $page_id ),
) );
}
}
}
}
}
add_action( 'rtmedia_add_admin_bar_media_sub_menu', 'rtmedia_add_admin_bar_media_sub_menu_for_upload', 10 );
@raftaar1191
Copy link
Author

raftaar1191 commented Mar 2, 2017

Please the above snippet in functions.php of child themes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment