/**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
 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);
 }
 /**
  * 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();
 }
Example #5
0
 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();
 }
Example #6
0
 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();
 }
Example #7
0
/**
 * 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;
}
Example #8
0
 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();
 }
 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();
 }
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;
}
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;
}
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) );
        }
    }
}
Example #13
0
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;
}
Example #14
0
/**
 * 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;
}
Example #15
0
/**
 * 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;
}
Example #16
0
 public static function myajax_notifications_everywhere()
 {
     $current_user = wp_get_current_user();
     $last_check = get_user_meta($current_user->ID, 'last_check_chat_id');
     if (!isset($last_check)) {
         $last_check = 0;
     }
     $args = array('wpse_pid' => $last_check, 'wpse_compare' => '>', 'post_type' => 'chat_message', 'post_status' => 'draft', 'posts_per_page' => 1, 'meta_query' => array(array('key' => 'receiver', 'value' => $current_user->ID)), 'orderby' => 'post_date', 'order' => 'ASC');
     $last_post = new WP_Query($args);
     if ($last_post->have_posts()) {
         while ($last_post->have_posts()) {
             $last_post->the_post();
             $author = get_the_author();
             $ID_post = get_the_ID();
             $author_ID = get_the_author_meta('ID');
             update_user_meta($current_user->ID, 'last_check_chat_id', $ID_post);
             $img_url = get_user_meta($author_ID, 'et_avatar_url', true);
             if (get_post_meta($ID_post, 'unreadInvitation', true) !== '') {
                 $invate_post = get_post(get_post_meta($ID_post, 'unreadInvitation', true));
                 //                    $message ="You've got an invitation from ".$author." to an interview on ".$invate_post->post_title.". Check messages!";
                 $message = sprintf(__("You've got an invitation from %s to an interview on %s. Check messages!", 'chat-frontend'), $author, $invate_post->post_title);
             } else {
                 $message = get_the_content();
                 if ($message == ' ') {
                     $message = sprintf(__("You've got an attachment from %s. Check messages!", 'chat-frontend'), $author);
                 }
             }
             //var_dump(get_avatar_url());
             $responsed = array('what' => 'chat_message', 'action' => 'notifications_everywhere', 'supplemental' => array('idmessage' => $ID_post, 'sender' => $author, 'message' => $message, 'status' => 'success', 'img' => $img_url));
             $Response = new WP_Ajax_Response($responsed);
             $Response->send();
             exit;
         }
     } else {
         echo 'No new message here';
     }
     exit;
 }
Example #17
0
 /**
  * Handles AJAX response
  *
  * @since 6.3
  * @access public
  */
 public function template_redirect()
 {
     $theme_my_login = Theme_My_Login::get_object();
     if (Theme_My_Login::is_tml_page() && isset($_GET['ajax'])) {
         define('DOING_AJAX', true);
         $instance =& $theme_my_login->get_instance();
         $instance->set_option('default_action', !empty($theme_my_login->request_action) ? $theme_my_login->request_action : 'login');
         $instance->set_option('gravatar_size', 75);
         $instance->set_option('before_title', '<h2>');
         $instance->set_option('after_title', '</h2>');
         $data = $instance->display();
         send_origin_headers();
         @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
         @header('X-Robots-Tag: noindex');
         send_nosniff_header();
         nocache_headers();
         $x = new WP_Ajax_Response(array('what' => 'login', 'action' => $theme_my_login->request_action, 'data' => $theme_my_login->errors->get_error_code() ? $theme_my_login->errors : $data, 'supplemental' => array('html' => $data, 'success' => is_user_logged_in())));
         $x->send();
         exit;
     }
 }
