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


PHP sanitize_meta函数代码示例

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


在下文中一共展示了sanitize_meta函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_sanitize_meta

 function test_sanitize_meta()
 {
     $meta = sanitize_meta('some_meta', 'unsanitized', 'post');
     $this->assertEquals('unsanitized', $meta);
     register_meta('post', 'some_meta', array($this, '_meta_sanitize_cb'));
     $meta = sanitize_meta('some_meta', 'unsanitized', 'post');
     $this->assertEquals('sanitized', $meta);
 }
开发者ID:boonebgorges,项目名称:wp,代码行数:8,代码来源:meta.php

示例2: circleflip_multimenu_save_metabox

function circleflip_multimenu_save_metabox($page_ID, $page, $update)
{
    if (!current_user_can('edit_page', $page_ID) || !isset($_POST['circleflip_multimenu_menu']) || !isset($_POST['circleflip_multimenu_nonce']) || !wp_verify_nonce($_POST['circleflip_multimenu_nonce'], 'circleflip-multimenu-save')) {
        return;
    }
    $_override_menu = sanitize_meta('_circleflip_multimenu', $_POST['circleflip_multimenu_menu'], 'page');
    update_post_meta($page_ID, '_circleflip_multimenu', $_override_menu);
}
开发者ID:purgesoftwares,项目名称:purges,代码行数:8,代码来源:circleflip-multimenu.php

示例3: circleflip_headerBuilder_save_metabox

function circleflip_headerBuilder_save_metabox($page_ID, $page, $update)
{
    if (!current_user_can('edit_page', $page_ID) || !isset($_POST['circleflip_headerBuilder_menu']) || !isset($_POST['circleflip_headerBuilder_nonce']) || !wp_verify_nonce($_POST['circleflip_headerBuilder_nonce'], 'circleflip-headerBuilder-save')) {
        return;
    }
    $_override_menu = sanitize_meta('_circleflip_headerBuilder', $_POST['circleflip_headerBuilder_menu'], 'page');
    $_override_slider = sanitize_meta('_circleflip_headerBuilder_slider', $_POST['circleflip_headerBuilder_slider'], 'page');
    update_post_meta($page_ID, '_circleflip_headerBuilder', $_override_menu);
    update_post_meta($page_ID, '_circleflip_headerBuilder_slider', $_override_slider);
}
开发者ID:purgesoftwares,项目名称:purges,代码行数:10,代码来源:circleflip-headerBuilder.php

