我试图创建一个从tinyMCE工具栏启动的弹出窗口。
当我对弹出窗口的内容添加wp_enqueue_media()
调用时,我会在跟踪中获得以下异常:
[28-May-2015 01:32:00 UTC] PHP Fatal error: Call to undefined function wp_get_current_user() in /Applications/MAMP/htdocs/devblog/wp-includes/capabilities.php on line 1385
[28-May-2015 01:32:00 UTC] PHP Stack trace:
[28-May-2015 01:32:00 UTC] PHP 1. {main}() /Applications/MAMP/htdocs/devblog/wp-admin/media-upload.php:0
[28-May-2015 01:32:00 UTC] PHP 2. require_once() /Applications/MAMP/htdocs/devblog/wp-admin/media-upload.php:16
[28-May-2015 01:32:00 UTC] PHP 3. require_once() /Applications/MAMP/htdocs/devblog/wp-admin/admin.php:31
[28-May-2015 01:32:00 UTC] PHP 4. require_once() /Applications/MAMP/htdocs/devblog/wp-load.php:37
[28-May-2015 01:32:00 UTC] PHP 5. require_once() /Applications/MAMP/htdocs/devblog/wp-config.php:80
[28-May-2015 01:32:00 UTC] PHP 6. include_once() /Applications/MAMP/htdocs/devblog/wp-settings.php:215
[28-May-2015 01:32:00 UTC] PHP 7. ZipRecipes::zrdn_iframe_content($post_info = *uninitialized*, $get_info = *uninitialized*) /Applications/MAMP/htdocs/devblog/wp-content/plugins/zip-recipes/zip-recipes.php:48
[28-May-2015 01:32:00 UTC] PHP 8. ZipRecipes::view($name = *uninitialized*, $args = *uninitialized*) /Applications/MAMP/htdocs/devblog/wp-content/plugins/zip-recipes/class.ziprecipes.php:1348
[28-May-2015 01:32:00 UTC] PHP 9. include() /Applications/MAMP/htdocs/devblog/wp-content/plugins/zip-recipes/class.ziprecipes.php:1613
[28-May-2015 01:32:00 UTC] PHP 10. wp_enqueue_media($args = *uninitialized*) /Applications/MAMP/htdocs/devblog/wp-content/plugins/zip-recipes/views/create-update-recipe.php:51
[28-May-2015 01:32:00 UTC] PHP 11. get_allowed_mime_types($user = *uninitialized*) /Applications/MAMP/htdocs/devblog/wp-includes/media.php:2910
[28-May-2015 01:32:00 UTC] PHP 12. current_user_can($capability = *uninitialized*) /Applications/MAMP/htdocs/devblog/wp-includes/functions.php:2292
我的主插件文件有这个(相关代码):
if (strpos($_SERVER['REQUEST_URI'], 'media-upload.php') && strpos($_SERVER['REQUEST_URI'], '&type=z_recipe') && !strpos($_SERVER['REQUEST_URI'], '&wrt='))
{
ZipRecipes::zrdn_iframe_content($_POST, $_REQUEST);
exit;
}
和zrdn_iframe_content
生成一个普通的.php文件,其中只包含html和以下php:
<?php
// jQuery
wp_enqueue_script('jquery');
// This will enqueue the Media Uploader script
wp_enqueue_media();
?>
导致这种情况我做错了什么?
答案 0 :(得分:2)
在WordPress加载了必要的文件之前,您需要将wp_enqueue_media()
移动到不能运行的函数内部。这是函数的explained further in the WP Codex。
例如:
function load_custom_code() {
wp_enqueue_media();
}
add_action( 'admin_enqueue_scripts', 'load_custom_code' );