Example #18
0
 /**
  * Format Ajax response
  *
  * @param string $message
  * @param string $status
  *
  * @return void
  */
 static function ajax_response($message, $status)
 {
     $response = array('what' => 'meta-box');
     $response['data'] = 'error' === $status ? new WP_Error('error', $message) : $message;
     $x = new WP_Ajax_Response($response);
     $x->send();
 }
 /**
  * Updates the entry status
  *
  * Called via AJAX
  * Passes data off to either RGFormsModel::update_lead_property or RGFormsModel::delete_lead
  *
  * @access public
  * @static
  * @see RGFormsModel::update_lead_property
  * @see RGFormsModel::delete_lead
  */
 public static function update_lead_status()
 {
     check_ajax_referer('gf_delete_entry');
     $status = rgpost('status');
     $lead_id = rgpost('entry');
     $entry = GFAPI::get_entry($lead_id);
     $form = GFAPI::get_form($entry['form_id']);
     switch ($status) {
         case 'unspam':
             RGFormsModel::update_lead_property($lead_id, 'status', 'active');
             break;
         case 'delete':
             if (GFCommon::current_user_can_any('gravityforms_delete_entries')) {
                 RGFormsModel::delete_lead($lead_id);
             }
             break;
         default:
             RGFormsModel::update_lead_property($lead_id, 'status', $status);
             break;
     }
     require_once 'entry_list.php';
     $filter_links = GFEntryList::get_filter_links($form);
     $counts = array();
     foreach ($filter_links as $filter_link) {
         $id = $filter_link['id'] == '' ? 'all' : $filter_link['id'];
         $counts[$id . '_count'] = $filter_link['count'];
     }
     $x = new WP_Ajax_Response();
     $x->add(array('what' => 'gf_entry', 'id' => $lead_id, 'supplemental' => $counts));
     $x->send();
 }
Example #20
0
function g1_simple_slider_move_slide()
{
    $ajax_data = $_POST['ajax_data'];
    check_ajax_referer('g1_simple_slider-move_slide' . $ajax_data['slide_id']);
    $error_response = $success_response = new WP_Ajax_Response();
    $errors = new WP_Error();
    $post = get_post(absint($ajax_data['post_id']));
    $slide_id = absint($ajax_data['slide_id']);
    $after_slide_id = absint($ajax_data['after_slide_id']);
    $after_slide_post = $after_slide_id ? get_post($after_slide_id) : null;
    $slide_post = get_post($slide_id);
    if (!$post || !$slide_post || $after_slide_id && !$after_slide_post) {
        $errors->add('incorrect_input_data', 'At least one of the slides does not exist!');
    }
    if (count($errors->get_error_codes()) > 0) {
        $error_response->add(array('what' => 'errors', 'id' => $errors));
        $error_response->send();
        exit;
    }
    $slider = G1_Slider_Factory::get_simple_slider($post);
    $slide = $slider->get_slide($slide_post->ID);
    if ($after_slide_post) {
        $after_slide = $slider->get_slide($after_slide_post->ID);
        $slider->move_slide_after_slide($slide, $after_slide);
    } else {
        $first_slide = $slider->get_first_slide();
        $slider->move_slide_before_slide($slide, $first_slide);
    }
    $slider->save();
    $success_response->add(array('what' => 'success', 'id' => 1));
    $success_response->send();
    exit;
}
Example #21
0
 public function term_translation_choice()
 {
     $link = $_POST['value'] ? $this->edit_translation_link($_POST['value'], $_POST['taxonomy'], $_POST['post_type']) : $this->add_new_translation_link($_POST['term_id'], $_POST['taxonomy'], $_POST['post_type'], $this->model->get_language($_POST['lang']));
     $x = new WP_Ajax_Response(array('what' => 'link', 'data' => $link));
     $x->send();
 }
