本文整理汇总了PHP中wp_json_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_json_encode函数的具体用法?PHP wp_json_encode怎么用?PHP wp_json_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_json_encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index_post
/**
* Index a post under a given site index or the global index ($site_id = 0)
*
* @param array $post
* @param bool $blocking
* @since 0.1.0
* @return array|bool|mixed
*/
public function index_post($post, $blocking = true)
{
/**
* Filter post prior to indexing
*
* Allows for last minute indexing of post information.
*
* @since 1.7
*
* @param array Array of post information to index.
*/
$post = apply_filters('ep_pre_index_post', $post);
$index = trailingslashit(ep_get_index_name());
$path = $index . 'post/' . $post['post_id'];
if (function_exists('wp_json_encode')) {
$encoded_post = wp_json_encode($post);
} else {
$encoded_post = json_encode($post);
}
$request_args = array('body' => $encoded_post, 'method' => 'PUT', 'timeout' => 15, 'blocking' => $blocking);
$request = ep_remote_request($path, apply_filters('ep_index_post_request_args', $request_args, $post));
do_action('ep_index_post_retrieve_raw_response', $request, $post, $path);
if (!is_wp_error($request)) {
$response_body = wp_remote_retrieve_body($request);
return json_decode($response_body);
}
return false;
}
示例2: do_json_encode
function do_json_encode($data)
{
$json_options = 0;
if (defined('JSON_HEX_TAG')) {
$json_options += JSON_HEX_TAG;
}
if (defined('JSON_HEX_APOS')) {
$json_options += JSON_HEX_APOS;
}
if (defined('JSON_HEX_QUOT')) {
$json_options += JSON_HEX_QUOT;
}
if (defined('JSON_HEX_AMP')) {
$json_options += JSON_HEX_AMP;
}
if (defined('JSON_UNESCAPED_UNICODE')) {
$json_options += JSON_UNESCAPED_UNICODE;
}
if (version_compare($this->sitepress->get_wp_api()->phpversion(), '5.3.0', '<')) {
$json_data = wp_json_encode($data);
} else {
$json_data = wp_json_encode($data, $json_options);
}
return $json_data;
}
示例3: send_tracking_data
/**
* Decide whether to send tracking data or not.
*
* @param bool $override
*/
public static function send_tracking_data($override = false)
{
// Don't trigger this on AJAX Requests
if (defined('DOING_AJAX') && DOING_AJAX) {
return;
}
if (!self::is_allow_track()) {
return;
}
if (!apply_filters('elementor/tracker/send_override', $override)) {
// Send a maximum of once per week by default.
$last_send = self::_get_last_send_time();
if ($last_send && $last_send > apply_filters('elementor/tracker/last_send_interval', strtotime('-1 week'))) {
return;
}
} else {
// Make sure there is at least a 1 hour delay between override sends, we dont want duplicate calls due to double clicking links.
$last_send = self::_get_last_send_time();
if ($last_send && $last_send > strtotime('-1 hours')) {
return;
}
}
// Update time first before sending to ensure it is set
update_option('elementor_tracker_last_send', time());
// Send here..
$params = ['system' => self::_get_system_reports_data(), 'site_lang' => get_bloginfo('language'), 'email' => get_option('admin_email'), 'usages' => ['posts' => self::_get_posts_usage(), 'library' => self::_get_library_usage()]];
add_filter('https_ssl_verify', '__return_false');
$response = wp_safe_remote_post(self::$_api_url, ['timeout' => 25, 'blocking' => false, 'body' => ['data' => wp_json_encode($params)]]);
}
示例4: get_queue
/**
* Retrieve the current event queue
*
* @subcommand get-queue
*/
public function get_queue($args, $assoc_args)
{
// Build and make request
$queue_request = new \WP_REST_Request('POST', '/' . \Automattic\WP\Cron_Control\REST_API::API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API::ENDPOINT_LIST);
$queue_request->add_header('Content-Type', 'application/json');
$queue_request->set_body(wp_json_encode(array('secret' => \WP_CRON_CONTROL_SECRET)));
$queue_request = rest_do_request($queue_request);
// Oh well
if ($queue_request->is_error()) {
\WP_CLI::error($queue_request->as_error()->get_error_message());
}
// Get the decoded JSON object returned by the API
$queue_response = $queue_request->get_data();
// No events, nothing more to do
if (empty($queue_response['events'])) {
\WP_CLI::warning(__('No events in the current queue', 'automattic-cron-control'));
return;
}
// Prepare items for display
$events_for_display = $this->format_events($queue_response['events']);
$total_events_to_display = count($events_for_display);
\WP_CLI::line(sprintf(_n('Displaying one event', 'Displaying %s events', $total_events_to_display, 'automattic-cron-control'), number_format_i18n($total_events_to_display)));
// And reformat
$format = 'table';
if (isset($assoc_args['format'])) {
if ('ids' === $assoc_args['format']) {
\WP_CLI::error(__('Invalid output format requested', 'automattic-cron-control'));
} else {
$format = $assoc_args['format'];
}
}
\WP_CLI\Utils\format_items($format, $events_for_display, array('timestamp', 'action', 'instance', 'scheduled_for', 'internal_event', 'schedule_name', 'event_args'));
}
示例5: add_admin
/**
* Adding a new admin
*
* @param string $admin_name Name string.
* @param string $admin_id ID string.
*
* @return string
*/
public function add_admin($admin_name, $admin_id)
{
$success = 0;
// If one of the fields is empty.
if (empty($admin_name) || empty($admin_id)) {
$response_body = $this->get_response_body('not_present');
} else {
$admin_id = $this->parse_admin_id($admin_id);
if (!isset($this->options['fb_admins'][$admin_id])) {
$name = sanitize_text_field(urldecode($admin_name));
$admin_id = sanitize_text_field($admin_id);
if (preg_match('/[0-9]+?/', $admin_id) && preg_match('/[\\w\\s]+?/', $name)) {
$this->options['fb_admins'][$admin_id]['name'] = $name;
$this->options['fb_admins'][$admin_id]['link'] = urldecode('http://www.facebook.com/' . $admin_id);
$this->save_options();
$success = 1;
$response_body = $this->form->get_admin_link($admin_id, $this->options['fb_admins'][$admin_id]);
} else {
$response_body = $this->get_response_body('invalid_format');
}
} else {
$response_body = $this->get_response_body('already_exists');
}
}
return wp_json_encode(array('success' => $success, 'html' => $response_body));
}
示例6: get_json
/**
* Returns options & contents in JSON format
*
* @return string{JSON}
*/
public function get_json()
{
$out = array();
$out['options'] = self::$options;
$out['content'] = self::$options;
return wp_json_encode($out);
}
示例7: enqueue_pointers
/**
* Enqueue pointers and add script to page.
* @param array $pointers
*/
public function enqueue_pointers($pointers)
{
$pointers = wp_json_encode($pointers);
wp_enqueue_style('wp-pointer');
wp_enqueue_script('wp-pointer');
ac_enqueue_js("\n\t\t\tjQuery( function( \$ ) {\n\t\t\t\tvar ac_pointers = {$pointers};\n\n\t\t\t\tsetTimeout( init_ac_pointers, 800 );\n\n\t\t\t\tfunction init_ac_pointers() {\n\t\t\t\t\t\$.each( ac_pointers.pointers, function( i ) {\n\t\t\t\t\t\tshow_ac_pointer( i );\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tfunction show_ac_pointer( id ) {\n\t\t\t\t\tvar pointer = ac_pointers.pointers[ id ];\n\t\t\t\t\tvar options = \$.extend( pointer.options, {\n\t\t\t\t\t\tclose: function() {\n\t\t\t\t\t\t\t\$.post( ajaxurl, {\n\t\t\t\t\t\t\t\tpointer: id,\n\t\t\t\t\t\t\t\taction: 'dismiss-wp-pointer'\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t\tvar this_pointer = \$( pointer.target ).pointer( options );\n\t\t\t\t\tthis_pointer.pointer( 'open' );\n\t\t\t\t}\n\t\t\t});\n\t\t");
}
示例8: 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)));
}
}
示例9: get_attributes
/**
* Get the attributes for a field
*
* @param array $field
* @param mixed $value
* @return array
*/
static function get_attributes($field, $value = null)
{
$attributes = parent::get_attributes($field, $value);
$attributes = wp_parse_args($attributes, array('data-options' => wp_json_encode($field['js_options'])));
$attributes['type'] = 'text';
return $attributes;
}
示例10: wps_button_translation
/**
* Translation function
*/
function wps_button_translation()
{
$strings = array('button_label' => __('WPS Shortcode Helper', 'wps_helper_plugin'), 'msg' => __('Hello World!!!!', 'wps_helper_plugin'));
$locale = _WP_Editors::$mce_locale;
$translated = 'tinyMCE.addI18n("' . $locale . '.wps_button", ' . wp_json_encode($strings) . ");\n";
return $translated;
}
示例11: enqueue_pointers
/**
* Enqueue pointers and add script to page.
* @param array $pointers
*/
public function enqueue_pointers($pointers)
{
$pointers = wp_json_encode($pointers);
wp_enqueue_style('wp-pointer');
wp_enqueue_script('wp-pointer');
wc_enqueue_js("\n\t\t\tjQuery( function( \$ ) {\n\t\t\t\tvar wc_pointers = {$pointers};\n\n\t\t\t\tsetTimeout( init_wc_pointers, 800 );\n\n\t\t\t\tfunction init_wc_pointers() {\n\t\t\t\t\t\$.each( wc_pointers.pointers, function( i ) {\n\t\t\t\t\t\tshow_wc_pointer( i );\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tfunction show_wc_pointer( id ) {\n\t\t\t\t\tvar pointer = wc_pointers.pointers[ id ];\n\t\t\t\t\tvar options = \$.extend( pointer.options, {\n\t\t\t\t\t\tclose: function() {\n\t\t\t\t\t\t\tif ( pointer.next ) {\n\t\t\t\t\t\t\t\tshow_wc_pointer( pointer.next );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t\tvar this_pointer = \$( pointer.target ).pointer( options );\n\t\t\t\t\tthis_pointer.pointer( 'open' );\n\n\t\t\t\t\tif ( pointer.next_trigger ) {\n\t\t\t\t\t\t\$( pointer.next_trigger.target ).on( pointer.next_trigger.event, function() {\n\t\t\t\t\t\t\tsetTimeout( function() { this_pointer.pointer( 'close' ); }, 400 );\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t");
}
示例12: options_general_add_js
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_general_add_js()
{
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){
var $siteName = $( '#wp-admin-bar-site-name' ).children( 'a' ).first(),
homeURL = ( <?php
echo wp_json_encode(get_home_url());
?>
|| '' ).replace( /^(https?:\/\/)?(www\.)?/, '' );
$( '#blogname' ).on( 'input', function() {
var title = $.trim( $( this ).val() ) || homeURL;
// Truncate to 40 characters.
if ( 40 < title.length ) {
title = title.substring( 0, 40 ) + '\u2026';
}
$siteName.text( title );
});
$("input[name='date_format']").click(function(){
if ( "date_format_custom_radio" != $(this).attr("id") )
$("input[name='date_format_custom']").val( $(this).val() ).siblings('.example').text( $(this).siblings('span').text() );
});
$("input[name='date_format_custom']").focus(function(){
$( '#date_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='time_format']").click(function(){
if ( "time_format_custom_radio" != $(this).attr("id") )
$("input[name='time_format_custom']").val( $(this).val() ).siblings('.example').text( $(this).siblings('span').text() );
});
$("input[name='time_format_custom']").focus(function(){
$( '#time_format_custom_radio' ).prop( 'checked', true );
});
$("input[name='date_format_custom'], input[name='time_format_custom']").change( function() {
var format = $(this);
format.siblings('.spinner').css('display', 'inline-block'); // show(); can't be used here
$.post(ajaxurl, {
action: 'date_format_custom' == format.attr('name') ? 'date_format' : 'time_format',
date : format.val()
}, function(d) { format.siblings('.spinner').hide(); format.siblings('.example').text(d); } );
});
var languageSelect = $( '#WPLANG' );
$( 'form' ).submit( function() {
// Don't show a spinner for English and installed languages,
// as there is nothing to download.
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
$( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
}
});
});
//]]>
</script>
<?php
}
示例13: ajax_response
function ajax_response()
{
check_ajax_referer('ajax-custom-list-nonce', '_ajax_custom_list_nonce');
$this->prepare_items();
extract($this->_args);
extract($this->_pagination_args, EXTR_SKIP);
ob_start();
if (!empty($_REQUEST['no_placeholder'])) {
$this->display_rows();
} else {
$this->display_rows_or_placeholder();
}
$rows = ob_get_clean();
ob_start();
$this->print_column_headers();
$headers = ob_get_clean();
ob_start();
$this->pagination('top');
$pagination_top = ob_get_clean();
ob_start();
$this->pagination('bottom');
$pagination_bottom = ob_get_clean();
$response = array('rows' => $rows);
$response['pagination']['top'] = $pagination_top;
$response['pagination']['bottom'] = $pagination_bottom;
$response['column_headers'] = $headers;
if (isset($total_items)) {
$response['total_items_i18n'] = sprintf(_n('1 item', '%s items', $total_items), number_format_i18n($total_items));
}
if (isset($total_pages)) {
$response['total_pages'] = $total_pages;
$response['total_pages_i18n'] = number_format_i18n($total_pages);
}
die(wp_json_encode($response));
}
示例14: html
/**
* Get field HTML.
*
* @param mixed $meta
* @param array $field
* @return string
*/
static function html($meta, $field)
{
if (!is_array($meta)) {
$meta = (array) $meta;
}
// Filter to change the drag & drop box background string
$i18n_drop = apply_filters('rwmb_plupload_image_drop_string', _x('Drop images here', 'image upload', 'meta-box'), $field);
$i18n_or = apply_filters('rwmb_plupload_image_or_string', _x('or', 'image upload', 'meta-box'), $field);
$i18n_select = apply_filters('rwmb_plupload_image_select_string', _x('Select Files', 'image upload', 'meta-box'), $field);
// Uploaded images
// Check for max_file_uploads
$classes = array('rwmb-drag-drop', 'drag-drop', 'hide-if-no-js', 'new-files');
if (!empty($field['max_file_uploads']) && count($meta) >= (int) $field['max_file_uploads']) {
$classes[] = 'hidden';
}
$html = self::get_uploaded_images($meta, $field);
// Show form upload
$html .= sprintf('<div id="%s-dragdrop" class="%s" data-upload_nonce="%s" data-js_options="%s">
<div class = "drag-drop-inside">
<p class="drag-drop-info">%s</p>
<p>%s</p>
<p class="drag-drop-buttons"><input id="%s-browse-button" type="button" value="%s" class="button" /></p>
</div>
</div>', $field['id'], implode(' ', $classes), wp_create_nonce("rwmb-upload-images_{$field['id']}"), esc_attr(wp_json_encode($field['js_options'])), $i18n_drop, $i18n_or, $field['id'], $i18n_select);
return $html;
}
示例15: yourprefix_register_conditionals_demo_metabox
/**
* Hook in and add a demo metabox. Can only happen on the 'cmb2_init' hook.
*/
function yourprefix_register_conditionals_demo_metabox()
{
// Start with an underscore to hide fields from custom fields list.
$prefix = '_yourprefix_conditions_demo_';
/**
* Sample metabox to demonstrate the different conditions you can set.
*/
$cmb_demo = new_cmb2_box(array('id' => $prefix . 'metabox', 'title' => 'Test Metabox', 'object_types' => array('page')));
$cmb_demo->add_field(array('name' => 'Address', 'desc' => 'Write down an address for showing the other address options', 'id' => $prefix . 'address', 'type' => 'text'));
$cmb_demo->add_field(array('name' => 'Zipcode', 'id' => $prefix . 'zipcode', 'type' => 'text_medium', 'attributes' => array('required' => true, 'data-conditional-id' => $prefix . 'address')));
$cmb_demo->add_field(array('name' => 'Country', 'id' => $prefix . 'country', 'type' => 'text_medium', 'attributes' => array('required' => true, 'data-conditional-id' => $prefix . 'address')));
$cmb_demo->add_field(array('name' => 'Checkbox', 'id' => $prefix . 'checkbox', 'type' => 'checkbox'));
$cmb_demo->add_field(array('name' => 'Show if checked', 'id' => $prefix . 'show_if_checked', 'type' => 'text', 'attributes' => array('data-conditional-id' => $prefix . 'checkbox')));
$cmb_demo->add_field(array('name' => 'Show if unchecked', 'id' => $prefix . 'show_if_unchecked', 'type' => 'text', 'attributes' => array('data-conditional-id' => $prefix . 'checkbox', 'data-conditional-value' => 'off')));
$cmb_demo->add_field(array('name' => 'Reason', 'id' => $prefix . 'reason', 'type' => 'select', 'show_option_none' => true, 'options' => array('one' => 'Reason 1', 'two' => 'Reason 2', 'three' => 'Reason 3', 'other' => 'Other reason')));
$cmb_demo->add_field(array('name' => 'Other reason detail', 'desc' => 'Write down the reason', 'id' => $prefix . 'other_reason_detail', 'type' => 'textarea', 'attributes' => array('required' => true, 'data-conditional-id' => $prefix . 'reason', 'data-conditional-value' => 'other')));
$cmb_demo->add_field(array('name' => 'Reason 2', 'id' => $prefix . 'reason_2', 'type' => 'select', 'show_option_none' => true, 'options' => array('one' => 'Reason 1', 'two' => 'Reason 2', 'three' => 'Reason 3', 'other_price' => 'Other reason based on the price', 'other_quality' => 'Other reason based on the quality')));
$cmb_demo->add_field(array('name' => 'Other reason detail', 'desc' => 'Write down the reason', 'id' => $prefix . 'other_reason_detail_2', 'type' => 'textarea', 'attributes' => array('required' => true, 'data-conditional-id' => $prefix . 'reason_2', 'data-conditional-value' => wp_json_encode(array('other_price', 'other_quality')))));
$cmb_demo->add_field(array('name' => 'Sizes', 'id' => $prefix . 'sizes', 'type' => 'radio', 'show_option_none' => true, 'options' => array('xs' => 'XS', 's' => 'S', 'm' => 'M', 'l' => 'L', 'xl' => 'XL', 'custom' => 'Custom'), 'attributes' => array('required' => 'required')));
$cmb_demo->add_field(array('name' => 'Custom description', 'desc' => 'Write a description for your custom size', 'id' => $prefix . 'size_custom_description', 'type' => 'textarea', 'required' => true, 'attributes' => array('required' => true, 'data-conditional-id' => $prefix . 'sizes', 'data-conditional-value' => 'custom')));
// Example using conditionals with multi-check checkboxes.
$cmb_demo->add_field(array('name' => __('Test Multi Checkbox', 'cmb2'), 'desc' => __('field description (optional)', 'cmb2'), 'id' => $prefix . 'multi-checkbox', 'type' => 'multicheck', 'options' => array('check1' => __('Check One', 'cmb2'), 'check2' => __('Check Two', 'cmb2'), 'check3' => __('Check Three', 'cmb2'))));
$cmb_demo->add_field(array('name' => 'Multi-check: Shown if *any* checkbox is checked', 'id' => $prefix . 'multi-check-detail-test-no-value', 'type' => 'text', 'attributes' => array('required' => true, 'data-conditional-id' => $prefix . 'multi-checkbox')));
$cmb_demo->add_field(array('name' => 'Multi-check: Only shown if checkbox 2 is checked', 'id' => $prefix . 'multi-check-detail-test-string', 'type' => 'text', 'attributes' => array('data-conditional-id' => $prefix . 'multi-checkbox', 'data-conditional-value' => 'check2')));
$cmb_demo->add_field(array('name' => 'Multi-check : Shown if either checkbox 1 *or* 3 is checked', 'id' => $prefix . 'multi-check-detail-test-array', 'type' => 'text', 'attributes' => array('data-conditional-id' => $prefix . 'multi-checkbox', 'data-conditional-value' => wp_json_encode(array('check1', 'check3')))));
// Example conditionals within a group.
$group_id = $cmb_demo->add_field(array('id' => $prefix . 'repeatable-group', 'type' => 'group', 'description' => 'Repeatable group', 'options' => array('group_title' => 'Entry {#}', 'add_button' => 'Add Another Entry', 'remove_button' => 'Remove Entry', 'sortable' => true)));
$cmb_demo->add_group_field($group_id, array('name' => 'Checkbox in group', 'id' => 'checkbox', 'type' => 'checkbox'));
$cmb_demo->add_group_field($group_id, array('name' => 'Dependant field', 'id' => 'dependant', 'type' => 'text_small', 'attributes' => array('required' => true, 'data-conditional-id' => wp_json_encode(array($group_id, 'checkbox')), 'data-conditional-value' => 'on')));
}