从…起/wp-includes/script-loader.php
:
$scripts->add( \'media-grid\', "/wp-includes/js/media-grid$suffix.js", array( \'media-editor\' ), false, 1 );
发件人
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 ),
) );
因此,我们可以尝试注销首字母
media-grid.js
文件并加载我们自己的版本。这可以通过插件完成:
<?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 ),
) );
}
插件现在将加载
media-grid.js
在插件文件夹中找到文件。
Disclaimer: I have no experience in Backbone, so the following is just a PoC.
这会执行此操作,但会在导航到编辑页面之前加载模式。有骨干技能的人可能会找到更干净的解决方案。
将第490行更改为:
// Update browser url when navigating media details
if ( this.model ) {
this.gridRouter.navigate( this.gridRouter.baseUrl( \'?item=\' + this.model.id ) );
}
收件人:
// 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;
}