function wp_ajax_find_posts()
{
    global $wpdb;
    check_ajax_referer('find-posts');
    if (empty($_POST['ps'])) {
        wp_die();
    }
    if (!empty($_POST['post_type']) && in_array($_POST['post_type'], get_post_types())) {
        $what = $_POST['post_type'];
    } else {
        $what = 'post';
    }
    $s = stripslashes($_POST['ps']);
    preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
    $search_terms = array_map('_search_terms_tidy', $matches[0]);
    $searchand = $search = '';
    foreach ((array) $search_terms as $term) {
        $term = esc_sql(like_escape($term));
        $search .= "{$searchand}(({$wpdb->posts}.post_title LIKE '%{$term}%') OR ({$wpdb->posts}.post_content LIKE '%{$term}%'))";
        $searchand = ' AND ';
    }
    $term = esc_sql(like_escape($s));
    if (count($search_terms) > 1 && $search_terms[0] != $s) {
        $search .= " OR ({$wpdb->posts}.post_title LIKE '%{$term}%') OR ({$wpdb->posts}.post_content LIKE '%{$term}%')";
    }
    $posts = $wpdb->get_results("SELECT ID, post_title, post_status, post_date FROM {$wpdb->posts} WHERE post_type = '{$what}' AND post_status IN ('draft', 'publish') AND ({$search}) ORDER BY post_date_gmt DESC LIMIT 50");
    if (!$posts) {
        $posttype = get_post_type_object($what);
        wp_die($posttype->labels->not_found);
    }
    $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>' . __('Title') . '</th><th>' . __('Date') . '</th><th>' . __('Status') . '</th></tr></thead><tbody>';
    foreach ($posts as $post) {
        switch ($post->post_status) {
            case 'publish':
            case 'private':
                $stat = __('Published');
                break;
            case 'future':
                $stat = __('Scheduled');
                break;
            case 'pending':
                $stat = __('Pending Review');
                break;
            case 'draft':
                $stat = __('Draft');
                break;
        }
        if ('0000-00-00 00:00:00' == $post->post_date) {
            $time = '';
        } else {
            /* translators: date format in table columns, see http://php.net/date */
            $time = mysql2date(__('Y/m/d'), $post->post_date);
        }
        $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-' . $post->ID . '" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
        $html .= '<td><label for="found-' . $post->ID . '">' . esc_html($post->post_title) . '</label></td><td>' . esc_html($time) . '</td><td>' . esc_html($stat) . '</td></tr>' . "\n\n";
    }
    $html .= '</tbody></table>';
    $x = new WP_Ajax_Response();
    $x->add(array('what' => $what, 'data' => $html));
    $x->send();
}
Example #23
0
 /**
  * Update Font Control Instance - Ajax Function
  * 
  * Checks WordPress nonce and upon successful validation
  * updates a new font control instance. This function then 
  * constructs a new ajax response and sends it back to the
  * client.
  *
  * @since 1.2
  * @version 1.3.9
  * 
  */
 public function update_control_instance()
 {
     // Check admin nonce for security
     check_ajax_referer('tt_font_edit_control_instance', 'tt_font_edit_control_instance_nonce');
     // Make sure user has the required access level
     if (!current_user_can('edit_theme_options')) {
         wp_die(-1);
     }
     // Get control attributes
     $control_id = isset($_POST['controlId']) ? (string) esc_attr($_POST['controlId']) : (string) '0';
     $control_name = isset($_POST['controlName']) ? (string) esc_attr($_POST['controlName']) : __('Custom Font Control', $this->plugin_slug);
     $force_styles = false;
     $description = '';
     $selectors = array();
     if (isset($_POST['control-selectors'])) {
         $selectors = (array) $_POST['control-selectors'];
     }
     if (isset($_POST['force-styles'])) {
         $force_styles = 'true' == $_POST['force-styles'] ? true : false;
     }
     for ($i = 0; $i < count($selectors); $i++) {
         while (substr($selectors[$i], -1) == ',') {
             $selectors[$i] = rtrim($selectors[$i], ',');
         }
     }
     // Update control or create a new one if it doesn't exist
     $control = EGF_Posttype::update_font_control($control_id, $control_name, $selectors, $description, $force_styles);
     // Create array to hold additional xml data
     $supplimental_data = array('control_name' => get_the_title($control));
     $data = array('what' => 'control', 'id' => 1, 'data' => '', 'supplemental' => $supplimental_data);
     // Create a new WP_Ajax_Response obj and send the request
     $x = new WP_Ajax_Response($data);
     $x->send();
     wp_die();
 }
        /**
         * Send ajax response
         *
         * @param   array   $response   Part response in the format:
         *                              [id]        	=> 0 = no result, 1 = result
         *                              [data]      	=> html string (can be empty if no result)
         *                              [supplemental]  => (optional) supplemental info to pass
         *                              [tr_class]  	=> (optional) class for the wrapping row
         * @return  void
         */
        public function send_ajax_response($response)
        {
            $tr_class = '';
            if (isset($response['tr_class']) && $response['tr_class'] !== '') {
                $tr_class = ' class="' . esc_attr($response['tr_class']) . '"';
            }
            $data = '';
            if ($response['data'] !== '') {
                $data = '<tr' . $tr_class . '>
							<td>&nbsp;</td>
							<td colspan="{colspan}">
								' . $response['data'] . '
							</td>
						</tr>';
            }
            $supplemental = array();
            // Only accounts for the expected new view online link, everything else will be buggered
            if (isset($response['supplemental']) && $response['supplemental'] !== '') {
                $supplemental['url_link'] = ' | ' . $response['supplemental'];
            }
            /* Send the response */
            $ajax_response = new WP_Ajax_Response();
            $ajax_response->add(array('what' => self::$name, 'action' => $_POST['action'], 'id' => $response['id'], 'data' => $data, 'supplemental' => $supplemental));
            $ajax_response->send();
            exit;
        }