示例4: update_meta

 public static function update_meta($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '')
 {
     if (!$meta_type || !$meta_key) {
         return false;
     }
     if (!($object_id = absint($object_id))) {
         return false;
     }
     if (!($table = self::_get_table_name($meta_type))) {
         return false;
     }
     global $wpdb;
     $column = esc_sql($meta_type . '_id');
     $id_column = apply_filters('qsot-meta-id-field', 'meta_id', $meta_type);
     // expected_slashed ($meta_key)
     $meta_key = stripslashes($meta_key);
     $passed_value = $meta_value;
     $meta_value = stripslashes_deep($meta_value);
     $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
     if (null !== ($check = apply_filters("update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value))) {
         return (bool) $check;
     }
     if (!($meta_id = $wpdb->get_var($wpdb->prepare("SELECT {$id_column} FROM {$table} WHERE meta_key = %s AND {$column} = %d", $meta_key, $object_id)))) {
         return self::add_meta($meta_type, $object_id, $meta_key, $passed_value);
     }
     // Compare existing value to new value if no prev value given and the key exists only once.
     if (empty($prev_value)) {
         $old_value = self::get_meta($meta_type, $object_id, $meta_key);
         if (count($old_value) == 1 && $old_value[0] === $meta_value) {
             return false;
         }
     }
     $_meta_value = $meta_value;
     $meta_value = self::_maybe_json_encode($meta_value);
     $data = compact('meta_value');
     $where = array($column => $object_id, 'meta_key' => $meta_key);
     if (!empty($prev_value)) {
         $prev_value = self::_maybe_json_encode($prev_value);
         $where['meta_value'] = $prev_value;
     }
     do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
     $wpdb->update($table, $data, $where);
     wp_cache_delete($object_id, $meta_type . '_meta');
     do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
     return true;
 }
开发者ID:Jayriq,项目名称:opentickets-community,代码行数:46,代码来源:json-meta.class.php

示例5: update_metadata

/**
 * Update metadata for the specified object.  If no value already exists for the specified object
 * ID and metadata key, the metadata will be added.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 * @uses do_action() Calls 'update_{$meta_type}_meta' before updating metadata with meta_id of
 * 		metadata entry to update, object ID, meta key, and meta value
 * @uses do_action() Calls 'updated_{$meta_type}_meta' after updating metadata with meta_id of
 * 		updated metadata entry, object ID, meta key, and meta value
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Metadata key
 * @param string $meta_value Metadata value
 * @param string $prev_value Optional.  If specified, only update existing metadata entries with
 * 		the specified value.  Otherwise, update all entries.
 * @return bool True on successful update, false on failure.
 */
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '')
{
    if (!$meta_type || !$meta_key) {
        return false;
    }
    if (!($object_id = absint($object_id))) {
        return false;
    }
    if (!($table = _get_meta_table($meta_type))) {
        return false;
    }
    global $wpdb;
    $column = esc_sql($meta_type . '_id');
    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    // expected_slashed ($meta_key)
    $meta_key = stripslashes($meta_key);
    $meta_value = stripslashes_deep($meta_value);
    $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
    $check = apply_filters("update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value);
    if (null !== $check) {
        return (bool) $check;
    }
    if (!($meta_id = $wpdb->get_var($wpdb->prepare("SELECT {$id_column} FROM {$table} WHERE meta_key = %s AND {$column} = %d", $meta_key, $object_id)))) {
        return add_metadata($meta_type, $object_id, $meta_key, $meta_value);
    }
    // Compare existing value to new value if no prev value given and the key exists only once.
    if (empty($prev_value)) {
        $old_value = get_metadata($meta_type, $object_id, $meta_key);
        if (count($old_value) == 1) {
            if ($old_value[0] === $meta_value) {
                return false;
            }
        }
    }
    $_meta_value = $meta_value;
    $meta_value = maybe_serialize($meta_value);
    $data = compact('meta_value');
    $where = array($column => $object_id, 'meta_key' => $meta_key);
    if (!empty($prev_value)) {
        $prev_value = maybe_serialize($prev_value);
        $where['meta_value'] = $prev_value;
    }
    do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
    $wpdb->update($table, $data, $where);
    wp_cache_delete($object_id, $meta_type . '_meta');
    // users cache stores usermeta that must be cleared.
    if ('user' == $meta_type) {
        clean_user_cache($object_id);
    }
    do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
    return true;
}
开发者ID:fka2004,项目名称:webkit,代码行数:71,代码来源:meta.php

示例6: update

 /**
  * Update a meta field.
  *
  * ## OPTIONS
  *
  * <id>
  * : The ID of the object.
  *
  * <key>
  * : The name of the meta field to update.
  *
  * [<value>]
  * : The new value. If ommited, the value is read from STDIN.
  *
  * [--format=<format>]
  * : The serialization format for the value. Default is plaintext.
  *
  * @alias set
  */
 public function update($args, $assoc_args)
 {
     list($object_id, $meta_key) = $args;
     $meta_value = WP_CLI::get_value_from_arg_or_stdin($args, 2);
     $meta_value = WP_CLI::read_value($meta_value, $assoc_args);
     $object_id = $this->check_object_id($object_id);
     $meta_value = sanitize_meta($meta_key, $meta_value, $this->meta_type);
     $old_value = sanitize_meta($meta_key, get_metadata($this->meta_type, $object_id, $meta_key, true), $this->meta_type);
     if ($meta_value === $old_value) {
         WP_CLI::success("Value passed for custom field '{$meta_key}' is unchanged.");
     } else {
         $success = update_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
         if ($success) {
             WP_CLI::success("Updated custom field '{$meta_key}'.");
         } else {
             WP_CLI::error("Failed to update custom field '{$meta_key}'.");
         }
     }
 }
开发者ID:gilbitron,项目名称:wp-cli,代码行数:38,代码来源:CommandWithMeta.php

示例7: update_user_meta

 /**
  * Save the user's meta fields.
  *
  * @param   array $submitted The submitted values.
  * @param   array $keys The keys of fields that are to be updated.
  * @return  int Number of fields updated.
  * @access  public
  * @since   1.0.0
  */
 public function update_user_meta($submitted, $keys)
 {
     /* Exclude the core keys */
     $mapped_keys = $this->get_mapped_keys();
     $meta_fields = array_diff($keys, $this->get_core_keys());
     $updated = 0;
     foreach ($meta_fields as $field) {
         if (isset($submitted[$field])) {
             $meta_key = array_key_exists($field, $mapped_keys) ? $mapped_keys[$field] : $field;
             $meta_value = sanitize_meta($meta_key, $submitted[$field], 'user');
             update_user_meta($this->ID, $meta_key, $meta_value);
             $updated++;
         }
     }
     return $updated;
 }
开发者ID:rafecolton,项目名称:Charitable,代码行数:25,代码来源:class-charitable-user.php

示例8: get_post_type

* check if single Docu
*/
global $post;
$post_type = get_post_type($post->ID);
// check if we're using polylang plugin
if (function_exists('pll_register_string')) {
    // get button text setting value from polylang
    $pdfbutton_text = pll__('PDF Button');
} else {
    $pdfbutton_text = sanitize_option('dkpdf_pdfbutton_text', get_option('dkpdf_pdfbutton_text', 'PDF Button'));
}
$pdfbutton_align = sanitize_option('dkpdf_pdfbutton_align', get_option('dkpdf_pdfbutton_align', 'right'));
?>

<?php 
$hide_pdfbutton = sanitize_meta('_hide_pdfbutton', get_post_meta($post->ID, '_hide_pdfbutton'), 'checkbox');
// only show button if _hide_pdfbutton post meta is not checked
if (!$hide_pdfbutton) {
    ?>

	<div class="dkpdf-button-container" style="text-align:<?php 
    echo $pdfbutton_align;
    ?>
">

		<a class="dkpdf-button" href="<?php 
    echo esc_url(add_query_arg('pdf', $post->ID));
    ?>
" target="_blank"><span class="dkpdf-button-icon"><i class="fa fa-file-pdf-o"></i></span> <?php 
    echo $pdfbutton_text;
    ?>
开发者ID:LunkSnee,项目名称:dk-pdf,代码行数:31,代码来源:dkpdf-button.php

示例9: fw_update_metadata

/**
 * Update metadata for the specified object. If no value already exists for the specified object
 * ID and metadata key, the metadata will be added.
 *
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $object_id ID of the object metadata is for
 * @param string $meta_key Metadata key
 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
 * @param mixed $prev_value Optional. If specified, only update existing metadata entries with
 *        the specified value. Otherwise, update all entries.
 *
 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure.
 */
function fw_update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '')
{
    global $wpdb;
    if (!$meta_type || !$meta_key || !is_numeric($object_id)) {
        return false;
    }
    $object_id = absint($object_id);
    if (!$object_id) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
    // expected_slashed ($meta_key)
    //$meta_key = wp_unslash($meta_key);
    $passed_value = $meta_value;
    //$meta_value = wp_unslash($meta_value);
    $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
    /**
     * Filter whether to update metadata of a specific type.
     *
     * The dynamic portion of the hook, $meta_type, refers to the meta
     * object type (comment, post, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @param null|bool $check Whether to allow updating metadata for the given type.
     * @param int $object_id Object ID.
     * @param string $meta_key Meta key.
     * @param mixed $meta_value Meta value. Must be serializable if non-scalar.
     * @param mixed $prev_value Optional. If specified, only update existing
     *                              metadata entries with the specified value.
     *                              Otherwise, update all entries.
     */
    $check = apply_filters("update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value);
    if (null !== $check) {
        return (bool) $check;
    }
    // Compare existing value to new value if no prev value given and the key exists only once.
    if (empty($prev_value)) {
        $old_value = get_metadata($meta_type, $object_id, $meta_key);
        if (count($old_value) == 1) {
            if ($old_value[0] === $meta_value) {
                return false;
            }
        }
    }
    if (!($meta_id = $wpdb->get_var($wpdb->prepare("SELECT {$id_column} FROM {$table} WHERE meta_key = %s AND {$column} = %d LIMIT 1", $meta_key, $object_id)))) {
        return fw_add_metadata($meta_type, $object_id, $meta_key, $passed_value);
    }
    $_meta_value = $meta_value;
    $meta_value = maybe_serialize($meta_value);
    $data = compact('meta_value');
    $where = array($column => $object_id, 'meta_key' => $meta_key);
    if (!empty($prev_value)) {
        $prev_value = maybe_serialize($prev_value);
        $where['meta_value'] = $prev_value;
    }
    /**
     * Fires immediately before updating metadata of a specific type.
     *
     * The dynamic portion of the hook, $meta_type, refers to the meta
     * object type (comment, post, or user).
     *
     * @param int $meta_id ID of the metadata entry to update.
     * @param int $object_id Object ID.
     * @param string $meta_key Meta key.
     * @param mixed $meta_value Meta value.
     */
    do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
    if ('post' == $meta_type) {
        do_action('update_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
    }
    $result = $wpdb->update($table, $data, $where);
    if (!$result) {
        return false;
    }
    wp_cache_delete($object_id, $meta_type . '_meta');
    /**
     * Fires immediately after updating metadata of a specific type.
     *
     * The dynamic portion of the hook, $meta_type, refers to the meta
     * object type (comment, post, or user).
//.........这里部分代码省略.........
开发者ID:northpen,项目名称:northpen,代码行数:101,代码来源:meta.php

示例10: dslc_module_settings

/**
 * Module Settings
 *
 * Generates settings based on default values and user values
 *
 * @since 1.0
 */
function dslc_module_settings($options, $custom = false)
{
    // Array to hold the settings.
    $settings = array();
    // Go through all options.
    foreach ($options as $option) {
        if (isset($_POST[$option['id']])) {
            /**
             * Extension developers can decide for themselves
             * what escaping function to use for a particular option id.
             *
             * See switch block below for available options.
             */
            $default_settings_escape_function = 'esc_attr';
            $custom_settings_escape_function = $default_settings_escape_function;
            $custom_settings_escape_function = apply_filters('dslc_module_settings_cleaning_function', $default_settings_escape_function, $option['id']);
            // If value set use it?
            if ('content' === $option['id']) {
                $settings[$option['id']] = wp_kses_post($_POST[$option['id']]);
            } elseif ($custom_settings_escape_function !== $default_settings_escape_function) {
                switch ($custom_settings_escape_function) {
                    case 'wp_kses_post':
                        $settings[$option['id']] = wp_kses_post($_POST[$option['id']]);
                        break;
                    case 'sanitize_email':
                        $settings[$option['id']] = sanitize_email($_POST[$option['id']]);
                        break;
                    case 'sanitize_file_name':
                        $settings[$option['id']] = sanitize_file_name($_POST[$option['id']]);
                        break;
                    case 'sanitize_html_class':
                        $settings[$option['id']] = sanitize_html_class($_POST[$option['id']]);
                        break;
                    case 'sanitize_key':
                        $settings[$option['id']] = sanitize_key($_POST[$option['id']]);
                        break;
                    case 'sanitize_meta':
                        $settings[$option['id']] = sanitize_meta($_POST[$option['id']]);
                        break;
                    case 'sanitize_text_field':
                        $settings[$option['id']] = sanitize_text_field($_POST[$option['id']]);
                        break;
                    case 'sanitize_title':
                        $settings[$option['id']] = sanitize_title($_POST[$option['id']]);
                        break;
                    case 'esc_html':
                        $settings[$option['id']] = esc_html($_POST[$option['id']]);
                        break;
                    case 'esc_url':
                        $settings[$option['id']] = esc_url($_POST[$option['id']]);
                        break;
                    case 'esc_js':
                        $settings[$option['id']] = esc_js($_POST[$option['id']]);
                        break;
                    case 'esc_textarea':
                        $settings[$option['id']] = esc_textarea($_POST[$option['id']]);
                        break;
                    default:
                        $settings[$option['id']] = esc_attr($_POST[$option['id']]);
                        break;
                }
            } else {
                $settings[$option['id']] = esc_attr($_POST[$option['id']]);
            }
        } else {
            // If value not set use default?
            $settings[$option['id']] = $option['std'];
        }
    }
    return $settings;
}
开发者ID:NGorco,项目名称:Live-Composer,代码行数:78,代码来源:functions.php

示例11: process_product


//.........这里部分代码省略.........
         WC_Product_CSV_Import_Suite::log(__('> Inserting variation.', 'woocommerce-product-csv-import-suite'));
         $postdata = array('import_id' => $processing_product_id, 'post_date' => $post['post_date'] ? date('Y-m-d H:i:s', strtotime($post['post_date'])) : '', 'post_date_gmt' => $post['post_date_gmt'] ? date('Y-m-d H:i:s', strtotime($post['post_date_gmt'])) : '', 'post_status' => $post['post_status'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => 'product_variation');
         $post_id = wp_insert_post($postdata, true);
         if (is_wp_error($post_id)) {
             $this->add_import_result('failed', __('Failed to import product variation', 'woocommerce-product-csv-import-suite'), $processing_product_id, get_the_title($post['post_parent']), $post['sku']);
             WC_Product_CSV_Import_Suite::log(sprintf(__('Failed to import product &#8220;%s&#8221;', 'woocommerce-product-csv-import-suite'), esc_html($post['post_title'])));
             return;
         } else {
             WC_Product_CSV_Import_Suite::log(sprintf(__('> Inserted - post ID is %s.', 'woocommerce-product-csv-import-suite'), $post_id));
             // Set post title now we have an ID
             $postdata['ID'] = $post_id;
             $postdata['post_title'] = sprintf(__('Variation #%s of %s', 'woocommerce'), $post_id, get_the_title($post_parent));
             wp_update_post($postdata);
         }
     }
     // map pre-import ID to local ID
     if (empty($processing_product_id)) {
         $processing_product_id = (int) $post_id;
     }
     $this->processed_posts[intval($processing_product_id)] = (int) $post_id;
     $this->process_terms($post_id, $post['terms']);
     // Process post meta
     if (!empty($post['postmeta']) && is_array($post['postmeta'])) {
         foreach ($post['postmeta'] as $meta) {
             if ($key = apply_filters('import_post_meta_key', $meta['key'])) {
                 $insert_meta_data[$key] = maybe_unserialize($meta['value']);
             }
         }
     }
     // Import images and add to post
     if (!empty($post['images'])) {
         $featured = true;
         if ($merging) {
             // Remove old
             delete_post_meta($post_id, '_thumbnail_id');
             // Delete old attachments
             $attachments = get_posts('post_parent=' . $post_id . '&post_type=attachment&fields=ids&post_mime_type=image&numberposts=-1');
             foreach ($attachments as $attachment) {
                 $url = wp_get_attachment_url($attachment);
                 if (in_array($url, $post['images'])) {
                     if ($url == $post['images'][0]) {
                         $insert_meta_data['_thumbnail_id'] = $attachment;
                     }
                     unset($post['images'][array_search($url, $post['images'])]);
                 } else {
                     // Detach
                     $attachment_post = array();
                     $attachment_post['ID'] = $attachment;
                     $attachment_post['post_parent'] = '';
                     wp_update_post($attachment_post);
                 }
             }
             WC_Product_CSV_Import_Suite::log(__('> > Old images processed', 'woocommerce-product-csv-import-suite'));
         }
         if ($post['images']) {
             foreach ($post['images'] as $image) {
                 WC_Product_CSV_Import_Suite::log(sprintf(__('> > Importing image "%s"', 'woocommerce-product-csv-import-suite'), $image));
                 $wp_filetype = wp_check_filetype(basename($image), null);
                 $wp_upload_dir = wp_upload_dir();
                 $filename = basename($image);
                 $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_content' => '', 'post_status' => 'inherit');
                 $attachment_id = $this->process_attachment($attachment, $image, $post_id);
                 if (!is_wp_error($attachment_id)) {
                     if ($featured) {
                         $insert_meta_data['_thumbnail_id'] = $attachment_id;
                     }
                     update_post_meta($attachment_id, '_woocommerce_exclude_image', 0);
                     $featured = false;
                 } else {
                     WC_Product_CSV_Import_Suite::log('> > ' . $attachment_id->get_error_message());
                 }
             }
         }
         WC_Product_CSV_Import_Suite::log(__('> > Images set', 'woocommerce-product-csv-import-suite'));
     }
     // Delete existing meta first
     $wpdb->query('START TRANSACTION');
     $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ( '" . implode("','", array_map('esc_sql', array_keys($insert_meta_data))) . "' ) and post_id = %d", $post_id));
     // Format meta data
     foreach ($insert_meta_data as $key => $value) {
         $meta_key = wp_unslash($key);
         $meta_value = wp_unslash($value);
         $meta_value = sanitize_meta($meta_key, $meta_value, 'post');
         $meta_value = maybe_serialize($meta_value);
         $meta_values[] = $wpdb->prepare("( %d, %s, %s )", $post_id, $meta_key, $meta_value);
     }
     // Then insert meta data
     $wpdb->query("INSERT INTO {$wpdb->postmeta} ( post_id, meta_key, meta_value ) VALUES " . implode(',', $meta_values));
     $wpdb->query('COMMIT');
     if ($merging) {
         $this->add_import_result('merged', 'Merge successful', $post_id, get_the_title($post_parent), $post['sku']);
         WC_Product_CSV_Import_Suite::log(sprintf(__('> Finished merging variation ID %s.', 'woocommerce-product-csv-import-suite'), $post_id));
     } else {
         $this->add_import_result('imported', 'Import successful', $post_id, get_the_title($post_parent), $post['sku']);
         WC_Product_CSV_Import_Suite::log(sprintf(__('> Finished importing variation ID %s.', 'woocommerce-product-csv-import-suite'), $post_id));
     }
     wp_suspend_cache_invalidation(false);
     clean_post_cache($post_id);
     unset($post);
 }
开发者ID:arobbins,项目名称:spellestate,代码行数:101,代码来源:class-wc-pcsvis-product_variation-import.php

示例12: process_product


//.........这里部分代码省略.........
                                 $featured = false;
                             } else {
                                 $gallery_ids[$key] = $attachment;
                             }
                         }
                     }
                 } else {
                     // Detach image which is not being merged
                     $attachment_post = array();
                     $attachment_post['ID'] = $attachment;
                     $attachment_post['post_parent'] = '';
                     wp_update_post($attachment_post);
                     unset($attachment_post);
                 }
             }
             unset($attachments);
         }
         if ($post['images']) {
             foreach ($post['images'] as $image_key => $image) {
                 WC_Product_CSV_Import_Suite::log(sprintf(__('> > Importing image "%s"', 'woocommerce-product-csv-import-suite'), $image));
                 $filename = basename($image);
                 $attachment = array('post_title' => preg_replace('/\\.[^.]+$/', '', $processing_product_title . ' ' . ($image_key + 1)), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $post_id);
                 $attachment_id = $this->process_attachment($attachment, $image, $post_id);
                 if (!is_wp_error($attachment_id) && $attachment_id) {
                     WC_Product_CSV_Import_Suite::log(sprintf(__('> > Imported image "%s"', 'woocommerce-product-csv-import-suite'), $image));
                     // Set alt
                     update_post_meta($attachment_id, '_wp_attachment_image_alt', $processing_product_title);
                     update_post_meta($attachment_id, '_woocommerce_exclude_image', 0);
                     if ($featured) {
                         $insert_meta_data['_thumbnail_id'] = $attachment_id;
                     } else {
                         $gallery_ids[$image_key] = $attachment_id;
                     }
                     $featured = false;
                 } else {
                     WC_Product_CSV_Import_Suite::log(sprintf(__('> > Error importing image "%s"', 'woocommerce-product-csv-import-suite'), $image));
                     WC_Product_CSV_Import_Suite::log('> > ' . $attachment_id->get_error_message());
                 }
                 unset($attachment, $attachment_id);
             }
         }
         WC_Product_CSV_Import_Suite::log(__('> > Images set', 'woocommerce-product-csv-import-suite'));
         ksort($gallery_ids);
         $insert_meta_data['_product_image_gallery'] = implode(',', $gallery_ids);
     }
     // Import attributes
     if (!empty($post['attributes']) && is_array($post['attributes'])) {
         if ($merging) {
             $attributes = array_filter((array) WC_Product_CSV_Import_Suite::get_meta_data($post_id, '_product_attributes'));
             $attributes = array_merge($attributes, $post['attributes']);
         } else {
             $attributes = $post['attributes'];
         }
         // Sort attribute positions
         uasort($attributes, array($this, 'attributes_cmp'));
         $insert_meta_data['_product_attributes'] = $attributes;
     }
     // Import GPF
     if (!empty($post['gpf_data']) && is_array($post['gpf_data'])) {
         $insert_meta_data['_woocommerce_gpf_data'] = $post['gpf_data'];
     }
     if (!empty($post['upsell_skus']) && is_array($post['upsell_skus'])) {
         $this->upsell_skus[$post_id] = $post['upsell_skus'];
     }
     if (!empty($post['crosssell_skus']) && is_array($post['crosssell_skus'])) {
         $this->crosssell_skus[$post_id] = $post['crosssell_skus'];
     }
     // Sales
     $insert_meta_data['total_sales'] = absint(WC_Product_CSV_Import_Suite::get_meta_data($post_id, 'total_sales'));
     // Delete existing meta first
     $wpdb->query('START TRANSACTION');
     $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ( '" . implode("','", array_map('esc_sql', array_keys($insert_meta_data))) . "' ) and post_id = %d", $post_id));
     // Format meta data
     foreach ($insert_meta_data as $key => $value) {
         $meta_key = wp_unslash($key);
         $meta_value = wp_unslash($value);
         $meta_value = sanitize_meta($meta_key, $meta_value, 'post');
         $meta_value = maybe_serialize($meta_value);
         $meta_values[] = $wpdb->prepare("( %d, %s, %s )", $post_id, $meta_key, $meta_value);
     }
     // Then insert meta data
     $wpdb->query("INSERT INTO {$wpdb->postmeta} ( post_id, meta_key, meta_value ) VALUES " . implode(',', $meta_values));
     $wpdb->query('COMMIT');
     foreach ($insert_meta_data as $key => $value) {
         if ($key === '_file_paths') {
             do_action('woocommerce_process_product_file_download_paths', $post_id, 0, $value);
             break;
         }
     }
     if ($merging) {
         $this->add_import_result('merged', 'Merge successful', $post_id, $processing_product_title, $processing_product_sku);
         WC_Product_CSV_Import_Suite::log(sprintf(__('> Finished merging post ID %s.', 'woocommerce-product-csv-import-suite'), $post_id));
     } else {
         $this->add_import_result('imported', 'Import successful', $post_id, $processing_product_title, $processing_product_sku);
         WC_Product_CSV_Import_Suite::log(sprintf(__('> Finished importing post ID %s.', 'woocommerce-product-csv-import-suite'), $post_id));
     }
     wp_suspend_cache_invalidation(false);
     clean_post_cache($post_id);
     unset($post);
 }
