本文整理汇总了PHP中get_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP get_metadata函数的具体用法?PHP get_metadata怎么用?PHP get_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_metadata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getShortlink
/**
* Return a shortlink for a post, page, attachment, or blog.
*
* @since 1.0.0
*/
public function getShortlink($shortlink, $id, $context, $allow_slugs)
{
if (ot_get_option('bitly_service_active') == 'no') {
return false;
}
if (is_singular() && is_preview()) {
return false;
}
global $wp_query;
$post_id = '';
if ('query' == $context && is_singular()) {
$post_id = $wp_query->get_queried_object_id();
} else {
if ('post' == $context) {
$post = get_post($id);
$post_id = $post->ID;
}
}
if ($shortlink = get_metadata('post', $post_id, '_bitly_shortlink', true)) {
return $shortlink;
}
if (is_front_page() && !is_paged()) {
return apply_filters('bitly_front_page', false);
}
$url = get_permalink($post_id);
$domain = ot_get_option('bitly_domain');
$this->login(ot_get_option('bitly_login'));
$this->apiKey(ot_get_option('bitly_api_key'));
$shortlink = $this->shorten($url, $domain);
if (!empty($shortlink)) {
update_metadata('post', $post_id, '_bitly_shortlink', $shortlink);
return $shortlink;
}
return false;
}
示例2: get_formatted_address
function get_formatted_address($post_id)
{
$loc_data = get_metadata('post', $post_id);
// set up the address lines
$line1 = $loc_data['_dbd_address1'][0];
$line2 = $loc_data['_dbd_address2'][0];
$line3 = $loc_data['_dbd_city'][0];
if ($line3) {
$line3 .= ', ';
}
$line3 .= $loc_data['_dbd_state'][0];
if ($loc_data['_dbd_postalcode']) {
$line3 .= ' ' . $loc_data['_dbd_postalcode'][0];
}
// build the address
$address = [];
if ($line1) {
$address[] = $line1;
}
if ($line2) {
$address[] = $line2;
}
if ($line3) {
$address[] = $line3;
}
return implode('<br/>', $address);
}
示例3: acf_get_metadata
function acf_get_metadata($post_id = 0, $name = '', $hidden = false)
{
// vars
$value = null;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if (!$info['id']) {
return $value;
}
// option
if ($info['type'] === 'option') {
$name = $prefix . $post_id . '_' . $name;
$value = get_option($name, null);
// meta
} else {
$name = $prefix . $name;
$meta = get_metadata($info['type'], $info['id'], $name, false);
if (isset($meta[0])) {
$value = $meta[0];
}
}
// return
return $value;
}
示例4: EM_Person
function EM_Person($person_id = false, $username = false)
{
if (is_array($person_id)) {
if (array_key_exists('person_id', $person_id)) {
$person_id = $person_id['person_id'];
} elseif (array_key_exists('user_id', $person_id)) {
$person_id = $person_id['user_id'];
} else {
$person_id = $person_id['ID'];
}
} elseif (is_object($person_id) && get_class($person_id) == 'WP_User') {
$person_id = $person_id->ID;
//create new object if passed a wp_user
}
if ($username) {
parent::WP_User($person_id, $username);
} elseif (is_numeric($person_id) && $person_id == 0) {
$this->ID = 0;
$this->display_name = 'Non-Registered User';
$this->user_email = 'n/a';
} else {
parent::WP_User($person_id);
}
$this->phone = get_metadata('user', $this->ID, 'dbem_phone', true);
//extra field for EM
do_action('em_person', $this, $person_id, $username);
}
示例5: get_meta
/**
* Retrieve term meta field for a term.
*
*/
public static function get_meta($term_id, $key, $single = false)
{
if (current_theme_supports('extended-taxonomies')) {
return get_post_meta(self::get_post_for_extended_term($term_id)->ID, $key, $single);
}
return get_metadata('taxonomy', $term_id, $key, $single);
}
示例6: get
/**
* @param string $meta_type
* @param int $object_id
* @param string $multi_key 'abc' or 'ab/c/def'
* @param null|mixed $default_value If no option found in the database, this value will be returned
* @param bool|null $get_original_value Original value from db, no changes and translations
*
* @return mixed|null
*/
public static function get($meta_type, $object_id, $multi_key, $default_value = null, $get_original_value = null)
{
if ($get_original_value === null) {
$get_original_value = is_admin();
}
if (empty($multi_key)) {
trigger_error('Key not specified', E_USER_WARNING);
return null;
}
$multi_key = explode('/', $multi_key);
$key = array_shift($multi_key);
$multi_key = implode('/', $multi_key);
$cache_key = self::$cache_key . '/' . $meta_type . '/' . $object_id . '/' . $key;
try {
$values = FW_Cache::get($cache_key);
} catch (FW_Cache_Not_Found_Exception $e) {
$values = array();
$values['original'] = get_metadata($meta_type, $object_id, $key, true);
$values['prepared'] = fw_prepare_option_value($values['original']);
FW_Cache::set($cache_key, $values);
}
if (empty($multi_key)) {
return $values[$get_original_value ? 'original' : 'prepared'];
} else {
return fw_akg($multi_key, $values[$get_original_value ? 'original' : 'prepared'], $default_value);
}
}
示例7: __construct
public function __construct($menu_term_slug)
{
parent::__construct();
$menu = wp_get_nav_menu_object($menu_term_slug);
if (!empty($menu)) {
$this->menu = $menu;
$nav_menu_items = wp_get_nav_menu_items($this->menu->term_id);
cfd_tmp_dbg('nav_menu_items_raw.txt', $nav_menu_items, 'print');
foreach ($nav_menu_items as $item) {
$menu_item = wp_setup_nav_menu_item($item);
$menu_item->metadata = get_metadata('post', $item->ID);
foreach ($menu_item->metadata as $key => &$value) {
$value[0] = maybe_unserialize($value[0]);
}
if ($menu_item->type == 'post_type') {
$menu_item->parent = get_post($menu_item->metadata['_menu_item_object_id'][0]);
} elseif ($menu_item->type == 'taxonomy' && (!property_exists($menu, 'object') || $menu->object != 'custom')) {
$menu_item->term = get_term($menu_item->metadata['_menu_item_object_id'][0], $menu_item->metadata['_menu_item_object'][0]);
}
$this->items[] = $menu_item;
}
} else {
throw new Exception(__('Invalid menu id', 'cf-deploy') . ': ' . esc_attr($menu_term_slug));
}
}
示例8: __construct
function __construct($person_id = 0, $username = '', $blog_id = '')
{
if (is_array($person_id)) {
if (array_key_exists('person_id', $person_id)) {
$person_id = $person_id['person_id'];
} elseif (array_key_exists('user_id', $person_id)) {
$person_id = $person_id['user_id'];
} else {
$person_id = $person_id['ID'];
}
} elseif (is_object($person_id) && get_class($person_id) == 'WP_User') {
$person_id = $person_id->ID;
//create new object if passed a wp_user
}
if ($username) {
parent::__construct($person_id, $username);
} elseif (is_numeric($person_id) && $person_id <= 0) {
$this->data = new stdClass();
$this->ID = 0;
$this->display_name = 'Non-Registered User';
$this->user_email = '';
} else {
parent::__construct($person_id);
}
$this->phone = wp_kses_data(get_metadata('user', $this->ID, 'dbem_phone', true));
//extra field for EM
do_action('em_person', $this, $person_id, $username);
}
示例9: build_news_list
public function build_news_list()
{
$news_list = '';
$news_items = dn_utilities::get_news_items();
// show message for no news items if none found
if (!$news_items) {
return $this->build_no_news_message();
}
// display all news items
foreach ($news_items as $news_item) {
$date = date('l, M. jS', strtotime($news_item->post_date));
// format the url, overriding with a custom value if provided
$url = $news_item->link;
$target = '';
$custom_url = get_metadata('post', $news_item->ID)["_dn_custom_url"][0];
if ($custom_url) {
$url = $custom_url;
$target = '_new';
}
// add the news item
$news_list .= '<li>';
if ($news_item->thumb) {
$news_list .= '<div class="event-photo"><a href="' . $url . '" target="' . $target . '">' . $news_item->thumb . '</a></div>';
}
$news_list .= '<h3 class="title">' . $news_item->post_title . '</h3>';
$news_list .= '<div class="date">' . $date . '</div>';
$news_list .= '<div class="description">' . $news_item->post_excerpt . '</div>';
$news_list .= '<a class="details-link" href="' . $url . '" target="' . $target . '"><span>Details</span></a>';
$news_list .= '</li>';
}
$news_list = '<ul class="news">' . $news_list . '</ul>';
return $news_list;
}
示例10: wpsc_get_meta_by_timestamp
/**
* Calls function for each meta matching the timestamp criteria. Callback function
* will get a single parameter that is an object representing the meta.
*
* @since 3.8.12
*
* @param string $meta_object_type the WordPress meta object type
* @param int|string $timestamp timestamp to compare meta items against, if int a unix timestamp is assumed,
* if string a MYSQL timestamp is assumed
* @param string $comparison any one of the supported comparison operators,(=,>=,>,<=,<,<>,!=)
* @param string $meta_key restrict testing of meta to the values with the specified meta key
* @return array metadata matching the query
*/
function wpsc_get_meta_by_timestamp($meta_object_type, $timestamp = 0, $comparison = '>', $meta_key = '')
{
global $wpdb;
$meta_table = _wpsc_meta_table_name($meta_object_type);
$id_field_name = _wpsc_meta_key_name('visitor');
if ($timestamp == 0 || empty($timestamp)) {
$sql = 'SELECT ' . $id_field_name . ' AS id FROM ` ' . $meta_table . '` ';
} else {
// validate the comparison operator
if (!in_array($comparison, array('=', '>=', '>', '<=', '<', '<>', '!='))) {
return false;
}
if (is_int($timestamp)) {
$timestamp = date('Y-m-d H:i:s', $timestamp);
}
$sql = 'SELECT ' . $id_field_name . ' as id FROM `' . $meta_table . '` where meta_timestamp ' . $comparison . ' "%s"';
$sql = $wpdb->prepare($sql, $timestamp);
}
if (!empty($meta_key)) {
$sql .= ' AND meta_key = %s';
$sql = $wpdb->prepare($sql, $meta_key);
}
$meta_item_ids = $wpdb->get_col($sql, 0);
$meta_item_ids = array_map('intval', $meta_item_ids);
$meta_item_ids = apply_filters('wpsc_get_meta_by_timestamp', $meta_item_ids, $meta_object_type, $meta_key, $timestamp, $comparison);
$metas = array();
foreach ($meta_item_ids as $id) {
$metas[$id] = get_metadata($meta_object_type, $id, $meta_key);
}
return $metas;
}
示例11: acf_get_metadata
function acf_get_metadata($post_id, $name)
{
// vars
$value = null;
// post
if (is_numeric($post_id)) {
$meta = get_metadata('post', $post_id, $name, false);
if (isset($meta[0])) {
$value = $meta[0];
}
// user
} elseif (substr($post_id, 0, 5) == 'user_') {
$user_id = (int) substr($post_id, 5);
$meta = get_metadata('user', $user_id, $name, false);
if (isset($meta[0])) {
$value = $meta[0];
}
// comment
} elseif (substr($post_id, 0, 8) == 'comment_') {
$comment_id = (int) substr($post_id, 8);
$meta = get_metadata('comment', $comment_id, $name, false);
if (isset($meta[0])) {
$value = $meta[0];
}
} else {
$value = get_option("{$post_id}_{$name}", null);
}
// return
return $value;
}
示例12: payment_post_meta
public function payment_post_meta($payment_id)
{
ini_set('xdebug.var_display_max_depth', 5);
ini_set('xdebug.var_display_max_children', 256);
ini_set('xdebug.var_display_max_data', 1024);
?>
<div id="edd-payment-meta" class="postbox">
<h3 class="hndle"><?php
_e('Payment Postmeta Items', 'edd-dev-tools');
?>
</h3>
<div class="inside">
<div style="overlfow:auto">
<?php
$post_meta = get_metadata('post', $payment_id);
?>
<pre style="overflow: auto;word-wrap: break-word;">
<?php
foreach ($post_meta as $key => $value) {
if (is_serialized($value[0])) {
echo $key . '=> ';
var_dump(unserialize($value[0]));
} else {
echo $key . ' => ' . $value[0] . "\n";
}
}
?>
</pre>
</div>
</div>
</div>
<?php
}
示例13: get_formatted_contact_info
function get_formatted_contact_info($post_id)
{
$contact_data = get_metadata('post', $post_id);
// show the name on the first line or show that no name was provided
$name = $contact_data['_dbd_name'][0];
$name || ($name = 'No Name Set');
// show which fields are set on the 2nd line
$options_set = [];
if ($contact_data['_dbd_phone'][0]) {
$options_set[] = '<span class="dashicons-before dashicons-format-chat" title="' . esc_attr($contact_data['_dbd_phone'][0]) . '"></span>';
}
if ($contact_data['_dbd_email'][0]) {
$options_set[] = '<span class="dashicons-before dashicons-email" title="' . esc_attr($contact_data['_dbd_email'][0]) . '"></span>';
}
if ($contact_data['_dbd_website'][0]) {
$options_set[] = '<span class="dashicons-before dashicons-admin-site" title="' . esc_attr($contact_data['_dbd_website'][0]) . '"></span>';
}
if ($contact_data['_dbd_facebook'][0]) {
$options_set[] = '<span class="dashicons-before dashicons-facebook" title="' . esc_attr($contact_data['_dbd_facebook'][0]) . '"></span>';
}
$options = 'No contact fields set.';
if ($options_set) {
$options = implode(' ', $options_set);
}
return $name . '<br/>' . $options;
}
示例14: test_slashed_key_for_existing_metadata
/**
* @ticket 35795
*/
public function test_slashed_key_for_existing_metadata()
{
global $wpdb;
add_metadata('post', 123, wp_slash('foo\\foo'), 'bar');
update_metadata('post', 123, wp_slash('foo\\foo'), 'baz');
$found = get_metadata('post', 123, 'foo\\foo', true);
$this->assertSame('baz', $found);
}
示例15: read
/**
* Read/populate data properties specific to this order item.
*/
public function read($id)
{
parent::read($id);
if (!$this->get_id()) {
return;
}
$this->set_props(array('rate_id' => get_metadata('order_item', $this->get_id(), 'rate_id', true), 'label' => get_metadata('order_item', $this->get_id(), 'label', true), 'compound' => get_metadata('order_item', $this->get_id(), 'compound', true), 'tax_total' => get_metadata('order_item', $this->get_id(), 'tax_amount', true), 'shipping_tax_total' => get_metadata('order_item', $this->get_id(), 'shipping_tax_amount', true)));
}