2

By default, when I click on an item in the media library, it takes me to the Attachment Details page, e.g. .../wp-admin/upload.php?item=65.

What would I need to edit to make it go straight to the "Edit More Details" page instead? E.g. .../wp-admin/post.php?post=65&action=edit

I assumed it would be as simple as changing where the href is pointing - but there doesn't seem to be a href there! I'm assuming the link is generated a different way?

2
+50

From /wp-includes/script-loader.php:

$scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 );

From wp-admin/upload.php:

wp_enqueue_script( 'media-grid' );
wp_enqueue_script( 'media' );
wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
    'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
) );

So, we can try to unregister the initial media-grid.js file and load our own version. This can be done via a plugin:

<?php
/**
 * Plugin Name: Change Media Grid link
 * Plugin URI: http://wordpress.stackexchange.com/q/168981/17305
 */

add_action( 'admin_enqueue_scripts', 'loadmyscriptinstead_168981' );

function loadmyscriptinstead_168981 (){
    wp_deregister_script( 'media-grid' );

    wp_register_script( 'media-grid', plugin_dir_url( __FILE__ ) . 'media-grid.js', array( 'media-editor' ), false, 1 );

    wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
            'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
        ) );

}

The plugin will now load a modified version of the media-grid.js file found in the plugin folder.

Disclaimer: I have no experience in Backbone, so the following is just a PoC.

This does the job but loads the modal before navigating to the edit page. Someone with Backbone skills may find a cleaner solution.

Change Line 490 from:

// Update browser url when navigating media details
if ( this.model ) {
    this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) );
}

to:

// Update browser url when navigating media details
if ( this.model ) {
    this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) );

    var currentLocation = location.href;
    //replace upload.php by post.php
    var newRoute = currentLocation.replace('upload.php', 'post.php');
    //replace item ?item= by ?post=
    newRoute = newRoute.replace('?item=', '?post=');
    newRoute += '&action=edit';

    window.location = newRoute;
}
0

You would be changing the wordpress back-end, these changes will be lost when updating.

I suggest you press this button instead: http://i.imgur.com/5Ce3MzH.png (Only had a danish installation at hand, but it should look the same)

This gives you a detailed view, and all links in this view, leads to the "More details" page.

Hope this could help!

0

The link you want to modify is generated via Javascript in the file /wp-includes/js/media-grid.js (normally the minified version is loaded: /wp-includes/js/media-grid.min.js). At line 314 (in Wordpress 4.0.1) :

313:    routes: {
314:        'upload.php?item=:slug':    'showItem',
315:        'upload.php?search=:query': 'search'
316:    },

You can try modifying this to be:

313:    routes: {
314:        'post.php?action=edit&post=:slug':    'showItem',
315:        'upload.php?search=:query': 'search'
316:    },

I didn't try this my self though. @Jeppe is right about this modification being problematic, as updates will overwrite any changes made to the .js files.

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.