当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Ajax_Response类代码示例

本文整理汇总了PHP中WP_Ajax_Response的典型用法代码示例。如果您正苦于以下问题:PHP WP_Ajax_Response类的具体用法?PHP WP_Ajax_Response怎么用?PHP WP_Ajax_Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WP_Ajax_Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle_upload

 /**
  * Upload
  * Ajax callback function
  *
  * @return string Error or (XML-)response
  */
 static function handle_upload()
 {
     check_admin_referer('rwmb-upload-images_' . $_REQUEST['field_id']);
     $post_id = 0;
     if (is_numeric($_REQUEST['post_id'])) {
         $post_id = (int) $_REQUEST['post_id'];
     }
     // You can use WP's wp_handle_upload() function:
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => true, 'action' => 'plupload_image_upload'));
     $attachment = array('guid' => $file_attr['url'], 'post_mime_type' => $file_attr['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file['name'])), 'post_content' => '', 'post_status' => 'inherit');
     // Adds file as attachment to WordPress
     $id = wp_insert_attachment($attachment, $file_attr['file'], $post_id);
     if (!is_wp_error($id)) {
         wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file_attr['file']));
         // Save file ID in meta field
         if (isset($_REQUEST['field_id'])) {
             add_post_meta($post_id, $_REQUEST['field_id'], $id, false);
         }
         $response = new WP_Ajax_Response();
         $response->add(array('what' => 'rwmb_image_response', 'data' => self::img_html($id)));
         $response->send();
     }
     exit;
 }
开发者ID:scotlanddig,项目名称:bootstrap_basic,代码行数:31,代码来源:plupload-image.php

示例2: handle_upload

 /**
  * Upload
  * Ajax callback function
  *
  * @return error or (XML-)response
  */
 static function handle_upload()
 {
     header('Content-Type: text/html; charset=UTF-8');
     if (!defined('DOING_AJAX')) {
         define('DOING_AJAX', true);
     }
     check_ajax_referer('plupload_image');
     $post_id = 0;
     if (is_numeric($_REQUEST['post_id'])) {
         $post_id = (int) $_REQUEST['post_id'];
     }
     // you can use WP's wp_handle_upload() function:
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => true, 'action' => 'plupload_image_upload'));
     $attachment = array('post_mime_type' => $file_attr['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file['name'])), 'post_content' => '', 'post_status' => 'inherit');
     // Adds file as attachment to WordPress
     $id = wp_insert_attachment($attachment, $file_attr['file'], $post_id);
     if (!is_wp_error($id)) {
         $response = new WP_Ajax_Response();
         wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file_attr['file']));
         if (isset($_REQUEST['field_id'])) {
             // Save file ID in meta field
             add_post_meta($post_id, $_REQUEST['field_id'], $id, false);
         }
         $response->add(array('what' => 'rwmb_image_response', 'data' => self::img_html($id)));
         $response->send();
     }
     // faster than die();
     exit;
 }
开发者ID:hunghoang179,项目名称:sitenews,代码行数:36,代码来源:plupload-image.php

