作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我真的没有看到问题是,当我尝试在 wordpress 上使用我的媒体按钮时。这是我的源代码。
php:
<?php
/**
* @package OverviewPlugin
*/
namespace Inc\Base;
use Inc\Api\SettingsApi;
use Inc\Base\BaseController;
use Inc\Api\Callbacks\AdminCallbacks;
use Inc\Api\Callbacks\WorkerCallbacks;
/**
*
*/
class WorkerController extends BaseController
{
public $callbacks;
public $settings;
public function register()
{
if ( ! $this->activated( 'worker_manager' ) ) return;
$this->settings = new SettingsApi();
$this->callbacks = new WorkerCallbacks();
add_action( 'init', array( $this, 'worker_cpt' ) );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_action( 'save_post', array( $this, 'save_meta_box' ) );
add_action( 'manage_worker_posts_columns', array( $this, 'set_custom_columns' ) );
add_action( 'manage_worker_posts_custom_column', array( $this, 'set_custom_columns_data' ), 10, 2 );
add_filter( 'manage_edit-worker_sortable_columns', array( $this, 'set_custom_columns_sortable' ) );
$this->setShortcodePage();
add_shortcode( 'worker-display', array( $this, 'worker_display' ) );
add_action('admin_enqueue_scripts', array($this, 'my_admin_scripts'));
add_action('admin_enqueue_scripts', array($this,'my_admin_scripts'));
add_action('admin_enqueue_styles',array($this,'my_admin_styles'));
}
function my_admin_scripts() {
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script('my-upload', WP_PLUGIN_URL.'/overview-plugin/assets/worker.min.js', array('jquery','media-upload','thickbox'));
wp_enqueue_script('my-upload');
}
function my_admin_styles() {
wp_enqueue_style('thickbox');
}
public function worker_display()
{
ob_start();
echo "<link rel=\"stylesheet\" href=\"$this->plugin_url/assets/display.min.css\" type=\"text/css\" media=\"all\" />";
require_once( "$this->plugin_path/templates/display.php" );
echo "<script src=\"$this->plugin_url/assets/display.min.js\"></script>";
return ob_get_clean();
}
public function render_features_box($post)
{
wp_nonce_field( 'overview_worker', 'overview_worker_nonce' );
$data = get_post_meta( $post->ID, '_overview_worker_key', true );
$name = isset($data['name']) ? $data['name'] : '';
$description = isset($data['description']) ? $data['description'] : '';
$image = isset($data['image']) ? $data['image'] : '';
$position = isset($data['position']) ? $data['position'] : '';
$github = isset($data['github']) ? $data['github'] : '';
$linkedin = isset($data['linkedin']) ? $data['linkedin'] : '';
$xing = isset($data['xing']) ? $data['xing'] : '';
$facebook = isset($data['facebook']) ? $data['facebook'] : '';
$approved = isset($data['approved']) ? $data['approved'] : false;
$featured = isset($data['featured']) ? $data['featured'] : false;
?>
<p>
<label class="meta-label" for="overview_worker_name">Name</label>
<input type="text" id="overview_worker_name" name="overview_worker_name" class="widefat" value="<?php echo esc_attr( $name ); ?>">
</p>
<p>
<label class="meta-label" for="overview_worker_description">Short Description</label>
<input type="text" id="overview_worker_description" name="overview_worker_description" class="widefat" value="<?php echo esc_attr( $description ); ?>">
</p>
<p>
<label class="meta-label" for="overview_worker_image">Image</label>
<input id="upload_image" type="text" size="36" name="upload_image" value="<?php echo esc_attr( $image ); ?>" />
<input id="upload_image_button" type="button" value="Upload Image" />
</p>
jQuery(document).ready( function( $ ) {
$('#upload_image_button').click(function() {
formfield = $('#upload_image').val();
tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );
window.send_to_editor = function(html) {
imgurl = $(html).attr('src');
$('#upload_image').val(imgurl);
tb_remove();
}
return false;
});
});
worker.min.js:6 Uncaught ReferenceError: formfield is not defined
at HTMLInputElement.<anonymous> (worker.min.js:6)
at HTMLInputElement.dispatch (load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate,utils,underscore,thickbox,shortcode,media-upload,moxiejs,plupload&ver=5.3.2:3)
at HTMLInputElement.r.handle (load-scripts.php?c=1&load[chunk_0]=jquery-core,jquery-migrate,utils,underscore,thickbox,shortcode,media-upload,moxiejs,plupload&ver=5.3.2:3)
最佳答案
要么你可以这样做
formfield = $('#upload_image').val();
关于javascript - 我在尝试将上传媒体按钮添加到自定义元框时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59420481/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!