开发者ID:arobbins,项目名称:spellestate,代码行数:101,代码来源:class-wc-pcsvis-product-import.php

示例13: dsq_update_permalink

function dsq_update_permalink($post)
{
    global $dsq_api;
    if (DISQUS_DEBUG) {
        echo "updating post on disqus: {$post->ID}\n";
    }
    $response = $dsq_api->api->update_thread(null, array('thread_identifier' => dsq_identifier_for_post($post), 'title' => dsq_title_for_post($post), 'url' => dsq_link_for_post($post)));
    //Make sure that response exists so that warnings are not thrown
    if (!empty($response)) {
        $cleaned_thread_id = sanitize_meta('dsq_thread_id', $response->id, 'post');
        update_post_meta($post->ID, 'dsq_thread_id', $cleaned_thread_id);
    }
    return $response;
}
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:14,代码来源:disqus.php

示例14: updateByID

 /**
  * Update meta by ID.
  *
  * NOTE: This is the Connections equivalent of @see update_metadata_by_mid() in WordPress core ../wp-includes/meta.php
  *
  * @access public
  * @since  8.1.7
  * @static
  *
  * @global wpdb  $wpdb  WordPress database abstraction object.
  *
  * @uses   cnMeta::tableName()
  * @uses   cnMeta::getByID()
  * @uses   sanitize_meta()
  * @uses   cnFormatting::maybeJSONencode()
  * @uses   do_action()
  * @uses   wpdb::update()
  * @uses   wp_cache_delete()
  *
  * @param string $type  Type of object metadata is for (e.g., entry, term).
  * @param int    $id    ID for a specific meta row.
  * @param string $value Metadata value.
  * @param mixed  $key   string|bool Optional, you can provide a meta key to update it.
  *
  * @return bool         TRUE on successful update, FALSE on failure.
  */
 public static function updateByID($type, $id, $value, $key = FALSE)
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     // Make sure everything is valid.
     if (!$type || !is_numeric($id)) {
         return FALSE;
     }
     $id = absint($id);
     if (!$id) {
         return FALSE;
     }
     $table = self::tableName($type);
     $column = sanitize_key($type . '_id');
     $id_column = 'meta_id';
     // Fetch the meta and go on if it's found.
     if ($meta = self::getByID($type, $id)) {
         $original_key = $meta->meta_key;
         $object_id = $meta->{$column};
         // If a new meta_key (last parameter) was specified, change the meta key,
         // otherwise use the original key in the update statement.
         if (FALSE === $key) {
             $key = $original_key;
         } elseif (!is_string($key)) {
             return FALSE;
         }
         // Sanitize the meta
         $_meta_value = $value;
         $value = wp_unslash($value);
         $value = sanitize_meta($key, $value, 'cn_' . $type);
         $value = cnFormatting::maybeJSONencode($value);
         // Format the data query arguments.
         $data = array('meta_key' => $key, 'meta_value' => $value);
         // Format the where query arguments.
         $where = array();
         $where[$id_column] = $id;
         /** This action is documented in includes/class.meta.php */
         do_action("cn_update_{$type}_meta", $id, $object_id, $key, $_meta_value);
         // Run the update query, all fields in $data are %s, $where is a %d.
         $result = $wpdb->update($table, $data, $where, '%s', '%d');
         if (!$result) {
             return FALSE;
         }
         // Clear the caches.
         wp_cache_delete($object_id, 'cn_' . $type . '_meta');
         /** This action is documented in includes/class.meta.php */
         do_action("cn_updated_{$type}_meta", $id, $object_id, $key, $_meta_value);
         return TRUE;
     }
     // And if the meta was not found.
     return FALSE;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:78,代码来源:class.meta.php