示例3: initialize

 public static function initialize()
 {
     add_filter('media_upload_tabs', function ($tabs) {
         if (isset($_REQUEST['context']) && $_REQUEST['context'] == 'voce-image-setting') {
             return array('library' => __('Image Library'), 'type' => __('From Computer'));
         }
         return $tabs;
     });
     add_action('wp_ajax_set_voce_image_setting', function () {
         check_ajax_referer('set_voce_image_setting');
         if (!isset($_REQUEST['attachment_id']) || !isset($_REQUEST['setting_page']) || !isset($_REQUEST['setting_group']) || !isset($_REQUEST['setting_key'])) {
             die(0);
         }
         $attachment_id = (int) $_REQUEST['attachment_id'];
         $setting_key = trim(sanitize_key($_REQUEST['setting_key']));
         $setting_group = trim(sanitize_key($_REQUEST['setting_group']));
         $setting_page = trim(sanitize_key($_REQUEST['setting_page']));
         if ($attachment_id == -1) {
             Voce_Settings_API::GetInstance()->set_setting($setting_key, $setting_group, '');
             $response = new WP_Ajax_Response(array('what' => 'voce-image-setting', 'action' => 'set_voce_image_setting', 'id' => -1, 'data' => Voce_Image_Setting::render_html(false, $setting_key, $setting_group, $setting_page, true)));
             $response->send();
         } elseif ('attachment' == get_post_type($attachment_id)) {
             Voce_Settings_API::GetInstance()->set_setting($setting_key, $setting_group, $attachment_id);
             $response = new WP_Ajax_Response(array('what' => 'voce-image-setting', 'action' => 'set_voce_image_setting', 'id' => 1, 'data' => Voce_Image_Setting::render_html($attachment_id, $setting_key, $setting_group, $setting_page, true)));
             $response->send();
         }
     });
     add_action('admin_enqueue_scripts', function ($hook) {
         $allowed_hooks = apply_filters('voce-image-settings-js-hooks', array());
         if ('settings_page_' == substr($hook, 0, 14) || in_array($hook, $allowed_hooks)) {
             add_thickbox();
             wp_enqueue_script('voce-image-setting', plugins_url('/js/voce-image-setting.js', __FILE__), array('jquery', 'media-upload', 'wp-ajax-response'));
         } else {
             if ($hook == 'media-upload-popup') {
                 wp_enqueue_script('voce-image-setting-iframe', plugins_url('/js/voce-image-setting-iframe.js', __FILE__), array('jquery'));
             }
         }
     });
     add_filter('attachment_fields_to_edit', function ($form_fields, $post) {
         if (isset($_REQUEST['context']) && $_REQUEST['context'] == 'voce-image-setting') {
             $setting_key = isset($_REQUEST['setting_key']) ? $_REQUEST['setting_key'] : '';
             $setting_group = isset($_REQUEST['setting_group']) ? $_REQUEST['setting_group'] : '';
             $setting_page = isset($_REQUEST['setting_page']) ? $_REQUEST['setting_page'] : '';
         } elseif (($referer = wp_get_referer()) && ($query_vars = wp_parse_args(parse_url($referer, PHP_URL_QUERY))) && isset($query_vars['context']) && $query_vars['context'] == 'voce-image-setting') {
             $setting_key = isset($query_vars['setting_key']) ? $query_vars['setting_key'] : '';
             $setting_group = isset($query_vars['setting_group']) ? $query_vars['setting_group'] : '';
             $setting_page = isset($query_vars['setting_page']) ? $query_vars['setting_page'] : '';
         } else {
             return $form_fields;
         }
         $html = sprintf('<tr class="submit"><td></td><td><a data-attachment-id="%s" data-setting-page="%s" data-setting-group="%s" data-setting-key="%s" data-nonce="%s" class="set-voce-image-setting button">Choose Image</a></td></tr>', esc_attr($post->ID), esc_attr($setting_page), esc_attr($setting_group), esc_attr($setting_key), esc_attr(wp_create_nonce('set_voce_image_setting')));
         $form_fields = array('voce-image-setting' => array('label' => '', 'input' => 'html', 'html' => $html));
         return $form_fields;
     }, 20, 2);
 }
开发者ID:voceconnect,项目名称:voce-image-setting,代码行数:55,代码来源:voce-image-setting.php

