/** * Maps our FB response fields to the correct user fields as found in wp_update_user. Then * calls setUpNewFacebookUser, and passes the correct response via JSON to JS. * * @since 2.0.0 * * @return JSON A JSON object */ public function facebook_login() { check_ajax_referer('facebook-nonce', 'security'); $user = array('username' => $_POST['fb_response']['id'], 'user_login' => $_POST['fb_response']['id'], 'first_name' => $_POST['fb_response']['first_name'], 'last_name' => $_POST['fb_response']['last_name'], 'email' => $_POST['fb_response']['email'], 'user_url' => $_POST['fb_response']['link'], 'fb_id' => $_POST['fb_response']['id']); if (empty($user['username'])) { $status = $this->_zm_alr_helpers->status('invalid_username'); $user_id = false; } else { $user_obj = get_user_by('login', $user['user_login']); if ($user_obj == false) { $user_obj = $this->setupNewFacebookUser($user); } // A WP user account already exists that is NOT associated with a FB account if ($user_obj == 'existing_user_email') { $status = $this->_zm_alr_helpers->status('username_exists'); } elseif ($user_obj) { $user_id = $user_obj->ID; wp_set_auth_cookie($user_id, true); $status = $this->_zm_alr_helpers->status('success_login'); } else { $status = $this->_zm_alr_helpers->status('invalid_username'); } } $status = array_merge($status, $this->registerRedirect($user['user_login'])); wp_send_json($status); }
/** * AJAX callback method * * @return void */ public function run() { // check nonce $this->check_nonce(); // check if make is set if (!isset($_GET['make'])) { return; } // make $make = absint($_GET['make']); // models array $models = array(); // get raw models $models_raw = wp_car_manager()->service('make_model_manager')->get_models($make); // check & loop if (count($models_raw) > 0) { foreach ($models_raw as $model_raw) { // add to $models array $models[] = array('id' => $model_raw['id'], 'name' => $model_raw['name']); } } // send JSON wp_send_json($models); // bye exit; }
function moxie_press_endpoint_data() { global $wp_query; // get query vars $json = $wp_query->get('json'); $name = $wp_query->get('name'); // use this template redirect only if json is requested if ($json != 'true') { return; } // build the query $movie_data = array(); // default args $args = array('post_type' => 'movie', 'posts_per_page' => 100); if ($name != '') { $args['name'] = $name; } // add name if provided in query // check if this particular request is cached, if not, perform the query if (false === ($moxie_cached_request = get_transient('moxie_cached_request_' . json_encode($args)))) { $moxie_cached_request = new WP_Query($args); set_transient('moxie_cached_request_' . json_encode($args), $moxie_cached_request); } // prepare the object we want to send as response if ($moxie_cached_request->have_posts()) { while ($moxie_cached_request->have_posts()) { $moxie_cached_request->the_post(); $id = get_the_ID(); $movie_data[] = array('id' => $id, 'title' => get_the_title(), 'poster_url' => get_post_meta($id, 'moxie_press_poster_url', true), 'rating' => get_post_meta($id, 'moxie_press_rating', true), 'year' => get_post_meta($id, 'moxie_press_year', true), 'short_description' => get_post_meta($id, 'moxie_press_description', true), 'mdbid' => get_post_meta($id, 'moxie_press_mdbid', true)); } wp_reset_postdata(); } // send json data using built-in WP function wp_send_json(array('data' => $movie_data)); }
function ompf_portfolio_ajax() { $out = array('error' => 0); $args = array(); if (isset($_POST['portfolio_id']) && $_POST['portfolio_id']) { $args['portfolio_post_id'] = $_POST['portfolio_id']; } else { $out['error'] = 1; wp_send_json($out); } if (isset($_POST['category_id']) && $_POST['category_id']) { $args['category_id'] = $_POST['category_id']; } if (isset($_POST['paged']) && ($paged = intval($_POST['paged']))) { $args['query_args']['paged'] = $paged; } $portfolio = ompf_get_portfolio_thumbnails($args); $out['html'] = $portfolio['html']; if ($portfolio['pagination'] == 'pages') { $out['html_pagination'] = ompf_pagination_links($portfolio['paged'], $portfolio['max_num_pages'], array('empty_href' => true)); } elseif ($portfolio['pagination'] == 'scroll') { $out['html_pagination'] = ompf_loadmore_link($portfolio['paged'], $portfolio['max_num_pages'], array('empty_href' => true)); } else { $out['html_pagination'] = ''; } wp_send_json($out); }
/** * Handle action requests. * * @return array|void Output JSON if DOING_AJAX, otherwise return an array */ public function action_handler() { $response = array('success' => false, 'error' => null); if (empty($_POST['action']) || empty($_POST['name'])) { return false; } $action = $_POST['action']; $name = $_POST['name']; $result = false; switch ($action) { case 'carbon_add_sidebar': $result = $this->add_sidebar($name); break; case 'carbon_remove_sidebar': $result = $this->remove_sidebar($name); break; } if (is_wp_error($result)) { $response['error'] = $result->get_error_message(); } else { $response['success'] = (bool) $result; } if (defined('DOING_AJAX') && DOING_AJAX) { wp_send_json($response); } else { return $response; } }
/** * Check for an existing venue with the same name. * * @since 1.0.0 */ function audiotheme_ajax_is_new_venue() { global $wpdb; $sql = $wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE post_type='audiotheme_venue' AND post_title=%s ORDER BY post_title ASC LIMIT 1", stripslashes($_GET['name'])); $venue = $wpdb->get_col($sql); wp_send_json($venue); }
function ajax_subscribeform_action_callback() { global $wpdb; $error = ''; $status = 'error'; parse_str($_POST['data'], $_POST); //error_log(print_R($_POST,true)); if (empty($_POST['email'])) { $error = 'All fields are required to enter.'; } else { if (!wp_verify_nonce($_POST['_acf_nonce'], 'ajax_contactform')) { $error = __('Verification error, try again.', 'fws-ajax-contact-form'); } else { $firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); $lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); $email_check = check_email_address_mailgun($email); if ($email_check == 1) { $status = 'success'; $wpdb->insert($wpdb->prefix . "signups", array('title' => $_POST['title'] == 'Other' && trim($_POST['other_title']) !== '' ? $_POST['other_title'] : $_POST['title'], 'firstname' => $firstname, 'lastname' => $lastname, 'email' => $email, 'submittedtime' => date('Y-m-d H:i:s'))); $error = 'Thanks for signing up for campaign updates. We hope you find them useful. '; } else { $error = $email_check; } } } $resp = array('status' => $status, 'errmessage' => $error); wp_send_json($resp); }
public function ajax_hello_world() { $response = new stdClass(); $response->hello = 'world'; $response->time = current_time('mysql'); wp_send_json($response); }
public function __construct() { parent::__construct(); $this->setData(); $this->getList(); wp_send_json(array('status' => 'success', 'list' => $this->list)); }
function tlpFmSettingsUpdate() { global $TLPfoodmenu; $error = true; if ($TLPfoodmenu->verifyNonce()) { $data = array(); if ($_REQUEST['general']) { $general['slug'] = isset($_REQUEST['general']['slug']) ? $_REQUEST['general']['slug'] ? sanitize_title_with_dashes($_REQUEST['general']['slug']) : 'food-menu' : 'food-menu'; $general['character_limit'] = isset($_REQUEST['general']['character_limit']) ? $_REQUEST['general']['character_limit'] ? intval($_REQUEST['general']['character_limit']) : 150 : 150; $general['em_display_col'] = $_REQUEST['general']['em_display_col'] ? esc_attr($_REQUEST['general']['em_display_col']) : 2; $general['currency'] = $_REQUEST['general']['currency'] ? esc_attr($_REQUEST['general']['currency']) : null; $general['currency_position'] = $_REQUEST['general']['currency_position'] ? esc_attr($_REQUEST['general']['currency_position']) : null; $data['general'] = $general; $TLPfoodmenu->activate(); } if ($_REQUEST['others']) { $others['css'] = $_REQUEST['others']['css'] ? esc_attr($_REQUEST['others']['css']) : null; $data['others'] = $others; } update_option($TLPfoodmenu->options['settings'], $data); $error = false; $msg = __('Settings successfully updated', TLP_FOOD_MENU_SLUG); } else { $msg = __('Security Error !!', TLP_FOOD_MENU_SLUG); } $response = array('error' => $error, 'msg' => $msg); wp_send_json($response); die; }
function zn_mailchimp_subscribe() { $return = array(); if (isset($_POST['email']) && isset($_POST['mailchimp_list'])) { if ($mailchimp_api = zget_option('mailchimp_api', 'general_options')) { if (is_email($_POST['email'])) { require_once THEME_BASE . '/framework/classes/class-mailchimp.php'; $mailchimp = new ZnMailChimp($mailchimp_api); $email = $_POST['email']; $mailchimp_data = array('id' => $_POST['mailchimp_list'], 'email' => array('email' => $_POST['email'])); // NAME FIELD if (isset($_POST['name'])) { $mailchimp_data['merge_vars']['NAME'] = $_POST['name']; } // WEBSITE FIELD if (isset($_POST['website'])) { $mailchimp_data['merge_vars']['WEBSITE'] = $_POST['website']; } $message = $mailchimp->call('lists/subscribe', $mailchimp_data); if (!empty($message['error'])) { $return['error'] = true; $return['message'] = '<div class="alert alert-success alert-dismissable">' . $message['error'] . '</div>'; } else { //print_z($mailchimp_data); $return['message'] = '<div class="alert alert-success alert-dismissable">' . __('Thank you for subscribing !', 'zn_framework') . '</div>'; } } else { $return['error'] = true; $return['message'] = '<div class="alert alert-danger alert-dismissable">' . __('Please enter a valid email address !', 'zn_framework') . '</div>'; } } } wp_send_json($return); }
public function hoo_api() { global $post; // /if the page contains the hoo-api shortcode send json and exit :} if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'hoo-api')) { $locations_repo = $this->entity_manager->getRepository('Hoo\\Model\\Location'); $json_response = array(); $date = isset($_GET['date']) ? new \DateTime($_GET['date']) : new \DateTime(date('Y-m-d')); if (isset($_GET['location_id'])) { $location = Location::get_location_by_id_or_shortname($_GET['location_id'], $this->entity_manager); if (!$location) { return wp_send_json_error('Not Found'); } $hours = $location->get_hours_for_date($date); $json_response['location'] = $location->to_api_response(); $json_response['location']['address'] = $location->address->to_api_response(); $json_response['hours'] = $hours ? $hours->to_api_response() : null; $json_response['weekly'] = $location->get_weekly_hours(); } else { $locations_repo = $this->entity_manager->getRepository('Hoo\\Model\\Location'); foreach ($locations_repo->findBy(array('is_visible' => true)) as $location) { $hours = $location->get_hours_for_date($date); $json_response[]['location'] = $location->to_api_response(); $json_response[]['location']['address'] = $location->address->to_api_response(); $json_response[]['hours'] = $hours ? $hours->to_api_response() : null; $json_response[]['weekly'] = $location->get_weekly_hours(); } } wp_send_json($json_response); exit; } }
function cropImageWithFaceDectection($metadata, $attachment_id) { if (!isset($metadata['sizes'])) { return $metadata; } $upload_path = wp_upload_dir(); $path = $upload_path['basedir']; //handle the different media upload directory structures if (isset($path)) { $file = trailingslashit($upload_path['basedir'] . '/') . $metadata['file']; } else { $file = trailingslashit($upload_path['path']) . $metadata['file']; } $client = new Client('5e3a3ac24363af113e04a58c61637ea4', 'sXA4iYYphLzg1z8IAcFAtPf8UdcXKwHm', 'http://apicn.faceplusplus.com'); /** @var \FaceCrop\Type\Face[] $result */ $result = $client->detect('http://showbizviet.vn/upload/files/data/2013/8/2/18/466473/1825600192_cham-soc-da-chuan-nhu-ngoc-trinh%202.jpg'); $height = $result[0]->getPosition()->getHeight(); $width = $result[0]->getPosition()->getWidth(); $leftEye = $result[0]->getPosition()->getEyeLeft(); $mouthRight = $result[0]->getPosition()->getMouthRight(); $editor = wp_get_image_editor($file); $startX = $leftEye->x / $width * 100; $startY = $leftEye->y / $height * 100; $editor->crop($startX - 100, $startY - 100, 500, 300, 500, 300, false); $result = $editor->save($file); wp_send_json(array($result, $file)); return $metadata; }
function woo_king_get_cart() { global $woocommerce; $cart_data = '<div class="shopping_cart_inner"><ul>'; if (WC()->cart->cart_contents_count == 0) { $cart_data .= '<li class="no-product-in-cart">No products in the cart.</li>'; } foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); if ($_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters('woocommerce_cart_item_visible', true, $cart_item, $cart_item_key)) { if ($_product->is_sold_individually()) { $product_quantity = 1; } else { $product_quantity = $cart_item['quantity']; } $thumbnail = apply_filters('woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key); $cart_data .= '<li><a href="' . $_product->get_permalink($cart_item) . '">' . $thumbnail . $_product->get_title() . '</a> <span class="quantity">' . $product_quantity . ' x ' . WC()->cart->get_product_price($_product) . '</span></li>'; } } $cart_data .= '</ul>'; $cart_data .= '<div class="king-cart-footer"><a class="k-cart-button" href="' . $woocommerce->cart->get_cart_url() . '">Cart <i class="fa fa-shopping-cart"></i></a><span class="total">Total: ' . WC()->cart->get_cart_total() . '</span></div>'; $cart_data .= '</div>'; $data = array('cart_content' => $cart_data, 'count' => WC()->cart->cart_contents_count, 'total' => WC()->cart->get_cart_total()); wp_send_json($data); }
public function run() { // Check nonce if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'sp_ajax_sc_gpp')) { echo '-1'; return; } $identifier = esc_sql($_POST['identifier']); $ptl_manager = new SP_Connection_Manager(); if (isset($_POST['by_slug']) && 'true' == $_POST['by_slug']) { $ptl = $ptl_manager->get_link_by_slug($identifier); } else { $ptl = $ptl_manager->get_link($identifier); } // Get children $parent_posts = get_posts(array('post_type' => $ptl->get_child(), 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC')); $json_posts = array(); if (count($parent_posts) > 0) { foreach ($parent_posts as $parent_post) { $json_posts[$parent_post->ID] = $parent_post->post_title; } } // Send the JSON wp_send_json($json_posts); exit; // Better safe than sorry lol }
public function actionSaveImage() { if (!empty($_POST['imageUrl'])) { $url = \parse_url($_POST['imageUrl']); if ($curlDescriptor = \curl_init($_POST['imageUrl'])) { \curl_setopt($curlDescriptor, CURLOPT_HEADER, 0); \curl_setopt($curlDescriptor, CURLOPT_RETURNTRANSFER, 1); \curl_setopt($curlDescriptor, CURLOPT_BINARYTRANSFER, 1); $rawImage = \curl_exec($curlDescriptor); \curl_close($curlDescriptor); if ($rawImage) { include_once ABSPATH . 'wp-admin/includes/image.php'; include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/media.php'; $wpFileType = \wp_check_filetype(\basename($url['path']), null); $tmpDir = \ini_get('upload_tmp_dir') ? \ini_get('upload_tmp_dir') : \sys_get_temp_dir(); $tempName = $tmpDir . '/' . \uniqid() . '.' . $wpFileType['ext']; \file_put_contents($tempName, $rawImage); $_FILES['async-upload'] = array('name' => \trim(\str_replace(' ', '', basename($tempName))), 'type' => $wpFileType['type'], 'tmp_name' => $tempName, 'error' => 0, 'size' => \filesize($tempName)); \media_handle_upload('async-upload', 0, array(), array('test_form' => false, 'action' => 'upload-attachment')); \wp_send_json(array('status' => 'success')); } } } \wp_send_json(array('status' => 'error')); }
function motopressCESetError($message = '') { global $motopressCESettings; header('HTTP/1.1 500 Internal Server Error'); wp_send_json(array('debug' => $motopressCESettings ? $motopressCESettings['debug'] : false, 'message' => $message)); exit; }
/** * Wordlift wrapper for wl_send_json function * @see https://codex.wordpress.org/Function_Reference/wp_send_json * Ensure output buffer is cleaned */ function wl_core_send_json($response) { if (ob_get_contents()) { ob_clean(); } return wp_send_json($response); }
protected function process_access_token_request() { if (array_key_exists('code', $_REQUEST) && array_key_exists('post_id', $_REQUEST)) { global $pms_post_protected; global $pms_session; $post_id = intval($_REQUEST['post_id']); $settings = $this->get_settings(); $url = Postmatic_Social_Gplus_Authenticator::$ACCESS_URL; $client_id = $settings[Postmatic_Social_Gplus_Authenticator::$CLIENT_ID]; $client_secret = $settings[Postmatic_Social_Gplus_Authenticator::$CLIENT_SECRET]; $query_string = $this->to_query_string(array('code' => $_REQUEST['code'], 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $this->get_oauth_callback(), 'grant_type' => 'authorization_code')); $response = wp_remote_post(esc_url_raw($url), array('body' => $query_string, 'sslverify' => false)); if (is_wp_error($response)) { $error_string = $response->get_error_message(); throw new Exception($error_string); } else { $response_body = json_decode($response['body'], true); if ($response_body && is_array($response_body) && array_key_exists('access_token', $response_body)) { $access_token = $response_body['access_token']; $user_details = $this->get_user_details($access_token); $pms_session['user'] = $user_details; $pms_post_protected = true; $user_details['disconnect_content'] = $GLOBALS['postmatic-social']->disconnect_content($user_details, $post_id); wp_send_json($user_details); die; } else { throw new Exception(__('Missing the access_token parameter', 'postmatic-social')); } } } else { die; } }
/** * Handle Post Customizer AJAX requests * * @access public * @since 0.1.0 */ public function process_ajax_request() { check_ajax_referer('post-customizer'); if (empty($_POST['post_customizer_action'])) { return; } if ('get_sidebar' == $_POST['post_customizer_action']) { if (empty($_POST['post_id'])) { return; } $data = array('sidebarHTML' => $this->_render_sidebar_data($_POST['post_id'])); } elseif ('save_field' == $_POST['post-customizer_action'] && !empty($_POST['field']) && !empty($_POST['post_id'])) { $data = array(); switch ($_POST['field']) { case 'post_title': case 'post_content': wp_update_post(array('ID' => $_POST['post_id'], $_POST['field'] => $_POST['data'])); $data['changed'] = $_POST['field']; $data['value'] = $_POST['data']; break; } } else { //Error! } wp_send_json($data); }
public static function gzd_json_search_delivery_time() { ob_start(); check_ajax_referer('search-products', 'security'); $term = (string) wc_clean(stripslashes($_GET['term'])); $terms = array(); if (empty($term)) { die; } $args = array('hide_empty' => false); if (is_numeric($term)) { $args['include'] = array(absint($term)); } else { $args['name__like'] = (string) $term; } $query = get_terms('product_delivery_time', $args); if (!empty($query)) { foreach ($query as $term) { $terms[$term->term_id] = rawurldecode($term->name); } } else { $terms[rawurldecode($term)] = rawurldecode(sprintf(__("%s [new]", "woocommerce-germanized"), $term)); } wp_send_json($terms); }
/** * When user click login button Linkedin, it will execution function bellow * @return $link */ public function lkin_redirect() { try { // turn on session if (!isset($_SESSION)) { ob_start(); @session_start(); } /** * Step1: Request an Authorization Code */ $redirect_uri = home_url('?action=linked_auth_callback'); $link = $this->linkedin_base_url . '?'; $link .= 'response_type=code&'; $link .= 'client_id=' . $this->linkedin_api_key . '&'; $link .= 'redirect_uri=' . $redirect_uri . '&'; $link .= 'state=' . $this->state . '&'; $link .= 'scope=r_basicprofile r_emailaddress'; // wp_set_auth_cookie($link); $resp = array('success' => true, 'msg' => 'Success', 'redirect' => $link); } catch (Exception $e) { $resp = array('success' => false, 'msg' => $e->getMessage()); } wp_send_json($resp); }
public function handle_ajax_request() { $action = $_REQUEST['action']; $hook_info = $this->hook_map[$action]; $options = $hook_info['options']; if (isset($_SERVER["CONTENT_TYPE"]) && 0 === strpos($_SERVER["CONTENT_TYPE"], 'application/json')) { global $HTTP_RAW_POST_DATA; if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents("php://input"); } $data = json_decode($HTTP_RAW_POST_DATA, true); # if the request is coming from backbone, we need to non-200 error $send_non_200_error = true; } else { $data = $_REQUEST; $send_non_200_error = false; } if ($options['nonce'] && (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], $action))) { $this->send_json_error(array("error" => __("invalid nonce", "clef")), $send_non_200_error); } if (!current_user_can($options['capability'])) { $this->send_json_error(array("error" => __("user does not have correct capabilities", "clef")), $send_non_200_error); } $response = call_user_func($hook_info['function']); if (is_wp_error($response)) { $this->send_json_error(array("error" => $response->get_error_message()), $send_non_200_error); } else { wp_send_json($response); } }
private function emptyTrash() { if ($this->post_repo->emptyTrash($_POST['posttype'])) { return wp_send_json(array('status' => 'success', 'message' => __('Trash successfully emptied.'))); } $this->sendErrorResponse(); }
function motopressCEGetAttachmentThumbnail() { require_once dirname(__FILE__) . '/../verifyNonce.php'; require_once dirname(__FILE__) . '/../settings.php'; require_once dirname(__FILE__) . '/../access.php'; require_once dirname(__FILE__) . '/../functions.php'; require_once dirname(__FILE__) . '/../getLanguageDict.php'; $motopressCELang = motopressCEGetLanguageDict(); if (isset($_POST['id']) && !empty($_POST['id'])) { $id = (int) trim($_POST['id']); $attachment = get_post($id); if (!empty($attachment) && $attachment->post_type === 'attachment') { if (wp_attachment_is_image($id)) { $srcMedium = wp_get_attachment_image_src($id, 'medium'); $srcFull = wp_get_attachment_image_src($id, 'full'); if (isset($srcMedium[0]) && !empty($srcMedium[0]) && isset($srcFull[0]) && !empty($srcFull[0])) { $attachmentImageSrc = array(); $attachmentImageSrc['medium'] = $srcMedium[0]; $attachmentImageSrc['full'] = $srcFull[0]; wp_send_json($attachmentImageSrc); } else { motopressCESetError($motopressCELang->CEAttachmentImageSrc); } } else { motopressCESetError($motopressCELang->CEAttachmentNotImage); } } else { motopressCESetError($motopressCELang->CEAttachmentEmpty); } } else { motopressCESetError($motopressCELang->CEAttachmentThumbnailError); } exit; }
static function quiz_question_add() { $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; $text = isset($_REQUEST['text']) ? $_REQUEST['text'] : null; $question_id = isset($_REQUEST['question_id']) ? $_REQUEST['question_id'] : null; $question = LP_Question::instance($question_id ? $question_id : $type); $json = array('success' => false); if ($question) { if (!$question_id) { $question->set('post_title', $text ? $text : 'Your question text here'); $question->set('post_type', LP()->question_post_type); $question->set('post_status', 'publish'); } if (($question_id = $question->store()) && isset($_POST['quiz_id']) && ($quiz_id = $_POST['quiz_id'])) { $quiz_questions = (array) get_post_meta($quiz_id, '_lpr_quiz_questions', true); $quiz_questions[$question_id] = array('toggle' => 0); update_post_meta($quiz_id, '_lpr_quiz_questions', $quiz_questions); } ob_start(); $question->admin_interface(); $json['html'] = ob_get_clean(); $json['success'] = true; $json['question'] = get_post($question_id); } else { $json['msg'] = __('Can not create a question', 'learn_press'); } wp_send_json($json); die; }
/** * Process the request * @todo Setting for reassigning user's posts */ public function process() { // Verify the security nonce and die if it fails if (!isset($_POST['wp_delete_user_accounts_nonce']) || !wp_verify_nonce($_POST['wp_delete_user_accounts_nonce'], 'wp_delete_user_accounts_nonce')) { wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Request failed security check.', 'wp-delete-user-accounts'))); } // Don't permit admins to delete their own accounts if (current_user_can('manage_options')) { wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Administrators cannot delete their own accounts.', 'wp-delete-user-accounts'))); } // Get the current user $user_id = get_current_user_id(); // Get user meta $meta = get_user_meta($user_id); // Delete user's meta foreach ($meta as $key => $val) { delete_user_meta($user_id, $key); } // Destroy user's session wp_logout(); // Delete the user's account $deleted = wp_delete_user($user_id); if ($deleted) { // Send success message wp_send_json(array('status' => 'success', 'title' => __('Success!', 'wp-delete-user-accounts'), 'message' => __('Your account was successfully deleted. Fair well.', 'wp-delete-user-accounts'))); } else { wp_send_json(array('status' => 'fail', 'title' => __('Error!', 'wp-delete-user-accounts'), 'message' => __('Request failed.', 'wp-delete-user-accounts'))); } }
/** * Exports existing appointments to GCal. * @since v1.4.6 */ function json_export_appointments() { $msg = __('All done!', 'appointments'); $export = get_option('app_tmp_appointments_to_export', array()); if (empty($export)) { // Fetching the export appointments, since the cache is empty global $wpdb; $status = $this->_get_syncable_status(); if (is_array($status) && !empty($status)) { $clean_stat = "'" . join("','", array_values(array_filter(array_map('trim', $status)))) . "'"; $export = $wpdb->get_col("SELECT ID FROM {$this->app_table} WHERE status IN({$clean_stat})"); } } if (!empty($export)) { $app_id = array_pop($export); if (is_numeric($app_id)) { $this->update($app_id); } if (!empty($export)) { $msg = sprintf(__('Processing, %d appointments left.'), count($export)); } } update_option('app_tmp_appointments_to_export', $export); wp_send_json(array('msg' => $msg, 'remaining' => count($export))); die; }
public function __construct() { parent::__construct(); $this->setFormData(); $this->search(); return wp_send_json(array('status' => 'success', 'results' => $this->results)); }
public static function sniff_requests() { global $wp; if (isset($wp->query_vars['__api'])) { $articles = array(); sleep(1); $offset = isset($_GET['offset']) ? $_GET['offset'] : 0; $posts = PostCollection::getPosts($offset); if (count($posts) > 0) { $i = 0; foreach ($posts as $post) { $articles[$i]['articleId'] = $i; $articles[$i]['pos'] = $offset * PostCollection::$nbPostPerPage + $i + 1; $articles[$i]['title'] = $post->post_title; $articles[$i]['postId'] = $post->ID; $articles[$i]['description'] = Post::getDescription($post->ID); $articles[$i]['smallthumb'] = Post::getThumbnail($post->ID, 'medium')[0]; $articles[$i]['date'] = Helper::dateToDatetime($post->post_date)->format('d-m-y'); $articles[$i]['tags'] = Post::getTags($post->ID); $articles[$i]['bigthumb'] = Post::getThumbnail($post->ID, 'full')[0]; $articles[$i]['content'] = $post->post_content; $articles[$i]['uniqId'] = 'article-id-' . $articles[$i]['pos']; $articles[$i]['gallery'] = plugins\ImgGal\ImgGalFront::PH_build_array_gallery($post->ID); $articles[$i]['pattern'] = get_post_meta($post->ID, '_ph_pattern', true); $i++; } } wp_send_json($articles); die; } }