本文整理汇总了PHP中_get_meta_table函数的典型用法代码示例。如果您正苦于以下问题:PHP _get_meta_table函数的具体用法?PHP _get_meta_table怎么用?PHP _get_meta_table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_meta_table函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_metadata
protected function get_metadata($ids, $meta_type)
{
global $wpdb;
$table = _get_meta_table($meta_type);
$id = $meta_type . '_id';
if (!$table) {
return array();
}
return array_map(array($this, 'unserialize_meta'), $wpdb->get_results("SELECT {$id}, meta_key, meta_value, meta_id FROM {$table} WHERE {$id} IN ( " . implode(',', wp_parse_id_list($ids)) . ' )', OBJECT));
}
示例2: test_delete_term
/**
* @group delete_term
*/
public function test_delete_term()
{
$taxonomy = 'category';
$term_id = $this->factory->term->create(array('taxonomy' => $taxonomy));
$term = get_term($term_id, 'category');
$Meta = new Smart_Custom_Fields_Meta($term);
if (!_get_meta_table($Meta->get_meta_type())) {
$Meta->add('text', 'text');
$this->Ajax->delete_term($term_id, '', $taxonomy, $term);
$this->assertSame(array(), $Meta->get('text'));
}
}
示例3: replaceDomainInMeta
/**
* Replace the domain in meta tables
*
* @param string $type
* @param integer $id
* @param integer $objectId
* @param string $key
* @param mixed $value
*/
public function replaceDomainInMeta($type, $id, $objectId, $key, $value)
{
global $wpdb;
$table = _get_meta_table($type);
$column = sanitize_key($type . '_id');
$newValue = $this->replaceDomainRecursive($value);
if ($value !== $newValue) {
$data = ['meta_value' => maybe_serialize($newValue)];
$where = [$column => $objectId, 'meta_key' => $key, 'meta_value' => maybe_serialize($value)];
$wpdb->update($table, $data, $where);
}
}
示例4: get_metadata
protected function get_metadata($ids, $meta_type)
{
global $wpdb;
$table = _get_meta_table($meta_type);
$id = $meta_type . '_id';
if (!$table) {
return array();
}
$private_meta_whitelist_sql = "'" . implode("','", array_map('esc_sql', Jetpack_Sync_Defaults::$default_whitelist_meta_keys)) . "'";
$public_meta_blacklist_sql = "'" . implode("','", array_map('esc_sql', Jetpack_Sync_Defaults::$default_blacklist_meta_keys)) . "'";
return array_map(array($this, 'unserialize_meta'), $wpdb->get_results("SELECT {$id}, meta_key, meta_value, meta_id FROM {$table} WHERE {$id} IN ( " . implode(',', wp_parse_id_list($ids)) . ' )' . " AND ( ( meta_key LIKE '\\_%' AND meta_key IN ( {$private_meta_whitelist_sql} ) )" . " OR ( meta_key NOT LIKE '\\_%' AND meta_key NOT IN ( {$public_meta_blacklist_sql} ) ) )", OBJECT));
}
示例5: get_static_blocks_by_id
/**
* @param string|int $identifier
* @return array|bool
*/
function get_static_blocks_by_id($identifier)
{
/** @var $wpdb wpdb */
global $wpdb;
if (!($table = _get_meta_table('post'))) {
return false;
}
$postIds = $wpdb->get_col($wpdb->prepare("SELECT `post_id` FROM {$table} WHERE `meta_key` = '_identifier' AND `meta_value` = %s", $identifier));
if (empty($postIds)) {
return false;
}
return get_posts(array('include' => $postIds, 'post_type' => 'static_block'));
}
示例6: get_metadata
protected function get_metadata($ids, $meta_type)
{
global $wpdb;
$table = _get_meta_table($meta_type);
$id = $meta_type . '_id';
if (!$table) {
return array();
}
$private_meta_whitelist_sql = '';
$meta_module = Jetpack_Sync_Modules::get_module("meta");
switch ($meta_type) {
case 'post':
$private_meta_whitelist_sql = "'" . implode("','", array_map('esc_sql', $meta_module->get_post_meta_whitelist())) . "'";
break;
case 'comment':
$private_meta_whitelist_sql = "'" . implode("','", array_map('esc_sql', $meta_module->get_comment_meta_whitelist())) . "'";
break;
}
return array_map(array($this, 'unserialize_meta'), $wpdb->get_results("SELECT {$id}, meta_key, meta_value, meta_id FROM {$table} WHERE {$id} IN ( " . implode(',', wp_parse_id_list($ids)) . ' )' . " AND meta_key IN ( {$private_meta_whitelist_sql} ) ", OBJECT));
}
示例7: get_items
/**
* Retrieve custom fields for object.
*
* @param WP_REST_Request $request
* @return WP_REST_Request|WP_Error List of meta object data on success, WP_Error otherwise
*/
public function get_items($request)
{
$parent_id = (int) $request['parent_id'];
global $wpdb;
$table = _get_meta_table($this->parent_type);
$parent_column = $this->get_parent_column();
$id_column = $this->get_id_column();
// @codingStandardsIgnoreStart
$results = $wpdb->get_results($wpdb->prepare("SELECT {$id_column}, {$parent_column}, meta_key, meta_value FROM {$table} WHERE {$parent_column} = %d", $parent_id));
// @codingStandardsIgnoreEnd
$meta = array();
foreach ($results as $row) {
$value = $this->prepare_item_for_response($row, $request, true);
if (is_wp_error($value)) {
continue;
}
$meta[] = $this->prepare_response_for_collection($value);
}
return rest_ensure_response($meta);
}
示例8: get_all_meta
/**
* Retrieve custom fields for object.
*
* @param int $id Object ID
* @return (array[]|WP_Error) List of meta object data on success, WP_Error otherwise
*/
public function get_all_meta($id)
{
$check = $this->check_object($id);
if (is_wp_error($check)) {
return $check;
}
global $wpdb;
$table = _get_meta_table($this->type);
$parent_column = $this->get_parent_column();
$results = $wpdb->get_results($wpdb->prepare("SELECT meta_id, meta_key, meta_value FROM {$table} WHERE {$parent_column} = %d", $id));
$meta = array();
foreach ($results as $row) {
$value = $this->prepare_meta($id, $row, true);
if (is_wp_error($value)) {
continue;
}
$meta[] = $value;
}
return apply_filters('json_prepare_meta', $meta, $id);
}
示例9: get_objects_by_id
/**
* This implementation of get_objects_by_id() is a bit hacky since we're not passing in an array of meta IDs,
* but instead an array of post or comment IDs for which to retrieve meta for. On top of that,
* we also pass in an associative array where we expect there to be 'meta_key' and 'ids' keys present.
*
* This seemed to be required since if we have missing meta on WP.com and need to fetch it, we don't know what
* the meta key is, but we do know that we have missing meta for a given post or comment.
*
* @param string $object_type The type of object for which we retrieve meta. Either 'post' or 'comment'
* @param array $config Must include 'meta_key' and 'ids' keys
*
* @return array
*/
public function get_objects_by_id($object_type, $config)
{
global $wpdb;
$table = _get_meta_table($object_type);
if (!$table) {
return array();
}
if (!isset($config['meta_key']) || !isset($config['ids']) || !is_array($config['ids'])) {
return array();
}
$meta_key = $config['meta_key'];
$ids = $config['ids'];
$object_id_column = $object_type . '_id';
// Sanitize so that the array only has integer values
$ids_string = implode(', ', array_map('intval', $ids));
$metas = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table} WHERE {$object_id_column} IN ( {$ids_string} ) AND meta_key = %s", $meta_key));
$meta_objects = array();
foreach ((array) $metas as $meta_object) {
$meta_object = (array) $meta_object;
$meta_objects[$meta_object[$object_id_column]] = array('meta_type' => $object_type, 'meta_id' => $meta_object['meta_id'], 'meta_key' => $meta_key, 'meta_value' => $meta_object['meta_value'], 'object_id' => $meta_object[$object_id_column]);
}
return $meta_objects;
}
示例10: auto_upgrade_options
public function auto_upgrade_options()
{
$current_db_version = 1;
//Check version
if ($this->options['db_version'] < $current_db_version) {
global $wpdb;
//DB_VERSION 1: Since 2.1.0-b5
if ($this->options['db_version'] < 1) {
//RENAME meta_key _wjecf_matching_product_qty TO _wjecf_min_matching_product_qty
$where = array("meta_key" => "_wjecf_matching_product_qty");
$set = array('meta_key' => "_wjecf_min_matching_product_qty");
$wpdb->update(_get_meta_table('post'), $set, $where);
//RENAME meta_key woocommerce-jos-autocoupon TO _wjecf_is_auto_coupon
$where = array("meta_key" => "woocommerce-jos-autocoupon");
$set = array('meta_key' => "_wjecf_is_auto_coupon");
$wpdb->update(_get_meta_table('post'), $set, $where);
//Now we're version 1
$this->options['db_version'] = 1;
}
// Write options to database
update_option('wjecf_options', $this->options, false);
}
}
示例11: fw_delete_metadata
/**
* Delete metadata for the specified object.
*
* @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 Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete metadata entries
* with this value. Otherwise, delete all entries with the specified meta_key.
* @param bool $delete_all Optional, default is false. If true, delete matching metadata entries
* for all objects, ignoring the specified object_id. Otherwise, only delete matching
* metadata entries for the specified object_id.
*
* @return bool True on successful delete, false on failure.
*/
function fw_delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false)
{
/**
* @var WPDB $wpdb
*/
global $wpdb;
if (!$meta_type || !$meta_key || !is_numeric($object_id) && !$delete_all) {
return false;
}
$object_id = absint($object_id);
if (!$object_id && !$delete_all) {
return false;
}
$table = _get_meta_table($meta_type);
if (!$table) {
return false;
}
$type_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);
//$meta_value = wp_unslash($meta_value);
/**
* Filter whether to delete 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 $delete Whether to allow metadata deletion of 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 bool $delete_all Whether to delete the matching metadata entries
* for all objects, ignoring the specified $object_id.
* Default false.
*/
$check = apply_filters("delete_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $delete_all);
if (null !== $check) {
return (bool) $check;
}
$_meta_value = $meta_value;
$meta_value = maybe_serialize($meta_value);
$query = $wpdb->prepare("SELECT {$id_column} FROM {$table} WHERE meta_key = %s", $meta_key);
if (!$delete_all) {
$query .= $wpdb->prepare(" AND {$type_column} = %d", $object_id);
}
if ($meta_value) {
$query .= $wpdb->prepare(" AND meta_value = %s", $meta_value);
}
$meta_ids = $wpdb->get_col($query);
if (!count($meta_ids)) {
return false;
}
if ($delete_all) {
$object_ids = $wpdb->get_col($wpdb->prepare("SELECT {$type_column} FROM {$table} WHERE meta_key = %s", $meta_key));
}
/**
* Fires immediately before deleting metadata of a specific type.
*
* The dynamic portion of the hook, $meta_type, refers to the meta
* object type (comment, post, or user).
*
* @param array $meta_ids An array of metadata entry IDs to delete.
* @param int $object_id Object ID.
* @param string $meta_key Meta key.
* @param mixed $meta_value Meta value.
*/
do_action("delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value);
// Old-style action.
if ('post' == $meta_type) {
/**
* Fires immediately before deleting metadata for a post.
*
* @param array $meta_ids An array of post metadata entry IDs to delete.
*/
do_action('delete_postmeta', $meta_ids);
}
$query = "DELETE FROM {$table} WHERE {$id_column} IN( " . implode(',', $meta_ids) . " )";
$count = $wpdb->query($query);
if (!$count) {
return false;
}
if ($delete_all) {
//.........这里部分代码省略.........
示例12: executeSQL
protected function executeSQL()
{
$import_entry = $this->options['custom_type'] == 'import_users' ? 'user' : 'post';
// prepare bulk SQL query
$meta_table = _get_meta_table($import_entry);
if ($this->post_meta_to_insert) {
$values = array();
$already_added = array();
foreach (array_reverse($this->post_meta_to_insert) as $key => $value) {
if (!empty($value['meta_key']) and !in_array($value['pid'] . '-' . $value['meta_key'], $already_added)) {
$already_added[] = $value['pid'] . '-' . $value['meta_key'];
$values[] = '(' . $value['pid'] . ',"' . $value['meta_key'] . '",\'' . maybe_serialize($value['meta_value']) . '\')';
}
}
$this->wpdb->query("INSERT INTO {$meta_table} (`" . $import_entry . "_id`, `meta_key`, `meta_value`) VALUES " . implode(',', $values));
$this->post_meta_to_insert = array();
}
}
示例13: get_weather
public function get_weather($type)
{
global $wpdb;
$table = _get_meta_table('post');
$sql = "SELECT p.ID,p.post_title FROM " . $wpdb->posts . " as p " . " WHERE p.post_type LIKE %s";
$results = $wpdb->get_results($wpdb->prepare($sql, $type));
foreach ($results as $post) {
$post_id = $post->ID;
}
$meta_data = get_metadata('post', $post_id);
$data['post_id'] = $post_id;
$data['weather_url'] = $meta_data['weather_url']['0'];
$data['location'] = $meta_data['location']['0'];
$data['weather_data'] = $this->get_weather_details($data);
return $data;
}
示例14: update_meta_cache
/**
* Update the metadata cache for the specified objects.
*
* @since 2.9.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
* @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
* @return array|false Metadata cache for the specified objects, or false on failure.
*/
function update_meta_cache($meta_type, $object_ids)
{
global $wpdb;
if (!$meta_type || !$object_ids) {
return false;
}
$table = _get_meta_table($meta_type);
if (!$table) {
return false;
}
$column = sanitize_key($meta_type . '_id');
if (!is_array($object_ids)) {
$object_ids = preg_replace('|[^0-9,]|', '', $object_ids);
$object_ids = explode(',', $object_ids);
}
$object_ids = array_map('intval', $object_ids);
$cache_key = $meta_type . '_meta';
$ids = array();
$cache = array();
foreach ($object_ids as $id) {
$cached_object = wp_cache_get($id, $cache_key);
if (false === $cached_object) {
$ids[] = $id;
} else {
$cache[$id] = $cached_object;
}
}
if (empty($ids)) {
return $cache;
}
// Get meta info
$id_list = join(',', $ids);
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
$meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", ARRAY_A);
if (!empty($meta_list)) {
foreach ($meta_list as $metarow) {
$mpid = intval($metarow[$column]);
$mkey = $metarow['meta_key'];
$mval = $metarow['meta_value'];
// Force subkeys to be array type:
if (!isset($cache[$mpid]) || !is_array($cache[$mpid])) {
$cache[$mpid] = array();
}
if (!isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey])) {
$cache[$mpid][$mkey] = array();
}
// Add a value to the current pid/key:
$cache[$mpid][$mkey][] = $mval;
}
}
foreach ($ids as $id) {
if (!isset($cache[$id])) {
$cache[$id] = array();
}
wp_cache_add($id, $cache[$id], $cache_key);
}
return $cache;
}
示例15: save_postdata
/**
* Saves simple fields data when post is being saved
*/
function save_postdata($post_id = null, $post = null)
{
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
// so not checking nonce can lead to errors, for example losing post connector
if (!isset($_POST['simple_fields_nonce']) || !wp_verify_nonce($_POST['simple_fields_nonce'], plugin_basename(__FILE__))) {
return $post_id;
}
// verify if this is an auto save routine. If it is our form has not been submitted, so we dont want to do anything
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// why dont' we want to save revisions? i'll do that from now on, let's se what happens
// dont's save if is revision
// preview is a revison? should save then so preview with fields work
// if (wp_is_post_revision($post_id) !== FALSE) return $post_id;
// attach post connector
// only save if being found in post variable, beacuse it may not exist if meta box is hidden/not outputted on page
if (isset($_POST["simple_fields_selected_connector"])) {
$simple_fields_selected_connector = isset($_POST["simple_fields_selected_connector"]) ? $_POST["simple_fields_selected_connector"] : null;
update_post_meta($post_id, "_simple_fields_selected_connector", $simple_fields_selected_connector);
}
$post_id = (int) $post_id;
$fieldgroups = isset($_POST["simple_fields_fieldgroups"]) ? $_POST["simple_fields_fieldgroups"] : null;
$field_groups_option = $this->get_field_groups();
if (!($table = _get_meta_table("post"))) {
return false;
}
global $wpdb;
// We have a post_id and we have fieldgroups
if ($post_id && is_array($fieldgroups)) {
// Delete all exisiting custom fields meta that are not part of the keep-list
$post_meta = get_post_custom($post_id);
// new format.. can be anything... how to get it?
$arr_meta_keys_to_keep = array("_simple_fields_been_saved", "_simple_fields_selected_connector");
foreach ($post_meta as $meta_key => $meta_val) {
if (strpos($meta_key, "_simple_fields_") === 0) {
// this is a meta for simple fields, check if it should be kept or deleted
if (!in_array($meta_key, $arr_meta_keys_to_keep)) {
delete_post_meta($post_id, $meta_key);
}
}
}
// cleanup missing keys, due to checkboxes not being checked
$fieldgroups_fixed = $fieldgroups;
foreach ($fieldgroups as $one_field_group_id => $one_field_group_fields) {
foreach ($one_field_group_fields as $posted_id => $posted_vals) {
if ($posted_id == "added") {
continue;
}
$fieldgroups_fixed[$one_field_group_id][$posted_id] = array();
// loopa igenom "added"-värdena och fixa så att allt finns
foreach ($one_field_group_fields["added"] as $added_id => $added_val) {
$fieldgroups_fixed[$one_field_group_id][$posted_id][$added_id] = @$fieldgroups[$one_field_group_id][$posted_id][$added_id];
}
}
}
$fieldgroups = $fieldgroups_fixed;
// Save info about the fact that this post have been saved. This info is used to determine if a post should get default values or not.
update_post_meta($post_id, "_simple_fields_been_saved", "1");
// Loop through each fieldgroups
#sf_d($fieldgroups, '$fieldgroups');
foreach ($fieldgroups as $one_field_group_id => $one_field_group_fields) {
// Loop through each field in each field group
#simple_fields::debug("one_field_group_fields", $one_field_group_fields);
#sf_d($one_field_group_fields);
// Get info about the field group that are saved
// (We only get ID:s posted, so no meta info about the group)
$arr_fieldgroup_info = $this->get_field_group($one_field_group_id);
foreach ($one_field_group_fields as $one_field_id => $one_field_values) {
// one_field_id = id på fältet vi sparar. t.ex. id:et på "måndag" eller "tisdag"
// one_field_values = sparade värden för detta fält, sorterat i den ordning som syns i admin
// dvs. nyaste överst (med key "new0"), och sedan key 0, key 1, osv.
#simple_fields::debug("save, loop fields, one_field_id", $one_field_id);
#simple_fields::debug("save, loop fields, one_field_values", $one_field_values);
// determine type of field we are saving
$field_info = isset($field_groups_option[$one_field_group_id]["fields"][$one_field_id]) ? $field_groups_option[$one_field_group_id]["fields"][$one_field_id] : NULL;
$field_type = $field_info["type"];
// @todo: this should be a function
#simple_fields::debug("save, field_type", $field_type);
$do_wpautop = false;
if ($field_type == "textarea" && isset($field_info["type_textarea_options"]["use_html_editor"]) && $field_info["type_textarea_options"]["use_html_editor"] == 1) {
// it's a tiny edit area, so use wpautop to fix p and br
$do_wpautop = true;
}
$do_wpautop = apply_filters("simple_fields_save_postdata_do_wpautop", $do_wpautop, $post_id);
// save entered value for each added group
$num_in_set = 0;
foreach ($one_field_values as $one_field_value) {
// $one_field_id may be "added" because it's... a special kind of input field
$arr_field_info = array();
$one_field_slug = "";
if ("added" === $one_field_id) {
$one_field_slug = "added";
} else {
#sf_d($arr_fieldgroup_info["fields"], 'fields');
foreach ($arr_fieldgroup_info["fields"] as $one_field_in_fieldgroup) {
//.........这里部分代码省略.........