示例4: add_user_link_ajax

 /**
  * AJAX handler for adding/updating a link
  *
  * Callback for "wp_ajax_add-user-link" hook in file "wp-admin/admin-ajax.php"
  *
  * @since 6.0
  * @access public
  */
 function add_user_link_ajax()
 {
     global $theme_my_login;
     if (!current_user_can('manage_options')) {
         die('-1');
     }
     check_ajax_referer('add-user-link');
     // Create a reference to current links
     $links =& $theme_my_login->options->get_option('user_links');
     $c = 0;
     if (isset($_POST['new_user_link'])) {
         // Add a new link
         foreach ($_POST['new_user_link'] as $role => $link) {
             // Make sure input isn't empty
             if (is_array($link) && !empty($link)) {
                 // Clean the input
                 $clean_title = wp_kses($link['title'], null);
                 $clean_url = wp_kses($link['url'], null);
                 // Make sure input isn't empty after cleaning
                 if (empty($clean_title) || empty($clean_url)) {
                     die('1');
                 }
                 // Add new link
                 $links[$role][] = array('title' => $clean_title, 'url' => $clean_url);
                 // Save links
                 $theme_my_login->options->set_option('user_links', $links);
                 $theme_my_login->options->save();
                 $link_row = array_merge(array('id' => max(array_keys($links[$role]))), end($links[$role]));
                 $x = new WP_Ajax_Response(array('what' => $role . '-link', 'id' => $link_row['id'], 'data' => $this->get_link_row($link_row, $role, $c), 'position' => 1, 'supplemental' => array('user_role' => $role)));
             }
         }
     } else {
         // Update a link
         foreach ($_POST['user_links'] as $role => $link) {
             // Set the link ID
             $id = key($link);
             // Clean the input
             $clean_title = wp_kses($link[$id]['title'], null);
             $clean_url = wp_kses($link[$id]['url'], null);
             // Make sure the requested link ID exists
             if (!isset($links[$role][$id])) {
                 die('0');
             }
             // Update the link if it has changed
             if ($links[$role][$id]['title'] != $clean_title || $links[$role][$id]['url'] != $clean_url) {
                 $links[$role][$id] = array('title' => $clean_title, 'url' => $clean_url);
                 $theme_my_login->options->set_option('user_links', $links);
                 $theme_my_login->options->save();
             }
             $link_row = array_merge(array('id' => $id), $links[$role][$id]);
             $x = new WP_Ajax_Response(array('what' => $role . '-link', 'id' => $id, 'old_id' => $id, 'data' => $this->get_link_row($link_row, $role, $c), 'position' => 0, 'supplemental' => array('user_role' => $role)));
         }
     }
     $x->send();
 }
开发者ID:moscarar,项目名称:cityhow,代码行数:63,代码来源:custom-user-links-admin.php

示例5: wpGrade_ajax_import_widgets

 function wpGrade_ajax_import_widgets()
 {
     $response = array('what' => 'import_widgets', 'action' => 'import_submit', 'id' => 'true');
     // check if user is allowed to save and if its his intention with
     // a nonce check
     if (function_exists('check_ajax_referer')) {
         check_ajax_referer('wpGrade_nonce_import_demo_widgets');
     }
     require_once wpgrade::themefilepath('inc/import/import-demo-widgets' . EXT);
     $response = new WP_Ajax_Response($response);
     $response->send();
 }
开发者ID:pwzCypher,项目名称:wp-push,代码行数:12,代码来源:callbacks.php

示例6: media_lang_choice

 public function media_lang_choice()
 {
     preg_match('#([0-9]+)#', $_POST['post_id'], $matches);
     $post_id = $matches[1];
     $lang = $this->model->get_language($_POST['lang']);
     ob_start();
     if ($lang) {
         include PLL_ADMIN_INC . '/view-translations-media.php';
         $data = ob_get_contents();
     }
     $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => $data));
     ob_end_clean();
     $x->send();
 }
开发者ID:kivivuori,项目名称:jotain,代码行数:14,代码来源:admin-filters-media.php

示例7: video_ajax_get_video_preview

/**
 * retrieve configuration's form for video présentation
*/
function video_ajax_get_video_preview()
{
    if (!check_ajax_referer('video-ajax-nonce', 'ajaxNonce', false)) {
        die('Busted!');
    }
    $response = array('what' => 'video_ajax_get_video_preview', 'action' => 'video_ajax_get_video_preview', 'id' => '1');
    $meta_video_url = isset($_POST['video_url']) ? $_POST['video_url'] : "";
    $meta_video_width = isset($_POST['video_width']) ? $_POST['video_width'] : "";
    $meta_video_height = isset($_POST['video_height']) ? $_POST['video_height'] : "";
    $results = get_video_embed_code($meta_video_url, $meta_video_width, $meta_video_height);
    $response['data'] = $results;
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->send();
    exit;
}
开发者ID:studio-montana,项目名称:custom,代码行数:18,代码来源:video-ajax.php

示例8: validate_imsi_ajax

 public static function validate_imsi_ajax()
 {
     $imsi = sanitize_text_field($_POST['imsi']);
     $doing_ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false;
     $ajax_response = array();
     if ($doing_ajax) {
         $imsi_data = self::validate_imsi($imsi);
         $ajax_response['imsi_data'] = json_encode($imsi_data);
     }
     $response = array('what' => 'validate_imsi', 'action' => 'validate_imsi', 'id' => 1, 'data' => json_encode($ajax_response));
     ob_end_clean();
     ob_start();
     $xmlResponse = new WP_Ajax_Response($response);
     $xmlResponse->send();
     ob_end_flush();
 }
