/** * 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; }
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); }
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; }
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); }
/** * 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); }
/** * @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); } }
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)); } }
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); }
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; }
/** * 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; }
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; }
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 }
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; }
/** * @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); }
/** * 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))); }
/** * 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('tax_class' => get_metadata('order_item', $this->get_id(), '_tax_class', true), 'tax_status' => get_metadata('order_item', $this->get_id(), '_tax_status', true), 'total' => get_metadata('order_item', $this->get_id(), '_line_total', true), 'taxes' => get_metadata('order_item', $this->get_id(), '_line_tax_data', true))); }
/** * Read/populate data properties specific to this order item. */ public function read($id) { parent::read($id); if ($this->get_id()) { $this->set_discount(get_metadata('order_item', $this->get_id(), 'discount_amount', true)); $this->set_discount_tax(get_metadata('order_item', $this->get_id(), 'discount_amount_tax', true)); } }
/** * Intercepts a meta value request for a revision * * Returns the revision associated meta if present or the original event meta otherwise. * * @param mixed $original_value * @param int $object_id * @param string $meta_key * @param bool $single * * @return mixed */ public function intercept_post_metadata($original_value, $object_id, $meta_key, $single) { if ($object_id != $this->event_id) { return $original_value; } $revision_meta_value = get_metadata('post', $this->latest_revision->ID, $meta_key, $single); return empty($revision_meta_value) ? $original_value : $revision_meta_value; }
/** * 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('method_id' => get_metadata('order_item', $this->get_id(), 'method_id', true), 'total' => get_metadata('order_item', $this->get_id(), 'cost', true), 'taxes' => get_metadata('order_item', $this->get_id(), 'taxes', true))); }
/** * 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('discount' => get_metadata('order_item', $this->get_id(), 'discount_amount', true), 'discount_tax' => get_metadata('order_item', $this->get_id(), 'discount_amount_tax', true))); }
/** * Retrieve customer meta field for a customer. * * For internal use only. Use Give_Customer->get_meta() for public usage. * * @param int $customer_id Customer ID. * @param string $meta_key The meta key to retrieve. * @param bool $single Whether to return a single value. * * @return mixed Will be an array if $single is false. Will be value of meta data field if $single is true. * * @access private * @since 1.6 */ public function get_meta($customer_id = 0, $meta_key = '', $single = false) { $customer_id = $this->sanitize_customer_id($customer_id); if (false === $customer_id) { return false; } return get_metadata('customer', $customer_id, $meta_key, $single); }
public function subscriber_ids() { $ids = get_metadata($this->meta_type, $this->id, self::SUBSCRIBED_META_KEY, true); if (!$ids) { $ids = array(); } return $ids; }
function carbon_get_user_meta($id, $name, $type = null) { $name = $name[0] == '_' ? $name : '_' . $name; if ($type == 'complex') { return carbon_get_complex_fields('UserMeta', $name, $id); } return get_metadata('user', $id, $name, true); }
/** * 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('product_id' => get_metadata('order_item', $this->get_id(), '_product_id', true), 'variation_id' => get_metadata('order_item', $this->get_id(), '_variation_id', true), 'quantity' => get_metadata('order_item', $this->get_id(), '_qty', true), 'tax_class' => get_metadata('order_item', $this->get_id(), '_tax_class', true), 'subtotal' => get_metadata('order_item', $this->get_id(), '_line_subtotal', true), 'total' => get_metadata('order_item', $this->get_id(), '_line_total', true), 'taxes' => get_metadata('order_item', $this->get_id(), '_line_tax_data', true))); }
/** * Grabs series by custom field. Checks for other articles in the series. * Series identified custom field key 'Series' and unique value. * * @todo Fix the multiple hyphens in the series class. * @todo Allow filtering of title. * * @since 0.1 * @param array $args Array of arguments. */ function custom_field_series( $args = array() ) { global $post; $textdomain = hybrid_get_textdomain(); $series_meta = get_metadata( 'post', $post->ID, 'Series', true ); if ( $series_meta ) { $defaults = array( 'order' => 'DESC', 'orderby' => 'ID', 'include' => '', 'exclude' => '', 'post_type' => 'any', 'numberposts' => -1, 'meta_key' => 'Series', 'meta_value' => $series_meta, 'echo' => true ); $args = apply_filters( 'custom_field_series_args', $args ); $args = wp_parse_args( $args, $defaults ); $series_posts = get_posts( $args ); if ( $series_posts ) { $class = str_replace( array( '_', ' ', ' ' ) , '-', $series_meta ); $class = preg_replace('/[^A-Za-z0-9-]/', '', $class ); $class = strtolower( $class ); $series = '<div class="series series-' . $class . '">'; $series .= '<h4 class="series-title">' . __( 'Articles in this series', $textdomain) . '</h4>'; $series .= '<ul>'; foreach ( $series_posts as $serial ) { if ( $serial->ID == $post->ID ) $series .= '<li class="current-post">' . $serial->post_title . '</li>'; else $series .= '<li><a href="' . get_permalink( $serial->ID ) . '" title="' . esc_attr( $serial->post_title ) . '">' . $serial->post_title . '</a></li>'; } $series .= '</ul></div>'; } } $series = apply_filters( 'custom_field_series', $series ); if ( $args['echo'] && $series ) echo $series; elseif ( $series ) return $series; }
/** * Does sanity check on every subscription, and repairs them as needed * * @param array $subscription subscription data to be upgraded * @param integer $item_id id of order item meta * @return array a repaired subscription array */ public static function maybe_repair_subscription($subscription, $item_id) { global $wpdb; $item_meta = get_metadata('order_item', $item_id); foreach (self::integrity_check($subscription) as $function) { $subscription = call_user_func('WCS_Repair_2_0::repair_' . $function, $subscription, $item_id, $item_meta); } return $subscription; }
/** * Display the Page Builder content for the revision. * * @param $value * @param $field * @param $revision * * @return string * @since 0.1.0 */ function pootlepb_revisions_field($value, $field, $revision) { $parent_id = wp_is_post_revision($revision->ID); $panels_data = get_metadata('post', $revision->ID, 'panels_data', true); if (empty($panels_data)) { return ''; } return $GLOBALS['Pootle_Page_Builder_Render_Layout']->panels_render($parent_id, false, $panels_data); }
/** * Display the Page Builder content for the revision. * * @param $value * @param $field * @param $revision * @return string */ function siteorigin_panels_revisions_field($value, $field, $revision) { $parent_id = wp_is_post_revision($revision->ID); $panels_data = get_metadata('post', $revision->ID, 'panels_data', true); if (empty($panels_data)) { return ''; } return siteorigin_panels_render($parent_id, false, $panels_data); }
/** * Hijacks retrieving of cached oEmbed. * Returns cached data from relevant object metadata (vs postmeta) * * @since 0.9.5 * @param boolean $check Whether to retrieve postmeta or override * @param int $object_id Object ID * @param string $meta_key Object metakey * @return mixed Object's oEmbed cached data */ public static function hijack_oembed_cache_get($check, $object_id, $meta_key) { if (!self::$hijack || self::$object_id != $object_id && 1987645321 !== $object_id) { return $check; } // get cached data $data = 'options-page' === self::$object_type ? cmb_Meta_Box::get_option(self::$object_id, self::$embed_args['cache_key']) : get_metadata(self::$object_type, self::$object_id, $meta_key, true); return $data; }
function hocwp_term_get_meta($term_id, $meta_key, $single = true) { $version = hocwp_get_wp_version(); if (version_compare($version, '4.4', '>=')) { return get_term_meta($term_id, $meta_key, $single); } hocwp_term_register_termmeta_table(); return get_metadata('term', $term_id, $meta_key, $single); }