本文整理汇总了PHP中wp_send_json_error函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_send_json_error函数的具体用法?PHP wp_send_json_error怎么用?PHP wp_send_json_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_send_json_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: do_forgot_password_ajax
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);
}
}
示例2: wpml_save_term
/**
* Ajax handler for adding a term via Ajax.
*/
public static function wpml_save_term()
{
if (!wpml_is_action_authenticated('wpml_save_term')) {
wp_send_json_error('Wrong Nonce');
}
global $sitepress;
$lang = filter_input(INPUT_POST, 'term_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$taxonomy = filter_input(INPUT_POST, 'taxonomy');
$slug = filter_input(INPUT_POST, 'slug');
$name = filter_input(INPUT_POST, 'name');
$trid = filter_input(INPUT_POST, 'trid', FILTER_SANITIZE_NUMBER_INT);
$description = filter_input(INPUT_POST, 'description');
$new_term_object = false;
if ($name !== "" && $taxonomy && $trid && $lang) {
$args = array('taxonomy' => $taxonomy, 'lang_code' => $lang, 'term' => $name, 'trid' => $trid, 'overwrite' => true);
if ($slug) {
$args['slug'] = $slug;
}
if ($description) {
$args['description'] = $description;
}
$res = WPML_Terms_Translations::create_new_term($args);
if ($res && isset($res['term_taxonomy_id'])) {
/* res holds the term taxonomy id, we return the whole term objects to the ajax call */
$new_term_object = get_term_by('term_taxonomy_id', (int) $res['term_taxonomy_id'], $taxonomy);
$lang_details = $sitepress->get_element_language_details($new_term_object->term_taxonomy_id, 'tax_' . $new_term_object->taxonomy);
$new_term_object->trid = $lang_details->trid;
$new_term_object->language_code = $lang_details->language_code;
WPML_Terms_Translations::icl_save_term_translation_action($taxonomy, $res);
}
}
wp_send_json_success($new_term_object);
}
示例3: send_json_error
public static function send_json_error($data, $send_non_200)
{
if ($send_non_200) {
header('HTTP/1.0 400');
}
wp_send_json_error($data);
}
示例4: ajax_image_crop
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);
}
示例5: cue_ajax_parse_shortcode
/**
* 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()));
}
示例6: icl_get_job_original_field_content
function icl_get_job_original_field_content()
{
global $iclTranslationManagement;
if (!wpml_is_action_authenticated('icl_get_job_original_field_content')) {
die('Wrong Nonce');
}
$job_id = filter_input(INPUT_POST, 'tm_editor_job_id', FILTER_SANITIZE_NUMBER_INT);
$field = filter_input(INPUT_POST, 'tm_editor_job_field');
$data = array();
$job = $job_id !== null && $field !== null ? $job = $iclTranslationManagement->get_translation_job($job_id) : null;
$elements = $job && isset($job->elements) ? $job->elements : array();
foreach ($elements as $element) {
$sanitized_type = sanitize_title($element->field_type);
if ($field === 'icl_all_fields' || $sanitized_type === $field) {
// if we find a field by that name we need to decode its contents according to its format
$field_contents = TranslationManagement::decode_field_data($element->field_data, $element->field_format);
if (is_scalar($field_contents)) {
$field_contents = strpos($field_contents, "\n") !== false ? wpautop($field_contents) : $field_contents;
$data[] = array('field_type' => $sanitized_type, 'field_data' => $field_contents);
}
}
}
if ((bool) $data !== false) {
wp_send_json_success($data);
} else {
wp_send_json_error(0);
}
}
示例7: apiErrors
/**
* List of simple error messages
*
* @param string $code
* @return string json response with appropriate error code
*/
function apiErrors($code)
{
switch ($code) {
case 'method':
$data = array('messages' => 'GET is currently the only request method accepted, as of v1 of the API.', 'documentation' => '/api/v1/docs');
break;
case 'resource':
$data = array('messages' => 'The API requires a valid resource in order to return a response. Try looking for \'books\'', 'documentation' => '/api/v1/docs');
break;
case 'version':
$data = array('messages' => 'The version you\'re requesting is not supported. Current version of the API is v1', 'documentation' => '/api/v1/docs');
break;
case 'format':
$data = array('messages' => 'The format that is being requested is not supported. Try \'json\'', 'documentation' => '/api/v1/docs');
break;
case 'empty':
$data = array('messages' => 'There are no records that can be returned with the request that was made', 'documentation' => '/api/v1/docs');
break;
case 'offset':
$data = array('messages' => 'The offset is a larger value than the number of books available', 'documentation' => '/api/v1/docs');
break;
default:
$data = array('messages' => 'Something went wrong with your API request', 'documentation' => '/api/v1/docs');
}
return wp_send_json_error($data);
}
示例8: x_demo_content_setup_ajax_callback
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'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();
}
示例9: ajax_get_data
/**
* 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'])));
}
示例10: install
/**
* 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'));
}
}
示例11: ajax_save
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))));
}
}
示例12: create_duplicate
function create_duplicate($project_id)
{
//Get all data post type project, message, task_list, milestone
$prev_pro_data = $this->fatch_projcet_data($project_id);
$new_pro_arg = $this->fill_array($prev_pro_data[$project_id]);
//create duplicate new project
$new_pro_id = $this->insert_duplicate($new_pro_arg, $project_id);
if (!$new_pro_id) {
wp_send_json_error('Unknown Error', 'cpm');
}
//remove project post type from data array
unset($prev_pro_data[$project_id]);
foreach ($prev_pro_data as $prev_post_id => $post_obj) {
if ($post_obj->post_type == 'milestone') {
$args = $this->fill_array($post_obj, $new_pro_id);
//Insert message, task list and milestone
$new_milestone_id[$post_obj->ID] = $this->insert_duplicate($args, $post_obj->ID);
unset($prev_pro_data[$prev_post_id]);
}
}
foreach ($prev_pro_data as $prev_post_id => $post_obj) {
$args = $this->fill_array($post_obj, $new_pro_id);
$new_milestone_id = isset($new_milestone_id) ? $new_milestone_id : array();
//Insert message, task list and milestone
$id = $this->insert_duplicate($args, $post_obj->ID, $new_milestone_id);
//If post type task list then fatch task and insert duplicate
if ($post_obj->post_type == 'task_list') {
$task = array('post_parent' => $post_obj->ID, 'post_type' => 'task', 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'ID');
$task_data = get_children($task);
$this->insert_duplicate_task($task_data, $id);
}
}
return $new_pro_id;
}
示例13: get_posts_by_letter_rendered
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();
}
示例14: jo_save_flow_star
/**
* Saves star/unstar value for Flows on Recent Flows page
*
*@since 1.0.0
*@param Gets parameters form AJAX $_POST
*/
public function jo_save_flow_star()
{
global $wpdb;
//get flow id
$flow_id = (int) $_POST['flow_id'];
//get if flow was starred and invert
if (isset($_POST['is_starred'])) {
//make sure value is 1 or null and invert value
if ($_POST['is_starred'] == 1 || $_POST['is_starred'] == '1') {
$is_starred = false;
} elseif ($_POST['is_starred'] == null || $_POST['is_starred'] == false) {
$is_starred = 1;
} else {
wp_send_json_error(array('jo_success' => false, 'message' => 'star value 1 or null'));
}
} else {
$is_starred = false;
}
// Update the meta field in the database.
$is_success = update_post_meta($flow_id, 'jumpoff_flow_flag', $is_starred);
if ($is_success) {
$message = 'UPDATED ' . $flow_id . ' jumpoff_flow_flag ' . $is_starred . ' | ' . $_POST['is_starred'];
} else {
$message = 'not updated ' . $flow_id . ' jumpoff_flow_flag ' . $is_starred . ' | ' . $_POST['is_starred'];
}
$starred = get_post_meta($flow_id, 'jumpoff_flow_flag', false);
$starred = $starred[0];
wp_send_json_success(array('success' => $is_success, 'message' => $message, 'starred' => $starred, 'id' => $flow_id));
}
示例15: hoo_api
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;
}
}