开发者ID:vilmark,项目名称:vilmark_main,代码行数:16,代码来源:IMSI.php

示例9: media_lang_choice

 public function media_lang_choice()
 {
     check_ajax_referer('pll_language', '_pll_nonce');
     preg_match('#([0-9]+)#', $_POST['post_id'], $matches);
     $post_id = $matches[1];
     $lang = $this->model->get_language($_POST['lang']);
     ob_start();
     if ($lang) {
         include PLL_ADMIN_INC . '/view-translations-media.php';
         $data = ob_get_contents();
     }
     $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => $data));
     ob_end_clean();
     // flag
     $x->Add(array('what' => 'flag', 'data' => empty($lang->flag) ? esc_html($lang->slug) : $lang->flag));
     $x->send();
 }
开发者ID:WordPressArt,项目名称:conisia,代码行数:17,代码来源:admin-filters-media.php

示例10: cherry_plugin_export_content

function cherry_plugin_export_content()
{
    $exclude_files = array('xml', 'json');
    /**
     * Filters folders to exclude from export parser
     * @var array
     */
    $exclude_folder = apply_filters('cherry_export_exclude_folders', array('woocommerce_uploads', 'wc-logs'));
    $response = array('what' => 'status', 'action' => 'export_content', 'id' => '1', 'data' => __('Export content done', CHERRY_PLUGIN_DOMAIN));
    $response_file = array('what' => 'file', 'action' => 'export_content', 'id' => '2');
    $zip_name = UPLOAD_BASE_DIR . '/sample_data.zip';
    cherry_plugin_delete_file($zip_name);
    if (is_dir(UPLOAD_BASE_DIR)) {
        $file_string = cherry_plugin_scan_dir(UPLOAD_BASE_DIR, $exclude_folder, $exclude_files);
    }
    $zip = new PclZip($zip_name);
    $result = $zip->create($file_string, PCLZIP_OPT_REMOVE_ALL_PATH);
    //export json
    $json_file = cherry_plugin_export_json();
    if (is_wp_error($json_file)) {
        $response['data'] = "Error : " . $json_file->get_error_message();
    } else {
        $zip->add($json_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        cherry_plugin_delete_file($json_file);
    }
    //export xml
    $xml_file = cherry_plugin_export_xml();
    if (is_wp_error($xml_file)) {
        $response['data'] = "Error : " . $xml_file->get_error_message();
    } else {
        $zip->add($xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        cherry_plugin_delete_file($xml_file);
    }
    $nonce = wp_create_nonce('cherry_plugin_download_content');
    $file_url = add_query_arg(array('action' => 'cherry_plugin_get_export_file', 'file' => $zip_name, '_wpnonce' => $nonce), admin_url('admin-ajax.php'));
    if ($result == 0) {
        $response['data'] = "Error : " . $zip->errorInfo(true);
    } else {
        $response_file['data'] = $file_url;
    }
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->add($response_file);
    $xmlResponse->send();
    exit;
}
开发者ID:drupalninja,项目名称:schome_org,代码行数:45,代码来源:export-functions.php

示例11: maurisco_cf_plugin_callback

function maurisco_cf_plugin_callback()
{
    //	error_log('maurisco_cf_plugin_callback 1');
    //    $nonce = $_POST['maurisco_cf_nonce'];
    // The first thing we do is check the nonce and kill the script if wrong
    //    if ( ! wp_verify_nonce( $nonce, 'return_posts' ) ){
    //        die ( 'Wrong nonce!');
    //    }
    //    error_log($nonce);
    error_log(serialize($_POST));
    $name_0 = $_POST['name_0'] ? $_POST['name_0'] : null;
    $email_0 = $_POST['email_0'] ? $_POST['email_0'] : null;
    $name_1 = $_POST['name_1'] ? $_POST['name_1'] : null;
    $email_1 = $_POST['email_1'] ? $_POST['email_1'] : null;
    $name_2 = $_POST['name_2'] ? $_POST['name_2'] : null;
    $email_2 = $_POST['email_2'] ? $_POST['email_2'] : null;
    $phone = $_POST['phone'] ? $_POST['phone'] : null;
    $event_date = $_POST['event_date'] ? $_POST['event_date'] : null;
    $event_location_1 = $_POST['event_location_1'] ? $_POST['event_location_1'] : null;
    $event_type = $_POST['event_type'] ? $_POST['event_type'] : null;
    $question_1 = $_POST['question_1'] ? $_POST['question_1'] : null;
    $question_2 = $_POST['question_2'] ? $_POST['question_2'] : null;
    $comment_1 = $_POST['comment_1'] ? $_POST['comment_1'] : null;
    $userIp = $_POST['userIp'];
    $maurisco_api_id = get_option('maurisco_api_id');
    $maurisco_api_key = get_option('maurisco_api_key');
    get_transient('maurisco_lead_types_t');
    $type_arr = maurisco_cf_get_leadtypes();
    $event_type_id = maurisco_filter_lead_type($type_arr, $event_type);
    if (defined(MARUISCO_CF_DEBUG)) {
        $url = 'https://192.168.1.157:8000/api/v1/lead';
    } else {
        $url = 'https://mauris.co/api/v1/lead';
    }
    $data = array('apiId' => $maurisco_api_id, 'apiKey' => $maurisco_api_key, 'event_date' => $event_date, 'clients' => array('email_0' => $email_0, 'name_0' => $name_0, 'name_1' => $name_1, 'name_2' => $name_2), 'phone' => $phone, 'event_location_1' => $event_location_1, 'event_type' => $event_type, 'type' => $event_type_id, 'question_1' => $question_1, 'question_2' => $question_2, 'comment_1' => $comment_1, 'ip' => $userIp);
    $result = wp_remote_post($url, array('sslverify' => false, 'body' => $data));
    error_log(serialize($result));
    $response = array('what' => 'maurisco_cf_form', 'action' => 'post inquiry', 'id' => '1', 'data' => '<p>OK</p>');
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->send();
    die;
}
开发者ID:eatrero,项目名称:maurisco-contact-form-plugin,代码行数:42,代码来源:mauriscocf.php

示例12: edd_dwqa_categories_created_edd_term

function edd_dwqa_categories_created_edd_term($term_id, $tt_id, $taxonomy)
{
    $term = get_term_by('id', $term_id, $taxonomy);
    if (!empty($term) && $term->parent == 0 && $taxonomy == 'download_category') {
        $tag = wp_insert_term($term->name, 'dwqa-question_category', $_POST);
        if (!$tag || is_wp_error($tag)) {
            // || (!$tag = get_term( $tag['term_id'], $taxonomy ))
            $message = __('An error has occurred. DW Q&A category could not be added!', 'edd_dwqa_categories');
            if (is_wp_error($tag) && $tag->get_error_message()) {
                $message = $tag->get_error_message();
            }
            $x = new WP_Ajax_Response();
            $x->add(array('what' => 'taxonomy', 'data' => new WP_Error('error', $message)));
            $x->send();
        } else {
            //global $wpdb;
            //$wpdb->query( $wpdb->prepare("INSERT INTO ".$wpdb->prefix."js_dwqa_categories (id, dwqa_category_id, edd_product_id, edd_category_id) VALUES ('', %d, '', %d)", $tag->term_id, $term_id) );
        }
    }
}
开发者ID:jomsocial,项目名称:eddDwqaCategories,代码行数:20,代码来源:edd_dwqa_categories.php

示例13: cherry_plugin_export_content

function cherry_plugin_export_content()
{
    $exclude_files = array('xml', 'json');
    $exclude_folder = array('woocommerce_uploads');
    $response = array('what' => 'status', 'action' => 'export_content', 'id' => '1', 'data' => __('Export content done', CHERRY_PLUGIN_DOMAIN));
    $response_file = array('what' => 'file', 'action' => 'export_content', 'id' => '2');
    $zip_name = UPLOAD_BASE_DIR . '/sample_data.zip';
    cherry_plugin_delete_file($zip_name);
    if (is_dir(UPLOAD_BASE_DIR)) {
        $file_string = cherry_plugin_scan_dir(UPLOAD_BASE_DIR, $exclude_folder, $exclude_files);
    }
    $zip = new PclZip($zip_name);
    $result = $zip->create($file_string, PCLZIP_OPT_REMOVE_ALL_PATH);
    //export json
    $json_file = cherry_plugin_export_json();
    if (is_wp_error($json_file)) {
        $response['data'] = "Error : " . $json_file->get_error_message();
    } else {
        $zip->add($json_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        cherry_plugin_delete_file($json_file);
    }
    //export xml
    $xml_file = cherry_plugin_export_xml();
    if (is_wp_error($xml_file)) {
        $response['data'] = "Error : " . $xml_file->get_error_message();
    } else {
        $zip->add($xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
        cherry_plugin_delete_file($xml_file);
    }
    if ($result == 0) {
        $response['data'] = "Error : " . $zip->errorInfo(true);
    } else {
        $response_file['data'] = $zip_name;
    }
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->add($response_file);
    $xmlResponse->send();
    exit;
}
开发者ID:hoangluanlee,项目名称:dlbh,代码行数:39,代码来源:export-functions.php

示例14: wall_ajax_get_wall_presentation_results

/**
 * retrieve configuration's form for wall présentation
*/
function wall_ajax_get_wall_presentation_results()
{
    if (!check_ajax_referer('wall-ajax-nonce', 'ajaxNonce', false)) {
        die('Busted!');
    }
    $response = array('what' => 'wall_ajax_get_wall_presentation_results', 'action' => 'wall_ajax_get_wall_presentation_results', 'id' => '1');
    $wall_args = array();
    foreach ($_POST as $k => $v) {
        if (startsWith($k, "meta_wall_")) {
            $wall_args[$k] = $v;
        }
    }
    ob_start();
    $wall_template = locate_ressource(CUSTOM_PLUGIN_TOOLS_FOLDER . WALL_TOOL_NAME . '/templates/tool-wall-display.php');
    if (!empty($wall_template)) {
        include $wall_template;
    }
    $results = ob_get_contents();
    ob_end_clean();
    $response['data'] = $results;
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->send();
    exit;
}
开发者ID:studio-montana,项目名称:custom,代码行数:27,代码来源:wall-ajax.php

示例15: bp_activity_admin_reply

/**
 * AJAX receiver for Activity replies via the admin screen.
 *
 * Processes requests to add new activity comments, and echoes HTML for a new
 * table row.
 *
 * @since BuddyPress (1.6.0)
 */
function bp_activity_admin_reply()
{
    // Check nonce
    check_ajax_referer('bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply');
    $parent_id = !empty($_REQUEST['parent_id']) ? (int) $_REQUEST['parent_id'] : 0;
    $root_id = !empty($_REQUEST['root_id']) ? (int) $_REQUEST['root_id'] : 0;
    // $parent_id is required
    if (empty($parent_id)) {
        die('-1');
    }
    // If $root_id not set (e.g. for root items), use $parent_id
    if (empty($root_id)) {
        $root_id = $parent_id;
    }
    // Check that a reply has been entered
    if (empty($_REQUEST['content'])) {
        die(__('ERROR: Please type a reply.', 'buddypress'));
    }
    // Check parent activity exists
    $parent_activity = new BP_Activity_Activity($parent_id);
    if (empty($parent_activity->component)) {
        die(__('ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress'));
    }
    // @todo: Check if user is allowed to create new activity items
    // if ( ! current_user_can( 'bp_new_activity' ) )
    if (!current_user_can('bp_moderate')) {
        die('-1');
    }
    // Add new activity comment
    $new_activity_id = bp_activity_new_comment(array('activity_id' => $root_id, 'content' => $_REQUEST['content'], 'parent_id' => $parent_id));
    // Fetch the new activity item, as we need it to create table markup to return
    $new_activity = new BP_Activity_Activity($new_activity_id);
    // This needs to be set for the BP_Activity_List_Table constructor to work
    set_current_screen('toplevel_page_bp-activity');
    // Set up an output buffer
    ob_start();
    $list_table = new BP_Activity_List_Table();
    $list_table->single_row((array) $new_activity);
    // Get table markup
    $response = array('data' => ob_get_contents(), 'id' => $new_activity_id, 'position' => -1, 'what' => 'bp_activity');
    ob_end_clean();
    // Send response
    $r = new WP_Ajax_Response();
    $r->add($response);
    $r->send();
    exit;
}
开发者ID:un1coin,项目名称:ovn-space,代码行数:55,代码来源:bp-activity-admin.php


注:本文中的WP_Ajax_Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。