function do_x_post_password_cb()
 {
     //snag from wp-login.php:386-393
     require_once ABSPATH . 'wp-includes/class-phpass.php';
     // By default, use the portable hash from phpass
     $wp_hasher = new PasswordHash(8, true);
     // 10 days
     setcookie('wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword(stripslashes($_POST['pass'])), time() + 864000, COOKIEPATH);
     //fake it so it's available in the loop below
     $_COOKIE['wp-postpass_' . COOKIEHASH] = $wp_hasher->HashPassword(stripslashes($_POST['pass']));
     $q = new WP_Query("p={$_POST['pid']}");
     if ($q->have_posts()) {
         while ($q->have_posts()) {
             $q->the_post();
             // verifies password hash
             if (post_password_required()) {
                 wp_send_json_error('Invalid password');
             }
             // get post title
             ob_start();
             the_title(sprintf('<a href="%s" rel="bookmark">', esc_url(get_permalink())), '</a>');
             $title = ob_get_clean();
             // get post content
             ob_start();
             the_content();
             $content = ob_get_clean();
         }
     }
     wp_reset_postdata();
     $return = array('title' => $title, 'content' => $content);
     wp_send_json_success($return);
 }
function do_forgot_password_ajax()
{
    if (isset($_POST['forgot_password_form_submitted']) && isset($_POST['forgot_password_form_nonce_field']) && wp_verify_nonce($_POST['forgot_password_form_nonce_field'], 'forgot_password_form_submitted')) {
        if (isset($_POST['username'])) {
            $username = sanitize_text_field($_REQUEST['username']);
            $user = get_user_by('login', $username);
            if (!$user) {
                $return = array('message' => "Sorry the username you provided is not registered");
                wp_send_json_error($return);
            } else {
                // Send an email that the account has been created
                do_action('cloderia_user_reset_password', $username);
                $return = array('message' => "A new password has been sent to your email");
                wp_send_json_success($return);
            }
        } else {
            $return = array('message' => "Please provide a valid username");
            wp_send_json_error($return);
        }
    } else {
        $message = "Invalid form operation.";
        $return = array('message' => $message);
        wp_send_json_error($return);
    }
}
Example #3
0
 /**
  * Upload
  * Ajax callback function
  *
  * @return string Error or (XML-)response
  */
 static function handle_upload()
 {
     global $wpdb;
     $post_id = isset($_REQUEST['post_id']) ? intval($_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);
         wp_send_json_success(self::img_html($id));
     }
     exit;
 }
 /**
  *
  * 	Process the infoz
  *	@since 1.0
  */
 function user_info()
 {
     if (isset($_POST['action'])) {
         // bail out if this user isnt logged in
         if (!is_user_logged_in()) {
             return;
         }
         if (!wp_verify_nonce($_POST['nonce'], 'process-user-info')) {
             return;
         }
         $user_id = get_current_user_id();
         if ($_POST['action'] == 'process_user_info') {
             $gender = isset($_POST['gender']) ? sanitize_text_field($_POST['gender']) : false;
             $age = isset($_POST['age']) ? sanitize_text_field($_POST['age']) : false;
             $education = isset($_POST['education']) ? sanitize_text_field($_POST['education']) : false;
             $employment = isset($_POST['employment']) ? sanitize_text_field($_POST['employment']) : false;
             $data = array('gender' => $gender, 'age' => $age, 'education' => $education, 'employment' => $employment);
             update_user_meta($user_id, 'user_info', $data);
             update_user_meta($user_id, 'user_info_completed', 1);
             do_action('user_info_updated', $user_id, $data);
             wp_send_json_success();
         } else {
             wp_send_json_error();
         }
     } else {
         wp_send_json_error();
     }
 }
 /**
  * Save an image
  */
 public function save_image()
 {
     check_ajax_referer(self::NONCE_SAVE_IMAGE, 'nonce');
     $attachment_id = isset($_POST['attachment_id']) ? absint($_POST['attachment_id']) : false;
     if ($this->is_attachment($attachment_id)) {
         // faces
         if (isset($_POST['faces'])) {
             if ($_POST['faces']) {
                 update_post_meta($attachment_id, 'faces', $_POST['faces']);
             } else {
                 delete_post_meta($attachment_id, 'faces');
             }
         }
         // hotspots
         if (isset($_POST['hotspots'])) {
             if ($_POST['hotspots']) {
                 update_post_meta($attachment_id, 'hotspots', $_POST['hotspots']);
             } else {
                 delete_post_meta($attachment_id, 'hotspots');
             }
         }
         // regenerate thumbs
         $resized = MEAUH_Attachment::regenerate($attachment_id);
         if ($resized) {
             wp_send_json_success(array('resized' => $resized));
         }
     } else {
         wp_send_json_error();
     }
 }