Example #25
0
 /**
  * Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window
  *
  * Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php.
  *
  * @since 2.20
  *
  * @param string The taxonomy name, from $_POST['action']
  *
  * @return void Sends JSON response with updated HTML for the checklist
  */
 private static function _mla_ajax_add_flat_term($key)
 {
     $taxonomy = get_taxonomy($key);
     check_ajax_referer($_POST['action'], '_ajax_nonce-add-' . $key, true);
     if (!current_user_can($taxonomy->cap->edit_terms)) {
         wp_die(-1);
     }
     $new_names = explode(',', $_POST['new' . $key]);
     $new_terms_markup = '';
     foreach ($new_names as $name) {
         if ('' === sanitize_title($name)) {
             continue;
         }
         if (!($id = term_exists($name, $key))) {
             $id = wp_insert_term($name, $key);
         }
         if (is_wp_error($id)) {
             continue;
         }
         if (is_array($id)) {
             $id = absint($id['term_id']);
         } else {
             continue;
         }
         $term = get_term($id, $key);
         $name = $term->name;
         $new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n";
     }
     // foreach new_name
     $input_new_parent_name = "new{$key}_parent";
     $supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
     $add = array('what' => $key, 'id' => $id, 'data' => $new_terms_markup, 'position' => -1, 'supplemental' => array('newcat_parent' => $supplemental));
     $x = new WP_Ajax_Response($add);
     $x->send();
 }
Example #26
0
 function pf_ajax_thing_deleter()
 {
     ob_start();
     if (isset($_POST['post_id'])) {
         $id = $_POST['post_id'];
     } else {
         die('Option not sent');
     }
     if (isset($_POST['made_readable'])) {
         $read_status = $_POST['made_readable'];
     } else {
         $read_status = false;
     }
     $returned = self::pf_thing_deleter($id, $read_status);
     var_dump($returned);
     $vd = ob_get_clean();
     ob_end_clean();
     $response = array('what' => 'pressforward', 'action' => 'pf_ajax_thing_deleter', 'id' => $id, 'data' => (string) $vd);
     $xmlResponse = new WP_Ajax_Response($response);
     $xmlResponse->send();
     die;
 }
