当我停留在插件选项页面时,我试图包括两个脚本,wp\\u media和my personal,但Wordpress没有包括它。有人帮忙吗?
/**
* Activate the plugin.
*/
function waterstampPrefix_activate() {
// Trigger our function that registers the custom post type plugin.
waterstampPrefix_setup_object_menu();
// Clear the permalinks after the post type has been registered.
flush_rewrite_rules();
}
register_activation_hook( __FILE__, \'waterstampPrefix_activate\' );
/**
* Deactivation plugin.
*/
function waterstampPrefix_deactivate() {
// Unregister the post type, so the rules are no longer in memory.
remove_menu_page( \'Waterstamp options\' );
// Clear the permalinks to remove our post type\'s rules from the database.
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, \'waterstampPrefix_deactivate\' );
/* Register the "waterstamp" menu object
*/
add_action( \'init\', \'waterstampPrefix_setup_object_menu\' );
function waterstampPrefix_setup_object_menu() {
/** Step 2 (from text above). */
add_action( \'admin_menu\', \'waterstamp_menu\' );
/** Step 1. */
function waterstamp_menu() {
add_options_page( \'Waterstamp options\', \'Waterstamp\', \'manage_options\', \'waterstamp-options\', \'waterstamp_options\' );
}
/** Step 3. */
function waterstamp_options() {
if ( !is_admin() ) {
wp_die( __( \'You do not have sufficient permissions to access this page.\' ) );
}
echo \'<div class="wrap">\';
echo \'<h1>Waterstamp</h1>\';
echo \'<p>Select the photos you would put the watermark</p>\';
//wp_die(plugin_dir_url( __FILE__ ) . \'js/app.js\');
function load_wp_media(){
wp_enqueue_media();
wp_enqueue_script( \'waterStampScript\', plugin_dir_url( __FILE__ ) . \'js/app.js\', array(\'jquery\'));
}
add_action( \'admin_enqueue_scripts\', \'load_wp_media\' );
if( wp_script_is( \'waterStampScript\', \'enqueued\' ) ){
wp_die(\'incluso!!!\');
}
$image_id = get_option( \'myprefix_image_id\' );
if( intval( $image_id ) > 0 ) {
// Change with the image size you want to use
$image = wp_get_attachment_image( $image_id, \'medium\', false, array( \'id\' => \'myprefix-preview-image\' ) );
} else {
// Some default image
$image = \'<img id="myprefix-preview-image" src="http://beepeers.com/assets/images/commerces/default-image.jpg">\';
}
echo $image;
echo \'<input type="hidden" name="myprefix_image_id" id="myprefix_image_id" value="\'; echo esc_attr( $image_id ); echo \'" class="regular-text">\';
echo \'<input type="button" class="button-primary" value="Select a image" id="myprefix_media_manager">\';
}
}
最合适的回答,由SO网友:anton 整理而成
Wordpress火灾admin_enqueue_scripts
挂起时间早于add_options_page
, 你把你的admin_enqueue_scripts
.
解决方案很简单,您需要admin_enqueue_scripts
钩在add_options_page
函数回调。
function load_wp_media(){
wp_enqueue_media();
wp_enqueue_script( \'waterStampScript\', plugin_dir_url( __FILE__ ) . \'js/app.js\', array(\'jquery\'));
}
add_action( \'admin_enqueue_scripts\', \'load_wp_media\' );