WordPress.org

Support

Support » Plugins and Hacks » adding a media submenu issues

adding a media submenu issues

  • There is a slight usability issue with 3.1/3.2 regarding some plugins that depend on wp-admin\edit_tags.php.

    For example, let’s say the plugin defines Media->Media-Tags. Clicking on ‘Media-Tags’ submenu does not keep the context in the ‘Media’ section but it jumps up to the ‘Posts’ section instead. The reason is ‘edit_tags.php’ does not handle $parent_file == <media>

    I’ve hacked the offending code here: edit_tags.php ~ li26 [RC3]

    if ( 'post' != $post_type ) {
    	$parent_file = "edit.php?post_type=$post_type";
    	$submenu_file = "edit-tags.php?taxonomy=$taxonomy&post_type=$post_type";
    } else if ( 'link_category' == $tax->name ) {
    	$parent_file = 'link-manager.php';
    	$submenu_file = 'edit-tags.php?taxonomy=link_category';
    //// [alx359] fix when adding a 'media' submenu
    } else if ( false !== strpos($tax->name, 'media') ) {
    	$parent_file = 'upload.php';
    	$submenu_file = "edit-tags.php?taxonomy=$taxonomy";
    ////
    } else {
    	$parent_file = 'edit.php';
    	$submenu_file = "edit-tags.php?taxonomy=$taxonomy";
    }

    I’m aware this is not a robust enough fix (shouldn’t depend on the ‘media’ piece on the title, and should be menu-neutral). At least hope the devs would do it better.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi alx359,

    Can you provide some example code to replicate the problem?

    Hello Dion,

    Sure, the scenario is installing plugins that add tagging functionality to the Media Library, via reusing edit_tags.php. Two of them with the same issue explained currently on my machine:

    plugins\file-gallery\file-gallery.php ~ li 765 [v.1.7-RC2]

    /**
     * Adds media tags submenu
     */
    function file_gallery_media_submenu()
    {
    add_submenu_page('upload.php', __("Media tags", "file-gallery"), __("Media tags", "file-gallery"), 'upload_files', 'edit-tags.php?taxonomy=' . FILE_GALLERY_MEDIA_TAG_NAME);
    }
    add_action('admin_menu', 'file_gallery_media_submenu');

    plugins\media-tags\mediatags_admin.php ~ li 314 [v.3.0.4]

    // Adds the 'Media-Tags' submenu option under the Media nav
    
    add_media_page( _x("Media-Tags", 'menu label', MEDIA_TAGS_I18N_DOMAIN),
    				_x("Media Tags", 'page label', MEDIA_TAGS_I18N_DOMAIN),
    				MEDIATAGS_MANAGE_TERMS_CAP,
    				"edit-tags.php?taxonomy=media-tags" );

    HTH

    BTW,
    Made the attempt yesterday and now to log-in to the Trac as recommended here, with my usr/psw for these forums. For some reason, I couldn’t.

    Alright, so, Basically Core doesn’t support taxonomies in the Media menu very well..

    The posts menu is being used as that’s whats being specified in the call, by not including a ‘post_type’ parameter to the url, WordPress is assuming it’s for the ‘post’ Post type. The URL being accessed, and specified in the add_*_page() call needs to be unique.

    The solution in this case is to use something like the following until a time when Core supports attachment taxonomies better.

    function foobar_tax() {
    	add_media_page( "Foobar", "Foobar Tags",
    				'upload_files',
    				"edit-tags.php?taxonomy=foobar&post_type=attachment" );
    }
    add_action('admin_menu', 'foobar_tax');
    function foobar_tax_menu_correction($parent_file) {
    	if ( 'edit.php?post_type=attachment' == $parent_file )
    		$parent_file = 'upload.php';
    
    	return $parent_file;
    }
    add_action('parent_file', 'foobar_tax_menu_correction');

    Also; Since this is not specific to Alpha/Betas, i’m moving this to the Plugin ndevelopment forum.
    There’s a trac ticket for Taxonomy support in the Media menu: http://core.trac.wordpress.org/ticket/13414

    Made the attempt yesterday and now to log-in to the Trac as recommended here, with my usr/psw for these forums. For some reason, I couldn’t.

    Try changing your password on the forums and see if that helps.

    Thanks Dion! The tip was very helpful. It helped a lot and with other issues.

    alx359, did it work? I can’t seem to get it to work for me. Was there something else that you wound up doing?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘adding a media submenu issues’ is closed to new replies.