/**
 * Ajax handler for type assignment fix troubleshoot action
 */
function icl_repair_broken_type_and_language_assignments()
{
    global $sitepress;
    $lang_setter = new WPML_Fix_Type_Assignments($sitepress);
    $rows_fixed = $lang_setter->run();
    wp_send_json_success($rows_fixed);
}
 /**
  * Ajax handler for saving label translations from the WPML Taxonomy Translations menu.
  */
 public function save_label_translations()
 {
     if (!wpml_is_action_authenticated('wpml_tt_save_labels_translation')) {
         wp_send_json_error('Wrong Nonce');
     }
     $general = isset($_POST['plural']) ? sanitize_text_field($_POST['plural']) : false;
     $singular = isset($_POST['singular']) ? sanitize_text_field($_POST['singular']) : false;
     $taxonomy = isset($_POST['taxonomy']) ? sanitize_text_field($_POST['taxonomy']) : false;
     $language = isset($_POST['taxonomy_language_code']) ? sanitize_text_field($_POST['taxonomy_language_code']) : false;
     if ($singular && $general && $taxonomy && $language) {
         $tax_label_data = $this->get_label_translations(false, $taxonomy);
         if (isset($tax_label_data['id_singular']) && $tax_label_data['id_singular'] && isset($tax_label_data['id_general']) && $tax_label_data['id_general']) {
             $original_id_singular = $tax_label_data['id_singular'];
             $original_id_plural = $tax_label_data['id_general'];
             icl_add_string_translation($original_id_singular, $language, $singular, ICL_TM_COMPLETE);
             $singular_result = (string) icl_get_string_by_id($original_id_singular, $language);
             icl_add_string_translation($original_id_plural, $language, $general, ICL_TM_COMPLETE);
             $plural_result = (string) icl_get_string_by_id($original_id_plural, $language);
             if ($singular_result && $plural_result) {
                 $result = array('singular' => $singular_result, 'general' => $plural_result, 'lang' => $language);
                 wp_send_json_success($result);
             }
         }
     }
     wp_send_json_error();
 }
Example #8
0
 /**
  * Tries to install the plugin
  *
  * @access public
  */
 public function install()
 {
     $this->check_capabilities();
     $download = $_POST['download'];
     $license = $_POST['license'];
     $message = __('An Error Occured', 'maera');
     $download_type = $this->_check_download($download);
     /**
      * Throw error of the product is not free and license it empty
      */
     if (empty($download) || empty($license) && 'free' !== $download_type) {
         wp_send_json_error($message);
     }
     /**
      * Install the plugin if it's free
      */
     if ('free' === $download_type) {
         $installed = $this->_install_plugin($download, "");
         wp_send_json_success($installed);
     }
     /**
      * Check for license and then install if it's a valid licens
      */
     if ($this->_check_license($license, $download)) {
         $installed = $this->_install_plugin($download, $license);
         wp_send_json_success($installed);
     } else {
         wp_send_json_error(__('Invalid License', 'maera'));
     }
 }