function wp_ajax_find_posts()
{
    global $wpdb;
    check_ajax_referer('find-posts');
    $post_types = get_post_types(array('public' => true), 'objects');
    unset($post_types['attachment']);
    $s = wp_unslash($_POST['ps']);
    $searchand = $search = '';
    $args = array('post_type' => array_keys($post_types), 'post_status' => 'any', 'posts_per_page' => 50);
    if ('' !== $s) {
        $args['s'] = $s;
    }
    $posts = get_posts($args);
    if (!$posts) {
        wp_die(__('No items found.'));
    }
    $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>' . __('Title') . '</th><th class="no-break">' . __('Type') . '</th><th class="no-break">' . __('Date') . '</th><th class="no-break">' . __('Status') . '</th></tr></thead><tbody>';
    foreach ($posts as $post) {
        $title = trim($post->post_title) ? $post->post_title : __('(no title)');
        switch ($post->post_status) {
            case 'publish':
            case 'private':
                $stat = __('Published');
                break;
            case 'future':
                $stat = __('Scheduled');
                break;
            case 'pending':
                $stat = __('Pending Review');
                break;
            case 'draft':
                $stat = __('Draft');
                break;
        }
        if ('0000-00-00 00:00:00' == $post->post_date) {
            $time = '';
        } else {
            /* translators: date format in table columns, see http://php.net/date */
            $time = mysql2date(__('Y/m/d'), $post->post_date);
        }
        $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-' . $post->ID . '" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
        $html .= '<td><label for="found-' . $post->ID . '">' . esc_html($title) . '</label></td><td class="no-break">' . esc_html($post_types[$post->post_type]->labels->singular_name) . '</td><td class="no-break">' . esc_html($time) . '</td><td class="no-break">' . esc_html($stat) . ' </td></tr>' . "\n\n";
    }
    $html .= '</tbody></table>';
    $x = new WP_Ajax_Response();
    $x->add(array('data' => $html));
    $x->send();
}
function ht_profile_nudge_ajax_action_add_bio()
{
    $nonce = $_POST['nonce'];
    $itext = $_POST['itext'];
    $widget_id = $_POST['widget_id'];
    global $current_user;
    $success = false;
    $current_user = wp_get_current_user();
    if ($current_user->ID) {
        $userid = $current_user->ID;
    }
    if (!wp_verify_nonce($nonce, 'update_profile_add_bio_' . $widget_id)) {
        // This nonce is not valid.
        $html = __("Security check - there is something wrong", "govintranet");
    } else {
        // The nonce was valid.
        // Do stuff here.
        $response = new WP_Ajax_Response();
        $userid = $_POST['userid'];
        $current_user = wp_get_current_user();
        $current_userid = $current_user->ID;
        //
        if ($itext == '') {
            $html = __('Tell us a little more', 'govintranet');
        } elseif ($userid != $current_userid) {
            $html = __("Security check - can\\'t check your identity", "govintranet");
        } else {
            $itext = sanitize_text_field($itext);
            update_user_meta($current_userid, 'description', $itext, '');
            $html = __('<strong>Updated.</strong> Thank you', 'govintranet') . ' <span class="dashicons dashicons-smiley"></span>';
            $success = true;
        }
    }
    if ($success) {
        // Request successful
        $response->add(array('data' => 'success', 'supplemental' => array('message' => '<div class="alert alert-success alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button>' . $html . '</div>')));
    } else {
        // Request failed
        $response->add(array('data' => 'error', 'supplemental' => array('message' => '<div class="alert alert-danger">' . $html . '</div>')));
    }
    $response->send();
    exit;
}
Example #29
0
/**
 * Ajax handler for adding a user.
 *
 * @since 3.1.0
 *
 * @global WP_List_Table $wp_list_table
 *
 * @param string $action Action to perform.
 */
function wp_ajax_add_user($action)
{
    global $wp_list_table;
    if (empty($action)) {
        $action = 'add-user';
    }
    check_ajax_referer($action);
    if (!current_user_can('create_users')) {
        wp_die(-1);
    }
    if (!($user_id = edit_user())) {
        wp_die(0);
    } elseif (is_wp_error($user_id)) {
        $x = new WP_Ajax_Response(array('what' => 'user', 'id' => $user_id));
        $x->send();
    }
    $user_object = get_userdata($user_id);
    $wp_list_table = _get_list_table('WP_Users_List_Table');
    $role = current($user_object->roles);
    $x = new WP_Ajax_Response(array('what' => 'user', 'id' => $user_id, 'data' => $wp_list_table->single_row($user_object, '', $role), 'supplemental' => array('show-link' => sprintf(__('User %s added'), '<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'), 'role' => $role)));
    $x->send();
}
Example #30
0
 /**
  * Test that charset in the xml tag matches blog_charset
  * @ticket 19448
  */
 public function test_response_charset_in_xml()
 {
     // Generate an ajax response
     ob_start();
     $ajax_response = new WP_Ajax_Response();
     $ajax_response->send();
     // Check the XML tag
     $contents = ob_get_clean();
     $this->assertRegExp('/<\\?xml\\s+version=\'1.0\'\\s+encoding=\'' . preg_quote(get_option('blog_charset')) . '\'\\s+standalone=\'yes\'\\?>/', $contents);
 }