示例15: ppr_save_metadata

 function ppr_save_metadata($post_id, $post)
 {
     if ($post->post_type == 'revision' || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // verify authorization
     if (isset($_POST['pprredirect_noncename'])) {
         if (!wp_verify_nonce($_REQUEST['pprredirect_noncename'], 'pprredirect_noncename')) {
             return $post_id;
         }
     }
     // check allowed to editing
     if (!current_user_can('edit_posts', $post_id)) {
         return $post_id;
     }
     if (!empty($my_meta_data)) {
         unset($my_meta_data);
     }
     $my_meta_data = array();
     if (isset($_POST['pprredirect_active']) || isset($_POST['pprredirect_url']) || isset($_POST['pprredirect_type']) || isset($_POST['pprredirect_newwindow']) || isset($_POST['pprredirect_relnofollow']) || isset($_POST['pprredirect_meta_secs'])) {
         $protocols = apply_filters('qppr_allowed_protocols', array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn', 'tel', 'fax', 'xmpp'));
         // find & save the form data & put it into an array
         $my_meta_data['_pprredirect_active'] = isset($_REQUEST['pprredirect_active']) ? sanitize_meta('_pprredirect_active', $this->isOne_none(intval($_REQUEST['pprredirect_active'])), 'post') : '';
         $my_meta_data['_pprredirect_newwindow'] = isset($_REQUEST['pprredirect_newwindow']) ? sanitize_meta('_pprredirect_newwindow', $this->isOne_none($_REQUEST['pprredirect_newwindow']), 'post') : '';
         $my_meta_data['_pprredirect_relnofollow'] = isset($_REQUEST['pprredirect_relnofollow']) ? sanitize_meta('_pprredirect_relnofollow', $this->isOne_none(intval($_REQUEST['pprredirect_relnofollow'])), 'post') : '';
         $my_meta_data['_pprredirect_type'] = isset($_REQUEST['pprredirect_type']) ? sanitize_meta('_pprredirect_type', sanitize_text_field($_REQUEST['pprredirect_type']), 'post') : '';
         $my_meta_data['_pprredirect_rewritelink'] = isset($_REQUEST['pprredirect_rewritelink']) ? sanitize_meta('_pprredirect_rewritelink', $this->isOne_none(intval($_REQUEST['pprredirect_rewritelink'])), 'post') : '';
         $my_meta_data['_pprredirect_url'] = isset($_REQUEST['pprredirect_url']) ? esc_url_raw($_REQUEST['pprredirect_url'], $protocols) : '';
         $my_meta_data['_pprredirect_meta_secs'] = isset($_REQUEST['pprredirect_meta_secs']) && $_REQUEST['pprredirect_meta_secs'] != '' ? (int) $_REQUEST['pprredirect_meta_secs'] : '';
         $info = $this->appip_parseURI($my_meta_data['_pprredirect_url']);
         //$my_meta_data['_pprredirect_url'] = esc_url_raw($info['url']);
         $my_meta_data['_pprredirect_url'] = $info['url'];
         if ($my_meta_data['_pprredirect_url'] == 'http://' || $my_meta_data['_pprredirect_url'] == 'https://' || $my_meta_data['_pprredirect_url'] == '') {
             $my_meta_data['_pprredirect_url'] = '';
             //reset to nothing
             $my_meta_data['_pprredirect_type'] = NULL;
             //clear Type if no URL is set.
             $my_meta_data['_pprredirect_active'] = NULL;
             //turn it off if no URL is set
             $my_meta_data['_pprredirect_rewritelink'] = NULL;
             //turn it off if no URL is set
             $my_meta_data['_pprredirect_newwindow'] = NULL;
             //turn it off if no URL is set
             $my_meta_data['_pprredirect_relnofollow'] = NULL;
             //turn it off if no URL is set
         }
         // Add values of $my_meta_data as custom fields
         if (count($my_meta_data) > 0) {
             foreach ($my_meta_data as $key => $value) {
                 $value = implode(',', (array) $value);
                 if ($value == '' || $value == NULL || $value == ',') {
                     delete_post_meta($post->ID, $key);
                 } else {
                     if (get_post_meta($post->ID, $key, true) != '') {
                         update_post_meta($post->ID, $key, $value);
                     } else {
                         add_post_meta($post->ID, $key, $value);
                     }
                 }
             }
         }
         $this->qppr_try_to_clear_cache_plugins();
     }
 }
开发者ID:kol4ak,项目名称:autoiservice,代码行数:64,代码来源:page_post_redirect_plugin.php


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