本文整理汇总了PHP中cmb_Meta_Box::nonce方法的典型用法代码示例。如果您正苦于以下问题:PHP cmb_Meta_Box::nonce方法的具体用法?PHP cmb_Meta_Box::nonce怎么用?PHP cmb_Meta_Box::nonce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cmb_Meta_Box
的用法示例。
在下文中一共展示了cmb_Meta_Box::nonce方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: intercept_post_id
/**
* Get data before saving to CMB.
*/
public function intercept_post_id()
{
// Check for $_POST data
if (empty($_POST)) {
return false;
}
// Check nonce
if (!(isset($_POST['submit-cmb'], $_POST['wp_meta_box_nonce']) && wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce()))) {
return;
}
// Setup and sanitize data
if (isset($_POST[$this->prefix . 'place_name'])) {
$this->new_submission = wp_insert_post(array('post_title' => sanitize_text_field($_POST[$this->prefix . 'place_name']), 'post_author' => get_current_user_id(), 'post_status' => 'draft', 'post_type' => 'accommodations', 'post_content' => wp_kses($_POST[$this->prefix . 'place_notes'], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span>')), true);
// If no errors, save the data into a new post draft
if (!is_wp_error($this->new_submission)) {
$address = sanitize_text_field($_POST['address']);
$lat = sanitize_text_field($_POST['lat']);
$lng = sanitize_text_field($_POST['lng']);
$formatted_address = sanitize_text_field($_POST['formatted_address']);
// Update the meta field in the database.
update_post_meta($this->new_submission, 'address', $address);
update_post_meta($this->new_submission, 'lat', $lat);
update_post_meta($this->new_submission, 'lng', $lng);
update_post_meta($this->new_submission, 'formatted_address', $formatted_address);
update_post_meta($this->new_submission, 'place_image_id', $_POST['place_image_id']);
//update post parent in place_image_id
$image = array('ID' => get_post_meta($this->new_submission, 'place_image_id', 1), 'post_parent' => $this->new_submission);
wp_update_post($image);
set_post_thumbnail($this->new_submission, get_post_meta($this->new_submission, 'place_image_id', 1));
return $this->new_submission;
}
}
return false;
}
示例2: do_save
/**
* Handles saving of the $_POST data
* @since 0.1.3
* @param int $term_id Term's ID
*/
public function do_save($term_id)
{
if (!class_exists('cmb_Meta_Box')) {
return;
}
if (!isset($_POST['term_opt_name'], $_POST['wp_meta_box_nonce'], $_POST['action']) || !wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce())) {
return;
}
$this->do_override_filters($term_id);
// Save the metabox if it's been submitted
cmb_save_metabox_fields($this->fields(), $this->id());
}
示例3: intercept_post_id
/**
* Get data before saving to CMB.
*/
public function intercept_post_id()
{
// Check for $_POST data
if (empty($_POST)) {
return false;
}
// Check nonce
if (!(isset($_POST['submit-cmb'], $_POST['wp_meta_box_nonce']) && wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce()))) {
return;
}
// Setup and sanitize data
if (isset($_POST[$this->prefix . 'memorial_first_name'])) {
add_filter('user_has_cap', array($this, 'grant_publish_caps'), 0, 3);
$this->new_submission = wp_insert_post(array('post_title' => sanitize_text_field($_POST[$this->prefix . 'memorial_first_name'] . ' ' . $_POST[$this->prefix . 'memorial_last_name']), 'post_author' => get_current_user_id(), 'post_status' => 'draft', 'post_type' => 'memorials', 'post_content_filtered' => wp_kses($_POST[$this->prefix . 'memorial_story'], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span>')), true);
// If no errors, save the data into a new post draft
if (!is_wp_error($this->new_submission)) {
return $this->new_submission;
}
}
return false;
}
示例4: cmb_metabox_form
/**
* Display a metabox form & save it on submission
* @since 1.0.0
* @param array $meta_box Metabox config array
* @param int $object_id Object ID
* @param boolean $return Whether to return or echo form
* @return string CMB html form markup
*/
function cmb_metabox_form($meta_box, $object_id, $echo = true)
{
$meta_box = cmb_Meta_Box::set_mb_defaults($meta_box);
// Make sure form should be shown
if (!apply_filters('cmb_show_on', true, $meta_box)) {
return '';
}
// Make sure that our object type is explicitly set by the metabox config
cmb_Meta_Box::set_object_type(cmb_Meta_Box::set_mb_type($meta_box));
// Save the metabox if it's been submitted
// check permissions
// @todo more hardening?
if (isset($_POST['submit-cmb'], $_POST['object_id'], $_POST['wp_meta_box_nonce']) && wp_verify_nonce($_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce()) && $_POST['object_id'] == $object_id) {
cmb_save_metabox_fields($meta_box, $object_id);
}
// Show specific metabox form
// Get cmb form
ob_start();
cmb_print_metabox($meta_box, $object_id);
$form = ob_get_contents();
ob_end_clean();
$form_format = apply_filters('cmb_frontend_form_format', '<form class="cmb-form" method="post" id="%s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%s">%s<input type="submit" name="submit-cmb" value="%s" class="button-primary"></form>', $object_id, $meta_box, $form);
$form = sprintf($form_format, $meta_box['id'], $object_id, $form, __('Save'));
if ($echo) {
echo $form;
}
return $form;
}