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


PHP wp_send_json_success函数代码示例

本文整理汇总了PHP中wp_send_json_success函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_send_json_success函数的具体用法?PHP wp_send_json_success怎么用?PHP wp_send_json_success使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_send_json_success函数的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);
    }
}
开发者ID:ebanfa,项目名称:shadow-plugin-theme,代码行数:25,代码来源:content-signin-ajax.php

示例2: user_info

 /**
  *
  * 	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();
     }
 }
开发者ID:bearded-avenger,项目名称:familyoutside,代码行数:33,代码来源:process.user-info.php

示例3: handle_upload

 /**
  * 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;
 }
开发者ID:thonysmith,项目名称:LearnPress,代码行数:35,代码来源:plupload-image.php

示例4: icl_repair_broken_type_and_language_assignments

/**
 * 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);
}
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:10,代码来源:functions-troubleshooting.php

示例5: save_image

 /**
  * 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();
     }
 }
开发者ID:cigraphics,项目名称:my-eyes-are-up-here,代码行数:33,代码来源:class-meauh-ajax.php

示例6: save_label_translations

 /**
  * 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();
 }
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:29,代码来源:class-wpml-st-label-translation.php

示例7: do_x_post_password_cb

 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);
 }
开发者ID:trepmal,项目名称:ajax-password-protected,代码行数:32,代码来源:ajax-password-protected.php

示例8: 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'));
     }
 }
开发者ID:wpmu,项目名称:maera,代码行数:35,代码来源:class-Maera_EDD_RI_Client.php

示例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'])));
 }
开发者ID:rilwis,项目名称:user-visit-log,代码行数:10,代码来源:dashboard.php

示例10: 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();
}
开发者ID:MusicForMyself,项目名称:auto_loader_html,代码行数:34,代码来源:autoloader.php

示例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))));
     }
 }
开发者ID:cs-team,项目名称:kanban,代码行数:31,代码来源:class-task_hour.php

示例12: get_current_user_info

 /**
  * 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)));
     }
 }
开发者ID:luubinhan,项目名称:wp-simple-ajax,代码行数:15,代码来源:class-dependency-loader.php

示例13: get_select_box

 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);
     }
 }
开发者ID:devgeniem,项目名称:acf-flexible-icons,代码行数:32,代码来源:plugin.php

示例14: set_theme

 static function set_theme()
 {
     $stylesheet = sanitize_text_field($_POST['stylesheet']);
     do_action('jetpack_start_select_theme', $stylesheet);
     switch_theme($stylesheet);
     wp_send_json_success();
 }
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:7,代码来源:select-theme.php

示例15: audiotheme_ajax_get_playlist_records

/**
 * 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);
}
开发者ID:TyRichards,项目名称:ty_the_band,代码行数:37,代码来源:ajax.php


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