[wp-trac] [WordPress Trac] #22887: JavaScript inserted using "attachment_fields_to_edit" executes too early
WordPress Trac
noreply at wordpress.org
Mon May 26 13:54:00 UTC 2014
#22887: JavaScript inserted using "attachment_fields_to_edit" executes too early
--------------------------+------------------------------
Reporter: liviumirea | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 3.5
Severity: normal | Resolution:
Keywords: close | Focuses: javascript
--------------------------+------------------------------
Changes (by ericlewis):
* keywords: => close
* focuses: => javascript
Comment:
Can't reproduce, using this code in an mu-plugin:
{{{
#!php
<?php
/**
* Remove the new media button, add the old media button.
*/
function rejigger_media_button_actions() {
remove_action( 'media_buttons', 'media_buttons' );
add_action( 'media_buttons', 'old_media_buttons' );
}
add_action( 'admin_init', 'rejigger_media_button_actions' );
/**
* Create the HTML for the old media button.
*/
function old_media_buttons( $editor_id = 'content' ) {
printf( '<a href="%s" class="thickbox add_media" id="%s-add_media"
title="%s" onclick="return false;">%s</a>',
esc_url( get_upload_iframe_src() ),
esc_attr( $editor_id ),
esc_attr__( 'Add Media' ),
sprintf( 'Upload/Insert <img src="%s" width="15"
height="15" />',
esc_url( admin_url( 'images/media-
button.png?ver=20111005' ) ) ) );
}
add_action('attachment_fields_to_edit', 'bug_test', 20, 2);
function bug_test($form_fields, $post) {
if (!is_array($form_fields)) {
$form_fields = array();
}
$form_fields['bug_test'] = array(
'label' => 'Bug test',
'input' => 'html',
'html' => '
<div id="bug_test_div"></div>
<script
type="text/javascript">alert(jQuery("#bug_test_div").size())</script>
',
'value' => 0
);
return $form_fields;
}
}}}
At this point you have to jump through hoops to use the thickbox version
of the media modal (retired 5 major versions ago), so I lean towards
close.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/22887#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list