d user data object. * * @param string $option User option name. * @param int $user Optional. User ID. * @param bool $check_blog_options Whether to check for an option in the options table if a per-user option does not exist. Default is true. * @return mixed */ function get_user_option( $option, $user = 0, $check_blog_options = true ) { global $wpdb; $option = preg_replace('|[^a-z0-9_]|i', '', $option); if ( empty($user) ) $user = wp_get_current_user(); else $user = get_userdata($user); if ( isset( $user->{$wpdb->prefix . $option} ) ) // Blog specific $result = $user->{$wpdb->prefix . $option}; elseif ( isset( $user->{$option} ) ) // User specific and cross-blog $result = $user->{$option}; elseif ( $check_blog_options ) // Blog global $result = get_option( $option ); else $result = false; return apply_filters("get_user_option_{$option}", $result, $option, $user); } /** * Update user option with global blog capability. * * User options are just like user metadata except that they have support for * global blog options. If the 'global' parameter is false, which it is by default * it will prepend the WordPress table prefix to the option name. * * @since 2.0.0 * @uses $wpdb WordPress database object for queries * * @param int $user_id User ID * @param string $option_name User option name. * @param mixed $newvalue User option value. * @param bool $global Optional. Whether option name is blog specific or not. * @return unknown */ function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { global $wpdb; if ( !$global ) $option_name = $wpdb->prefix . $option_name; return update_usermeta( $user_id, $option_name, $newvalue ); } /** * Get users for the blog. * * For setups that use the multi-blog feature. Can be used outside of the * multi-blog feature. * * @since 2.2.0 * @uses $wpdb WordPress database object for queries * @uses $blog_id The Blog id of the blog for those that use more than one blog * * @param int $id Blog ID. * @return array List of users that are part of that Blog ID */ function get_users_of_blog( $id = '' ) { global $wpdb, $blog_id; if ( empty($id) ) $id = (int) $blog_id; $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$wpdb->prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ); return $users; } // // User meta functions // /** * Remove user meta data. * * @since 2.0.0 * @uses $wpdb WordPress database object for queries. * * @param int $user_id User ID. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. * @return bool True deletion completed and false if user_id is not a number. */ function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { global $wpdb; if ( !is_numeric( $user_id ) ) return false; $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if ( is_array($meta_value) || is_object($meta_value) ) $meta_value = serialize($meta_value); $meta_value = trim( $meta_value ); $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); if ( $cur && $cur->umeta_id ) do_action( 'delete_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); if ( ! empty($meta_value) ) $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id, $meta_key, $meta_value) ); else $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); wp_cache_delete($user_id, 'users'); if ( $cur && $cur->umeta_id ) do_action( 'deleted_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); return true; } /** * Retrieve user metadata. * * If $user_id is not a number, then the function will fail over with a 'false' * boolean return value. Other returned values depend on whether there is only * one item to be returned, which be that single item type. If there is more * than one metadata value, then it will be list of metadata values. * * @since 2.0.0 * @uses $wpdb WordPress database object for queries. * * @param int $user_id User ID * @param string $meta_key Optional. Metadata key. * @return mixed */ function get_usermeta( $user_id, $meta_key = '') { global $wpdb; $user_id = (int) $user_id; if ( !$user_id ) return false; if ( !empty($meta_key) ) { $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); $user = wp_cache_get($user_id, 'users'); // Check the cached user object if ( false !== $user && isset($user->$meta_key) ) $metas = array($user->$meta_key); else $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); } else { $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d", $user_id) ); } if ( empty($metas) ) { if ( empty($meta_key) ) return array(); else return ''; } $metas = array_map('maybe_unserialize', $metas); if ( count($metas) == 1 ) return $metas[0]; else return $metas; } /** * Update metadata of user. * * There is no need to serialize values, they will be serialized if it is * needed. The metadata key can only be a string with underscores. All else will * be removed. * * Will remove the metadata, if the meta value is empty. * * @since 2.0.0 * @uses $wpdb WordPress database object for queries * * @param int $user_id User ID * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. * @return bool True on successful update, false on failure. */ function update_usermeta( $user_id, $meta_key, $meta_value ) { global $wpdb; if ( !is_numeric( $user_id ) ) return false; $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); /** @todo Might need fix because usermeta data is assumed to be already escaped */ if ( is_string($meta_value) ) $meta_value = stripslashes($meta_value); $meta_value = maybe_serialize($meta_value); if (empty($meta_value)) { return delete_usermeta($user_id, $meta_key); } $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); if ( $cur ) do_action( 'update_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); if ( !$cur ) $wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value') ); else if ( $cur->meta_value != $meta_value ) $wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key') ); else return false; wp_cache_delete($user_id, 'users'); if ( !$cur ) do_action( 'added_usermeta', $wpdb->insert_id, $user_id, $meta_key, $meta_value ); else do_action( 'updated_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); return true; } // // Private helper functions // /** * Setup global user vars. * * Used by set_current_user() for back compat. Might be deprecated in the * future. * * @since 2.0.4 * @global string $userdata User description. * @global string $user_login The user username for logging in * @global int $user_level The level of the user * @global int $user_ID The ID of the user * @global string $user_email The email address of the user * @global string $user_url The url in the user's profile * @global string $user_pass_md5 MD5 of the user's password * @global string $user_identity The display name of the user * * @param int $for_user_id Optional. User ID to setup global data. */ function setup_userdata($for_user_id = '') { global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity; if ( '' == $for_user_id ) $user = wp_get_current_user(); else $user = new WP_User($for_user_id); if ( 0 == $user->ID ) return; $userdata = $user->data; $user_login = $user->user_login; $user_level = (int) isset($user->user_level) ? $user->user_level : 0; $user_ID = (int) $user->ID; $user_email = $user->user_email; $user_url = $user->user_url; $user_pass_md5 = md5($user->user_pass); $user_identity = $user->display_name; } /** * Create dropdown HTML content of users. * * The content can either be displayed, which it is by default or retrieved by * setting the 'echo' argument. The 'include' and 'exclude' arguments do not * need to be used; all users will be displayed in that case. Only one can be * used, either 'include' or 'exclude', but not both. * * The available arguments are as follows: *
    *
  1. show_option_all - Text to show all and whether HTML option exists.
  2. *
  3. show_option_none - Text for show none and whether HTML option exists. *
  4. *
  5. orderby - SQL order by clause for what order the users appear. Default is * 'display_name'.
  6. *
  7. order - Default is 'ASC'. Can also be 'DESC'.
  8. *
  9. include - User IDs to include.
  10. *
  11. exclude - User IDs to exclude.
  12. *
  13. multi - Default is 'false'. Whether to skip the ID attribute on the 'select' element.
  14. *
  15. show - Default is 'display_name'. User table column to display. If the selected item is empty then the user_login will be displayed in parentesis
  16. *
  17. echo - Default is '1'. Whether to display or retrieve content.
  18. *
  19. selected - Which User ID is selected.
  20. *
  21. name - Default is 'user'. Name attribute of select element.
  22. *
  23. class - Class attribute of select element.
  24. *
* * @since 2.3.0 * @uses $wpdb WordPress database object for queries * * @param string|array $args Optional. Override defaults. * @return string|null Null on display. String of HTML content on retrieve. */ function wp_dropdown_users( $args = '' ) { global $wpdb; $defaults = array( 'show_option_all' => '', 'show_option_none' => '', 'orderby' => 'display_name', 'order' => 'ASC', 'include' => '', 'exclude' => '', 'multi' => 0, 'show' => 'display_name', 'echo' => 1, 'selected' => 0, 'name' => 'user', 'class' => '' ); $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $query = "SELECT * FROM $wpdb->users"; $query_where = array(); if ( is_array($include) ) $include = join(',', $include); $include = preg_replace('/[^0-9,]/', '', $include); // (int) if ( $include ) $query_where[] = "ID IN ($include)"; if ( is_array($exclude) ) $exclude = join(',', $exclude); $exclude = preg_replace('/[^0-9,]/', '', $exclude); // (int) if ( $exclude ) $query_where[] = "ID NOT IN ($exclude)"; if ( $query_where ) $query .= " WHERE " . join(' AND', $query_where); $query .= " ORDER BY $orderby $order"; $users = $wpdb->get_results( $query ); $output = ''; if ( !empty($users) ) { $id = $multi ? "" : "id='$name'"; $output = ""; } $output = apply_filters('wp_dropdown_users', $output); if ( $echo ) echo $output; return $output; } /** * Add user meta data as properties to given user object. * * The finished user data is cached, but the cache is not used to fill in the * user data for the given object. Once the function has been used, the cache * should be used to retrieve user data. The purpose seems then to be to ensure * that the data in the object is always fresh. * * @access private * @since 2.5.0 * @uses $wpdb WordPress database object for queries * * @param object $user The user data object. */ function _fill_user( &$user ) { global $wpdb; $show = $wpdb->hide_errors(); $metavalues = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = %d", $user->ID)); $wpdb->show_errors($show); if ( $metavalues ) { foreach ( (array) $metavalues as $meta ) { $value = maybe_unserialize($meta->meta_value); $user->{$meta->meta_key} = $value; } } $level = $wpdb->prefix . 'user_level'; if ( isset( $user->{$level} ) ) $user->user_level = $user->{$level}; // For backwards compat. if ( isset($user->first_name) ) $user->user_firstname = $user->first_name; if ( isset($user->last_name) ) $user->user_lastname = $user->last_name; if ( isset($user->description) ) $user->user_description = $user->description; wp_cache_add($user->ID, $user, 'users'); wp_cache_add($user->user_login, $user->ID, 'userlogins'); wp_cache_add($user->user_email, $user->ID, 'useremail'); wp_cache_add($user->user_nicename, $user->ID, 'userslugs'); } /** * Sanitize every user field. * * If the context is 'raw', then the user object or array will get minimal santization of the int fields. * * @since 2.3.0 * @uses sanitize_user_field() Used to sanitize the fields. * * @param object|array $user The User Object or Array * @param string $context Optional, default is 'display'. How to sanitize user fields. * @return object|array The now sanitized User Object or Array (will be the same type as $user) */ function sanitize_user_object($user, $context = 'display') { if ( is_object($user) ) { if ( !isset($user->ID) ) $user->ID = 0; if ( isset($user->data) ) $vars = get_object_vars( $user->data ); else $vars = get_object_vars($user); foreach ( array_keys($vars) as $field ) { if ( is_string($user->$field) || is_numeric($user->$field) ) $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context); } $user->filter = $context; } else { if ( !isset($user['ID']) ) $user['ID'] = 0; foreach ( array_keys($user) as $field ) $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context); $user['filter'] = $context; } return $user; } /** * Sanitize user field based on context. * * Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The * 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display' * when calling filters. * * @since 2.3.0 * @uses apply_filters() Calls 'edit_$field' and '${field_no_prefix}_edit_pre' passing $value and * $user_id if $context == 'edit' and field name prefix == 'user_'. * * @uses apply_filters() Calls 'edit_user_$field' passing $value and $user_id if $context == 'db'. * @uses apply_filters() Calls 'pre_$field' passing $value if $context == 'db' and field name prefix == 'user_'. * @uses apply_filters() Calls '${field}_pre' passing $value if $context == 'db' and field name prefix != 'user_'. * * @uses apply_filters() Calls '$field' passing $value, $user_id and $context if $context == anything * other than 'raw', 'edit' and 'db' and field name prefix == 'user_'. * @uses apply_filters() Calls 'user_$field' passing $value if $context == anything other than 'raw', * 'edit' and 'db' and field name prefix != 'user_'. * * @param string $field The user Object field name. * @param mixed $value The user Object value. * @param int $user_id user ID. * @param string $context How to sanitize user fields. Looks for 'raw', 'edit', 'db', 'display', * 'attribute' and 'js'. * @return mixed Sanitized value. */ function sanitize_user_field($field, $value, $user_id, $context) { $int_fields = array('ID'); if ( in_array($field, $int_fields) ) $value = (int) $value; if ( 'raw' == $context ) return $value; if ( !is_string($value) && !is_numeric($value) ) return $value; $prefixed = false; if ( false !== strpos($field, 'user_') ) { $prefixed = true; $field_no_prefix = str_replace('user_', '', $field); } if ( 'edit' == $context ) { if ( $prefixed ) { $value = apply_filters("edit_$field", $value, $user_id); } else { $value = apply_filters("edit_user_$field", $value, $user_id); } if ( 'description' == $field ) $value = esc_html($value); else $value = esc_attr($value); } else if ( 'db' == $context ) { if ( $prefixed ) { $value = apply_filters("pre_$field", $value); } else { $value = apply_filters("pre_user_$field", $value); } } else { // Use display filters by default. if ( $prefixed ) $value = apply_filters($field, $value, $user_id, $context); else $value = apply_filters("user_$field", $value, $user_id, $context); } if ( 'user_url' == $field ) $value = esc_url($value); if ( 'attribute' == $context ) $value = esc_attr($value); else if ( 'js' == $context ) $value = esc_js($value); return $value; } ?> ject = get_post($id); if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) { $parent = get_post($object->post_parent); if ( 'page' == $parent->post_type ) $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front else $parentlink = get_permalink( $object->post_parent ); if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) $name = 'attachment/' . $object->post_name; // // is paged so we use the explicit attachment marker else $name = $object->post_name; if (strpos($parentlink, '?') === false) $link = user_trailingslashit( trailingslashit($parentlink) . $name ); } if (! $link ) { $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id"; } return apply_filters('attachment_link', $link, $id); } /** * Retrieve the permalink for the year archives. * * @since 1.5.0 * * @param int|bool $year False for current year or year for permalink. * @return string */ function get_year_link($year) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); $yearlink = $wp_rewrite->get_year_permastruct(); if ( !empty($yearlink) ) { $yearlink = str_replace('%year%', $year, $yearlink); return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year); } else { return apply_filters('year_link', trailingslashit(get_option('home')) . '?m=' . $year, $year); } } /** * Retrieve the permalink for the month archives with year. * * @since 1.0.0 * * @param bool|int $year False for current year. Integer of year. * @param bool|int $month False for current month. Integer of month. * @return string */ function get_month_link($year, $month) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); if ( !$month ) $month = gmdate('m', time()+(get_option('gmt_offset') * 3600)); $monthlink = $wp_rewrite->get_month_permastruct(); if ( !empty($monthlink) ) { $monthlink = str_replace('%year%', $year, $monthlink); $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month); } else { return apply_filters('month_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2), $year, $month); } } /** * Retrieve the permalink for the day archives with year and month. * * @since 1.0.0 * * @param bool|int $year False for current year. Integer of year. * @param bool|int $month False for current month. Integer of month. * @param bool|int $day False for current day. Integer of day. * @return string */ function get_day_link($year, $month, $day) { global $wp_rewrite; if ( !$year ) $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); if ( !$month ) $month = gmdate('m', time()+(get_option('gmt_offset') * 3600)); if ( !$day ) $day = gmdate('j', time()+(get_option('gmt_offset') * 3600)); $daylink = $wp_rewrite->get_day_permastruct(); if ( !empty($daylink) ) { $daylink = str_replace('%year%', $year, $daylink); $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day); } else { return apply_filters('day_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day); } } /** * Retrieve the permalink for the feed type. * * @since 1.5.0 * * @param string $feed Optional, defaults to default feed. Feed type. * @return string */ function get_feed_link($feed = '') { global $wp_rewrite; $permalink = $wp_rewrite->get_feed_permastruct(); if ( '' != $permalink ) { if ( false !== strpos($feed, 'comments_') ) { $feed = str_replace('comments_', '', $feed); $permalink = $wp_rewrite->get_comment_feed_permastruct(); } if ( get_default_feed() == $feed ) $feed = ''; $permalink = str_replace('%feed%', $feed, $permalink); $permalink = preg_replace('#/+#', '/', "/$permalink"); $output = get_option('home') . user_trailingslashit($permalink, 'feed'); } else { if ( empty($feed) ) $feed = get_default_feed(); if ( false !== strpos($feed, 'comments_') ) $feed = str_replace('comments_', 'comments-', $feed); $output = trailingslashit(get_option('home')) . "?feed={$feed}"; } return apply_filters('feed_link', $output, $feed); } /** * Retrieve the permalink for the post comments feed. * * @since 2.2.0 * * @param int $post_id Optional. Post ID. * @param string $feed Optional. Feed type. * @return string */ function get_post_comments_feed_link($post_id = '', $feed = '') { global $id; if ( empty($post_id) ) $post_id = (int) $id; if ( empty($feed) ) $feed = get_default_feed(); if ( '' != get_option('permalink_structure') ) { $url = trailingslashit( get_permalink($post_id) ) . 'feed'; if ( $feed != get_default_feed() ) $url .= "/$feed"; $url = user_trailingslashit($url, 'single_feed'); } else { $type = get_post_field('post_type', $post_id); if ( 'page' == $type ) $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id"; else $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id"; } return apply_filters('post_comments_feed_link', $url); } /** * Display the comment feed link for a post. * * Prints out the comment feed link for a post. Link text is placed in the * anchor. If no link text is specified, default text is used. If no post ID is * specified, the current post is used. * * @package WordPress * @subpackage Feed * @since 2.5.0 * * @param string $link_text Descriptive text. * @param int $post_id Optional post ID. Default to current post. * @param string $feed Optional. Feed format. * @return string Link to the comment feed for the current post. */ function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { $url = get_post_comments_feed_link($post_id, $feed); if ( empty($link_text) ) $link_text = __('Comments Feed'); echo apply_filters( 'post_comments_feed_link_html', "$link_text", $post_id, $feed ); } /** * Retrieve the feed link for a given author. * * Returns a link to the feed for all posts by a given author. A specific feed * can be requested or left blank to get the default feed. * * @package WordPress * @subpackage Feed * @since 2.5.0 * * @param int $author_id ID of an author. * @param string $feed Optional. Feed type. * @return string Link to the feed for the author specified by $author_id. */ function get_author_feed_link( $author_id, $feed = '' ) { $author_id = (int) $author_id; $permalink_structure = get_option('permalink_structure'); if ( empty($feed) ) $feed = get_default_feed(); if ( '' == $permalink_structure ) { $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id; } else { $link = get_author_posts_url($author_id); if ( $feed == get_default_feed() ) $feed_link = 'feed'; else $feed_link = "feed/$feed"; $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); } $link = apply_filters('author_feed_link', $link, $feed); return $link; } /** * Retrieve the feed link for a category. * * Returns a link to the feed for all post in a given category. A specific feed * can be requested or left blank to get the default feed. * * @package WordPress * @subpackage Feed * @since 2.5.0 * * @param int $cat_id ID of a category. * @param string $feed Optional. Feed type. * @return string Link to the feed for the category specified by $cat_id. */ function get_category_feed_link($cat_id, $feed = '') { $cat_id = (int) $cat_id; $category = get_category($cat_id); if ( empty($category) || is_wp_error($category) ) return false; if ( empty($feed) ) $feed = get_default_feed(); $permalink_structure = get_option('permalink_structure'); if ( '' == $permalink_structure ) { $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id; } else { $link = get_category_link($cat_id); if( $feed == get_default_feed() ) $feed_link = 'feed'; else $feed_link = "feed/$feed"; $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); } $link = apply_filters('category_feed_link', $link, $feed); return $link; } /** * Retrieve permalink for feed of tag. * * @since 2.3.0 * * @param int $tag_id Tag ID. * @param string $feed Optional. Feed type. * @return string */ function get_tag_feed_link($tag_id, $feed = '') { $tag_id = (int) $tag_id; $tag = get_tag($tag_id); if ( empty($tag) || is_wp_error($tag) ) return false; $permalink_structure = get_option('permalink_structure'); if ( empty($feed) ) $feed = get_default_feed(); if ( '' == $permalink_structure ) { $link = trailingslashit(get_option('home')) . "?feed=$feed&tag=" . $tag->slug; } else { $link = get_tag_link($tag->term_id); if ( $feed == get_default_feed() ) $feed_link = 'feed'; else $feed_link = "feed/$feed"; $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); } $link = apply_filters('tag_feed_link', $link, $feed); return $link; } /** * Retrieve edit tag link. * * @since 2.7.0 * * @param int $tag_id Tag ID * @return string */ function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { $tag = get_term($tag_id, $taxonomy); if ( !current_user_can('manage_categories') ) return; $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&tag_ID=' . $tag->term_id); return apply_filters( 'get_edit_tag_link', $location ); } /** * Display or retrieve edit tag link with formatting. * * @since 2.7.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param int|object $tag Tag object or ID * @return string|null HTML content, if $echo is set to false. */ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { $tag = get_term($tag, 'post_tag'); if ( !current_user_can('manage_categories') ) return; if ( empty($link) ) $link = __('Edit This'); $link = '' . $link . ''; echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; } /** * Retrieve the permalink for the feed of the search results. * * @since 2.5.0 * * @param string $search_query Optional. Search query. * @param string $feed Optional. Feed type. * @return string */ function get_search_feed_link($search_query = '', $feed = '') { if ( empty($search_query) ) $search = esc_attr( urlencode(get_search_query()) ); else $search = esc_attr( urlencode(stripslashes($search_query)) ); if ( empty($feed) ) $feed = get_default_feed(); $link = trailingslashit(get_option('home')) . "?s=$search&feed=$feed"; $link = apply_filters('search_feed_link', $link); return $link; } /** * Retrieve the permalink for the comments feed of the search results. * * @since 2.5.0 * * @param string $search_query Optional. Search query. * @param string $feed Optional. Feed type. * @return string */ function get_search_comments_feed_link($search_query = '', $feed = '') { if ( empty($search_query) ) $search = esc_attr( urlencode(get_search_query()) ); else $search = esc_attr( urlencode(stripslashes($search_query)) ); if ( empty($feed) ) $feed = get_default_feed(); $link = trailingslashit(get_option('home')) . "?s=$search&feed=comments-$feed"; $link = apply_filters('search_feed_link', $link); return $link; } /** * Retrieve edit posts link for post. * * Can be used within the WordPress loop or outside of it. Can be used with * pages, posts, attachments, and revisions. * * @since 2.3.0 * * @param int $id Optional. Post ID. * @param string $context Optional, default to display. How to write the '&', defaults to '&'. * @return string */ function get_edit_post_link( $id = 0, $context = 'display' ) { if ( !$post = &get_post( $id ) ) return; if ( 'display' == $context ) $action = 'action=edit&'; else $action = 'action=edit&'; switch ( $post->post_type ) : case 'page' : if ( !current_user_can( 'edit_page', $post->ID ) ) return; $file = 'page'; $var = 'post'; break; case 'attachment' : if ( !current_user_can( 'edit_post', $post->ID ) ) return; $file = 'media'; $var = 'attachment_id'; break; case 'revision' : if ( !current_user_can( 'edit_post', $post->ID ) ) return; $file = 'revision'; $var = 'revision'; $action = ''; break; default : if ( !current_user_can( 'edit_post', $post->ID ) ) return apply_filters( 'get_edit_post_link', '', $post->ID, $context );; $file = 'post'; $var = 'post'; break; endswitch; return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context ); } /** * Display edit post link for post. * * @since 1.0.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param int $id Optional. Post ID. */ function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) { if ( !$post = &get_post( $id ) ) return; if ( !$url = get_edit_post_link( $post->ID ) ) return; if ( null === $link ) $link = __('Edit This'); $link = '' . $link . ''; echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after; } /** * Retrieve delete posts link for post. * * Can be used within the WordPress loop or outside of it. Can be used with * pages, posts, attachments, and revisions. * * @since 2.9.0 * * @param int $id Optional. Post ID. * @param string $context Optional, default to display. How to write the '&', defaults to '&'. * @return string */ function get_delete_post_link($id = 0, $context = 'display') { if ( !$post = &get_post( $id ) ) return; if ( 'display' == $context ) $action = 'action=trash&'; else $action = 'action=trash&'; switch ( $post->post_type ) : case 'page' : if ( !current_user_can( 'delete_page', $post->ID ) ) return; $file = 'page'; $var = 'post'; break; case 'attachment' : if ( !current_user_can( 'delete_post', $post->ID ) ) return; $file = 'media'; $var = 'attachment_id'; break; case 'revision' : if ( !current_user_can( 'delete_post', $post->ID ) ) return; $file = 'revision'; $var = 'revision'; $action = ''; break; default : if ( !current_user_can( 'edit_post', $post->ID ) ) return apply_filters( 'get_delete_post_link', '', $post->ID, $context );; $file = 'post'; $var = 'post'; break; endswitch; return apply_filters( 'get_delete_post_link', wp_nonce_url( admin_url("$file.php?{$action}$var=$post->ID"), "trash-{$file}_" . $post->ID ), $context ); } /** * Retrieve edit comment link. * * @since 2.3.0 * * @param int $comment_id Optional. Comment ID. * @return string */ function get_edit_comment_link( $comment_id = 0 ) { $comment = &get_comment( $comment_id ); $post = &get_post( $comment->comment_post_ID ); if ( $post->post_type == 'page' ) { if ( !current_user_can( 'edit_page', $post->ID ) ) return; } else { if ( !current_user_can( 'edit_post', $post->ID ) ) return; } $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; return apply_filters( 'get_edit_comment_link', $location ); } /** * Display or retrieve edit comment link with formatting. * * @since 1.0.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @return string|null HTML content, if $echo is set to false. */ function edit_comment_link( $link = null, $before = '', $after = '' ) { global $comment, $post; if ( $post->post_type == 'page' ) { if ( !current_user_can( 'edit_page', $post->ID ) ) return; } else { if ( !current_user_can( 'edit_post', $post->ID ) ) return; } if ( null === $link ) $link = __('Edit This'); $link = '' . $link . ''; echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; } /** * Display edit bookmark (literally a URL external to blog) link. * * @since 2.7.0 * * @param int $link Optional. Bookmark ID. * @return string */ function get_edit_bookmark_link( $link = 0 ) { $link = get_bookmark( $link ); if ( !current_user_can('manage_links') ) return; $location = admin_url('link.php?action=edit&link_id=') . $link->link_id; return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); } /** * Display edit bookmark (literally a URL external to blog) link anchor content. * * @since 2.7.0 * * @param string $link Optional. Anchor text. * @param string $before Optional. Display before edit link. * @param string $after Optional. Display after edit link. * @param int $bookmark Optional. Bookmark ID. */ function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { $bookmark = get_bookmark($bookmark); if ( !current_user_can('manage_links') ) return; if ( empty($link) ) $link = __('Edit This'); $link = '' . $link . ''; echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; } // Navigation links /** * Retrieve previous post link that is adjacent to current post. * * @since 1.5.0 * * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @return string */ function get_previous_post($in_same_cat = false, $excluded_categories = '') { return get_adjacent_post($in_same_cat, $excluded_categories); } /** * Retrieve next post link that is adjacent to current post. * * @since 1.5.0 * * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @return string */ function get_next_post($in_same_cat = false, $excluded_categories = '') { return get_adjacent_post($in_same_cat, $excluded_categories, false); } /** * Retrieve adjacent post link. * * Can either be next or previous post link. * * @since 2.5.0 * * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @param bool $previous Optional. Whether to retrieve previous post. * @return string */ function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { global $post, $wpdb; if ( empty($post) || !is_single() || is_attachment() ) return null; $current_post_date = $post->post_date; $join = ''; $posts_in_ex_cats_sql = ''; if ( $in_same_cat || !empty($excluded_categories) ) { $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; if ( $in_same_cat ) { $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids'); $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; } $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; if ( !empty($excluded_categories) ) { $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); if ( !empty($cat_array) ) { $excluded_categories = array_diff($excluded_categories, $cat_array); $posts_in_ex_cats_sql = ''; } if ( !empty($excluded_categories) ) { $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; } } } $adjacent = $previous ? 'previous' : 'next'; $op = $previous ? '<' : '>'; $order = $previous ? 'DESC' : 'ASC'; $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories ); $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories ); $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; $query_key = 'adjacent_post_' . md5($query); $result = wp_cache_get($query_key, 'counts'); if ( false !== $result ) return $result; $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort"); if ( null === $result ) $result = ''; wp_cache_set($query_key, $result, 'counts'); return $result; } /** * Get adjacent post relational link. * * Can either be next or previous post relational link. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @param bool $previous Optional, default is true. Whether display link to previous post. * @return string */ function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { if ( $previous && is_attachment() ) $post = & get_post($GLOBALS['post']->post_parent); else $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); if ( empty($post) ) return; if ( empty($post->post_title) ) $post->post_title = $previous ? __('Previous Post') : __('Next Post'); $date = mysql2date(get_option('date_format'), $post->post_date); $title = str_replace('%title', $post->post_title, $title); $title = str_replace('%date', $date, $title); $title = apply_filters('the_title', $title, $post); $link = $previous ? "\n"; $adjacent = $previous ? 'previous' : 'next'; return apply_filters( "{$adjacent}_post_rel_link", $link ); } /** * Display relational links for the posts adjacent to the current post. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); } /** * Display relational link for the next post adjacent to the current post. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); } /** * Display relational link for the previous post adjacent to the current post. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); } /** * Retrieve boundary post. * * Boundary being either the first or last post by publish date within the contraitns specified * by in same category or excluded categories. * * @since 2.8.0 * * @param bool $in_same_cat Optional. Whether returned post should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @param bool $previous Optional. Whether to retrieve first post. * @return object */ function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) { global $post, $wpdb; if ( empty($post) || !is_single() || is_attachment() ) return null; $cat_array = array(); $excluded_categories = array(); if ( !empty($in_same_cat) || !empty($excluded_categories) ) { if ( !empty($in_same_cat) ) { $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids'); } if ( !empty($excluded_categories) ) { $excluded_categories = array_map('intval', explode(',', $excluded_categories)); if ( !empty($cat_array) ) $excluded_categories = array_diff($excluded_categories, $cat_array); $inverse_cats = array(); foreach ( $excluded_categories as $excluded_category) $inverse_cats[] = $excluded_category * -1; $excluded_categories = $inverse_cats; } } $categories = implode(',', array_merge($cat_array, $excluded_categories) ); $order = $start ? 'ASC' : 'DESC'; return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) ); } /** * Get boundary post relational link. * * Can either be start or end post relational link. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @param bool $start Optional, default is true. Whether display link to first post. * @return string */ function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { $posts = get_boundary_post($in_same_cat,$excluded_categories,$start); // Even though we limited get_posts to return only 1 item it still returns an array of objects. $post = $posts[0]; if ( empty($post) ) return; if ( empty($post->post_title) ) $post->post_title = $start ? __('First Post') : __('Last Post'); $date = mysql2date(get_option('date_format'), $post->post_date); $title = str_replace('%title', $post->post_title, $title); $title = str_replace('%date', $date, $title); $title = apply_filters('the_title', $title, $post); $link = $start ? "\n"; $boundary = $start ? 'start' : 'end'; return apply_filters( "{$boundary}_post_rel_link", $link ); } /** * Display relational link for the first post. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true); } /** * Get site index relational link. * * @since 2.8.0 * * @return string */ function get_index_rel_link() { $link = "\n"; return apply_filters( "index_rel_link", $link ); } /** * Display relational link for the site index. * * @since 2.8.0 */ function index_rel_link() { echo get_index_rel_link(); } /** * Get parent post relational link. * * @since 2.8.0 * * @param string $title Optional. Link title format. * @return string */ function get_parent_post_rel_link($title = '%title') { if ( ! empty( $GLOBALS['post'] ) && ! empty( $GLOBALS['post']->post_parent ) ) $post = & get_post($GLOBALS['post']->post_parent); if ( empty($post) ) return; $date = mysql2date(get_option('date_format'), $post->post_date); $title = str_replace('%title', $post->post_title, $title); $title = str_replace('%date', $date, $title); $title = apply_filters('the_title', $title, $post); $link = "\n"; return apply_filters( "parent_post_rel_link", $link ); } /** * Display relational link for parent item * * @since 2.8.0 */ function parent_post_rel_link($title = '%title') { echo get_parent_post_rel_link($title); } /** * Display previous post link that is adjacent to the current post. * * @since 1.5.0 * * @param string $format Optional. Link anchor format. * @param string $link Optional. Link permalink format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); } /** * Display next post link that is adjacent to the current post. * * @since 1.5.0 * * @param string $format Optional. Link anchor format. * @param string $link Optional. Link permalink format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); } /** * Display adjacent post link. * * Can be either next post link or previous. * * @since 2.5.0 * * @param string $format Link anchor format. * @param string $link Link permalink format. * @param bool $in_same_cat Optional. Whether link should be in same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @param bool $previous Optional, default is true. Whether display link to previous post. */ function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { if ( $previous && is_attachment() ) $post = & get_post($GLOBALS['post']->post_parent); else $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); if ( !$post ) return; $title = $post->post_title; if ( empty($post->post_title) ) $title = $previous ? __('Previous Post') : __('Next Post'); $title = apply_filters('the_title', $title, $post); $date = mysql2date(get_option('date_format'), $post->post_date); $rel = $previous ? 'prev' : 'next'; $string = ''; $link = str_replace('%title', $title, $link); $link = str_replace('%date', $date, $link); $link = $string . $link . ''; $format = str_replace('%link', $link, $format); $adjacent = $previous ? 'previous' : 'next'; echo apply_filters( "{$adjacent}_post_link", $format, $link ); } /** * Retrieve get links for page numbers. * * @since 1.5.0 * * @param int $pagenum Optional. Page ID. * @return string */ function get_pagenum_link($pagenum = 1) { global $wp_rewrite; $pagenum = (int) $pagenum; $request = remove_query_arg( 'paged' ); $home_root = parse_url(get_option('home')); $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; $home_root = preg_quote( trailingslashit( $home_root ), '|' ); $request = preg_replace('|^'. $home_root . '|', '', $request); $request = preg_replace('|^/+|', '', $request); if ( !$wp_rewrite->using_permalinks() || is_admin() ) { $base = trailingslashit( get_bloginfo( 'home' ) ); if ( $pagenum > 1 ) { $result = add_query_arg( 'paged', $pagenum, $base . $request ); } else { $result = $base . $request; } } else { $qs_regex = '|\?.*?$|'; preg_match( $qs_regex, $request, $qs_match ); if ( !empty( $qs_match[0] ) ) { $query_string = $qs_match[0]; $request = preg_replace( $qs_regex, '', $request ); } else { $query_string = ''; } $request = preg_replace( '|page/\d+/?$|', '', $request); $request = preg_replace( '|^index\.php|', '', $request); $request = ltrim($request, '/'); $base = trailingslashit( get_bloginfo( 'url' ) ); if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) $base .= 'index.php/'; if ( $pagenum > 1 ) { $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' ); } $result = $base . $request . $query_string; } $result = apply_filters('get_pagenum_link', $result); return $result; } /** * Retrieve next posts pages link. * * Backported from 2.1.3 to 2.0.10. * * @since 2.0.10 * * @param int $max_page Optional. Max pages. * @return string */ function get_next_posts_page_link($max_page = 0) { global $paged; if ( !is_single() ) { if ( !$paged ) $paged = 1; $nextpage = intval($paged) + 1; if ( !$max_page || $max_page >= $nextpage ) return get_pagenum_link($nextpage); } } /** * Display or return the next posts pages link. * * @since 0.71 * * @param int $max_page Optional. Max pages. * @param boolean $echo Optional. Echo or return; */ function next_posts( $max_page = 0, $echo = true ) { $output = esc_url( get_next_posts_page_link( $max_page ) ); if ( $echo ) echo $output; else return $output; } /** * Return the next posts pages link. * * @since 2.7.0 * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. * @return string|null */ function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) { global $paged, $wp_query; if ( !$max_page ) { $max_page = $wp_query->max_num_pages; } if ( !$paged ) $paged = 1; $nextpage = intval($paged) + 1; if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) { $attr = apply_filters( 'next_posts_link_attributes', '' ); return '". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; } } /** * Display the next posts pages link. * * @since 0.71 * @uses get_next_posts_link() * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. */ function next_posts_link( $label = 'Next Page »', $max_page = 0 ) { echo get_next_posts_link( $label, $max_page ); } /** * Retrieve previous post pages link. * * Will only return string, if not on a single page or post. * * Backported to 2.0.10 from 2.1.3. * * @since 2.0.10 * * @return string|null */ function get_previous_posts_page_link() { global $paged; if ( !is_single() ) { $nextpage = intval($paged) - 1; if ( $nextpage < 1 ) $nextpage = 1; return get_pagenum_link($nextpage); } } /** * Display or return the previous posts pages link. * * @since 0.71 * * @param boolean $echo Optional. Echo or return; */ function previous_posts( $echo = true ) { $output = esc_url( get_previous_posts_page_link() ); if ( $echo ) echo $output; else return $output; } /** * Return the previous posts pages link. * * @since 2.7.0 * * @param string $label Optional. Previous page link text. * @return string|null */ function get_previous_posts_link( $label = '« Previous Page' ) { global $paged; if ( !is_single() && $paged > 1 ) { $attr = apply_filters( 'previous_posts_link_attributes', '' ); return '". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .''; } } /** * Display the previous posts page link. * * @since 0.71 * @uses get_previous_posts_link() * * @param string $label Optional. Previous page link text. */ function previous_posts_link( $label = '« Previous Page' ) { echo get_previous_posts_link( $label ); } /** * Return post pages link navigation for previous and next pages. * * @since 2.8 * * @param string|array $args Optional args. * @return string The posts link navigation. */ function get_posts_nav_link( $args = array() ) { global $wp_query; $return = ''; if ( !is_singular() ) { $defaults = array( 'sep' => ' — ', 'prelabel' => __('« Previous Page'), 'nxtlabel' => __('Next Page »'), ); $args = wp_parse_args( $args, $defaults ); $max_num_pages = $wp_query->max_num_pages; $paged = get_query_var('paged'); //only have sep if there's both prev and next results if ($paged < 2 || $paged >= $max_num_pages) { $args['sep'] = ''; } if ( $max_num_pages > 1 ) { $return = get_previous_posts_link($args['prelabel']); $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']); $return .= get_next_posts_link($args['nxtlabel']); } } return $return; } /** * Display post pages link navigation for previous and next pages. * * @since 0.71 * * @param string $sep Optional. Separator for posts navigation links. * @param string $prelabel Optional. Label for previous pages. * @param string $nxtlabel Optional Label for next pages. */ function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); echo get_posts_nav_link($args); } /** * Retrieve page numbers links. * * @since 2.7.0 * * @param int $pagenum Optional. Page number. * @return string */ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { global $post, $wp_rewrite; $pagenum = (int) $pagenum; $result = get_permalink( $post->ID ); if ( 'newest' == get_option('default_comments_page') ) { if ( $pagenum != $max_page ) { if ( $wp_rewrite->using_permalinks() ) $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); else $result = add_query_arg( 'cpage', $pagenum, $result ); } } elseif ( $pagenum > 1 ) { if ( $wp_rewrite->using_permalinks() ) $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); else $result = add_query_arg( 'cpage', $pagenum, $result ); } $result .= '#comments'; $result = apply_filters('get_comments_pagenum_link', $result); return $result; } /** * Return the link to next comments pages. * * @since 2.7.1 * * @param string $label Optional. Label for link text. * @param int $max_page Optional. Max page. * @return string|null */ function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); $nextpage = intval($page) + 1; if ( empty($max_page) ) $max_page = $wp_query->max_num_comment_pages; if ( empty($max_page) ) $max_page = get_comment_pages_count(); if ( $nextpage > $max_page ) return; if ( empty($label) ) $label = __('Newer Comments »'); return ''. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; } /** * Display the link to next comments pages. * * @since 2.7.0 * * @param string $label Optional. Label for link text. * @param int $max_page Optional. Max page. */ function next_comments_link( $label = '', $max_page = 0 ) { echo get_next_comments_link( $label, $max_page ); } /** * Return the previous comments page link. * * @since 2.7.1 * * @param string $label Optional. Label for comments link text. * @return string|null */ function get_previous_comments_link( $label = '' ) { if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); if ( intval($page) <= 1 ) return; $prevpage = intval($page) - 1; if ( empty($label) ) $label = __('« Older Comments'); return '' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .''; } /** * Display the previous comments page link. * * @since 2.7.0 * * @param string $label Optional. Label for comments link text. */ function previous_comments_link( $label = '' ) { echo get_previous_comments_link( $label ); } /** * Create pagination links for the comments on the current post. * * @see paginate_links() * @since 2.7.0 * * @param string|array $args Optional args. See paginate_links. * @return string Markup for pagination links. */ function paginate_comments_links($args = array()) { global $wp_query, $wp_rewrite; if ( !is_singular() || !get_option('page_comments') ) return; $page = get_query_var('cpage'); if ( !$page ) $page = 1; $max_page = get_comment_pages_count(); $defaults = array( 'base' => add_query_arg( 'cpage', '%#%' ), 'format' => '', 'total' => $max_page, 'current' => $page, 'echo' => true, 'add_fragment' => '#comments' ); if ( $wp_rewrite->using_permalinks() ) $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged'); $args = wp_parse_args( $args, $defaults ); $page_links = paginate_links( $args ); if ( $args['echo'] ) echo $page_links; else return $page_links; } /** * Retrieve shortcut link. * * Use this in 'a' element 'href' attribute. * * @since 2.6.0 * * @return string */ function get_shortcut_link() { $link = "javascript: var d=document, w=window, e=w.getSelection, k=d.getSelection, x=d.selection, s=(e?e():(k)?k():(x?x.createRange().text:0)), f='" . admin_url('press-this.php') . "', l=d.location, e=encodeURIComponent, u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=4'; a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;}; if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a(); void(0)"; $link = str_replace(array("\r", "\n", "\t"), '', $link); return apply_filters('shortcut_link', $link); } /** * Retrieve the site url. * * Returns the 'site_url' option with the appropriate protocol, 'https' if * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is * overridden. * * @package WordPress * @since 2.6.0 * * @param string $path Optional. Path relative to the site url. * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. * @return string Site url link with optional path appended. */ function site_url($path = '', $scheme = null) { // should the list of allowed schemes be maintained elsewhere? $orig_scheme = $scheme; if ( !in_array($scheme, array('http', 'https')) ) { if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) $scheme = 'https'; elseif ( ('login' == $scheme) && ( force_ssl_admin() ) ) $scheme = 'https'; elseif ( ('admin' == $scheme) && force_ssl_admin() ) $scheme = 'https'; else $scheme = ( is_ssl() ? 'https' : 'http' ); } $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') ); if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= '/' . ltrim($path, '/'); return apply_filters('site_url', $url, $path, $orig_scheme); } /** * Retrieve the url to the admin area. * * @package WordPress * @since 2.6.0 * * @param string $path Optional path relative to the admin url * @return string Admin url link with optional path appended */ function admin_url($path = '') { $url = site_url('wp-admin/', 'admin'); if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= ltrim($path, '/'); return apply_filters('admin_url', $url, $path); } /** * Retrieve the url to the includes directory. * * @package WordPress * @since 2.6.0 * * @param string $path Optional. Path relative to the includes url. * @return string Includes url link with optional path appended. */ function includes_url($path = '') { $url = site_url() . '/' . WPINC . '/'; if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= ltrim($path, '/'); return apply_filters('includes_url', $url, $path); } /** * Retrieve the url to the content directory. * * @package WordPress * @since 2.6.0 * * @param string $path Optional. Path relative to the content url. * @return string Content url link with optional path appended. */ function content_url($path = '') { $scheme = ( is_ssl() ? 'https' : 'http' ); $url = WP_CONTENT_URL; if ( 0 === strpos($url, 'http') ) { if ( is_ssl() ) $url = str_replace( 'http://', "{$scheme}://", $url ); } if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= '/' . ltrim($path, '/'); return apply_filters('content_url', $url, $path); } /** * Retrieve the url to the plugins directory or to a specific file within that directory. * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name. * * @package WordPress * @since 2.6.0 * * @param string $path Optional. Path relative to the plugins url. * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__ * @return string Plugins url link with optional path appended. */ function plugins_url($path = '', $plugin = '') { $scheme = ( is_ssl() ? 'https' : 'http' ); if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) { $url = WPMU_PLUGIN_URL; } else { $url = WP_PLUGIN_URL; } if ( 0 === strpos($url, 'http') ) { if ( is_ssl() ) $url = str_replace( 'http://', "{$scheme}://", $url ); } if ( !empty($plugin) && is_string($plugin) ) { $folder = dirname(plugin_basename($plugin)); if ('.' != $folder) $url .= '/' . ltrim($folder, '/'); } if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= '/' . ltrim($path, '/'); return apply_filters('plugins_url', $url, $path, $plugin); } /** * Output rel=canonical for singular queries * * @package WordPress * @since 2.9.0 */ function rel_canonical() { if ( !is_singular() ) return; global $wp_the_query; if ( !$id = $wp_the_query->get_queried_object_id() ) return; $link = get_permalink( $id ); echo "\n"; } ?> nd passed to _walk_bookmarks(). * @see get_bookmarks() For other arguments that can be set in this function and * passed to get_bookmarks(). * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks * * @since 2.1.0 * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return * the html * @uses get_terms() Gets all of the categories that are for links. * * @param string|array $args Optional. Overwrite the defaults of the function * @return string|null Will only return if echo option is set to not echo. * Default is not return anything. */ function wp_list_bookmarks($args = '') { $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'exclude_category' => '', 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1, 'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '

', 'title_after' => '

', 'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat', 'category_before' => '
  • ', 'category_after' => '
  • ' ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $output = ''; if ( $categorize ) { //Split the bookmarks into ul's for each category $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0)); foreach ( (array) $cats as $cat ) { $params = array_merge($r, array('category'=>$cat->term_id)); $bookmarks = get_bookmarks($params); if ( empty($bookmarks) ) continue; $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); $catname = apply_filters( "link_category", $cat->name ); $output .= "$title_before$catname$title_after\n\t\n$category_after\n"; } } else { //output one single list using title_li for the title $bookmarks = get_bookmarks($r); if ( !empty($bookmarks) ) { if ( !empty( $title_li ) ){ $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); $output .= "$title_before$title_li$title_after\n\t\n$category_after\n"; } else { $output .= _walk_bookmarks($bookmarks, $r); } } } $output = apply_filters( 'wp_list_bookmarks', $output ); if ( !$echo ) return $output; echo $output; } ?>