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


PHP RW_Meta_Box::ajax_response方法代码示例

本文整理汇总了PHP中RW_Meta_Box::ajax_response方法的典型用法代码示例。如果您正苦于以下问题:PHP RW_Meta_Box::ajax_response方法的具体用法?PHP RW_Meta_Box::ajax_response怎么用?PHP RW_Meta_Box::ajax_response使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RW_Meta_Box的用法示例。


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

示例1: handle_upload

 /**
  * Upload
  * Ajax callback function
  *
  * @return string Error or (XML-)response
  */
 static function handle_upload()
 {
     global $wpdb;
     $post_id = is_numeric($_REQUEST['post_id']) ? $_REQUEST['post_id'] : 0;
     $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : '';
     check_ajax_referer("rwmb-upload-images_{$field_id}");
     // You can use WP's wp_handle_upload() function:
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => false));
     //Get next menu_order
     $meta = get_post_meta($post_id, $field_id, false);
     if (empty($meta)) {
         $next = 0;
     } else {
         $meta = implode(',', (array) $meta);
         $max = $wpdb->get_var("\n\t\t\t\t\tSELECT MAX(menu_order) FROM {$wpdb->posts}\n\t\t\t\t\tWHERE post_type = 'attachment'\n\t\t\t\t\tAND ID in ({$meta})\n\t\t\t\t");
         $next = is_numeric($max) ? (int) $max + 1 : 0;
     }
     $attachment = array('guid' => $file_attr['url'], 'post_mime_type' => $file_attr['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file['name'])), 'post_content' => '', 'post_status' => 'inherit', 'menu_order' => $next);
     // 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
         add_post_meta($post_id, $field_id, $id, false);
         RW_Meta_Box::ajax_response(self::img_html($id), 'success');
     }
     exit;
 }
开发者ID:Kafia,项目名称:Mark-WordPress-Theme-,代码行数:35,代码来源:plupload-image.php

示例2: wp_ajax_attach_media

 /**
  * Ajax callback for attaching media to field
  *
  * @return void
  */
 static function wp_ajax_attach_media()
 {
     $post_id = is_numeric($_REQUEST['post_id']) ? $_REQUEST['post_id'] : 0;
     $field_id = isset($_POST['field_id']) ? $_POST['field_id'] : 0;
     $attachment_id = isset($_POST['attachment_id']) ? $_POST['attachment_id'] : 0;
     check_ajax_referer("rwmb-attach-media_{$field_id}");
     add_post_meta($post_id, $field_id, $attachment_id, false);
     RW_Meta_Box::ajax_response(self::img_html($attachment_id), 'success');
 }
开发者ID:abdulhadikaryana,项目名称:kebudayaan,代码行数:14,代码来源:image-advanced.php