Example #9
0
 /**
  * Ajax callback to get data for overview widget
  */
 public function ajax_get_data()
 {
     if (!check_ajax_referer('get-data', false, false)) {
         wp_send_json_error();
     }
     wp_send_json_success($this->get_data(intval($_GET['user']), strip_tags($_GET['from']), strip_tags($_GET['to'])));
 }
function get_posts_by_letter_rendered($first_letter = NULL, $limit = NULL)
{
    global $wp_query;
    /** Validating parameters **/
    $first_letter = (!$first_letter and isset($_POST['letter'])) ? $_POST['letter'] : $first_letter;
    $first_letter = (!$first_letter and !isset($_POST['letter'])) ? 'A' : $first_letter;
    $limit = ($limit === NULL and isset($_POST['limit'])) ? $_POST['limit'] : $limit;
    $limit = ($limit === NULL and !isset($_POST['limit'])) ? -1 : $limit;
    // $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $paged = detect_page_from_url();
    $args = array('post_type' => 'realizadores', 'post_status' => 'publish', 'posts_per_page' => $limit, 'paged' => $paged, 'tax_query' => array(array('taxonomy' => 'letters', 'field' => 'name', 'terms' => $first_letter)));
    $query_to_render = new WP_Query($args);
    //Start recording echoed values
    $echoed = '';
    ob_start();
    global $post;
    ob_start();
    echo "<h2>{$first_letter}</h2>";
    if ($query_to_render->have_posts()) {
        while ($query_to_render->have_posts()) {
            $query_to_render->the_post();
            setup_postdata($post);
            get_template_part('templates/feed', 'small-item');
        }
    }
    wp_reset_postdata();
    echo "<div class='end_of_letter' data-letter='{$first_letter}'></div>";
    $echoed = ob_get_contents();
    ob_end_clean();
    if ($echoed !== '') {
        wp_send_json_success(json_encode($echoed));
    }
    wp_send_json_error();
}
Example #11
0
 static function ajax_save()
 {
     if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) {
         wp_send_json_error();
     }
     do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     $user_id_author = isset($_POST['user_id_author']) ? $_POST['user_id_author'] : get_current_user_id();
     if (empty($_POST['user_id_worked'])) {
         $_POST['user_id_worked'] = $user_id_author;
     }
     try {
         $operator = substr($_POST['operator'], 0, 1) == '-' ? '-' : '+';
         $val = sprintf('%s%s', $operator, abs(floatval($_POST['operator'])));
     } catch (Exception $e) {
         wp_send_json_error(array('message' => sprintf('Error saving %s', str_replace('_', ' ', self::$slug))));
     }
     eval(sprintf('$hours = 0%s;', $val));
     $data = array('task_id' => $_POST['task']['id'], 'worked_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'hours' => $hours, 'status_is' => $_POST['task']['status_id'], 'user_id_author' => $user_id_author, 'user_id_worked' => $_POST['user_id_worked']);
     $is_successful = self::_insert($data);
     do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug));
     if (!empty($_POST['comment'])) {
         do_action(sprintf('%s_before_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug));
         Kanban_Comment::add($_POST['comment'], 'system', $_POST['task']['id']);
         do_action(sprintf('%s_after_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug));
     }
     if ($is_successful) {
         wp_send_json_success(array('message' => sprintf('%s saved', str_replace('_', ' ', self::$slug))));
     } else {
         wp_send_json_error(array('message' => sprintf('Error saving %s', str_replace('_', ' ', self::$slug))));
     }
 }
 /**
  * Retrieves information about the user who is currently logged into the site.
  *
  * This function is intended to be called via the client-side of the public-facing
  * side of the site.
  *
  * @since    1.0.0
  */
 public function get_current_user_info()
 {
     $user_id = get_current_user_id();
     if ($this->user_is_logged_in($user_id) && $this->user_exists($user_id)) {
         wp_send_json_success(wp_json_encode(get_user_by('id', $user_id)));
     }
 }
Example #13
0
 function get_select_box()
 {
     $return = (object) ["options" => $this->get_icons()];
     if (isset($_REQUEST["layout_id"]) && ctype_xdigit($_REQUEST["layout_id"]) && isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) {
         $field_id = $_REQUEST["layout_id"];
         $post_id = $_REQUEST["id"];
     } else {
         wp_send_json_success($return);
     }
     $post = get_post($post_id);
     $post_obj = unserialize($post->post_content);
     $found = false;
     foreach ($post_obj["layouts"] as $obj) {
         if ($obj["key"] == $field_id) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         wp_send_json_success($return);
     }
     if (is_array($obj) && isset($obj["icon"])) {
         if (!empty($obj["icon"])) {
             $return->icon = $obj["icon"];
             wp_send_json_success($return);
         } else {
             wp_send_json_success($return);
         }
     } else {
         wp_send_json_success($return);
     }
 }
Example #14
0
 static function set_theme()
 {
     $stylesheet = sanitize_text_field($_POST['stylesheet']);
     do_action('jetpack_start_select_theme', $stylesheet);
     switch_theme($stylesheet);
     wp_send_json_success();
 }
Example #15
0
/**
 * Retrieve a list of records and their corresponding tracks for use in Cue.
 *
 * @since 1.5.0
 */
function audiotheme_ajax_get_playlist_records()
{
    global $wpdb;
    $data = array();
    $page = isset($_POST['paged']) ? absint($_POST['paged']) : 1;
    $posts_per_page = isset($_POST['posts_per_page']) ? absint($_POST['posts_per_page']) : 2;
    $records = new WP_Query(array('post_type' => 'audiotheme_record', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'paged' => $page, 'orderby' => 'title', 'order' => 'ASC'));
    if ($records->have_posts()) {
        foreach ($records->posts as $record) {
            $image = wp_get_attachment_image_src(get_post_thumbnail_id($record->ID), array(120, 120));
            $data[$record->ID] = array('id' => $record->ID, 'title' => $record->post_title, 'artist' => get_audiotheme_record_artist($record->ID), 'release' => get_audiotheme_record_release_year($record->ID), 'thumbnail' => $image[0], 'tracks' => array());
        }
        $tracks = $wpdb->get_results("SELECT p.ID, p.post_title, p2.ID AS record_id\r\n\t\t\tFROM {$wpdb->posts} p\r\n\t\t\tINNER JOIN {$wpdb->posts} p2 ON p.post_parent=p2.ID\r\n\t\t\tWHERE p.post_type='audiotheme_track' AND p.post_status='publish'\r\n\t\t\tORDER BY p.menu_order ASC");
        if ($tracks) {
            foreach ($tracks as $track) {
                if (!isset($data[$track->record_id])) {
                    continue;
                }
                $data[$track->record_id]['tracks'][] = array('id' => $track->ID, 'title' => $track->post_title);
            }
        }
        // Remove records that don't have any tracks.
        foreach ($data as $key => $item) {
            if (empty($item['tracks'])) {
                unset($data[$key]);
            }
        }
    }
    $send['maxNumPages'] = $records->max_num_pages;
    $send['records'] = array_values($data);
    wp_send_json_success($send);
}
function icl_repair_broken_type_and_language_assignments()
{
    global $sitepress;
    $lang_setter = $sitepress->get_language_setter();
    $rows_fixed = $lang_setter->repair_broken_assignments();
    wp_send_json_success($rows_fixed);
}
/**
 * Ajax handler to create dummy doc on creation
 *
 * @since 1.4
 */
function bp_docs_create_dummy_doc()
{
    add_filter('wp_insert_post_empty_content', '__return_false');
    $doc_id = wp_insert_post(array('post_type' => bp_docs_get_post_type_name(), 'post_status' => 'auto-draft'));
    remove_filter('wp_insert_post_empty_content', '__return_false');
    wp_send_json_success(array('doc_id' => $doc_id));
}
Example #18
0
 /**
  * Pass global $post object.
  *
  * @link https://github.com/iseulde/wp-front-end-editor/pull/228
  */
 function ajax_post()
 {
     require_once ABSPATH . '/wp-admin/includes/post.php';
     if (!wp_verify_nonce($_POST['_wpnonce'], 'update-post_' . $_POST['post_ID'])) {
         wp_send_json_error(array('message' => __('You are not allowed to edit this item.')));
     }
     $_POST['post_title'] = strip_tags($_POST['post_title']);
     $post_id = edit_post();
     if (isset($_POST['save']) || isset($_POST['publish'])) {
         $status = get_post_status($post_id);
         if (isset($_POST['publish'])) {
             switch ($status) {
                 case 'pending':
                     $message = 8;
                     break;
                 case 'future':
                     $message = 9;
                     break;
                 default:
                     $message = 6;
             }
         } else {
             $message = 'draft' == $status ? 10 : 1;
         }
     } else {
         $message = 4;
     }
     // MOD by CAC
     global $post;
     // end MOD
     $post = get_post($post_id);
     wp_send_json_success(array('message' => $this->get_message($post, $message), 'post' => $post, 'processedPostContent' => apply_filters('the_content', $post->post_content)));
 }
 public function ajax()
 {
     $apiArgs = isset($_GET["apiArgs"]) ? $_GET["apiArgs"] : array();
     if (!$apiArgs) {
         wp_send_json_error(array("error" => "MISSING_APIARGS"));
         exit;
     }
     if (empty($apiArgs["since_id"]) || !is_numeric($apiArgs["since_id"])) {
         wp_send_json_error(array("error" => "MISSING_SINCE_ID"));
         exit;
     }
     // $since_id = isset( $_GET["since_id"] ) ? absint($_GET["since_id"]) : null;
     $logQueryArgs = $apiArgs;
     $logQuery = new SimpleHistoryLogQuery();
     $answer = $logQuery->query($logQueryArgs);
     // Use our own repsonse array instead of $answer to keep size down
     $json_data = array();
     $numNewRows = isset($answer["total_row_count"]) ? $answer["total_row_count"] : 0;
     $json_data["num_new_rows"] = $numNewRows;
     $json_data["num_mysql_queries"] = get_num_queries();
     if ($numNewRows) {
         // We have new rows
         // Append strings
         $textRowsFound = sprintf(_n('1 new event', '%d new events', $numNewRows, 'simple-history'), $numNewRows);
         $json_data["strings"] = array("newRowsFound" => $textRowsFound);
     }
     wp_send_json_success($json_data);
 }
 /**
  * Upload an image via plupload.
  *
  * @return
  */
 function charitable_plupload_image_upload()
 {
     $post_id = (int) filter_input(INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT);
     $field_id = (string) filter_input(INPUT_POST, 'field_id');
     check_ajax_referer('charitable-upload-images-' . $field_id);
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => false));
     if (isset($file_attr['error'])) {
         wp_send_json_error($file_attr);
     }
     $attachment = array('guid' => $file_attr['url'], 'post_mime_type' => $file_attr['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file['name'])), 'post_content' => '', 'post_status' => 'inherit');
     /**
      * Insert the file as an attachment.
      */
     $attachment_id = wp_insert_attachment($attachment, $file_attr['file'], $post_id);
     if (is_wp_error($attachment_id)) {
         wp_send_json_error();
     }
     wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file_attr['file']));
     $size = (string) filter_input(INPUT_POST, 'size');
     $max_uploads = (int) filter_input(INPUT_POST, 'max_uploads', FILTER_SANITIZE_NUMBER_INT);
     if (!$size) {
         $size = 'thumbnail';
     }
     ob_start();
     charitable_template('form-fields/picture-preview.php', array('image' => $attachment_id, 'field' => array('key' => $field_id, 'size' => $size, 'max_uploads' => $max_uploads)));
     wp_send_json_success(ob_get_clean());
 }
Example #21
0
 /**
  * Listens for changes to the event log settings updating and returning
  * an appropriate response.
  */
 public function listen()
 {
     $fields = wp_parse_args($_POST, array('check' => '', 'log-level' => '', 'log-engine' => ''));
     foreach ($fields as &$single_field) {
         $single_field = sanitize_text_field($single_field);
     }
     if (!wp_verify_nonce($fields['check'], 'logging-controls')) {
         return;
     }
     /**
      * Fires before log settings are committed.
      *
      * This will not happen unless a nonce check has already passed.
      */
     do_action('tribe_common_update_log_settings');
     $this->update_logging_level($fields['log-level']);
     $this->update_logging_engine($fields['log-engine']);
     /**
      * Fires immediately after log settings have been committed.
      */
     do_action('tribe_common_updated_log_settings');
     $data = array('logs' => $this->get_available_logs());
     if (!empty($fields['log-view'])) {
         $data['entries'] = $this->get_log_entries($fields['log-view']);
     }
     wp_send_json_success($data);
 }
Example #22
0
 function ajax_upgrade()
 {
     // options
     $options = acf_parse_args($_POST, array('version' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce')) {
         wp_send_json_error();
     }
     // vars
     $path = acf_get_path("admin/updates/{$options['version']}.php");
     // load version
     if (!file_exists($path)) {
         wp_send_json_error();
     }
     // load any errors / feedback from update
     ob_start();
     // include
     include $path;
     // get feedback
     $feedback = ob_get_clean();
     // update successful
     update_option('acf_version', $options['version']);
     // check for relevant updates. If none are found, update this to the plugin version
     $updates = acf_get_updates();
     if (empty($updates)) {
         update_option('acf_version', acf_get_setting('version'));
     }
     // return
     wp_send_json_success(array('feedback' => $feedback));
 }
 static function modal_status()
 {
     $modal_status = sanitize_text_field($_POST['modal_status']);
     $result = update_option('jpstart_modal_status', $modal_status);
     do_action('jetpack_start_modal_status_change', $modal_status);
     wp_send_json_success($result);
 }
 /**
  * Ajax handler to retrieve content from Resource space and add as attachment.
  */
 function ajax_get_image()
 {
     $resource_id = intval($_POST['resource_id']);
     $parent_post_id = isset($_POST['post']) ? intval($_POST['post']) : 0;
     if (empty($resource_id)) {
         wp_send_json_error(esc_html__('Empty resource id', 'resourcespace'));
     }
     $url = PJ_RESOURCE_SPACE_DOMAIN . '/plugins/api_search/';
     $key = PJ_RESOURCE_SPACE_KEY;
     $url = add_query_arg(array('key' => $key, 'search' => $resource_id, 'prettyfieldnames' => 1, 'previewsize' => 'pre', 'original' => true), $url);
     $request_args = array('headers' => array());
     // Pass basic auth header if available.
     if (defined('PJ_RESOURCE_SPACE_AUTHL') && defined('PJ_RESOURCE_SPACE_AUTHP')) {
         $request_args['headers']['Authorization'] = 'Basic ' . base64_encode(PJ_RESOURCE_SPACE_AUTHL . ':' . PJ_RESOURCE_SPACE_AUTHP);
     }
     $response = wp_remote_get($url, $request_args);
     if (200 == wp_remote_retrieve_response_code($response)) {
         $data = json_decode(wp_remote_retrieve_body($response));
     } else {
         wp_send_json_error(esc_html__('Unable to query API', 'resourcespace'));
     }
     if (count($data) < 1) {
         wp_send_json_error(esc_html__('Resource not found', 'resourcespace'));
     }
     // Request original URL.
     // $attachment_id = $this->sideload_image( $data[0]->original );
     // Request preview size.
     $attachment_id = $this->sideload_image($data[0]->preview);
     if (is_wp_error($attachment_id)) {
         wp_send_json_error($attachment_id->get_error_message());
     } else {
         wp_send_json_success(wp_prepare_attachment_for_js($attachment_id));
     }
     exit;
 }
Example #25
0
/**
 * Parse the Cue shortcode for display within a TinyMCE view.
 *
 * @since 1.3.0
 */
function cue_ajax_parse_shortcode()
{
    global $wp_scripts;
    if (empty($_POST['shortcode'])) {
        wp_send_json_error();
    }
    $shortcode = do_shortcode(wp_unslash($_POST['shortcode']));
    if (empty($shortcode)) {
        wp_send_json_error(array('type' => 'no-items', 'message' => __('No items found.')));
    }
    $head = '';
    $styles = wpview_media_sandbox_styles();
    foreach ($styles as $style) {
        $head .= '<link type="text/css" rel="stylesheet" href="' . $style . '">';
    }
    $head .= '<link rel="stylesheet" href="' . CUE_URL . 'assets/css/cue.min.css' . '">';
    $head .= '<style type="text/css">.cue-tracks { max-height: none;}</style>';
    if (!empty($wp_scripts)) {
        $wp_scripts->done = array();
    }
    ob_start();
    echo $shortcode;
    wp_print_scripts('cue');
    wp_send_json_success(array('head' => $head, 'body' => ob_get_clean()));
}
 public function ajax_handler($data)
 {
     CS_Shortcode_Preserver::init();
     if ($this->sandbox_the_content) {
         CS_Shortcode_Preserver::sandbox('cs_render_the_content');
     }
     add_filter('cs_preserve_shortcodes_no_wrap', '__return_true');
     $this->orchestrator = $this->plugin->component('Element_Orchestrator');
     $this->orchestrator->load_elements();
     $this->mk1 = new Cornerstone_Legacy_Renderer($this->plugin->component('Legacy_Elements'));
     global $post;
     if (!isset($data['post_id']) || !($post = get_post((int) $data['post_id']))) {
         wp_send_json_error(array('message' => 'post_id not set'));
     }
     setup_postdata($post);
     $this->enqueue_extractor = $this->plugin->loadComponent('Enqueue_Extractor');
     $this->enqueue_extractor->start();
     if (isset($data['raw_markup'])) {
         $this->raw_markup = (bool) $data['raw_markup'];
     }
     if (!isset($data['batch'])) {
         wp_send_json_error(array('message' => 'No element data recieved'));
     }
     $jobs = $this->batch($data['batch']);
     $scripts = $this->enqueue_extractor->get_scripts();
     if (is_wp_error($jobs)) {
         wp_send_json_error(array('message' => $jobs->get_error_message()));
     }
     $result = array('jobs' => $jobs, 'scripts' => $scripts);
     //Suppress PHP error output unless debugging
     if (CS()->common()->isDebug()) {
         return wp_send_json_success($result);
     }
     return @wp_send_json_success($result);
 }
Example #27
0
 public function ajax_image_crop()
 {
     $res = false;
     if (!current_user_can('edit_posts') || empty($_REQUEST["nonce"]) || !wp_verify_nonce($_REQUEST["nonce"], 'pe_theme_image_crop')) {
         wp_send_json_error();
         wp_die(0);
     }
     $id = $_REQUEST["id"];
     $idx = $_REQUEST["idx"];
     $size = $_REQUEST["size"];
     list($w, $h) = explode("x", $size);
     $crop = $_REQUEST["crop"];
     $orig = $_REQUEST["orig"];
     $res = $this->master->image->crop($orig, $crop, $w, $h);
     if (!empty($res["cburl"])) {
         $res["idx"] = absint($idx);
         $meta = get_post_meta($id, PE_THEME_META, true);
         if (empty($meta)) {
             $meta = new StdClass();
             $meta->thumbnails = new StdClass();
         }
         $meta->thumbnails->thumbs[$size] = $crop;
         update_post_meta($id, PE_THEME_META, $this->update_attachment_metadata($meta, $id, null));
     }
     wp_send_json_success($res);
     wp_die(0);
 }
Example #28
0
function x_demo_content_setup_ajax_callback()
{
    // Uncomment to simulate a timeout
    // header("HTTP/1.0 408 Request Timeout"); die();
    //
    // Get API data.
    //
    $errorMessage = __('We&apos;re sorry, the demo failed to finish importing.', '__x__');
    if (!isset($_POST['demo'])) {
        wp_send_json_error(array('message' => $errorMessage, 'debug_message' => 'POST data missing demo.'));
    }
    $request = wp_remote_get($_POST['demo']);
    if (is_wp_error($request)) {
        wp_send_json_error(array('message' => $errorMessage, 'debug_message' => $request->get_error_message()));
    }
    //
    // API data.
    //
    $data = json_decode($request['body'], true);
    if (!is_array($data)) {
        wp_send_json_error(array('message' => $errorMessage, 'debug_message' => 'Requested demo is improperly formatted.'));
    }
    //
    // Run demo setup.
    //
    $error = false;
    ob_start();
    include_once 'setup.php';
    if ($error !== false) {
        wp_send_json_error(array('message' => $errorMessage, 'debug_message' => $error, 'buffer' => ob_get_clean()));
    }
    ob_clean();
    wp_send_json_success();
}
 /**
  * @internal
  */
 public static function _admin_action_get_ajax_response()
 {
     /**
      * @var WPDB $wpdb
      */
     global $wpdb;
     $type = FW_Request::POST('data/type');
     $names = json_decode(FW_Request::POST('data/names'), true);
     $title = FW_Request::POST('data/string');
     $items = array();
     switch ($type) {
         case 'posts':
             $items = $wpdb->get_results(call_user_func_array(array($wpdb, 'prepare'), array_merge(array("SELECT ID val, post_title title " . "FROM {$wpdb->posts} " . "WHERE post_title LIKE %s " . "AND post_status IN ( 'publish', 'private' ) " . "AND post_type IN ( " . implode(', ', array_fill(1, count($names), '%s')) . " ) " . "LIMIT 100", '%' . $wpdb->esc_like($title) . '%'), $names)));
             break;
         case 'taxonomy':
             $items = $wpdb->get_results(call_user_func_array(array($wpdb, 'prepare'), array_merge(array("SELECT terms.term_id val, terms.name title " . "FROM {$wpdb->terms} as terms, {$wpdb->term_taxonomy} as taxonomies " . "WHERE terms.name LIKE %s AND taxonomies.taxonomy IN ( " . implode(', ', array_fill(1, count($names), '%s')) . " ) " . "AND terms.term_id = taxonomies.term_id " . "AND taxonomies.term_id = taxonomies.term_taxonomy_id " . "LIMIT 100", '%' . $wpdb->esc_like($title) . '%'), $names)));
             break;
         case 'users':
             if (empty($names)) {
                 $items = $wpdb->get_results($wpdb->prepare("SELECT users.id val, users.user_nicename title " . "FROM {$wpdb->users} as users " . "WHERE users.user_nicename LIKE %s " . "LIMIT 100", '%' . $wpdb->esc_like($title) . '%'));
             } else {
                 $like_user_meta = array();
                 foreach ($names as $name) {
                     $like_user_meta[] = '%' . $wpdb->esc_like($name) . '%';
                 }
                 $items = $wpdb->get_results(call_user_func_array(array($wpdb, 'prepare'), array_merge(array("SELECT users.id val, users.user_nicename title " . "FROM {$wpdb->users} as users, {$wpdb->usermeta} as usermeta " . "WHERE users.user_nicename LIKE %s AND usermeta.meta_key = 'wp_capabilities' " . "AND ( " . implode(' OR ', array_fill(1, count($like_user_meta), 'usermeta.meta_value LIKE %s')) . " ) " . "AND usermeta.user_id = users.ID", '%' . $wpdb->esc_like($title) . '%'), $like_user_meta)));
             }
             break;
     }
     wp_send_json_success($items);
 }
Example #30
0
 public static function die_success($response, $response_code = 200)
 {
     if (200 !== $response_code) {
         status_header($response_code);
     }
     wp_send_json_success($response);
 }