doubian19900911 2013-01-23 13:18
浏览 48

Wordpress / Jetpack:我的代码中有哪些部分导致Jetpack崩溃?

I have created a custom post type (images) for handling event images, to which I have also added a custom image uploader meta field, and everything works exactly the way I want it to, EXCEPT, it breaks jetpack. I know from experience with Jetpack that a plugin may create unexpected output, causing the "-32700" error with jetpack, but i don't know which part of the code is causing it. The code for the image uploader is:

<?php
function add_custom_meta_boxes() {

// Define the custom attachment for posts
add_meta_box(
    'wp_image_attachment',
    'Custom Attachment',
    'wp_image_attachment',
    'images',
    'side'
);


} // end add_custom_meta_boxes
add_action('add_meta_boxes', 'add_custom_meta_boxes');

function wp_image_attachment() {

wp_nonce_field(plugin_basename(__FILE__), 'wp_image_attachment_nonce');

$html = '<p class="description">';
    $html .= 'Upload your image here.';
$html .= '</p>';
$html .= '<input type="file" id="wp_image_attachment" name="wp_image_attachment" value="" size="25">';

echo $html;

} // end wp_image_attachment


function save_custom_meta_data($id) {

/* --- security verification --- */
if(!wp_verify_nonce($_POST['wp_image_attachment_nonce'], plugin_basename(__FILE__))) {
  return $id;
} // end if

if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  return $id;
} // end if

if('page' == $_POST['post_type']) {
  if(!current_user_can('edit_page', $id)) {
    return $id;
  } // end if
} else {
    if(!current_user_can('edit_page', $id)) {
        return $id;
    } // end if
} // end if
/* - end security verification - */

// Make sure the file array isn't empty
if(!empty($_FILES['wp_image_attachment']['name'])) {

    // Setup the array of supported file types. In this case, it's just PDF.
    $supported_types = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png');

    // Get the file type of the upload
    $arr_file_type = wp_check_filetype(basename($_FILES['wp_image_attachment']['name']));
    $uploaded_type = $arr_file_type['type'];

    // Check if the type is supported. If not, throw an error.
    if(in_array($uploaded_type, $supported_types)) {

        // Use the WordPress API to upload the file
        $upload = wp_upload_bits($_FILES['wp_image_attachment']['name'], null, file_get_contents($_FILES['wp_image_attachment']['tmp_name']));

        if(isset($upload['error']) && $upload['error'] != 0) {
            wp_die('There was an error uploading your file. The error is: ' . $upload['error']);
        } else {
            add_post_meta($id, 'wp_image_attachment', $upload);
            update_post_meta($id, 'wp_image_attachment', $upload);      
        } // end if/else

    } else {
        wp_die("The file type that you've uploaded is not an image.");
    } // end if/else

} // end if

} // end save_custom_meta_data
add_action('save_post', 'save_custom_meta_data');

function update_edit_form() {
echo ' enctype="multipart/form-data"';
} // end update_edit_form
add_action('post_edit_form_tag', 'update_edit_form');

?>

I know that's a lot of code to be putting here, but I got shouted at last time I linked to pastebin [ ;) ], but any help would be greatly appreciated, as the site is nearly finished, but i'd really like to utilize the Publicize feature of Jetpack, so i'd prefer not to sacrifice it, but I NEED this bit to work.

Many thanks in advance! :)

  • 写回答

1条回答 默认 最新

  • drmeu26880 2013-01-23 13:32
    关注

    Booooo! Rookie error! The unexpected output seems to have been caused by that section of my plugin being added onto the original custom post type section, which, of course ended with

    ?> 
    

    and the above section started with

    <?php 
    

    which wordpress didn't seem to like.

    Problem solved. For now...

    *NB: This can probably be deleted now, or left for future reference :) *

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法