示例3: wp_ajax_get_embed

 /**
  * Ajax callback for returning oEmbed HTML
  *
  * @return void
  */
 static function wp_ajax_get_embed()
 {
     global $post;
     $url = isset($_POST['oembed_url']) ? $_POST['oembed_url'] : 0;
     $post_id = is_numeric($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
     if (isset($_REQUEST['post_id'])) {
         $post = get_post($_REQUEST['post_id']);
     }
     $embed = self::get_embed($url);
     RW_Meta_Box::ajax_response($embed, 'success');
     exit;
 }
开发者ID:luskyj89,项目名称:mt-wordpress,代码行数:17,代码来源:oembed.php

示例4: wp_ajax_reorder_images

 /**
  * Ajax callback for reordering images
  *
  * @return void
  */
 static function wp_ajax_reorder_images()
 {
     $field_id = isset($_POST['field_id']) ? $_POST['field_id'] : 0;
     $order = isset($_POST['order']) ? $_POST['order'] : 0;
     check_admin_referer("rwmb-reorder-images_{$field_id}");
     parse_str($order, $items);
     $items = $items['item'];
     $order = 1;
     foreach ($items as $item) {
         wp_update_post(array('ID' => $item, 'menu_order' => $order++));
     }
     RW_Meta_Box::ajax_response(__('Order saved', 'wpsight'), 'success');
 }
开发者ID:phucanh92,项目名称:vietlong,代码行数:18,代码来源:image.php

示例5: wp_ajax_delete_file

 /**
  * Ajax callback for deleting files.
  * Modified from a function used by "Verve Meta Boxes" plugin
  *
  * @link http://goo.gl/LzYSq
  * @return void
  */
 static function wp_ajax_delete_file()
 {
     $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0;
     $field_id = isset($_POST['field_id']) ? $_POST['field_id'] : 0;
     $attachment_id = isset($_POST['attachment_id']) ? intval($_POST['attachment_id']) : 0;
     check_admin_referer("rwmb-delete-file_{$field_id}");
     $ok = delete_post_meta($post_id, $field_id, $attachment_id);
     $ok = $ok && wp_delete_attachment($attachment_id);
     if ($ok) {
         RW_Meta_Box::ajax_response('', 'success');
     } else {
         RW_Meta_Box::ajax_response(__('Error: Cannot delete file', 'bootstrap'), 'error');
     }
 }
开发者ID:scotlanddig,项目名称:bootstrap_basic,代码行数:21,代码来源:file.php

示例6: wp_ajax_reorder_images

 /**
  * Ajax callback for reordering images
  *
  * @return void
  */
 static function wp_ajax_reorder_images()
 {
     $field_id = isset($_POST['field_id']) ? $_POST['field_id'] : 0;
     $order = isset($_POST['order']) ? $_POST['order'] : 0;
     $post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
     check_ajax_referer("rwmb-reorder-images_{$field_id}");
     parse_str($order, $items);
     $items = $items['item'];
     delete_post_meta($post_id, $field_id);
     foreach ($items as $item) {
         add_post_meta($post_id, $field_id, $item, false);
     }
     RW_Meta_Box::ajax_response(__('Order saved', 'rwmb'), 'success');
 }
开发者ID:RDePoppe,项目名称:luminaterealestate,代码行数:19,代码来源:image.php

示例7: wp_ajax_save_map

 static function wp_ajax_save_map()
 {
     $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : 0;
     $map_address = isset($_POST['map_address']) ? $_POST['map_address'] : '';
     $map_location = isset($_POST['map_location']) ? $_POST['map_location'] : '';
     if ($post_id) {
         if (!empty($map_location)) {
             update_post_meta($post_id, '_map_geo', $map_location);
             update_post_meta($post_id, '_map_location', $map_location);
         }
         if (!empty($map_address)) {
             update_post_meta($post_id, '_map_address', $map_address);
         }
         RW_Meta_Box::ajax_response(__('Map Address saved', 'wpsight'), 'success');
     } else {
         RW_Meta_Box::ajax_response(__('Map Address saving fail', 'wpsight'), 'error');
     }
 }
开发者ID:phucanh92,项目名称:vietlong,代码行数:18,代码来源:map.php

示例8: wp_ajax_reorder_images

 /**
  * Ajax callback for reordering images
  *
  * @return void
  */
 static function wp_ajax_reorder_images()
 {
     $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0;
     $field_id = isset($_POST['field_id']) ? $_POST['field_id'] : 0;
     $order = isset($_POST['order']) ? $_POST['order'] : 0;
     check_admin_referer("rwmb-reorder-images_{$field_id}");
     parse_str($order, $items);
     $items = $items['item'];
     $order = 1;
     // Delete old meta values
     delete_post_meta($post_id, $field_id);
     foreach ($items as $item) {
         wp_update_post(array('ID' => $item, 'post_parent' => $post_id, 'menu_order' => $order++));
         // Save images in that order to meta field
         // That helps retrieving values easier
         add_post_meta($post_id, $field_id, $item, false);
     }
     RW_Meta_Box::ajax_response(__('Order saved', 'rwmb'), 'success');
 }
开发者ID:ignacioabejaro,项目名称:xtecblocs,代码行数:24,代码来源:image.php

示例9: handle_upload

 /**
  * Upload
  * Ajax callback function
  *
  * @return string Error or (XML-)response
  */
 static function handle_upload()
 {
     $post_id = is_numeric($_REQUEST['post_id']) ? $_REQUEST['post_id'] : 0;
     $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : '';
     check_admin_referer("rwmb-upload-images_{$field_id}");
     // You can use WP's wp_handle_upload() function:
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => false));
     $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
         add_post_meta($post_id, $field_id, $id, false);
         // Fake field array. We need ID and force_delete only
         $field = array('id' => $field_id, 'force_delete' => isset($_REQUEST['force_delete']) ? intval($_REQUEST['force_delete']) : 0);
         RW_Meta_Box::ajax_response(self::img_html($id, $field), 'success');
     }
     exit;
 }
开发者ID:phucanh92,项目名称:vietlong,代码行数:27,代码来源:plupload-image.php

示例10: wp_ajax_delete_file

 /**
  * Ajax callback for deleting files.
  * Modified from a function used by "Verve Meta Boxes" plugin
  *
  * @link http://goo.gl/LzYSq
  * @return void
  */
 static function wp_ajax_delete_file()
 {
     $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0;
     $field_id = isset($_POST['field_id']) ? $_POST['field_id'] : 0;
     $attachment_id = isset($_POST['attachment_id']) ? intval($_POST['attachment_id']) : 0;
     $force_delete = isset($_POST['force_delete']) ? intval($_POST['force_delete']) : 0;
     check_ajax_referer("rwmb-delete-file_{$field_id}");
     // get saved ids
     $saved_ids = get_post_meta($post_id, $field_id, true);
     // sanitize
     $saved_ids = array_map('absint', $saved_ids);
     // exclude attachment from saved list
     $saved_ids = array_diff($saved_ids, array(absint($attachment_id)));
     // update
     update_post_meta($post_id, $field_id, $saved_ids);
     $ok = $force_delete ? wp_delete_attachment($attachment_id) : true;
     if ($ok) {
         RW_Meta_Box::ajax_response('', 'success');
     } else {
         RW_Meta_Box::ajax_response(__('Error: Cannot delete file', LANGUAGE_ZONE), 'error');
     }
     exit;
 }
开发者ID:proj-2014,项目名称:vlan247-test-wp,代码行数:30,代码来源:metabox-fields.php


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