本文整理汇总了PHP中wp_is_post_autosave函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_is_post_autosave函数的具体用法?PHP wp_is_post_autosave怎么用?PHP wp_is_post_autosave使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_is_post_autosave函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_orders_value
public static function update_orders_value( $post_id, $post ) {
if ( is_int( wp_is_post_revision( $post_id ) ) ) return;
if ( is_int( wp_is_post_autosave( $post_id ) ) ) return;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id;
if ( $post->post_type != 'product' ) return $post_id;
if ( version_compare( WC()->version, '2.2.0', '<' ) ) {
$product = get_product( $post );
} else {
$product = wc_get_product( $post );
}
if ( $product ) {
if ( $product->is_on_sale() ) {
update_post_meta( $post_id, '_psad_onsale_order', 2 );
} else {
update_post_meta( $post_id, '_psad_onsale_order', 1 );
}
if ( $product->is_featured() ) {
update_post_meta( $post_id, '_psad_featured_order', 2 );
} else {
update_post_meta( $post_id, '_psad_featured_order', 1 );
}
}
}
示例2: save_default_post_categories
/**
* This function set post in default category.
*
* @param $post_ID
*
* @return mixed
*/
public function save_default_post_categories($post_ID)
{
if (wp_is_post_autosave($post_ID) || wp_is_post_revision($post_ID)) {
return $post_ID;
}
$categories = wp_get_post_categories($post_ID);
if (count($categories) === 1 && $categories[0] === (int) get_option('default_category')) {
$cats = (array) $this->get_default_post_category_by_lang(get_post_meta($post_ID, 'translation_lang', true));
wp_set_post_categories($post_ID, $cats);
}
}
开发者ID:albertso,项目名称:Unyson-Translation-Extension,代码行数:18,代码来源:class-fw-extension-translate-terms.php
示例3: wc_tab_manager_meta_boxes_save
/**
* Runs when a post is saved and does an action which the write panel save scripts can hook into.
*
* @access public
* @param int $post_id post identifier
* @param object $post post object
*/
function wc_tab_manager_meta_boxes_save($post_id, $post)
{
if (empty($post_id) || empty($post) || empty($_POST)) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (is_int(wp_is_post_revision($post))) {
return;
}
if (is_int(wp_is_post_autosave($post))) {
return;
}
if (empty($_POST['woocommerce_meta_nonce']) || !wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
if ('wc_product_tab' != $post->post_type) {
return;
}
do_action('woocommerce_process_wc_product_tab_meta', $post_id, $post);
woocommerce_meta_boxes_save_errors();
}
示例4: dwci_meta_save_event
/**
* Function responsible for saving the event post.
*/
function dwci_meta_save_event($post_id)
{
$is_autosave = wp_is_post_autosave($post_id);
$is_revision = wp_is_post_revision($post_id);
$is_valid_nonce = isset($_POST['dwci_events_nonce']) && wp_verify_nonce($_POST['dwci_events_nonce'], 'ppl-event-nonce') ? true : false;
if ($is_autosave || $is_revision || !$is_valid_nonce) {
return;
}
if (isset($_POST['event_id'])) {
update_post_meta($post_id, 'event_id', sanitize_text_field($_POST['event_id']));
}
if (!isset($_POST['event_id']) || empty($_POST['event_id'])) {
//exit('EVPPTF01032016');
return;
//$error = new WP_Error( 'event_id', sprintf( __( 'You have forgotten to specify the %1$s for your function. %2$s Error triggered inside %3$s on line %4$s.', TEXTDOMAIN ), '$args[\'event_id\']', "\n", __FILE__, __LINE__ ) );
}
if (isset($_POST['event_date'])) {
update_post_meta($post_id, 'event_date', sanitize_text_field($_POST['event_date']));
}
if (isset($_POST['event_reg_start'])) {
update_post_meta($post_id, 'event_reg_start', sanitize_text_field($_POST['event_reg_start']));
}
if (isset($_POST['event_open_seats'])) {
update_post_meta($post_id, 'event_open_seats', sanitize_text_field($_POST['event_open_seats']));
}
}
示例5: save_post
/**
* Generate a pdf for the post when it is updated.
* @param $post_id
* @param $post
*/
public static function save_post($post_id, $post)
{
if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id) || !post_type_supports($post->post_type, 'print_pdf') || isset($_REQUEST['bulk_edit'])) {
return $post_id;
}
self::save_pdf($post);
}
示例6: save_meta_boxes
/**
* Check if we're saving, the trigger an action based on the post type.
* @param int $post_id
* @param object $post
*/
public function save_meta_boxes($post_id, $post)
{
// $post_id and $post are required
if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
return;
}
// Don't save meta boxes for revisions or autosaves
if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
return;
}
// Check the nonce
if (empty($_POST['restaurantpress_meta_nonce']) || !wp_verify_nonce($_POST['restaurantpress_meta_nonce'], 'restaurantpress_save_data')) {
return;
}
// Check the post being saved == the $post_id to prevent triggering this call for other save_post events
if (empty($_POST['post_ID']) || $_POST['post_ID'] != $post_id) {
return;
}
// Check user has permission to edit
if (!current_user_can('edit_post', $post_id)) {
return;
}
// We need this save event to run once to avoid potential endless loops. This would have been perfect:
self::$saved_meta_boxes = true;
// Check the post type
if (in_array($post->post_type, array('food_menu', 'food_group'))) {
do_action('restaurantpress_process_' . $post->post_type . '_meta', $post_id, $post);
}
}
示例7: save_meta_box
public function save_meta_box($post_id)
{
// Checks save status
$is_autosave = wp_is_post_autosave($post_id);
$is_revision = wp_is_post_revision($post_id);
$is_valid_nonce = isset($_POST['heimdall_meta_box_nonce']) && wp_verify_nonce($_POST['heimdall_meta_box_nonce'], 'heimdall_meta_box') ? 'true' : 'false';
// Exits script depending on save status
if ($is_autosave || $is_revision || !$is_valid_nonce) {
return $post_id;
}
// Check the user's permissions.
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} else {
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
}
// Update the post meta
if (isset($_POST['heimdall_secured_page'])) {
update_post_meta($post_id, '_heimdall_secured_page', 1);
} else {
delete_post_meta($post_id, '_heimdall_secured_page');
}
if (isset($_POST['heimdall_whitelist']) && is_array($_POST['heimdall_whitelist'])) {
update_post_meta($post_id, '_heimdall_whitelist', $_POST['heimdall_whitelist']);
} else {
delete_post_meta($post_id, '_heimdall_whitelist');
}
}
示例8: save_meta_boxes
/**
* Save meta boxes.
*
* @param int $post_id
* @param object $post
*/
public function save_meta_boxes($post_id, $post)
{
// Can't proceed without a post id or post.
if (empty($post_id) || empty($post)) {
return;
}
// Don't save meta boxes for revisions or autosaves
if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
return;
}
// Check the post being saved has the same id as the post id.
// This will prevent other save post events.
if ($this->valid_post_id($post_id)) {
return;
}
// Check if our nonce is vailed.
if (!wp_verify_nonce(papi_get_sanitized_post('papi_meta_nonce'), 'papi_save_data')) {
return;
}
// Check for any of the capabilities before we save the code.
if (!current_user_can('edit_posts') || !current_user_can('edit_pages')) {
return;
}
$this->save_properties($post_id);
}
示例9: save
function save($post_id)
{
/**
* Perform checks
*/
if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
return;
}
if (isset($_REQUEST['doing_wp_cron'])) {
return;
}
if (isset($_REQUEST['post_view'])) {
return;
}
if (!isset($_POST['post_type']) || 'gc' != $_POST['post_type']) {
return;
}
/**
* Save data
*/
$post = get_post($post_id);
if (!get_post_meta($post_id, '_gc_id', true) && 'publish' == $post->post_status) {
update_post_meta($post_id, '_gc_id', self::get_id($post->post_title));
}
}
示例10: __action_save_post
public function __action_save_post($post_id)
{
if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) {
return $post_id;
}
$post_type = get_post_type($post_id);
foreach ($this->connection_factory->get_connections() as $connection) {
$connection_args = $connection->get_args();
if (isset($_POST[$connection->get_name() . '_' . 'to']) && isset($_POST[$connection->get_name() . '_to_nonce']) && wp_verify_nonce($_POST[$connection->get_name() . '_to_nonce'], 'set_' . $connection->get_name() . '_to_' . $post_id)) {
if (in_array($post_type, $connection->from())) {
$to_ids = empty($_POST[$connection->get_name() . '_to']) ? array() : array_map('intval', explode(',', $_POST[$connection->get_name() . '_to']));
$connection->set_connected_to($post_id, $to_ids);
}
}
if ($connection_args['reciprocal'] && isset($_POST[$connection->get_name() . '_' . 'from']) && isset($_POST[$connection->get_name() . '_from_nonce']) && wp_verify_nonce($_POST[$connection->get_name() . '_from_nonce'], 'set_' . $connection->get_name() . '_from_' . $post_id)) {
if (in_array($post_type, $connection->to())) {
$from_ids = empty($_POST[$connection->get_name() . '_from']) ? array() : array_map('intval', explode(',', $_POST[$connection->get_name() . '_from']));
$current_from_ids = $connection->get_connected_from_objects($post_id);
//remove this post from all the posts this item was removed from
foreach (array_diff($current_from_ids, $from_ids) as $from_id_to_remove) {
$current_to_ids = $connection->get_connected_to_objects($from_id_to_remove);
if (false !== ($offset = array_search($post_id, $current_to_ids))) {
array_splice($current_to_ids, $offset, 1);
}
$connection->set_connected_to($from_id_to_remove, $current_to_ids);
}
//add this post to all of the currently selected items
foreach (array_diff($from_ids, $current_from_ids) as $from_id_to_add) {
$connection->set_connected_to($from_id_to_add, array($post_id), true);
}
}
}
}
}
示例11: can_save_post_meta
/**
* Determines whether or not post meta can be saved.
*
* @param int $post_id The id of the post being saved.
* @param string $action The feature's action.
* @param string $nonce The feature's nonce.
* @return boolean Whether the post meta can saved or not.
*/
public function can_save_post_meta($post_id, $action, $nonce)
{
$is_autosave = wp_is_post_autosave($post_id);
$is_revision = wp_is_post_revision($post_id);
$is_valid_nonce = isset($_POST[$nonce]) && wp_verify_nonce($_POST[$nonce], $action);
return !($is_autosave || $is_revision) && $is_valid_nonce;
}
示例12: possiblyAddPostThumbnail
public function possiblyAddPostThumbnail($postId, $post = false)
{
if (!$post) {
$post = get_post($postId);
}
if (false === (wp_is_post_autosave($postId) || wp_is_post_revision($postId)) && post_type_supports($post->post_type, 'thumbnail')) {
$thumb = get_post_thumbnail_id($postId);
if (empty($thumb)) {
// get images as attachements
$images = get_posts(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $postId, 'order' => 'ASC', 'orderby' => 'post_date', 'numberposts' => 1));
if (!is_array($images) || count($images) == 0) {
// if there are no attachments, search post content
preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $matches);
// search for uploaded images in the post
if (isset($matches) && isset($matches[1][0]) && strlen(trim($matches[1][0])) > 0) {
$image = $matches[1][0];
$this->uploadThumb($post, $image);
}
} else {
$image = array_shift($images);
update_post_meta($postId, '_thumbnail_id', $image->ID);
return true;
}
}
}
}
示例13: save
/**
* Save meta data
*
* @param int $post_id
* @param \WP_Post $post
*/
public function save($post_id, $post)
{
if (empty($post_id) || empty($post) || empty($_POST)) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (is_int(wp_is_post_revision($post))) {
return;
}
if (is_int(wp_is_post_autosave($post))) {
return;
}
if (empty($_POST['license_wp_nonce']) || !wp_verify_nonce($_POST['license_wp_nonce'], 'save_meta_data')) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
if ($post->post_type != 'api_product') {
return;
}
do_action('license_wp_save_api_product', $post_id, $post);
}
示例14: site_subheader_metabox_save
function site_subheader_metabox_save($post_id)
{
// Checks save status
$is_autosave = wp_is_post_autosave($post_id);
$is_revision = wp_is_post_revision($post_id);
$is_valid_nonce = isset($_POST['sc_nonce']) && wp_verify_nonce($_POST['sc_nonce'], basename(__FILE__)) ? 'true' : 'false';
// Exits script depending on save status
if ($is_autosave || $is_revision || !$is_valid_nonce) {
return;
}
// Checks for input and sanitizes/saves if needed
if (isset($_POST['site-subheader-title'])) {
update_post_meta($post_id, 'site-subheader-title', sanitize_text_field($_POST['site-subheader-title']));
}
if (isset($_POST['site-subheader-text'])) {
update_post_meta($post_id, 'site-subheader-text', sanitize_text_field($_POST['site-subheader-text']));
}
if (isset($_POST['button-title'])) {
update_post_meta($post_id, 'button-title', sanitize_text_field($_POST['button-title']));
}
if (isset($_POST['button-url'])) {
update_post_meta($post_id, 'button-url', sanitize_text_field($_POST['button-url']));
}
if (isset($_POST['button-alt'])) {
update_post_meta($post_id, 'button-alt', sanitize_text_field($_POST['button-alt']));
}
}
示例15: save_data
/**
* Saves Metabox data to a database.
*
* @param int $post_id ID of the post we are working with.
* @param object $post Post object.
* @since 0.1.0
*/
public function save_data($post_id, $post)
{
// Check if nonce is set.
if (!isset($_POST['_portfolio_toolkit_nonce'])) {
return;
}
// In case it is, verify it.
$nonce = sanitize_key($_POST['_portfolio_toolkit_nonce']);
if (!wp_verify_nonce($nonce, plugin_basename(__FILE__))) {
return;
}
// Return if it is a revision or autosave.
if (wp_is_post_autosave($post->ID) || wp_is_post_revision($post->ID)) {
return;
}
// Is the user allowed to edit the post or page?
if (!current_user_can('edit_post', $post->ID)) {
return;
}
// Loop through meta array, saving or deleting data.
foreach ($this->get_fields() as $field) {
if (isset($_POST[$field['name']])) {
// Sanitize and save data.
if ('url' == $field['sntz']) {
$value = esc_url_raw(wp_unslash($_POST[$field['name']]));
} else {
$value = sanitize_text_field(wp_unslash($_POST[$field['name']]));
}
update_post_meta($post->ID, $field['name'], $value);
} else {
delete_post_meta($post->ID, $field['name']);
}
}
}