不知何故,添加到“Insert Into URL”的帖子相互矛盾

时间:2011-12-30 作者:Trip

我添加了第二个上传图像(doc\\u thumb\\u box)。它们彼此完全独立工作。但是,当添加第二个URL时,第一个URL(doc\\u uri\\u box)不再将URL的值粘贴到框中。相反both 如果框中有任何内容,则将变为空白。

是否有明显的矛盾之处?

public static function doc_thumb_box() {
global $post;

$thumb = get_post_meta( $post->ID, \'upload_image\', true );

function my_admin_scripts() {
wp_enqueue_script(\'media-upload\');
wp_enqueue_script(\'thickbox\');
wp_enqueue_script(\'my-upload\');
}

function my_admin_styles() {
wp_enqueue_style(\'thickbox\');
}

if (isset($_GET[\'page\']) && $_GET[\'page\'] == \'my_plugin_page\') {
add_action(\'admin_print_scripts\', \'my_admin_scripts\');
add_action(\'admin_print_styles\', \'my_admin_styles\');
}

echo \'Enter a URL or upload an image for the thumb.\';
echo \'<br />\';
echo \'<br />\';
echo \'<label for="upload_image">\';
echo \'<input id="upload_image" type="text" size="36" name="upload_image" value=" \' . $thumb . \'" />\';
echo \'<input id="upload_image_button" type="button" value="Upload Thumb" />\';


echo "<script type=\\"text/javascript\\">
jQuery(document).ready(function() {

jQuery(\'#upload_image_button\').click(function() {
 formfield = jQuery(\'#upload_image\').attr(\'name\');
 tb_show(\'\', \'media-upload.php?type=image&amp;TB_iframe=true\');
 return false;
});

window.send_to_editor = function(html) {
 imgurl = jQuery(\'img\',html).attr(\'src\');
 jQuery(\'#upload_image\').val(imgurl);
 tb_remove();
}

});
</script>\\r\\n";

}

public static function doc_uri_box() {
    global $post;

    $uri = get_post_meta( $post->ID, \'wpa_upload_doc\', true );
    echo "<style type=\\"text/css\\">
#edit-slug-box {
display: none;
}

</style>";
   echo \'<p>Please provide the abosulte url of the file (including the <code>http://</code>):</p>\';
    echo \'<input type="text" id="wpa_upload_doc" name="wpa_upload_doc" value="\' . $uri . \'" size="25" style="width:85%" />\';
    echo \'<input class="button" id="upload_doc_button" type="button" value="Upload Publication" alt="Upload Publication" />\';
    echo "<script type=\\"text/javascript\\">

jQuery(document).ready(function() {
jQuery(\'#upload_doc_button\').click(function() {
    formfield = jQuery(\'#wpa_upload_doc\').attr(\'name\');     
    tb_show(\'Upload Publication\', \'media-upload.php?TB_iframe=1&width=640&height=263\');
    return false;
});

window.send_to_editor = function(html) {
    var docurl = jQuery(html).attr(\'href\');
    jQuery(\'#wpa_upload_doc\').val(docurl);
    tb_remove();
}
});
</script>\\r\\n";
}

UPDATE

对于doc_uri_box() 方法,我发现window.send_to_editor 永远不会执行代码块!真奇怪。。

1 个回复
SO网友:Trip

所以这里有一些不必要的变量。

我不需要定义formfield 作为var,因为它未使用。我定义了两次window.send_to_editor 在每个单击功能中

This is the final version of both the jQuery functions ( the source of the problem)

jQuery(\'#upload_doc_button\').live(\'click\', function() {

    window.send_to_editor = function(html) {
        var docurl = jQuery(html).attr(\'href\');
      jQuery(\'#wpa_upload_doc\').val(docurl);
        tb_remove();
    }

    tb_show(\'Upload Publication\', \'media-upload.php?TB_iframe=1&width=640&height=263\');
    return false;
}); 


jQuery(\'#upload_image_button\').click(function() {

 window.send_to_editor = function(html) {
  imgurl = jQuery(\'img\',html).attr(\'src\');
  jQuery(\'#upload_image\').val(imgurl);
  tb_remove();
 }

 tb_show(\'\', \'media-upload.php?type=image&amp;TB_iframe=true\');
 return false;
});

结束

相关推荐

在Image.php图库的末尾添加“更多图库”页面

在许多杂志网站上,当你点击一个图库(在WP中使用image.php模板完成)时,最后一次点击会将你带到一个“更多图库”页面。我想实现类似的目标,并希望通过为“更多画廊”页面制作模板来实现这一目标。问题是我不知道如何让我的下一个/上一个链接在最后一张图片上显示上一个链接,该链接会重定向到“更多画廊”页面,而不是另一张图片。I figure the best way to do this would be to add a statement to the previous link which sends