/** * WordPress Link Template Functions * * @package WordPress * @subpackage Template */ /** * Displays the permalink for the current post. * * @since 1.2.0 * @since 4.4.0 Added the `$post` parameter. * * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. */ function the_permalink( $post = 0 ) { /** * Filters the display of the permalink for the current post. * * @since 1.5.0 * @since 4.4.0 Added the `$post` parameter. * * @param string $permalink The permalink for the current post. * @param int|WP_Post $post Post ID, WP_Post object, or 0. Default 0. */ echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) ); } /** * Retrieves a trailing-slashed string if the site is set for adding trailing slashes. * * Conditionally adds a trailing slash if the permalink structure has a trailing * slash, strips the trailing slash if not. The string is passed through the * {@see 'user_trailingslashit'} filter. Will remove trailing slash from string, if * site is not set to have them. * * @since 2.2.0 * * @global WP_Rewrite $wp_rewrite * * @param string $string URL with or without a trailing slash. * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc) * for use in the filter. Default empty string. * @return string The URL with the trailing slash appended or stripped. */ function user_trailingslashit( $string, $type_of_url = '' ) { global $wp_rewrite; if ( $wp_rewrite->use_trailing_slashes ) { $string = trailingslashit( $string ); } else { $string = untrailingslashit( $string ); } /** * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. * * @since 2.2.0 * * @param string $string URL with or without a trailing slash. * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback', * 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed', * 'category', 'page', 'year', 'month', 'day', 'post_type_archive'. */ return apply_filters( 'user_trailingslashit', $string, $type_of_url ); } /** * Displays the permalink anchor for the current post. * * The permalink mode title will use the post title for the 'a' element 'id' * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute. * * @since 0.71 * * @param string $mode Optional. Permalink mode. Accepts 'title' or 'id'. Default 'id'. */ function permalink_anchor( $mode = 'id' ) { $post = get_post(); switch ( strtolower( $mode ) ) { case 'title': $title = sanitize_title( $post->post_title ) . '-' . $post->ID; echo ''; break; case 'id': default: echo ''; break; } } /** * Retrieves the full permalink for the current post or post ID. * * This function is an alias for get_permalink(). * * @since 3.9.0 * * @see get_permalink() * * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param bool $leavename Optional. Whether to keep post name or page name. Default false. * * @return string|false The permalink URL or false if post does not exist. */ function get_the_permalink( $post = 0, $leavename = false ) { return get_permalink( $post, $leavename ); } /** * Retrieves the full permalink for the current post or post ID. * * @since 1.0.0 * * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param bool $leavename Optional. Whether to keep post name or page name. Default false. * @return string|false The permalink URL or false if post does not exist. */ function get_permalink( $post = 0, $leavename = false ) { $rewritecode = array( '%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', $leavename ? '' : '%postname%', '%post_id%', '%category%', '%author%', $leavename ? '' : '%pagename%', ); if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) { $sample = true; } else { $post = get_post( $post ); $sample = false; } if ( empty( $post->ID ) ) { return false; } if ( $post->post_type == 'page' ) { return get_page_link( $post, $leavename, $sample ); } elseif ( $post->post_type == 'attachment' ) { return get_attachment_link( $post, $leavename ); } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) { return get_post_permalink( $post, $leavename, $sample ); } $permalink = get_option( 'permalink_structure' ); /** * Filters the permalink structure for a post before token replacement occurs. * * Only applies to posts with post_type of 'post'. * * @since 3.0.0 * * @param string $permalink The site's permalink structure. * @param WP_Post $post The post in question. * @param bool $leavename Whether to keep the post name. */ $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { $unixtime = strtotime( $post->post_date ); $category = ''; if ( strpos( $permalink, '%category%' ) !== false ) { $cats = get_the_category( $post->ID ); if ( $cats ) { $cats = wp_list_sort( $cats, array( 'term_id' => 'ASC', ) ); /** * Filters the category that gets used in the %category% permalink token. * * @since 3.5.0 * * @param WP_Term $cat The category to use in the permalink. * @param array $cats Array of all categories (WP_Term objects) associated with the post. * @param WP_Post $post The post in question. */ $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post ); $category_object = get_term( $category_object, 'category' ); $category = $category_object->slug; if ( $category_object->parent ) { $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; } } // show default category in permalinks, without // having to assign it explicitly if ( empty( $category ) ) { $default_category = get_term( get_option( 'default_category' ), 'category' ); if ( $default_category && ! is_wp_error( $default_category ) ) { $category = $default_category->slug; } } } $author = ''; if ( strpos( $permalink, '%author%' ) !== false ) { $authordata = get_userdata( $post->post_author ); $author = $authordata->user_nicename; } $date = explode( ' ', date( 'Y m d H i s', $unixtime ) ); $rewritereplace = array( $date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name, ); $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) ); $permalink = user_trailingslashit( $permalink, 'single' ); } else { // if they're not using the fancy permalink option $permalink = home_url( '?p=' . $post->ID ); } /** * Filters the permalink for a post. * * Only applies to posts with post_type of 'post'. * * @since 1.5.0 * * @param string $permalink The post's permalink. * @param WP_Post $post The post in question. * @param bool $leavename Whether to keep the post name. */ return apply_filters( 'post_link', $permalink, $post, $leavename ); } /** * Retrieves the permalink for a post of a custom post type. * * @since 3.0.0 * * @global WP_Rewrite $wp_rewrite * * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. * @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false. * @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false. * @return string|WP_Error The post permalink. */ function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { global $wp_rewrite; $post = get_post( $id ); if ( is_wp_error( $post ) ) { return $post; } $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); $slug = $post->post_name; $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); $post_type = get_post_type_object( $post->post_type ); if ( $post_type->hierarchical ) { $slug = get_page_uri( $post ); } if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) { if ( ! $leavename ) { $post_link = str_replace( "%$post->post_type%", $slug, $post_link ); } $post_link = home_url( user_trailingslashit( $post_link ) ); } else { if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) { $post_link = add_query_arg( $post_type->query_var, $slug, '' ); } else { $post_link = add_query_arg( array( 'post_type' => $post->post_type, 'p' => $post->ID, ), '' ); } $post_link = home_url( $post_link ); } /** * Filters the permalink for a post of a custom post type. * * @since 3.0.0 * * @param string $post_link The post's permalink. * @param WP_Post $post The post in question. * @param bool $leavename Whether to keep the post name. * @param bool $sample Is it a sample permalink. */ return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample ); } /** * Retrieves the permalink for the current page or page ID. * * Respects page_on_front. Use this one. * * @since 1.5.0 * * @param int|WP_Post $post Optional. Post ID or object. Default uses the global `$post`. * @param bool $leavename Optional. Whether to keep the page name. Default false. * @param bool $sample Optional. Whether it should be treated as a sample permalink. * Default false. * @return string The page permalink. */ function get_page_link( $post = false, $leavename = false, $sample = false ) { $post = get_post( $post ); if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) { $link = home_url( '/' ); } else { $link = _get_page_link( $post, $leavename, $sample ); } /** * Filters the permalink for a page. * * @since 1.5.0 * * @param string $link The page's permalink. * @param int $post_id The ID of the page. * @param bool $sample Is it a sample permalink. */ return apply_filters( 'page_link', $link, $post->ID, $sample ); } /** * Retrieves the page permalink. * * Ignores page_on_front. Internal use only. * * @since 2.1.0 * @access private * * @global WP_Rewrite $wp_rewrite * * @param int|WP_Post $post Optional. Post ID or object. Default uses the global `$post`. * @param bool $leavename Optional. Whether to keep the page name. Default false. * @param bool $sample Optional. Whether it should be treated as a sample permalink. * Default false. * @return string The page permalink. */ function _get_page_link( $post = false, $leavename = false, $sample = false ) { global $wp_rewrite; $post = get_post( $post ); $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); $link = $wp_rewrite->get_page_permastruct(); if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) { if ( ! $leavename ) { $link = str_replace( '%pagename%', get_page_uri( $post ), $link ); } $link = home_url( $link ); $link = user_trailingslashit( $link, 'page' ); } else { $link = home_url( '?page_id=' . $post->ID ); } /** * Filters the permalink for a non-page_on_front page. * * @since 2.1.0 * * @param string $link The page's permalink. * @param int $post_id The ID of the page. */ return apply_filters( '_get_page_link', $link, $post->ID ); } /** * Retrieves the permalink for an attachment. * * This can be used in the WordPress Loop or outside of it. * * @since 2.0.0 * * @global WP_Rewrite $wp_rewrite * * @param int|object $post Optional. Post ID or object. Default uses the global `$post`. * @param bool $leavename Optional. Whether to keep the page name. Default false. * @return string The attachment permalink. */ function get_attachment_link( $post = null, $leavename = false ) { global $wp_rewrite; $link = false; $post = get_post( $post ); $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false; if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) { $parent = false; } if ( $wp_rewrite->using_permalinks() && $parent ) { if ( 'page' == $parent->post_type ) { $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front } else { $parentlink = get_permalink( $post->post_parent ); } if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { $name = 'attachment/' . $post->post_name; // // is paged so we use the explicit attachment marker } else { $name = $post->post_name; } if ( strpos( $parentlink, '?' ) === false ) { $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' ); } if ( ! $leavename ) { $link = str_replace( '%postname%', $name, $link ); } } elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) { $link = home_url( user_trailingslashit( $post->post_name ) ); } if ( ! $link ) { $link = home_url( '/?attachment_id=' . $post->ID ); } /** * Filters the permalink for an attachment. * * @since 2.0.0 * * @param string $link The attachment's permalink. * @param int $post_id Attachment ID. */ return apply_filters( 'attachment_link', $link, $post->ID ); } /** * Retrieves the permalink for the year archives. * * @since 1.5.0 * * @global WP_Rewrite $wp_rewrite * * @param int|bool $year False for current year or year for permalink. * @return string The permalink for the specified year archive. */ function get_year_link( $year ) { global $wp_rewrite; if ( ! $year ) { $year = gmdate( 'Y', current_time( 'timestamp' ) ); } $yearlink = $wp_rewrite->get_year_permastruct(); if ( ! empty( $yearlink ) ) { $yearlink = str_replace( '%year%', $year, $yearlink ); $yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) ); } else { $yearlink = home_url( '?m=' . $year ); } /** * Filters the year archive permalink. * * @since 1.5.0 * * @param string $yearlink Permalink for the year archive. * @param int $year Year for the archive. */ return apply_filters( 'year_link', $yearlink, $year ); } /** * Retrieves the permalink for the month archives with year. * * @since 1.0.0 * * @global WP_Rewrite $wp_rewrite * * @param bool|int $year False for current year. Integer of year. * @param bool|int $month False for current month. Integer of month. * @return string The permalink for the specified month and year archive. */ function get_month_link( $year, $month ) { global $wp_rewrite; if ( ! $year ) { $year = gmdate( 'Y', current_time( 'timestamp' ) ); } if ( ! $month ) { $month = gmdate( 'm', current_time( 'timestamp' ) ); } $monthlink = $wp_rewrite->get_month_permastruct(); if ( ! empty( $monthlink ) ) { $monthlink = str_replace( '%year%', $year, $monthlink ); $monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink ); $monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) ); } else { $monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) ); } /** * Filters the month archive permalink. * * @since 1.5.0 * * @param string $monthlink Permalink for the month archive. * @param int $year Year for the archive. * @param int $month The month for the archive. */ return apply_filters( 'month_link', $monthlink, $year, $month ); } /** * Retrieves the permalink for the day archives with year and month. * * @since 1.0.0 * * @global WP_Rewrite $wp_rewrite * * @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 The permalink for the specified day, month, and year archive. */ function get_day_link( $year, $month, $day ) { global $wp_rewrite; if ( ! $year ) { $year = gmdate( 'Y', current_time( 'timestamp' ) ); } if ( ! $month ) { $month = gmdate( 'm', current_time( 'timestamp' ) ); } if ( ! $day ) { $day = gmdate( 'j', current_time( 'timestamp' ) ); } $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 ); $daylink = home_url( user_trailingslashit( $daylink, 'day' ) ); } else { $daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) ); } /** * Filters the day archive permalink. * * @since 1.5.0 * * @param string $daylink Permalink for the day archive. * @param int $year Year for the archive. * @param int $month Month for the archive. * @param int $day The day for the archive. */ return apply_filters( 'day_link', $daylink, $year, $month, $day ); } /** * Displays the permalink for the feed type. * * @since 3.0.0 * * @param string $anchor The link's anchor text. * @param string $feed Optional. Feed type. Default empty. */ function the_feed_link( $anchor, $feed = '' ) { $link = '' . $anchor . ''; /** * Filters the feed link anchor tag. * * @since 3.0.0 * * @param string $link The complete anchor tag for a feed link. * @param string $feed The feed type, or an empty string for the * default feed type. */ echo apply_filters( 'the_feed_link', $link, $feed ); } /** * Retrieves the permalink for the feed type. * * @since 1.5.0 * * @global WP_Rewrite $wp_rewrite * * @param string $feed Optional. Feed type. Default empty. * @return string The feed permalink. */ 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 = home_url( user_trailingslashit( $permalink, 'feed' ) ); } else { if ( empty( $feed ) ) { $feed = get_default_feed(); } if ( false !== strpos( $feed, 'comments_' ) ) { $feed = str_replace( 'comments_', 'comments-', $feed ); } $output = home_url( "?feed={$feed}" ); } /** * Filters the feed type permalink. * * @since 1.5.0 * * @param string $output The feed permalink. * @param string $feed Feed type. */ return apply_filters( 'feed_link', $output, $feed ); } /** * Retrieves the permalink for the post comments feed. * * @since 2.2.0 * * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. * @param string $feed Optional. Feed type. Default empty. * @return string The permalink for the comments feed for the given post. */ function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { $post_id = absint( $post_id ); if ( ! $post_id ) { $post_id = get_the_ID(); } if ( empty( $feed ) ) { $feed = get_default_feed(); } $post = get_post( $post_id ); $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; if ( '' != get_option( 'permalink_structure' ) ) { if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) { $url = _get_page_link( $post_id ); } else { $url = get_permalink( $post_id ); } if ( $unattached ) { $url = home_url( '/feed/' ); if ( $feed !== get_default_feed() ) { $url .= "$feed/"; } $url = add_query_arg( 'attachment_id', $post_id, $url ); } else { $url = trailingslashit( $url ) . 'feed'; if ( $feed != get_default_feed() ) { $url .= "/$feed"; } $url = user_trailingslashit( $url, 'single_feed' ); } } else { if ( $unattached ) { $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id, ), home_url( '/' ) ); } elseif ( 'page' == $post->post_type ) { $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id, ), home_url( '/' ) ); } else { $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id, ), home_url( '/' ) ); } } /** * Filters the post comments feed permalink. * * @since 1.5.1 * * @param string $url Post comments feed permalink. */ return apply_filters( 'post_comments_feed_link', $url ); } /** * Displays 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. * * @since 2.5.0 * * @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'. * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. * @param string $feed Optional. Feed format. Default empty. */ 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' ); } $link = '' . $link_text . ''; /** * Filters the post comment feed link anchor tag. * * @since 2.8.0 * * @param string $link The complete anchor tag for the comment feed link. * @param int $post_id Post ID. * @param string $feed The feed type, or an empty string for the default feed type. */ echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed ); } /** * Retrieves 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. * * @since 2.5.0 * * @param int $author_id Author ID. * @param string $feed Optional. Feed type. Default empty. * @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 = home_url( "?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' ); } /** * Filters the feed link for a given author. * * @since 1.5.1 * * @param string $link The author feed link. * @param string $feed Feed type. */ $link = apply_filters( 'author_feed_link', $link, $feed ); return $link; } /** * Retrieves the feed link for a category. * * Returns a link to the feed for all posts in a given category. A specific feed * can be requested or left blank to get the default feed. * * @since 2.5.0 * * @param int $cat_id Category ID. * @param string $feed Optional. Feed type. Default empty. * @return string Link to the feed for the category specified by $cat_id. */ function get_category_feed_link( $cat_id, $feed = '' ) { return get_term_feed_link( $cat_id, 'category', $feed ); } /** * Retrieves the feed link for a term. * * Returns a link to the feed for all posts in a given term. A specific feed * can be requested or left blank to get the default feed. * * @since 3.0.0 * * @param int $term_id Term ID. * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. * @param string $feed Optional. Feed type. Default empty. * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. */ function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { $term_id = (int) $term_id; $term = get_term( $term_id, $taxonomy ); if ( empty( $term ) || is_wp_error( $term ) ) { return false; } if ( empty( $feed ) ) { $feed = get_default_feed(); } $permalink_structure = get_option( 'permalink_structure' ); if ( '' == $permalink_structure ) { if ( 'category' == $taxonomy ) { $link = home_url( "?feed=$feed&cat=$term_id" ); } elseif ( 'post_tag' == $taxonomy ) { $link = home_url( "?feed=$feed&tag=$term->slug" ); } else { $t = get_taxonomy( $taxonomy ); $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); } } else { $link = get_term_link( $term_id, $term->taxonomy ); if ( $feed == get_default_feed() ) { $feed_link = 'feed'; } else { $feed_link = "feed/$feed"; } $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); } if ( 'category' == $taxonomy ) { /** * Filters the category feed link. * * @since 1.5.1 * * @param string $link The category feed link. * @param string $feed Feed type. */ $link = apply_filters( 'category_feed_link', $link, $feed ); } elseif ( 'post_tag' == $taxonomy ) { /** * Filters the post tag feed link. * * @since 2.3.0 * * @param string $link The tag feed link. * @param string $feed Feed type. */ $link = apply_filters( 'tag_feed_link', $link, $feed ); } else { /** * Filters the feed link for a taxonomy other than 'category' or 'post_tag'. * * @since 3.0.0 * * @param string $link The taxonomy feed link. * @param string $feed Feed type. * @param string $taxonomy The taxonomy name. */ $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); } return $link; } /** * Retrieves the permalink for a tag feed. * * @since 2.3.0 * * @param int $tag_id Tag ID. * @param string $feed Optional. Feed type. Default empty. * @return string The feed permalink for the given tag. */ function get_tag_feed_link( $tag_id, $feed = '' ) { return get_term_feed_link( $tag_id, 'post_tag', $feed ); } /** * Retrieves the edit link for a tag. * * @since 2.7.0 * * @param int $tag_id Tag ID. * @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'. * @return string The edit tag link URL for the given tag. */ function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { /** * Filters the edit link for a tag (or term in another taxonomy). * * @since 2.7.0 * * @param string $link The term edit link. */ return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); } /** * Displays or retrieves the edit link for a tag with formatting. * * @since 2.7.0 * * @param string $link Optional. Anchor text. Default empty. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. * @param WP_Term $tag Optional. Term object. If null, the queried object will be inspected. * Default null. */ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { $link = edit_term_link( $link, '', '', $tag, false ); /** * Filters the anchor tag for the edit link for a tag (or term in another taxonomy). * * @since 2.7.0 * * @param string $link The anchor tag for the edit link. */ echo $before . apply_filters( 'edit_tag_link', $link ) . $after; } /** * Retrieves the URL for editing a given term. * * @since 3.1.0 * @since 4.5.0 The `$taxonomy` argument was made optional. * * @param int $term_id Term ID. * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified * by `$term_id`. * @param string $object_type Optional. The object type. Used to highlight the proper post type * menu on the linked page. Defaults to the first object_type associated * with the taxonomy. * @return string|null The edit term link URL for the given term, or null on failure. */ function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) { $term = get_term( $term_id, $taxonomy ); if ( ! $term || is_wp_error( $term ) ) { return; } $tax = get_taxonomy( $term->taxonomy ); if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) { return; } $args = array( 'taxonomy' => $taxonomy, 'tag_ID' => $term->term_id, ); if ( $object_type ) { $args['post_type'] = $object_type; } elseif ( ! empty( $tax->object_type ) ) { $args['post_type'] = reset( $tax->object_type ); } if ( $tax->show_ui ) { $location = add_query_arg( $args, admin_url( 'term.php' ) ); } else { $location = ''; } /** * Filters the edit link for a term. * * @since 3.1.0 * * @param string $location The edit link. * @param int $term_id Term ID. * @param string $taxonomy Taxonomy name. * @param string $object_type The object type (eg. the post type). */ return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); } /** * Displays or retrieves the edit term link with formatting. * * @since 3.1.0 * * @param string $link Optional. Anchor text. Default empty. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. * @param object $term Optional. Term object. If null, the queried object will be inspected. Default null. * @param bool $echo Optional. Whether or not to echo the return. Default true. * @return string|void HTML content. */ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { if ( is_null( $term ) ) { $term = get_queried_object(); } if ( ! $term ) { return; } $tax = get_taxonomy( $term->taxonomy ); if ( ! current_user_can( 'edit_term', $term->term_id ) ) { return; } if ( empty( $link ) ) { $link = __( 'Edit This' ); } $link = '' . $link . ''; /** * Filters the anchor tag for the edit link of a term. * * @since 3.1.0 * * @param string $link The anchor tag for the edit link. * @param int $term_id Term ID. */ $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; if ( $echo ) { echo $link; } else { return $link; } } /** * Retrieves the permalink for a search. * * @since 3.0.0 * * @global WP_Rewrite $wp_rewrite * * @param string $query Optional. The query string to use. If empty the current query is used. Default empty. * @return string The search permalink. */ function get_search_link( $query = '' ) { global $wp_rewrite; if ( empty( $query ) ) { $search = get_search_query( false ); } else { $search = stripslashes( $query ); } $permastruct = $wp_rewrite->get_search_permastruct(); if ( empty( $permastruct ) ) { $link = home_url( '?s=' . urlencode( $search ) ); } else { $search = urlencode( $search ); $search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded. $link = str_replace( '%search%', $search, $permastruct ); $link = home_url( user_trailingslashit( $link, 'search' ) ); } /** * Filters the search permalink. * * @since 3.0.0 * * @param string $link Search permalink. * @param string $search The URL-encoded search term. */ return apply_filters( 'search_link', $link, $search ); } /** * Retrieves the permalink for the search results feed. * * @since 2.5.0 * * @global WP_Rewrite $wp_rewrite * * @param string $search_query Optional. Search query. Default empty. * @param string $feed Optional. Feed type. Default empty. * @return string The search results feed permalink. */ function get_search_feed_link( $search_query = '', $feed = '' ) { global $wp_rewrite; $link = get_search_link( $search_query ); if ( empty( $feed ) ) { $feed = get_default_feed(); } $permastruct = $wp_rewrite->get_search_permastruct(); if ( empty( $permastruct ) ) { $link = add_query_arg( 'feed', $feed, $link ); } else { $link = trailingslashit( $link ); $link .= "feed/$feed/"; } /** * Filters the search feed link. * * @since 2.5.0 * * @param string $link Search feed link. * @param string $feed Feed type. * @param string $type The search type. One of 'posts' or 'comments'. */ return apply_filters( 'search_feed_link', $link, $feed, 'posts' ); } /** * Retrieves the permalink for the search results comments feed. * * @since 2.5.0 * * @global WP_Rewrite $wp_rewrite * * @param string $search_query Optional. Search query. Default empty. * @param string $feed Optional. Feed type. Default empty. * @return string The comments feed search results permalink. */ function get_search_comments_feed_link( $search_query = '', $feed = '' ) { global $wp_rewrite; if ( empty( $feed ) ) { $feed = get_default_feed(); } $link = get_search_feed_link( $search_query, $feed ); $permastruct = $wp_rewrite->get_search_permastruct(); if ( empty( $permastruct ) ) { $link = add_query_arg( 'feed', 'comments-' . $feed, $link ); } else { $link = add_query_arg( 'withcomments', 1, $link ); } /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'search_feed_link', $link, $feed, 'comments' ); } /** * Retrieves the permalink for a post type archive. * * @since 3.1.0 * @since 4.5.0 Support for posts was added. * * @global WP_Rewrite $wp_rewrite * * @param string $post_type Post type. * @return string|false The post type archive permalink. */ function get_post_type_archive_link( $post_type ) { global $wp_rewrite; if ( ! $post_type_obj = get_post_type_object( $post_type ) ) { return false; } if ( 'post' === $post_type ) { $show_on_front = get_option( 'show_on_front' ); $page_for_posts = get_option( 'page_for_posts' ); if ( 'page' == $show_on_front && $page_for_posts ) { $link = get_permalink( $page_for_posts ); } else { $link = get_home_url(); } /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'post_type_archive_link', $link, $post_type ); } if ( ! $post_type_obj->has_archive ) { return false; } if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; if ( $post_type_obj->rewrite['with_front'] ) { $struct = $wp_rewrite->front . $struct; } else { $struct = $wp_rewrite->root . $struct; } $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); } else { $link = home_url( '?post_type=' . $post_type ); } /** * Filters the post type archive permalink. * * @since 3.1.0 * * @param string $link The post type archive permalink. * @param string $post_type Post type name. */ return apply_filters( 'post_type_archive_link', $link, $post_type ); } /** * Retrieves the permalink for a post type archive feed. * * @since 3.1.0 * * @param string $post_type Post type * @param string $feed Optional. Feed type. Default empty. * @return string|false The post type feed permalink. */ function get_post_type_archive_feed_link( $post_type, $feed = '' ) { $default_feed = get_default_feed(); if ( empty( $feed ) ) { $feed = $default_feed; } if ( ! $link = get_post_type_archive_link( $post_type ) ) { return false; } $post_type_obj = get_post_type_object( $post_type ); if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { $link = trailingslashit( $link ); $link .= 'feed/'; if ( $feed != $default_feed ) { $link .= "$feed/"; } } else { $link = add_query_arg( 'feed', $feed, $link ); } /** * Filters the post type archive feed link. * * @since 3.1.0 * * @param string $link The post type archive feed link. * @param string $feed Feed type. */ return apply_filters( 'post_type_archive_feed_link', $link, $feed ); } /** * Retrieves the URL used for the post preview. * * Allows additional query args to be appended. * * @since 4.4.0 * * @param int|WP_Post $post Optional. Post ID or `WP_Post` object. Defaults to global `$post`. * @param array $query_args Optional. Array of additional query args to be appended to the link. * Default empty array. * @param string $preview_link Optional. Base preview link to be used if it should differ from the * post permalink. Default empty. * @return string|null URL used for the post preview, or null if the post does not exist. */ function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) { $post = get_post( $post ); if ( ! $post ) { return; } $post_type_object = get_post_type_object( $post->post_type ); if ( is_post_type_viewable( $post_type_object ) ) { if ( ! $preview_link ) { $preview_link = set_url_scheme( get_permalink( $post ) ); } $query_args['preview'] = 'true'; $preview_link = add_query_arg( $query_args, $preview_link ); } /** * Filters the URL used for a post preview. * * @since 2.0.5 * @since 4.0.0 Added the `$post` parameter. * * @param string $preview_link URL used for the post preview. * @param WP_Post $post Post object. */ return apply_filters( 'preview_post_link', $preview_link, $post ); } /** * Retrieves the edit post 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|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. * @param string $context Optional. How to output the '&' character. Default '&'. * @return string|null The edit post link for the given post. null if the post type is invalid or does * not allow an editing UI. */ function get_edit_post_link( $id = 0, $context = 'display' ) { if ( ! $post = get_post( $id ) ) { return; } if ( 'revision' === $post->post_type ) { $action = ''; } elseif ( 'display' == $context ) { $action = '&action=edit'; } else { $action = '&action=edit'; } $post_type_object = get_post_type_object( $post->post_type ); if ( ! $post_type_object ) { return; } if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; } if ( $post_type_object->_edit_link ) { $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); } else { $link = ''; } /** * Filters the post edit link. * * @since 2.3.0 * * @param string $link The edit link. * @param int $post_id Post ID. * @param string $context The link context. If set to 'display' then ampersands * are encoded. */ return apply_filters( 'get_edit_post_link', $link, $post->ID, $context ); } /** * Displays the edit post link for post. * * @since 1.0.0 * @since 4.4.0 The `$class` argument was added. * * @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. * @param string $class Optional. Add custom class to link. Default 'post-edit-link'. */ function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { if ( ! $post = get_post( $id ) ) { return; } if ( ! $url = get_edit_post_link( $post->ID ) ) { return; } if ( null === $text ) { $text = __( 'Edit This' ); } $link = '' . $text . ''; /** * Filters the post edit link anchor tag. * * @since 2.3.0 * * @param string $link Anchor tag for the edit link. * @param int $post_id Post ID. * @param string $text Anchor text. */ echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after; } /** * Retrieves the delete posts link for post. * * Can be used within the WordPress loop or outside of it, with any post type. * * @since 2.9.0 * * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. * @param string $deprecated Not used. * @param bool $force_delete Optional. Whether to bypass trash and force deletion. Default false. * @return string|void The delete post link URL for the given post. */ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '3.0.0' ); } if ( ! $post = get_post( $id ) ) { return; } $post_type_object = get_post_type_object( $post->post_type ); if ( ! $post_type_object ) { return; } if ( ! current_user_can( 'delete_post', $post->ID ) ) { return; } $action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); /** * Filters the post delete link. * * @since 2.9.0 * * @param string $link The delete link. * @param int $post_id Post ID. * @param bool $force_delete Whether to bypass the trash and force deletion. Default false. */ return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete ); } /** * Retrieves the edit comment link. * * @since 2.3.0 * * @param int|WP_Comment $comment_id Optional. Comment ID or WP_Comment object. * @return string|void The edit comment link URL for the given comment. */ function get_edit_comment_link( $comment_id = 0 ) { $comment = get_comment( $comment_id ); if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { return; } $location = admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID; /** * Filters the comment edit link. * * @since 2.3.0 * * @param string $location The edit link. */ return apply_filters( 'get_edit_comment_link', $location ); } /** * Displays the edit comment link with formatting. * * @since 1.0.0 * * @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. */ function edit_comment_link( $text = null, $before = '', $after = '' ) { $comment = get_comment(); if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { return; } if ( null === $text ) { $text = __( 'Edit This' ); } $link = '' . $text . ''; /** * Filters the comment edit link anchor tag. * * @since 2.3.0 * * @param string $link Anchor tag for the edit link. * @param int $comment_id Comment ID. * @param string $text Anchor text. */ echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after; } /** * Displays the edit bookmark link. * * @since 2.7.0 * * @param int|stdClass $link Optional. Bookmark ID. Default is the id of the current bookmark. * @return string|void The edit bookmark link URL. */ 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; /** * Filters the bookmark edit link. * * @since 2.7.0 * * @param string $location The edit link. * @param int $link_id Bookmark ID. */ return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); } /** * Displays the edit bookmark link anchor content. * * @since 2.7.0 * * @param string $link Optional. Anchor text. Default empty. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. * @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. */ 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 . ''; /** * Filters the bookmark edit link anchor tag. * * @since 2.7.0 * * @param string $link Anchor tag for the edit link. * @param int $link_id Bookmark ID. */ echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; } /** * Retrieves the edit user link. * * @since 3.5.0 * * @param int $user_id Optional. User ID. Defaults to the current user. * @return string URL to edit user page or empty string. */ function get_edit_user_link( $user_id = null ) { if ( ! $user_id ) { $user_id = get_current_user_id(); } if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) { return ''; } $user = get_userdata( $user_id ); if ( ! $user ) { return ''; } if ( get_current_user_id() == $user->ID ) { $link = get_edit_profile_url( $user->ID ); } else { $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); } /** * Filters the user edit link. * * @since 3.5.0 * * @param string $link The edit link. * @param int $user_id User ID. */ return apply_filters( 'get_edit_user_link', $link, $user->ID ); } // Navigation links /** * Retrieves the previous post that is adjacent to the current post. * * @since 1.5.0 * * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no * corresponding post exists. */ function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); } /** * Retrieves the next post that is adjacent to the current post. * * @since 1.5.0 * * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no * corresponding post exists. */ function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); } /** * Retrieves the adjacent post. * * Can either be next or previous post. * * @since 2.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param bool $previous Optional. Whether to retrieve previous post. Default true * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no * corresponding post exists. */ function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { global $wpdb; if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) { return null; } $current_post_date = $post->post_date; $join = ''; $where = ''; $adjacent = $previous ? 'previous' : 'next'; if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and " if ( false !== strpos( $excluded_terms, ' and ' ) ) { _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) ); $excluded_terms = explode( ' and ', $excluded_terms ); } else { $excluded_terms = explode( ',', $excluded_terms ); } $excluded_terms = array_map( 'intval', $excluded_terms ); } /** * Filters the IDs of terms excluded from adjacent post queries. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * @since 4.4.0 * * @param array $excluded_terms Array of excluded term IDs. */ $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); if ( $in_same_term || ! empty( $excluded_terms ) ) { if ( $in_same_term ) { $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"; $where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { return ''; } $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); // Remove any exclusions from the term array to include. $term_array = array_diff( $term_array, (array) $excluded_terms ); $term_array = array_map( 'intval', $term_array ); if ( ! $term_array || is_wp_error( $term_array ) ) { return ''; } $where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')'; } if ( ! empty( $excluded_terms ) ) { $where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( ',', array_map( 'intval', $excluded_terms ) ) . ') )'; } } // 'post_status' clause depends on the current user. if ( is_user_logged_in() ) { $user_id = get_current_user_id(); $post_type_object = get_post_type_object( $post->post_type ); if ( empty( $post_type_object ) ) { $post_type_cap = $post->post_type; $read_private_cap = 'read_private_' . $post_type_cap . 's'; } else { $read_private_cap = $post_type_object->cap->read_private_posts; } /* * Results should include private posts belonging to the current user, or private posts where the * current user has the 'read_private_posts' cap. */ $private_states = get_post_stati( array( 'private' => true ) ); $where .= " AND ( p.post_status = 'publish'"; foreach ( (array) $private_states as $state ) { if ( current_user_can( $read_private_cap ) ) { $where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); } else { $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); } } $where .= ' )'; } else { $where .= " AND p.post_status = 'publish'"; } $op = $previous ? '<' : '>'; $order = $previous ? 'DESC' : 'ASC'; /** * Filters the JOIN clause in the SQL for an adjacent post query. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * @since 2.5.0 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters. * * @param string $join The JOIN clause in the SQL. * @param bool $in_same_term Whether post should be in a same taxonomy term. * @param array $excluded_terms Array of excluded term IDs. * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. * @param WP_Post $post WP_Post object. */ $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post ); /** * Filters the WHERE clause in the SQL for an adjacent post query. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * @since 2.5.0 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters. * * @param string $where The `WHERE` clause in the SQL. * @param bool $in_same_term Whether post should be in a same taxonomy term. * @param array $excluded_terms Array of excluded term IDs. * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. * @param WP_Post $post WP_Post object. */ $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post ); /** * Filters the ORDER BY clause in the SQL for an adjacent post query. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * @since 2.5.0 * @since 4.4.0 Added the `$post` parameter. * @since 4.9.0 Added the `$order` parameter. * * @param string $order_by The `ORDER BY` clause in the SQL. * @param WP_Post $post WP_Post object. * @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. */ $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; $query_key = 'adjacent_post_' . md5( $query ); $result = wp_cache_get( $query_key, 'counts' ); if ( false !== $result ) { if ( $result ) { $result = get_post( $result ); } return $result; } $result = $wpdb->get_var( $query ); if ( null === $result ) { $result = ''; } wp_cache_set( $query_key, $result, 'counts' ); if ( $result ) { $result = get_post( $result ); } return $result; } /** * Retrieves the adjacent post relational link. * * Can either be next or previous post relational link. * * @since 2.8.0 * * @param string $title Optional. Link title format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param bool $previous Optional. Whether to display link to previous or next post. Default true. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return string|void The adjacent post relational link URL. */ function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { if ( $previous && is_attachment() && $post = get_post() ) { $post = get_post( $post->post_parent ); } else { $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); } if ( empty( $post ) ) { return; } $post_title = the_title_attribute( array( 'echo' => false, 'post' => $post, ) ); if ( empty( $post_title ) ) { $post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); } $date = mysql2date( get_option( 'date_format' ), $post->post_date ); $title = str_replace( '%title', $post_title, $title ); $title = str_replace( '%date', $date, $title ); $link = $previous ? "\n"; $adjacent = $previous ? 'previous' : 'next'; /** * Filters the adjacent post relational link. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * @since 2.8.0 * * @param string $link The relational link. */ return apply_filters( "{$adjacent}_post_rel_link", $link ); } /** * Displays the relational links for the posts adjacent to the current post. * * @since 2.8.0 * * @param string $title Optional. Link title format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); } /** * Displays relational links for the posts adjacent to the current post for single post pages. * * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins * or theme templates. * * @since 3.0.0 * * @see adjacent_posts_rel_link() */ function adjacent_posts_rel_link_wp_head() { if ( ! is_single() || is_attachment() ) { return; } adjacent_posts_rel_link(); } /** * Displays the relational link for the next post adjacent to the current post. * * @since 2.8.0 * * @see get_adjacent_post_rel_link() * * @param string $title Optional. Link title format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); } /** * Displays the relational link for the previous post adjacent to the current post. * * @since 2.8.0 * * @see get_adjacent_post_rel_link() * * @param string $title Optional. Link title format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); } /** * Retrieves the boundary post. * * Boundary being either the first or last post by publish date within the constraints specified * by $in_same_term or $excluded_terms. * * @since 2.8.0 * * @param bool $in_same_term Optional. Whether returned post should be in a same taxonomy term. * Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. * Default empty. * @param bool $start Optional. Whether to retrieve first or last post. Default true * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return null|array Array containing the boundary post object if successful, null otherwise. */ function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { $post = get_post(); if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { return null; } $query_args = array( 'posts_per_page' => 1, 'order' => $start ? 'ASC' : 'DESC', 'update_post_term_cache' => false, 'update_post_meta_cache' => false, ); $term_array = array(); if ( ! is_array( $excluded_terms ) ) { if ( ! empty( $excluded_terms ) ) { $excluded_terms = explode( ',', $excluded_terms ); } else { $excluded_terms = array(); } } if ( $in_same_term || ! empty( $excluded_terms ) ) { if ( $in_same_term ) { $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); } if ( ! empty( $excluded_terms ) ) { $excluded_terms = array_map( 'intval', $excluded_terms ); $excluded_terms = array_diff( $excluded_terms, $term_array ); $inverse_terms = array(); foreach ( $excluded_terms as $excluded_term ) { $inverse_terms[] = $excluded_term * -1; } $excluded_terms = $inverse_terms; } $query_args['tax_query'] = array( array( 'taxonomy' => $taxonomy, 'terms' => array_merge( $term_array, $excluded_terms ), ), ); } return get_posts( $query_args ); } /** * Retrieves the previous post link that is adjacent to the current post. * * @since 3.7.0 * * @param string $format Optional. Link anchor format. Default '« %link'. * @param string $link Optional. Link permalink format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return string The link URL of the previous post in relation to the current post. */ function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy ); } /** * Displays the previous post link that is adjacent to the current post. * * @since 1.5.0 * * @see get_previous_post_link() * * @param string $format Optional. Link anchor format. Default '« %link'. * @param string $link Optional. Link permalink format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); } /** * Retrieves the next post link that is adjacent to the current post. * * @since 3.7.0 * * @param string $format Optional. Link anchor format. Default '« %link'. * @param string $link Optional. Link permalink format. Default '%title'. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return string The link URL of the next post in relation to the current post. */ function get_next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy ); } /** * Displays the next post link that is adjacent to the current post. * * @since 1.5.0 * @see get_next_post_link() * * @param string $format Optional. Link anchor format. Default '« %link'. * @param string $link Optional. Link permalink format. Default '%title' * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); } /** * Retrieves the adjacent post link. * * Can be either next post link or previous. * * @since 3.7.0 * * @param string $format Link anchor format. * @param string $link Link permalink format. * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty. * @param bool $previous Optional. Whether to display link to previous or next post. Default true. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. * @return string The link URL of the previous or next post in relation to the current post. */ function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { if ( $previous && is_attachment() ) { $post = get_post( get_post()->post_parent ); } else { $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); } if ( ! $post ) { $output = ''; } else { $title = $post->post_title; if ( empty( $post->post_title ) ) { $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); } /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $title, $post->ID ); $date = mysql2date( get_option( 'date_format' ), $post->post_date ); $rel = $previous ? 'prev' : 'next'; $string = ''; $inlink = str_replace( '%title', $title, $link ); $inlink = str_replace( '%date', $date, $inlink ); $inlink = $string . $inlink . ''; $output = str_replace( '%link', $inlink, $format ); } $adjacent = $previous ? 'previous' : 'next'; /** * Filters the adjacent post link. * * The dynamic portion of the hook name, `$adjacent`, refers to the type * of adjacency, 'next' or 'previous'. * * @since 2.6.0 * @since 4.2.0 Added the `$adjacent` parameter. * * @param string $output The adjacent post link. * @param string $format Link anchor format. * @param string $link Link permalink format. * @param WP_Post $post The adjacent post. * @param string $adjacent Whether the post is previous or next. */ return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent ); } /** * Displays the 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_term Optional. Whether link should be in a same taxonomy term. Default false. * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty. * @param bool $previous Optional. Whether to display link to previous or next post. Default true. * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. */ function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy ); } /** * Retrieves the link for a page number. * * @since 1.5.0 * * @global WP_Rewrite $wp_rewrite * * @param int $pagenum Optional. Page ID. Default 1. * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. * Otherwise, prepares the URL with esc_url_raw(). * @return string The link URL for the given page number. */ function get_pagenum_link( $pagenum = 1, $escape = true ) { global $wp_rewrite; $pagenum = (int) $pagenum; $request = remove_query_arg( 'paged' ); $home_root = parse_url( home_url() ); $home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : ''; $home_root = preg_quote( $home_root, '|' ); $request = preg_replace( '|^' . $home_root . '|i', '', $request ); $request = preg_replace( '|^/+|', '', $request ); if ( ! $wp_rewrite->using_permalinks() || is_admin() ) { $base = trailingslashit( get_bloginfo( 'url' ) ); 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( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); $request = ltrim( $request, '/' ); $base = trailingslashit( get_bloginfo( 'url' ) ); if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) { $base .= $wp_rewrite->index . '/'; } if ( $pagenum > 1 ) { $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); } $result = $base . $request . $query_string; } /** * Filters the page number link for the current request. * * @since 2.5.0 * * @param string $result The page number link. */ $result = apply_filters( 'get_pagenum_link', $result ); if ( $escape ) { return esc_url( $result ); } else { return esc_url_raw( $result ); } } /** * Retrieves the next posts page link. * * Backported from 2.1.3 to 2.0.10. * * @since 2.0.10 * * @global int $paged * * @param int $max_page Optional. Max pages. Default 0. * @return string|void The link URL for next posts page. */ 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 ); } } } /** * Displays or retrieves the next posts page link. * * @since 0.71 * * @param int $max_page Optional. Max pages. Default 0. * @param bool $echo Optional. Whether to echo the link. Default true. * @return string|void The link URL for next posts page if `$echo = false`. */ 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; } } /** * Retrieves the next posts page link. * * @since 2.7.0 * * @global int $paged * @global WP_Query $wp_query * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. Default 0. * @return string|void HTML-formatted next posts page link. */ function get_next_posts_link( $label = null, $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 ( null === $label ) { $label = __( 'Next Page »' ); } if ( ! is_single() && ( $nextpage <= $max_page ) ) { /** * Filters the anchor tag attributes for the next posts page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ $attr = apply_filters( 'next_posts_link_attributes', '' ); return '" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } } /** * Displays the next posts page link. * * @since 0.71 * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. Default 0. */ function next_posts_link( $label = null, $max_page = 0 ) { echo get_next_posts_link( $label, $max_page ); } /** * Retrieves the previous posts page 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 * * @global int $paged * * @return string|void The link for the previous posts page. */ 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 ); } } /** * Displays or retrieves the previous posts page link. * * @since 0.71 * * @param bool $echo Optional. Whether to echo the link. Default true. * @return string|void The previous posts page link if `$echo = false`. */ function previous_posts( $echo = true ) { $output = esc_url( get_previous_posts_page_link() ); if ( $echo ) { echo $output; } else { return $output; } } /** * Retrieves the previous posts page link. * * @since 2.7.0 * * @global int $paged * * @param string $label Optional. Previous page link text. * @return string|void HTML-formatted previous page link. */ function get_previous_posts_link( $label = null ) { global $paged; if ( null === $label ) { $label = __( '« Previous Page' ); } if ( ! is_single() && $paged > 1 ) { /** * Filters the anchor tag attributes for the previous posts page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ $attr = apply_filters( 'previous_posts_link_attributes', '' ); return '" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } } /** * Displays the previous posts page link. * * @since 0.71 * * @param string $label Optional. Previous page link text. */ function previous_posts_link( $label = null ) { echo get_previous_posts_link( $label ); } /** * Retrieves the post pages link navigation for previous and next pages. * * @since 2.8.0 * * @global WP_Query $wp_query * * @param string|array $args { * Optional. Arguments to build the post pages link navigation. * * @type string $sep Separator character. Default '—'. * @type string $prelabel Link text to display for the previous page link. * Default '« Previous Page'. * @type string $nxtlabel Link text to display for the next page link. * Default 'Next Page »'. * } * @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};)/i', '&$1', $args['sep'] ); $return .= get_next_posts_link( $args['nxtlabel'] ); } } return $return; } /** * Displays the post pages link navigation for previous and next pages. * * @since 0.71 * * @param string $sep Optional. Separator for posts navigation links. Default empty. * @param string $prelabel Optional. Label for previous pages. Default empty. * @param string $nxtlabel Optional Label for next pages. Default empty. */ function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { $args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) ); echo get_posts_nav_link( $args ); } /** * Retrieves the navigation to next/previous post, when applicable. * * @since 4.1.0 * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. * * @param array $args { * Optional. Default post navigation arguments. Default empty array. * * @type string $prev_text Anchor text to display in the previous post link. Default '%title'. * @type string $next_text Anchor text to display in the next post link. Default '%title'. * @type bool $in_same_term Whether link should be in a same taxonomy term. Default false. * @type array|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. * @type string $screen_reader_text Screen reader text for nav element. Default 'Post navigation'. * } * @return string Markup for post links. */ function get_the_post_navigation( $args = array() ) { $args = wp_parse_args( $args, array( 'prev_text' => '%title', 'next_text' => '%title', 'in_same_term' => false, 'excluded_terms' => '', 'taxonomy' => 'category', 'screen_reader_text' => __( 'Post navigation' ), ) ); $navigation = ''; $previous = get_previous_post_link( '', $args['prev_text'], $args['in_same_term'], $args['excluded_terms'], $args['taxonomy'] ); $next = get_next_post_link( '', $args['next_text'], $args['in_same_term'], $args['excluded_terms'], $args['taxonomy'] ); // Only add markup if there's somewhere to navigate to. if ( $previous || $next ) { $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] ); } return $navigation; } /** * Displays the navigation to next/previous post, when applicable. * * @since 4.1.0 * * @param array $args Optional. See get_the_post_navigation() for available arguments. * Default empty array. */ function the_post_navigation( $args = array() ) { echo get_the_post_navigation( $args ); } /** * Returns the navigation to next/previous set of posts, when applicable. * * @since 4.1.0 * * @global WP_Query $wp_query WordPress Query object. * * @param array $args { * Optional. Default posts navigation arguments. Default empty array. * * @type string $prev_text Anchor text to display in the previous posts link. * Default 'Older posts'. * @type string $next_text Anchor text to display in the next posts link. * Default 'Newer posts'. * @type string $screen_reader_text Screen reader text for nav element. * Default 'Posts navigation'. * } * @return string Markup for posts links. */ function get_the_posts_navigation( $args = array() ) { $navigation = ''; // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { $args = wp_parse_args( $args, array( 'prev_text' => __( 'Older posts' ), 'next_text' => __( 'Newer posts' ), 'screen_reader_text' => __( 'Posts navigation' ), ) ); $next_link = get_previous_posts_link( $args['next_text'] ); $prev_link = get_next_posts_link( $args['prev_text'] ); if ( $prev_link ) { $navigation .= ''; } if ( $next_link ) { $navigation .= ''; } $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] ); } return $navigation; } /** * Displays the navigation to next/previous set of posts, when applicable. * * @since 4.1.0 * * @param array $args Optional. See get_the_posts_navigation() for available arguments. * Default empty array. */ function the_posts_navigation( $args = array() ) { echo get_the_posts_navigation( $args ); } /** * Retrieves a paginated navigation to next/previous set of posts, when applicable. * * @since 4.1.0 * * @param array $args { * Optional. Default pagination arguments, see paginate_links(). * * @type string $screen_reader_text Screen reader text for navigation element. * Default 'Posts navigation'. * } * @return string Markup for pagination links. */ function get_the_posts_pagination( $args = array() ) { $navigation = ''; // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { $args = wp_parse_args( $args, array( 'mid_size' => 1, 'prev_text' => _x( 'Previous', 'previous set of posts' ), 'next_text' => _x( 'Next', 'next set of posts' ), 'screen_reader_text' => __( 'Posts navigation' ), ) ); // Make sure we get a string back. Plain is the next best thing. if ( isset( $args['type'] ) && 'array' == $args['type'] ) { $args['type'] = 'plain'; } // Set up paginated links. $links = paginate_links( $args ); if ( $links ) { $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] ); } } return $navigation; } /** * Displays a paginated navigation to next/previous set of posts, when applicable. * * @since 4.1.0 * * @param array $args Optional. See get_the_posts_pagination() for available arguments. * Default empty array. */ function the_posts_pagination( $args = array() ) { echo get_the_posts_pagination( $args ); } /** * Wraps passed links in navigational markup. * * @since 4.1.0 * @access private * * @param string $links Navigational links. * @param string $class Optional. Custom class for nav element. Default: 'posts-navigation'. * @param string $screen_reader_text Optional. Screen reader text for nav element. Default: 'Posts navigation'. * @return string Navigation template tag. */ function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) { if ( empty( $screen_reader_text ) ) { $screen_reader_text = __( 'Posts navigation' ); } $template = ' '; /** * Filters the navigation markup template. * * Note: The filtered template HTML must contain specifiers for the navigation * class (%1$s), the screen-reader-text value (%2$s), and placement of the * navigation links (%3$s): * * * * @since 4.4.0 * * @param string $template The default template. * @param string $class The class passed by the calling function. * @return string Navigation template. */ $template = apply_filters( 'navigation_markup_template', $template, $class ); return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links ); } /** * Retrieves the comments page number link. * * @since 2.7.0 * * @global WP_Rewrite $wp_rewrite * * @param int $pagenum Optional. Page number. Default 1. * @param int $max_page Optional. The maximum number of comment pages. Default 0. * @return string The comments page number link URL. */ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { global $wp_rewrite; $pagenum = (int) $pagenum; $result = get_permalink(); if ( 'newest' == get_option( 'default_comments_page' ) ) { if ( $pagenum != $max_page ) { if ( $wp_rewrite->using_permalinks() ) { $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); } else { $result = add_query_arg( 'cpage', $pagenum, $result ); } } } elseif ( $pagenum > 1 ) { if ( $wp_rewrite->using_permalinks() ) { $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); } else { $result = add_query_arg( 'cpage', $pagenum, $result ); } } $result .= '#comments'; /** * Filters the comments page number link for the current request. * * @since 2.7.0 * * @param string $result The comments page number link. */ return apply_filters( 'get_comments_pagenum_link', $result ); } /** * Retrieves the link to the next comments page. * * @since 2.7.1 * * @global WP_Query $wp_query * * @param string $label Optional. Label for link text. Default empty. * @param int $max_page Optional. Max page. Default 0. * @return string|void HTML-formatted link for the next page of comments. */ function get_next_comments_link( $label = '', $max_page = 0 ) { global $wp_query; if ( ! is_singular() ) { return; } $page = get_query_var( 'cpage' ); if ( ! $page ) { $page = 1; } $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 »' ); } /** * Filters the anchor tag attributes for the next comments page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ return '' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } /** * Displays the link to the next comments page. * * @since 2.7.0 * * @param string $label Optional. Label for link text. Default empty. * @param int $max_page Optional. Max page. Default 0. */ function next_comments_link( $label = '', $max_page = 0 ) { echo get_next_comments_link( $label, $max_page ); } /** * Retrieves the link to the previous comments page. * * @since 2.7.1 * * @param string $label Optional. Label for comments link text. Default empty. * @return string|void HTML-formatted link for the previous page of comments. */ function get_previous_comments_link( $label = '' ) { if ( ! is_singular() ) { return; } $page = get_query_var( 'cpage' ); if ( intval( $page ) <= 1 ) { return; } $prevpage = intval( $page ) - 1; if ( empty( $label ) ) { $label = __( '« Older Comments' ); } /** * Filters the anchor tag attributes for the previous comments page link. * * @since 2.7.0 * * @param string $attributes Attributes for the anchor tag. */ return '' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; } /** * Displays the link to the previous comments page. * * @since 2.7.0 * * @param string $label Optional. Label for comments link text. Default empty. */ function previous_comments_link( $label = '' ) { echo get_previous_comments_link( $label ); } /** * Displays or retrieves pagination links for the comments on the current post. * * @see paginate_links() * @since 2.7.0 * * @global WP_Rewrite $wp_rewrite * * @param string|array $args Optional args. See paginate_links(). Default empty array. * @return string|array|void Markup for comment page links or array of comment page links. */ function paginate_comments_links( $args = array() ) { global $wp_rewrite; if ( ! is_singular() ) { 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, 'type' => 'plain', 'add_fragment' => '#comments', ); if ( $wp_rewrite->using_permalinks() ) { $defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' ); } $args = wp_parse_args( $args, $defaults ); $page_links = paginate_links( $args ); if ( $args['echo'] && 'array' !== $args['type'] ) { echo $page_links; } else { return $page_links; } } /** * Retrieves navigation to next/previous set of comments, when applicable. * * @since 4.4.0 * * @param array $args { * Optional. Default comments navigation arguments. * * @type string $prev_text Anchor text to display in the previous comments link. * Default 'Older comments'. * @type string $next_text Anchor text to display in the next comments link. * Default 'Newer comments'. * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. * } * @return string Markup for comments links. */ function get_the_comments_navigation( $args = array() ) { $navigation = ''; // Are there comments to navigate through? if ( get_comment_pages_count() > 1 ) { $args = wp_parse_args( $args, array( 'prev_text' => __( 'Older comments' ), 'next_text' => __( 'Newer comments' ), 'screen_reader_text' => __( 'Comments navigation' ), ) ); $prev_link = get_previous_comments_link( $args['prev_text'] ); $next_link = get_next_comments_link( $args['next_text'] ); if ( $prev_link ) { $navigation .= ''; } if ( $next_link ) { $navigation .= ''; } $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'] ); } return $navigation; } /** * Displays navigation to next/previous set of comments, when applicable. * * @since 4.4.0 * * @param array $args See get_the_comments_navigation() for available arguments. Default empty array. */ function the_comments_navigation( $args = array() ) { echo get_the_comments_navigation( $args ); } /** * Retrieves a paginated navigation to next/previous set of comments, when applicable. * * @since 4.4.0 * * @see paginate_comments_links() * * @param array $args { * Optional. Default pagination arguments. * * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. * } * @return string Markup for pagination links. */ function get_the_comments_pagination( $args = array() ) { $navigation = ''; $args = wp_parse_args( $args, array( 'screen_reader_text' => __( 'Comments navigation' ), ) ); $args['echo'] = false; // Make sure we get a string back. Plain is the next best thing. if ( isset( $args['type'] ) && 'array' == $args['type'] ) { $args['type'] = 'plain'; } $links = paginate_comments_links( $args ); if ( $links ) { $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] ); } return $navigation; } /** * Displays a paginated navigation to next/previous set of comments, when applicable. * * @since 4.4.0 * * @param array $args See get_the_comments_pagination() for available arguments. Default empty array. */ function the_comments_pagination( $args = array() ) { echo get_the_comments_pagination( $args ); } /** * Retrieves the URL for the current site where the front end is accessible. * * Returns the 'home' option with the appropriate protocol. The protocol will be 'https' * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. * If `$scheme` is 'http' or 'https', is_ssl() is overridden. * * @since 3.0.0 * * @param string $path Optional. Path relative to the home URL. Default empty. * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts * 'http', 'https', 'relative', 'rest', or null. Default null. * @return string Home URL link with optional path appended. */ function home_url( $path = '', $scheme = null ) { return get_home_url( null, $path, $scheme ); } /** * Retrieves the URL for a given site where the front end is accessible. * * Returns the 'home' option with the appropriate protocol. The protocol will be 'https' * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. * If `$scheme` is 'http' or 'https', is_ssl() is overridden. * * @since 3.0.0 * * @global string $pagenow * * @param int $blog_id Optional. Site ID. Default null (current site). * @param string $path Optional. Path relative to the home URL. Default empty. * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts * 'http', 'https', 'relative', 'rest', or null. Default null. * @return string Home URL link with optional path appended. */ function get_home_url( $blog_id = null, $path = '', $scheme = null ) { global $pagenow; $orig_scheme = $scheme; if ( empty( $blog_id ) || ! is_multisite() ) { $url = get_option( 'home' ); } else { switch_to_blog( $blog_id ); $url = get_option( 'home' ); restore_current_blog(); } if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) { $scheme = 'https'; } else { $scheme = parse_url( $url, PHP_URL_SCHEME ); } } $url = set_url_scheme( $url, $scheme ); if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); } /** * Filters the home URL. * * @since 3.0.0 * * @param string $url The complete home URL including scheme and path. * @param string $path Path relative to the home URL. Blank string if no path is specified. * @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https', * 'relative', 'rest', or null. * @param int|null $blog_id Site ID, or null for the current site. */ return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); } /** * Retrieves the URL for the current site where WordPress application files * (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. * * 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. * * @since 3.0.0 * * @param string $path Optional. Path relative to the site URL. Default empty. * @param string $scheme Optional. Scheme to give the site URL context. See set_url_scheme(). * @return string Site URL link with optional path appended. */ function site_url( $path = '', $scheme = null ) { return get_site_url( null, $path, $scheme ); } /** * Retrieves the URL for a given site where WordPress application files * (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. * * 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. * * @since 3.0.0 * * @param int $blog_id Optional. Site ID. Default null (current site). * @param string $path Optional. Path relative to the site URL. Default empty. * @param string $scheme Optional. Scheme to give the site URL context. Accepts * 'http', 'https', 'login', 'login_post', 'admin', or * 'relative'. Default null. * @return string Site URL link with optional path appended. */ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { if ( empty( $blog_id ) || ! is_multisite() ) { $url = get_option( 'siteurl' ); } else { switch_to_blog( $blog_id ); $url = get_option( 'siteurl' ); restore_current_blog(); } $url = set_url_scheme( $url, $scheme ); if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); } /** * Filters the site URL. * * @since 2.7.0 * * @param string $url The complete site URL including scheme and path. * @param string $path Path relative to the site URL. Blank string if no path is specified. * @param string|null $scheme Scheme to give the site URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. * @param int|null $blog_id Site ID, or null for the current site. */ return apply_filters( 'site_url', $url, $path, $scheme, $blog_id ); } /** * Retrieves the URL to the admin area for the current site. * * @since 2.6.0 * * @param string $path Optional path relative to the admin URL. * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). * 'http' or 'https' can be passed to force those schemes. * @return string Admin URL link with optional path appended. */ function admin_url( $path = '', $scheme = 'admin' ) { return get_admin_url( null, $path, $scheme ); } /** * Retrieves the URL to the admin area for a given site. * * @since 3.0.0 * * @param int $blog_id Optional. Site ID. Default null (current site). * @param string $path Optional. Path relative to the admin URL. Default empty. * @param string $scheme Optional. The scheme to use. Accepts 'http' or 'https', * to force those schemes. Default 'admin', which obeys * force_ssl_admin() and is_ssl(). * @return string Admin URL link with optional path appended. */ function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { $url = get_site_url( $blog_id, 'wp-admin/', $scheme ); if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the admin area URL. * * @since 2.8.0 * * @param string $url The complete admin area URL including scheme and path. * @param string $path Path relative to the admin area URL. Blank string if no path is specified. * @param int|null $blog_id Site ID, or null for the current site. */ return apply_filters( 'admin_url', $url, $path, $blog_id ); } /** * Retrieves the URL to the includes directory. * * @since 2.6.0 * * @param string $path Optional. Path relative to the includes URL. Default empty. * @param string $scheme Optional. Scheme to give the includes URL context. Accepts * 'http', 'https', or 'relative'. Default null. * @return string Includes URL link with optional path appended. */ function includes_url( $path = '', $scheme = null ) { $url = site_url( '/' . WPINC . '/', $scheme ); if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the URL to the includes directory. * * @since 2.8.0 * * @param string $url The complete URL to the includes directory including scheme and path. * @param string $path Path relative to the URL to the wp-includes directory. Blank string * if no path is specified. */ return apply_filters( 'includes_url', $url, $path ); } /** * Retrieves the URL to the content directory. * * @since 2.6.0 * * @param string $path Optional. Path relative to the content URL. Default empty. * @return string Content URL link with optional path appended. */ function content_url( $path = '' ) { $url = set_url_scheme( WP_CONTENT_URL ); if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); } /** * Filters the URL to the content directory. * * @since 2.8.0 * * @param string $url The complete URL to the content directory including scheme and path. * @param string $path Path relative to the URL to the content directory. Blank string * if no path is specified. */ return apply_filters( 'content_url', $url, $path ); } /** * Retrieves a URL within the plugins or mu-plugins directory. * * Defaults to the plugins directory URL if no arguments are supplied. * * @since 2.6.0 * * @param string $path Optional. Extra path appended to the end of the URL, including * the relative directory if $plugin is supplied. Default empty. * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin. * The URL will be relative to its directory. Default empty. * Typically this is done by passing `__FILE__` as the argument. * @return string Plugins URL link with optional paths appended. */ function plugins_url( $path = '', $plugin = '' ) { $path = wp_normalize_path( $path ); $plugin = wp_normalize_path( $plugin ); $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) { $url = WPMU_PLUGIN_URL; } else { $url = WP_PLUGIN_URL; } $url = set_url_scheme( $url ); if ( ! empty( $plugin ) && is_string( $plugin ) ) { $folder = dirname( plugin_basename( $plugin ) ); if ( '.' != $folder ) { $url .= '/' . ltrim( $folder, '/' ); } } if ( $path && is_string( $path ) ) { $url .= '/' . ltrim( $path, '/' ); } /** * Filters the URL to the plugins directory. * * @since 2.8.0 * * @param string $url The complete URL to the plugins directory including scheme and path. * @param string $path Path relative to the URL to the plugins directory. Blank string * if no path is specified. * @param string $plugin The plugin file path to be relative to. Blank string if no plugin * is specified. */ return apply_filters( 'plugins_url', $url, $path, $plugin ); } /** * Retrieves the site URL for the current network. * * Returns the site URL with the appropriate protocol, 'https' if * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is * overridden. * * @since 3.0.0 * * @see set_url_scheme() * * @param string $path Optional. Path relative to the site URL. Default empty. * @param string $scheme Optional. Scheme to give the site URL context. Accepts * 'http', 'https', or 'relative'. Default null. * @return string Site URL link with optional path appended. */ function network_site_url( $path = '', $scheme = null ) { if ( ! is_multisite() ) { return site_url( $path, $scheme ); } $current_network = get_network(); if ( 'relative' == $scheme ) { $url = $current_network->path; } else { $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); } if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the network site URL. * * @since 3.0.0 * * @param string $url The complete network site URL including scheme and path. * @param string $path Path relative to the network site URL. Blank string if * no path is specified. * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https', * 'relative' or null. */ return apply_filters( 'network_site_url', $url, $path, $scheme ); } /** * Retrieves the home URL for the current network. * * Returns the home URL with the appropriate protocol, 'https' is_ssl() * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is * overridden. * * @since 3.0.0 * * @param string $path Optional. Path relative to the home URL. Default empty. * @param string $scheme Optional. Scheme to give the home URL context. Accepts * 'http', 'https', or 'relative'. Default null. * @return string Home URL link with optional path appended. */ function network_home_url( $path = '', $scheme = null ) { if ( ! is_multisite() ) { return home_url( $path, $scheme ); } $current_network = get_network(); $orig_scheme = $scheme; if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; } if ( 'relative' == $scheme ) { $url = $current_network->path; } else { $url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); } if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the network home URL. * * @since 3.0.0 * * @param string $url The complete network home URL including scheme and path. * @param string $path Path relative to the network home URL. Blank string * if no path is specified. * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https', * 'relative' or null. */ return apply_filters( 'network_home_url', $url, $path, $orig_scheme ); } /** * Retrieves the URL to the admin area for the network. * * @since 3.0.0 * * @param string $path Optional path relative to the admin URL. Default empty. * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() * and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Admin URL link with optional path appended. */ function network_admin_url( $path = '', $scheme = 'admin' ) { if ( ! is_multisite() ) { return admin_url( $path, $scheme ); } $url = network_site_url( 'wp-admin/network/', $scheme ); if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the network admin URL. * * @since 3.0.0 * * @param string $url The complete network admin URL including scheme and path. * @param string $path Path relative to the network admin URL. Blank string if * no path is specified. */ return apply_filters( 'network_admin_url', $url, $path ); } /** * Retrieves the URL to the admin area for the current user. * * @since 3.0.0 * * @param string $path Optional. Path relative to the admin URL. Default empty. * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() * and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Admin URL link with optional path appended. */ function user_admin_url( $path = '', $scheme = 'admin' ) { $url = network_site_url( 'wp-admin/user/', $scheme ); if ( $path && is_string( $path ) ) { $url .= ltrim( $path, '/' ); } /** * Filters the user admin URL for the current user. * * @since 3.1.0 * * @param string $url The complete URL including scheme and path. * @param string $path Path relative to the URL. Blank string if * no path is specified. */ return apply_filters( 'user_admin_url', $url, $path ); } /** * Retrieves the URL to the admin area for either the current site or the network depending on context. * * @since 3.1.0 * * @param string $path Optional. Path relative to the admin URL. Default empty. * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() * and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Admin URL link with optional path appended. */ function self_admin_url( $path = '', $scheme = 'admin' ) { if ( is_network_admin() ) { $url = network_admin_url( $path, $scheme ); } elseif ( is_user_admin() ) { $url = user_admin_url( $path, $scheme ); } else { $url = admin_url( $path, $scheme ); } /** * Filters the admin URL for the current site or network depending on context. * * @since 4.9.0 * * @param string $url The complete URL including scheme and path. * @param string $path Path relative to the URL. Blank string if no path is specified. * @param string $scheme The scheme to use. */ return apply_filters( 'self_admin_url', $url, $path, $scheme ); } /** * Sets the scheme for a URL. * * @since 3.4.0 * @since 4.4.0 The 'rest' scheme was added. * * @param string $url Absolute URL that includes a scheme * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', * 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null. * @return string $url URL with chosen scheme. */ function set_url_scheme( $url, $scheme = null ) { $orig_scheme = $scheme; if ( ! $scheme ) { $scheme = is_ssl() ? 'https' : 'http'; } elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) { $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http'; } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) { $scheme = is_ssl() ? 'https' : 'http'; } $url = trim( $url ); if ( substr( $url, 0, 2 ) === '//' ) { $url = 'http:' . $url; } if ( 'relative' == $scheme ) { $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); if ( $url !== '' && $url[0] === '/' ) { $url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); } } else { $url = preg_replace( '#^\w+://#', $scheme . '://', $url ); } /** * Filters the resulting URL after setting the scheme. * * @since 3.4.0 * * @param string $url The complete URL including scheme and path. * @param string $scheme Scheme applied to the URL. One of 'http', 'https', or 'relative'. * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login', * 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. */ return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme ); } /** * Retrieves the URL to the user's dashboard. * * If a user does not belong to any site, the global user dashboard is used. If the user * belongs to the current site, the dashboard for the current site is returned. If the user * cannot edit the current site, the dashboard to the user's primary site is returned. * * @since 3.1.0 * * @param int $user_id Optional. User ID. Defaults to current user. * @param string $path Optional path relative to the dashboard. Use only paths known to * both site and user admins. Default empty. * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() * and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Dashboard URL link with optional path appended. */ function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) { $user_id = $user_id ? (int) $user_id : get_current_user_id(); $blogs = get_blogs_of_user( $user_id ); if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { $url = user_admin_url( $path, $scheme ); } elseif ( ! is_multisite() ) { $url = admin_url( $path, $scheme ); } else { $current_blog = get_current_blog_id(); if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { $url = admin_url( $path, $scheme ); } else { $active = get_active_blog_for_user( $user_id ); if ( $active ) { $url = get_admin_url( $active->blog_id, $path, $scheme ); } else { $url = user_admin_url( $path, $scheme ); } } } /** * Filters the dashboard URL for a user. * * @since 3.1.0 * * @param string $url The complete URL including scheme and path. * @param int $user_id The user ID. * @param string $path Path relative to the URL. Blank string if no path is specified. * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme ); } /** * Retrieves the URL to the user's profile editor. * * @since 3.1.0 * * @param int $user_id Optional. User ID. Defaults to current user. * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() * and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Dashboard URL link with optional path appended. */ function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) { $user_id = $user_id ? (int) $user_id : get_current_user_id(); if ( is_user_admin() ) { $url = user_admin_url( 'profile.php', $scheme ); } elseif ( is_network_admin() ) { $url = network_admin_url( 'profile.php', $scheme ); } else { $url = get_dashboard_url( $user_id, 'profile.php', $scheme ); } /** * Filters the URL for a user's profile editor. * * @since 3.1.0 * * @param string $url The complete URL including scheme and path. * @param int $user_id The user ID. * @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ return apply_filters( 'edit_profile_url', $url, $user_id, $scheme ); } /** * Returns the canonical URL for a post. * * When the post is the same as the current requested page the function will handle the * pagination arguments too. * * @since 4.6.0 * * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`. * @return string|false The canonical URL, or false if the post does not exist or has not * been published yet. */ function wp_get_canonical_url( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } if ( 'publish' !== $post->post_status ) { return false; } $canonical_url = get_permalink( $post ); // If a canonical is being generated for the current page, make sure it has pagination if needed. if ( $post->ID === get_queried_object_id() ) { $page = get_query_var( 'page', 0 ); if ( $page >= 2 ) { if ( '' == get_option( 'permalink_structure' ) ) { $canonical_url = add_query_arg( 'page', $page, $canonical_url ); } else { $canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' ); } } $cpage = get_query_var( 'cpage', 0 ); if ( $cpage ) { $canonical_url = get_comments_pagenum_link( $cpage ); } } /** * Filters the canonical URL for a post. * * @since 4.6.0 * * @param string $canonical_url The post's canonical URL. * @param WP_Post $post Post object. */ return apply_filters( 'get_canonical_url', $canonical_url, $post ); } /** * Outputs rel=canonical for singular queries. * * @since 2.9.0 * @since 4.6.0 Adjusted to use `wp_get_canonical_url()`. */ function rel_canonical() { if ( ! is_singular() ) { return; } $id = get_queried_object_id(); if ( 0 === $id ) { return; } $url = wp_get_canonical_url( $id ); if ( ! empty( $url ) ) { echo '' . "\n"; } } /** * Returns a shortlink for a post, page, attachment, or site. * * This function exists to provide a shortlink tag that all themes and plugins can target. * A plugin must hook in to provide the actual shortlinks. Default shortlink support is * limited to providing ?p= style links for posts. Plugins can short-circuit this function * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'} * filter. * * @since 3.0.0 * * @param int $id Optional. A post or site id. Default is 0, which means the current post or site. * @param string $context Optional. Whether the id is a 'site' id, 'post' id, or 'media' id. If 'post', * the post_type of the post is consulted. If 'query', the current query is consulted * to determine the id and context. Default 'post'. * @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how * and whether to honor this. Default true. * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks * are not enabled. */ function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { /** * Filters whether to preempt generating a shortlink for the given post. * * Passing a truthy value to the filter will effectively short-circuit the * shortlink-generation process, returning that value instead. * * @since 3.0.0 * * @param bool|string $return Short-circuit return value. Either false or a URL string. * @param int $id Post ID, or 0 for the current post. * @param string $context The context for the link. One of 'post' or 'query', * @param bool $allow_slugs Whether to allow post slugs in the shortlink. */ $shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs ); if ( false !== $shortlink ) { return $shortlink; } $post_id = 0; if ( 'query' == $context && is_singular() ) { $post_id = get_queried_object_id(); $post = get_post( $post_id ); } elseif ( 'post' == $context ) { $post = get_post( $id ); if ( ! empty( $post->ID ) ) { $post_id = $post->ID; } } $shortlink = ''; // Return p= link for all public post types. if ( ! empty( $post_id ) ) { $post_type = get_post_type_object( $post->post_type ); if ( 'page' === $post->post_type && $post->ID == get_option( 'page_on_front' ) && 'page' == get_option( 'show_on_front' ) ) { $shortlink = home_url( '/' ); } elseif ( $post_type->public ) { $shortlink = home_url( '?p=' . $post_id ); } } /** * Filters the shortlink for a post. * * @since 3.0.0 * * @param string $shortlink Shortlink URL. * @param int $id Post ID, or 0 for the current post. * @param string $context The context for the link. One of 'post' or 'query', * @param bool $allow_slugs Whether to allow post slugs in the shortlink. Not used by default. */ return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs ); } /** * Injects rel=shortlink into the head if a shortlink is defined for the current page. * * Attached to the {@see 'wp_head'} action. * * @since 3.0.0 */ function wp_shortlink_wp_head() { $shortlink = wp_get_shortlink( 0, 'query' ); if ( empty( $shortlink ) ) { return; } echo "\n"; } /** * Sends a Link: rel=shortlink header if a shortlink is defined for the current page. * * Attached to the {@see 'wp'} action. * * @since 3.0.0 */ function wp_shortlink_header() { if ( headers_sent() ) { return; } $shortlink = wp_get_shortlink( 0, 'query' ); if ( empty( $shortlink ) ) { return; } header( 'Link: <' . $shortlink . '>; rel=shortlink', false ); } /** * Displays the shortlink for a post. * * Must be called from inside "The Loop" * * Call like the_shortlink( __( 'Shortlinkage FTW' ) ) * * @since 3.0.0 * * @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.' * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title. * @param string $before Optional HTML to display before the link. Default empty. * @param string $after Optional HTML to display after the link. Default empty. */ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { $post = get_post(); if ( empty( $text ) ) { $text = __( 'This is the short link.' ); } if ( empty( $title ) ) { $title = the_title_attribute( array( 'echo' => false ) ); } $shortlink = wp_get_shortlink( $post->ID ); if ( ! empty( $shortlink ) ) { $link = '' . $text . ''; /** * Filters the short link anchor tag for a post. * * @since 3.0.0 * * @param string $link Shortlink anchor tag. * @param string $shortlink Shortlink URL. * @param string $text Shortlink's text. * @param string $title Shortlink's title attribute. */ $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); echo $before, $link, $after; } } /** * Retrieves the avatar URL. * * @since 4.2.0 * * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param array $args { * Optional. Arguments to return instead of the default arguments. * * @type int $size Height and width of the avatar in pixels. Default 96. * @type string $default URL for the default image or a default type. Accepts '404' (return * a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), * 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', * or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or * 'gravatar_default' (the Gravatar logo). Default is the value of the * 'avatar_default' option, with a fallback of 'mystery'. * @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. * @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are * judged in that order. Default is the value of the 'avatar_rating' option. * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. * Default null. * @type array $processed_args When the function returns, the value will be the processed/sanitized $args * plus a "found_avatar" guess. Pass as a reference. Default null. * } * @return false|string The URL of the avatar we found, or false if we couldn't find an avatar. */ function get_avatar_url( $id_or_email, $args = null ) { $args = get_avatar_data( $id_or_email, $args ); return $args['url']; } /** * Check if this comment type allows avatars to be retrieved. * * @since 5.1.0 * * @param string $comment_type Comment type to check. * @return bool Whether the comment type is allowed for retrieving avatars. */ function is_avatar_comment_type( $comment_type ) { /** * Filters the list of allowed comment types for retrieving avatars. * * @since 3.0.0 * * @param array $types An array of content types. Default only contains 'comment'. */ $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); return in_array( $comment_type, (array) $allowed_comment_types, true ); } /** * Retrieves default data about the avatar. * * @since 4.2.0 * * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param array $args { * Optional. Arguments to return instead of the default arguments. * * @type int $size Height and width of the avatar image file in pixels. Default 96. * @type int $height Display height of the avatar in pixels. Defaults to $size. * @type int $width Display width of the avatar in pixels. Defaults to $size. * @type string $default URL for the default image or a default type. Accepts '404' (return * a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), * 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', * or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or * 'gravatar_default' (the Gravatar logo). Default is the value of the * 'avatar_default' option, with a fallback of 'mystery'. * @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. * @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are * judged in that order. Default is the value of the 'avatar_rating' option. * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. * Default null. * @type array $processed_args When the function returns, the value will be the processed/sanitized $args * plus a "found_avatar" guess. Pass as a reference. Default null. * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. * } * @return array $processed_args { * Along with the arguments passed in `$args`, this will contain a couple of extra arguments. * * @type bool $found_avatar True if we were able to find an avatar for this user, * false or not set if we couldn't. * @type string $url The URL of the avatar we found. * } */ function get_avatar_data( $id_or_email, $args = null ) { $args = wp_parse_args( $args, array( 'size' => 96, 'height' => null, 'width' => null, 'default' => get_option( 'avatar_default', 'mystery' ), 'force_default' => false, 'rating' => get_option( 'avatar_rating' ), 'scheme' => null, 'processed_args' => null, // if used, should be a reference 'extra_attr' => '', ) ); if ( is_numeric( $args['size'] ) ) { $args['size'] = absint( $args['size'] ); if ( ! $args['size'] ) { $args['size'] = 96; } } else { $args['size'] = 96; } if ( is_numeric( $args['height'] ) ) { $args['height'] = absint( $args['height'] ); if ( ! $args['height'] ) { $args['height'] = $args['size']; } } else { $args['height'] = $args['size']; } if ( is_numeric( $args['width'] ) ) { $args['width'] = absint( $args['width'] ); if ( ! $args['width'] ) { $args['width'] = $args['size']; } } else { $args['width'] = $args['size']; } if ( empty( $args['default'] ) ) { $args['default'] = get_option( 'avatar_default', 'mystery' ); } switch ( $args['default'] ) { case 'mm': case 'mystery': case 'mysteryman': $args['default'] = 'mm'; break; case 'gravatar_default': $args['default'] = false; break; } $args['force_default'] = (bool) $args['force_default']; $args['rating'] = strtolower( $args['rating'] ); $args['found_avatar'] = false; /** * Filters whether to retrieve the avatar URL early. * * Passing a non-null value in the 'url' member of the return array will * effectively short circuit get_avatar_data(), passing the value through * the {@see 'get_avatar_data'} filter and returning early. * * @since 4.2.0 * * @param array $args Arguments passed to get_avatar_data(), after processing. * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. */ $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); if ( isset( $args['url'] ) ) { /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'get_avatar_data', $args, $id_or_email ); } $email_hash = ''; $user = $email = false; if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { $id_or_email = get_comment( $id_or_email ); } // Process the user identifier. if ( is_numeric( $id_or_email ) ) { $user = get_user_by( 'id', absint( $id_or_email ) ); } elseif ( is_string( $id_or_email ) ) { if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) { // md5 hash list( $email_hash ) = explode( '@', $id_or_email ); } else { // email address $email = $id_or_email; } } elseif ( $id_or_email instanceof WP_User ) { // User Object $user = $id_or_email; } elseif ( $id_or_email instanceof WP_Post ) { // Post Object $user = get_user_by( 'id', (int) $id_or_email->post_author ); } elseif ( $id_or_email instanceof WP_Comment ) { if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { $args['url'] = false; /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'get_avatar_data', $args, $id_or_email ); } if ( ! empty( $id_or_email->user_id ) ) { $user = get_user_by( 'id', (int) $id_or_email->user_id ); } if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) { $email = $id_or_email->comment_author_email; } } if ( ! $email_hash ) { if ( $user ) { $email = $user->user_email; } if ( $email ) { $email_hash = md5( strtolower( trim( $email ) ) ); } } if ( $email_hash ) { $args['found_avatar'] = true; $gravatar_server = hexdec( $email_hash[0] ) % 3; } else { $gravatar_server = rand( 0, 2 ); } $url_args = array( 's' => $args['size'], 'd' => $args['default'], 'f' => $args['force_default'] ? 'y' : false, 'r' => $args['rating'], ); if ( is_ssl() ) { $url = 'https://secure.gravatar.com/avatar/' . $email_hash; } else { $url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash ); } $url = add_query_arg( rawurlencode_deep( array_filter( $url_args ) ), set_url_scheme( $url, $args['scheme'] ) ); /** * Filters the avatar URL. * * @since 4.2.0 * * @param string $url The URL of the avatar. * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param array $args Arguments passed to get_avatar_data(), after processing. */ $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); /** * Filters the avatar data. * * @since 4.2.0 * * @param array $args Arguments passed to get_avatar_data(), after processing. * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. */ return apply_filters( 'get_avatar_data', $args, $id_or_email ); } /** * Retrieves the URL of a file in the theme. * * Searches in the stylesheet directory before the template directory so themes * which inherit from a parent theme can just override one file. * * @since 4.7.0 * * @param string $file Optional. File to search for in the stylesheet directory. * @return string The URL of the file. */ function get_theme_file_uri( $file = '' ) { $file = ltrim( $file, '/' ); if ( empty( $file ) ) { $url = get_stylesheet_directory_uri(); } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { $url = get_stylesheet_directory_uri() . '/' . $file; } else { $url = get_template_directory_uri() . '/' . $file; } /** * Filters the URL to a file in the theme. * * @since 4.7.0 * * @param string $url The file URL. * @param string $file The requested file to search for. */ return apply_filters( 'theme_file_uri', $url, $file ); } /** * Retrieves the URL of a file in the parent theme. * * @since 4.7.0 * * @param string $file Optional. File to return the URL for in the template directory. * @return string The URL of the file. */ function get_parent_theme_file_uri( $file = '' ) { $file = ltrim( $file, '/' ); if ( empty( $file ) ) { $url = get_template_directory_uri(); } else { $url = get_template_directory_uri() . '/' . $file; } /** * Filters the URL to a file in the parent theme. * * @since 4.7.0 * * @param string $url The file URL. * @param string $file The requested file to search for. */ return apply_filters( 'parent_theme_file_uri', $url, $file ); } /** * Retrieves the path of a file in the theme. * * Searches in the stylesheet directory before the template directory so themes * which inherit from a parent theme can just override one file. * * @since 4.7.0 * * @param string $file Optional. File to search for in the stylesheet directory. * @return string The path of the file. */ function get_theme_file_path( $file = '' ) { $file = ltrim( $file, '/' ); if ( empty( $file ) ) { $path = get_stylesheet_directory(); } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { $path = get_stylesheet_directory() . '/' . $file; } else { $path = get_template_directory() . '/' . $file; } /** * Filters the path to a file in the theme. * * @since 4.7.0 * * @param string $path The file path. * @param string $file The requested file to search for. */ return apply_filters( 'theme_file_path', $path, $file ); } /** * Retrieves the path of a file in the parent theme. * * @since 4.7.0 * * @param string $file Optional. File to return the path for in the template directory. * @return string The path of the file. */ function get_parent_theme_file_path( $file = '' ) { $file = ltrim( $file, '/' ); if ( empty( $file ) ) { $path = get_template_directory(); } else { $path = get_template_directory() . '/' . $file; } /** * Filters the path to a file in the parent theme. * * @since 4.7.0 * * @param string $path The file path. * @param string $file The requested file to search for. */ return apply_filters( 'parent_theme_file_path', $path, $file ); } /** * Retrieves the URL to the privacy policy page. * * @since 4.9.6 * * @return string The URL to the privacy policy page. Empty string if it doesn't exist. */ function get_privacy_policy_url() { $url = ''; $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) { $url = (string) get_permalink( $policy_page_id ); } /** * Filters the URL of the privacy policy page. * * @since 4.9.6 * * @param string $url The URL to the privacy policy page. Empty string * if it doesn't exist. * @param int $policy_page_id The ID of privacy policy page. */ return apply_filters( 'privacy_policy_url', $url, $policy_page_id ); } /** * Displays the privacy policy link with formatting, when applicable. * * @since 4.9.6 * * @param string $before Optional. Display before privacy policy link. Default empty. * @param string $after Optional. Display after privacy policy link. Default empty. */ function the_privacy_policy_link( $before = '', $after = '' ) { echo get_the_privacy_policy_link( $before, $after ); } /** * Returns the privacy policy link with formatting, when applicable. * * @since 4.9.6 * * @param string $before Optional. Display before privacy policy link. Default empty. * @param string $after Optional. Display after privacy policy link. Default empty. * * @return string Markup for the link and surrounding elements. Empty string if it * doesn't exist. */ function get_the_privacy_policy_link( $before = '', $after = '' ) { $link = ''; $privacy_policy_url = get_privacy_policy_url(); $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); $page_title = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : ''; if ( $privacy_policy_url && $page_title ) { $link = sprintf( '%s', esc_url( $privacy_policy_url ), esc_html( $page_title ) ); } /** * Filters the privacy policy link. * * @since 4.9.6 * * @param string $link The privacy policy link. Empty string if it * doesn't exist. * @param string $privacy_policy_url The URL of the privacy policy. Empty string * if it doesn't exist. */ $link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url ); if ( $link ) { return $before . $link . $after; } return ''; } /** * Post format functions. * * @package WordPress * @subpackage Post */ /** * Retrieve the format slug for a post * * @since 3.1.0 * * @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop. * @return string|false The format if successful. False otherwise. */ function get_post_format( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) { return false; } $_format = get_the_terms( $post->ID, 'post_format' ); if ( empty( $_format ) ) { return false; } $format = reset( $_format ); return str_replace( 'post-format-', '', $format->slug ); } /** * Check if a post has any of the given formats, or any format. * * @since 3.1.0 * * @param string|array $format Optional. The format or formats to check. * @param object|int|null $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop. * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise. */ function has_post_format( $format = array(), $post = null ) { $prefixed = array(); if ( $format ) { foreach ( (array) $format as $single ) { $prefixed[] = 'post-format-' . sanitize_key( $single ); } } return has_term( $prefixed, 'post_format', $post ); } /** * Assign a format to a post * * @since 3.1.0 * * @param int|object $post The post for which to assign a format. * @param string $format A format to assign. Use an empty string or array to remove all formats from the post. * @return array|WP_Error|false WP_Error on error. Array of affected term IDs on success. */ function set_post_format( $post, $format ) { $post = get_post( $post ); if ( ! $post ) { return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); } if ( ! empty( $format ) ) { $format = sanitize_key( $format ); if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) { $format = ''; } else { $format = 'post-format-' . $format; } } return wp_set_post_terms( $post->ID, $format, 'post_format' ); } /** * Returns an array of post format slugs to their translated and pretty display versions * * @since 3.1.0 * * @return array The array of translated post format names. */ function get_post_format_strings() { $strings = array( 'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard 'aside' => _x( 'Aside', 'Post format' ), 'chat' => _x( 'Chat', 'Post format' ), 'gallery' => _x( 'Gallery', 'Post format' ), 'link' => _x( 'Link', 'Post format' ), 'image' => _x( 'Image', 'Post format' ), 'quote' => _x( 'Quote', 'Post format' ), 'status' => _x( 'Status', 'Post format' ), 'video' => _x( 'Video', 'Post format' ), 'audio' => _x( 'Audio', 'Post format' ), ); return $strings; } /** * Retrieves the array of post format slugs. * * @since 3.1.0 * * @return array The array of post format slugs as both keys and values. */ function get_post_format_slugs() { $slugs = array_keys( get_post_format_strings() ); return array_combine( $slugs, $slugs ); } /** * Returns a pretty, translated version of a post format slug * * @since 3.1.0 * * @param string $slug A post format slug. * @return string The translated post format name. */ function get_post_format_string( $slug ) { $strings = get_post_format_strings(); if ( ! $slug ) { return $strings['standard']; } else { return ( isset( $strings[ $slug ] ) ) ? $strings[ $slug ] : ''; } } /** * Returns a link to a post format index. * * @since 3.1.0 * * @param string $format The post format slug. * @return string|WP_Error|false The post format term link. */ function get_post_format_link( $format ) { $term = get_term_by( 'slug', 'post-format-' . $format, 'post_format' ); if ( ! $term || is_wp_error( $term ) ) { return false; } return get_term_link( $term ); } /** * Filters the request to allow for the format prefix. * * @access private * @since 3.1.0 * * @param array $qvs * @return array */ function _post_format_request( $qvs ) { if ( ! isset( $qvs['post_format'] ) ) { return $qvs; } $slugs = get_post_format_slugs(); if ( isset( $slugs[ $qvs['post_format'] ] ) ) { $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; } $tax = get_taxonomy( 'post_format' ); if ( ! is_admin() ) { $qvs['post_type'] = $tax->object_type; } return $qvs; } /** * Filters the post format term link to remove the format prefix. * * @access private * @since 3.1.0 * * @global WP_Rewrite $wp_rewrite * * @param string $link * @param object $term * @param string $taxonomy * @return string */ function _post_format_link( $link, $term, $taxonomy ) { global $wp_rewrite; if ( 'post_format' != $taxonomy ) { return $link; } if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) { return str_replace( "/{$term->slug}", '/' . str_replace( 'post-format-', '', $term->slug ), $link ); } else { $link = remove_query_arg( 'post_format', $link ); return add_query_arg( 'post_format', str_replace( 'post-format-', '', $term->slug ), $link ); } } /** * Remove the post format prefix from the name property of the term object created by get_term(). * * @access private * @since 3.1.0 * * @param object $term * @return object */ function _post_format_get_term( $term ) { if ( isset( $term->slug ) ) { $term->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); } return $term; } /** * Remove the post format prefix from the name property of the term objects created by get_terms(). * * @access private * @since 3.1.0 * * @param array $terms * @param string|array $taxonomies * @param array $args * @return array */ function _post_format_get_terms( $terms, $taxonomies, $args ) { if ( in_array( 'post_format', (array) $taxonomies ) ) { if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { foreach ( $terms as $order => $name ) { $terms[ $order ] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); } } else { foreach ( (array) $terms as $order => $term ) { if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); } } } } return $terms; } /** * Remove the post format prefix from the name property of the term objects created by wp_get_object_terms(). * * @access private * @since 3.1.0 * * @param array $terms * @return array */ function _post_format_wp_get_object_terms( $terms ) { foreach ( (array) $terms as $order => $term ) { if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { $terms[ $order ]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); } } return $terms; } /** * Taxonomy API: Core category-specific functionality * * @package WordPress * @subpackage Taxonomy */ /** * Retrieve list of category objects. * * If you change the type to 'link' in the arguments, then the link categories * will be returned instead. Also all categories will be updated to be backward * compatible with pre-2.3 plugins and themes. * * @since 2.1.0 * @see get_terms() Type of arguments that can be changed. * * @param string|array $args { * Optional. Arguments to retrieve categories. See get_terms() for additional options. * * @type string $taxonomy Taxonomy to retrieve terms for. In this case, default 'category'. * } * @return array List of categories. */ function get_categories( $args = '' ) { $defaults = array( 'taxonomy' => 'category' ); $args = wp_parse_args( $args, $defaults ); $taxonomy = $args['taxonomy']; /** * Filters the taxonomy used to retrieve terms when calling get_categories(). * * @since 2.7.0 * * @param string $taxonomy Taxonomy to retrieve terms from. * @param array $args An array of arguments. See get_terms(). */ $taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args ); // Back compat if ( isset( $args['type'] ) && 'link' == $args['type'] ) { _deprecated_argument( __FUNCTION__, '3.0.0', /* translators: 1: "type => link", 2: "taxonomy => link_category" */ sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), 'type => link', 'taxonomy => link_category' ) ); $taxonomy = $args['taxonomy'] = 'link_category'; } $categories = get_terms( $taxonomy, $args ); if ( is_wp_error( $categories ) ) { $categories = array(); } else { $categories = (array) $categories; foreach ( array_keys( $categories ) as $k ) { _make_cat_compat( $categories[ $k ] ); } } return $categories; } /** * Retrieves category data given a category ID or category object. * * If you pass the $category parameter an object, which is assumed to be the * category row object retrieved the database. It will cache the category data. * * If you pass $category an integer of the category ID, then that category will * be retrieved from the database, if it isn't already cached, and pass it back. * * If you look at get_term(), then both types will be passed through several * filters and finally sanitized based on the $filter parameter value. * * The category will converted to maintain backward compatibility. * * @since 1.5.1 * * @param int|object $category Category ID or Category row object * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a * WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT. * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. * @return object|array|WP_Error|null Category data in type defined by $output parameter. * WP_Error if $category is empty, null if it does not exist. */ function get_category( $category, $output = OBJECT, $filter = 'raw' ) { $category = get_term( $category, 'category', $output, $filter ); if ( is_wp_error( $category ) ) { return $category; } _make_cat_compat( $category ); return $category; } /** * Retrieve category based on URL containing the category slug. * * Breaks the $category_path parameter up to get the category slug. * * Tries to find the child path and will return it. If it doesn't find a * match, then it will return the first category matching slug, if $full_match, * is set to false. If it does not, then it will return null. * * It is also possible that it will return a WP_Error object on failure. Check * for it when using this function. * * @since 2.1.0 * * @param string $category_path URL containing category slugs. * @param bool $full_match Optional. Whether full path should be matched. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to * a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT. * @return WP_Term|array|WP_Error|null Type is based on $output value. */ function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) { $category_path = rawurlencode( urldecode( $category_path ) ); $category_path = str_replace( '%2F', '/', $category_path ); $category_path = str_replace( '%20', ' ', $category_path ); $category_paths = '/' . trim( $category_path, '/' ); $leaf_path = sanitize_title( basename( $category_paths ) ); $category_paths = explode( '/', $category_paths ); $full_path = ''; foreach ( (array) $category_paths as $pathdir ) { $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir ); } $categories = get_terms( 'category', array( 'get' => 'all', 'slug' => $leaf_path, ) ); if ( empty( $categories ) ) { return; } foreach ( $categories as $category ) { $path = '/' . $leaf_path; $curcategory = $category; while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) { $curcategory = get_term( $curcategory->parent, 'category' ); if ( is_wp_error( $curcategory ) ) { return $curcategory; } $path = '/' . $curcategory->slug . $path; } if ( $path == $full_path ) { $category = get_term( $category->term_id, 'category', $output ); _make_cat_compat( $category ); return $category; } } // If full matching is not required, return the first cat that matches the leaf. if ( ! $full_match ) { $category = get_term( reset( $categories )->term_id, 'category', $output ); _make_cat_compat( $category ); return $category; } } /** * Retrieve category object by category slug. * * @since 2.3.0 * * @param string $slug The category slug. * @return object Category data object */ function get_category_by_slug( $slug ) { $category = get_term_by( 'slug', $slug, 'category' ); if ( $category ) { _make_cat_compat( $category ); } return $category; } /** * Retrieve the ID of a category from its name. * * @since 1.0.0 * * @param string $cat_name Category name. * @return int 0, if failure and ID of category on success. */ function get_cat_ID( $cat_name ) { $cat = get_term_by( 'name', $cat_name, 'category' ); if ( $cat ) { return $cat->term_id; } return 0; } /** * Retrieve the name of a category from its ID. * * @since 1.0.0 * * @param int $cat_id Category ID * @return string Category name, or an empty string if category doesn't exist. */ function get_cat_name( $cat_id ) { $cat_id = (int) $cat_id; $category = get_term( $cat_id, 'category' ); if ( ! $category || is_wp_error( $category ) ) { return ''; } return $category->name; } /** * Check if a category is an ancestor of another category. * * You can use either an id or the category object for both parameters. If you * use an integer the category will be retrieved. * * @since 2.1.0 * * @param int|object $cat1 ID or object to check if this is the parent category. * @param int|object $cat2 The child category. * @return bool Whether $cat2 is child of $cat1 */ function cat_is_ancestor_of( $cat1, $cat2 ) { return term_is_ancestor_of( $cat1, $cat2, 'category' ); } /** * Sanitizes category data based on context. * * @since 2.3.0 * * @param object|array $category Category data * @param string $context Optional. Default is 'display'. * @return object|array Same type as $category with sanitized data for safe use. */ function sanitize_category( $category, $context = 'display' ) { return sanitize_term( $category, 'category', $context ); } /** * Sanitizes data in single category key field. * * @since 2.3.0 * * @param string $field Category key to sanitize * @param mixed $value Category value to sanitize * @param int $cat_id Category ID * @param string $context What filter to use, 'raw', 'display', etc. * @return mixed Same type as $value after $value has been sanitized. */ function sanitize_category_field( $field, $value, $cat_id, $context ) { return sanitize_term_field( $field, $value, $cat_id, 'category', $context ); } /* Tags */ /** * Retrieves all post tags. * * @since 2.3.0 * @see get_terms() For list of arguments to pass. * * @param string|array $args Tag arguments to use when retrieving tags. * @return WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof. */ function get_tags( $args = '' ) { $tags = get_terms( 'post_tag', $args ); if ( empty( $tags ) ) { $return = array(); return $return; } /** * Filters the array of term objects returned for the 'post_tag' taxonomy. * * @since 2.3.0 * * @param WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof. * @param array $args An array of arguments. @see get_terms() */ $tags = apply_filters( 'get_tags', $tags, $args ); return $tags; } /** * Retrieve post tag by tag ID or tag object. * * If you pass the $tag parameter an object, which is assumed to be the tag row * object retrieved the database. It will cache the tag data. * * If you pass $tag an integer of the tag ID, then that tag will * be retrieved from the database, if it isn't already cached, and pass it back. * * If you look at get_term(), then both types will be passed through several * filters and finally sanitized based on the $filter parameter value. * * @since 2.3.0 * * @param int|WP_Term|object $tag A tag ID or object. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to * a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT. * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. * @return WP_Term|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist. */ function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { return get_term( $tag, 'post_tag', $output, $filter ); } /* Cache */ /** * Remove the category cache data based on ID. * * @since 2.1.0 * * @param int $id Category ID */ function clean_category_cache( $id ) { clean_term_cache( $id, 'category' ); } /** * Update category structure to old pre 2.3 from new taxonomy structure. * * This function was added for the taxonomy support to update the new category * structure with the old category one. This will maintain compatibility with * plugins and themes which depend on the old key or property names. * * The parameter should only be passed a variable and not create the array or * object inline to the parameter. The reason for this is that parameter is * passed by reference and PHP will fail unless it has the variable. * * There is no return value, because everything is updated on the variable you * pass to it. This is one of the features with using pass by reference in PHP. * * @since 2.3.0 * @since 4.4.0 The `$category` parameter now also accepts a WP_Term object. * @access private * * @param array|object|WP_Term $category Category Row object or array */ function _make_cat_compat( &$category ) { if ( is_object( $category ) && ! is_wp_error( $category ) ) { $category->cat_ID = $category->term_id; $category->category_count = $category->count; $category->category_description = $category->description; $category->cat_name = $category->name; $category->category_nicename = $category->slug; $category->category_parent = $category->parent; } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { $category['cat_ID'] = &$category['term_id']; $category['category_count'] = &$category['count']; $category['category_description'] = &$category['description']; $category['cat_name'] = &$category['name']; $category['category_nicename'] = &$category['slug']; $category['category_parent'] = &$category['parent']; } } /** * Deprecated functions from past WordPress versions. You shouldn't use these * functions and look for the alternatives instead. The functions will be * removed in a later version. * * @package WordPress * @subpackage Deprecated */ /* * Deprecated functions come here to die. */ /** * Retrieves all post data for a given post. * * @since 0.71 * @deprecated 1.5.1 Use get_post() * @see get_post() * * @param int $postid Post ID. * @return array Post data. */ function get_postdata($postid) { _deprecated_function( __FUNCTION__, '1.5.1', 'get_post()' ); $post = get_post($postid); $postdata = array ( 'ID' => $post->ID, 'Author_ID' => $post->post_author, 'Date' => $post->post_date, 'Content' => $post->post_content, 'Excerpt' => $post->post_excerpt, 'Title' => $post->post_title, 'Category' => $post->post_category, 'post_status' => $post->post_status, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_password' => $post->post_password, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged, 'post_type' => $post->post_type, 'post_name' => $post->post_name ); return $postdata; } /** * Sets up the WordPress Loop. * * Use The Loop instead. * * @link https://codex.wordpress.org/The_Loop * * @since 1.0.1 * @deprecated 1.5.0 */ function start_wp() { global $wp_query; _deprecated_function( __FUNCTION__, '1.5.0', __('new WordPress Loop') ); // Since the old style loop is being used, advance the query iterator here. $wp_query->next_post(); setup_postdata( get_post() ); } /** * Returns or prints a category ID. * * @since 0.71 * @deprecated 0.71 Use get_the_category() * @see get_the_category() * * @param bool $echo Optional. Whether to echo the output. Default true. * @return int Category ID. */ function the_category_ID($echo = true) { _deprecated_function( __FUNCTION__, '0.71', 'get_the_category()' ); // Grab the first cat in the list. $categories = get_the_category(); $cat = $categories[0]->term_id; if ( $echo ) echo $cat; return $cat; } /** * Prints a category with optional text before and after. * * @since 0.71 * @deprecated 0.71 Use get_the_category_by_ID() * @see get_the_category_by_ID() * * @param string $before Optional. Text to display before the category. Default empty. * @param string $after Optional. Text to display after the category. Default empty. */ function the_category_head( $before = '', $after = '' ) { global $currentcat, $previouscat; _deprecated_function( __FUNCTION__, '0.71', 'get_the_category_by_ID()' ); // Grab the first cat in the list. $categories = get_the_category(); $currentcat = $categories[0]->category_id; if ( $currentcat != $previouscat ) { echo $before; echo get_the_category_by_ID($currentcat); echo $after; $previouscat = $currentcat; } } /** * Prints a link to the previous post. * * @since 1.5.0 * @deprecated 2.0.0 Use previous_post_link() * @see previous_post_link() * * @param string $format * @param string $previous * @param string $title * @param string $in_same_cat * @param int $limitprev * @param string $excluded_categories */ function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') { _deprecated_function( __FUNCTION__, '2.0.0', 'previous_post_link()' ); if ( empty($in_same_cat) || 'no' == $in_same_cat ) $in_same_cat = false; else $in_same_cat = true; $post = get_previous_post($in_same_cat, $excluded_categories); if ( !$post ) return; $string = ''.$previous; if ( 'yes' == $title ) $string .= apply_filters('the_title', $post->post_title, $post->ID); $string .= ''; $format = str_replace('%', $string, $format); echo $format; } /** * Prints link to the next post. * * @since 0.71 * @deprecated 2.0.0 Use next_post_link() * @see next_post_link() * * @param string $format * @param string $next * @param string $title * @param string $in_same_cat * @param int $limitnext * @param string $excluded_categories */ function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') { _deprecated_function( __FUNCTION__, '2.0.0', 'next_post_link()' ); if ( empty($in_same_cat) || 'no' == $in_same_cat ) $in_same_cat = false; else $in_same_cat = true; $post = get_next_post($in_same_cat, $excluded_categories); if ( !$post ) return; $string = ''.$next; if ( 'yes' == $title ) $string .= apply_filters('the_title', $post->post_title, $post->ID); $string .= ''; $format = str_replace('%', $string, $format); echo $format; } /** * Whether user can create a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $blog_id Not Used * @param int $category_id Not Used * @return bool */ function user_can_create_post($user_id, $blog_id = 1, $category_id = 'None') { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); $author_data = get_userdata($user_id); return ($author_data->user_level > 1); } /** * Whether user can create a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $blog_id Not Used * @param int $category_id Not Used * @return bool */ function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); $author_data = get_userdata($user_id); return ($author_data->user_level >= 1); } /** * Whether user can edit a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $post_id * @param int $blog_id Not Used * @return bool */ function user_can_edit_post($user_id, $post_id, $blog_id = 1) { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); $author_data = get_userdata($user_id); $post = get_post($post_id); $post_author_data = get_userdata($post->post_author); if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2)) || ($author_data->user_level > $post_author_data->user_level) || ($author_data->user_level >= 10) ) { return true; } else { return false; } } /** * Whether user can delete a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $post_id * @param int $blog_id Not Used * @return bool */ function user_can_delete_post($user_id, $post_id, $blog_id = 1) { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); // right now if one can edit, one can delete return user_can_edit_post($user_id, $post_id, $blog_id); } /** * Whether user can set new posts' dates. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $blog_id Not Used * @param int $category_id Not Used * @return bool */ function user_can_set_post_date($user_id, $blog_id = 1, $category_id = 'None') { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); $author_data = get_userdata($user_id); return (($author_data->user_level > 4) && user_can_create_post($user_id, $blog_id, $category_id)); } /** * Whether user can delete a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $post_id * @param int $blog_id Not Used * @return bool returns true if $user_id can edit $post_id's date */ function user_can_edit_post_date($user_id, $post_id, $blog_id = 1) { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); $author_data = get_userdata($user_id); return (($author_data->user_level > 4) && user_can_edit_post($user_id, $post_id, $blog_id)); } /** * Whether user can delete a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $post_id * @param int $blog_id Not Used * @return bool returns true if $user_id can edit $post_id's comments */ function user_can_edit_post_comments($user_id, $post_id, $blog_id = 1) { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); // right now if one can edit a post, one can edit comments made on it return user_can_edit_post($user_id, $post_id, $blog_id); } /** * Whether user can delete a post. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $post_id * @param int $blog_id Not Used * @return bool returns true if $user_id can delete $post_id's comments */ function user_can_delete_post_comments($user_id, $post_id, $blog_id = 1) { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); // right now if one can edit comments, one can delete comments return user_can_edit_post_comments($user_id, $post_id, $blog_id); } /** * Can user can edit other user. * * @since 1.5.0 * @deprecated 2.0.0 Use current_user_can() * @see current_user_can() * * @param int $user_id * @param int $other_user * @return bool */ function user_can_edit_user($user_id, $other_user) { _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); $user = get_userdata($user_id); $other = get_userdata($other_user); if ( $user->user_level > $other->user_level || $user->user_level > 8 || $user->ID == $other->ID ) return true; else return false; } /** * Gets the links associated with category $cat_name. * * @since 0.71 * @deprecated 2.1.0 Use get_bookmarks() * @see get_bookmarks() * * @param string $cat_name Optional. The category name to use. If no match is found uses all. * @param string $before Optional. The html to output before the link. * @param string $after Optional. The html to output after the link. * @param string $between Optional. The html to output between the link/image and its description. Not used if no image or $show_images is true. * @param bool $show_images Optional. Whether to show images (if defined). * @param string $orderby Optional. The order to output the links. E.g. 'id', 'name', 'url', 'description' or 'rating'. Or maybe owner. * If you start the name with an underscore the order will be reversed. You can also specify 'rand' as the order which will return links in a * random order. * @param bool $show_description Optional. Whether to show the description if show_images=false/not defined. * @param bool $show_rating Optional. Show rating stars/chars. * @param int $limit Optional. Limit to X entries. If not specified, all entries are shown. * @param int $show_updated Optional. Whether to show last updated timestamp */ function get_linksbyname($cat_name = "noname", $before = '', $after = '
', $between = " ", $show_images = true, $orderby = 'id', $show_description = true, $show_rating = false, $limit = -1, $show_updated = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); $cat_id = -1; $cat = get_term_by('name', $cat_name, 'link_category'); if ( $cat ) $cat_id = $cat->term_id; get_links($cat_id, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated); } /** * Gets the links associated with the named category. * * @since 1.0.1 * @deprecated 2.1.0 Use wp_list_bookmarks() * @see wp_list_bookmarks() * * @param string $category The category to use. * @param string $args * @return string|null */ function wp_get_linksbyname($category, $args = '') { _deprecated_function(__FUNCTION__, '2.1.0', 'wp_list_bookmarks()'); $defaults = array( 'after' => '
', 'before' => '', 'categorize' => 0, 'category_after' => '', 'category_before' => '', 'category_name' => $category, 'show_description' => 1, 'title_li' => '', ); $r = wp_parse_args( $args, $defaults ); return wp_list_bookmarks($r); } /** * Gets an array of link objects associated with category $cat_name. * * $links = get_linkobjectsbyname( 'fred' ); * foreach ( $links as $link ) { * echo '
  • ' . $link->link_name . '
  • '; * } * * @since 1.0.1 * @deprecated 2.1.0 Use get_bookmarks() * @see get_bookmarks() * * @param string $cat_name The category name to use. If no match is found uses all. * @param string $orderby The order to output the links. E.g. 'id', 'name', 'url', 'description', or 'rating'. * Or maybe owner. If you start the name with an underscore the order will be reversed. You can also * specify 'rand' as the order which will return links in a random order. * @param int $limit Limit to X entries. If not specified, all entries are shown. * @return array */ function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); $cat_id = -1; $cat = get_term_by('name', $cat_name, 'link_category'); if ( $cat ) $cat_id = $cat->term_id; return get_linkobjects($cat_id, $orderby, $limit); } /** * Gets an array of link objects associated with category n. * * Usage: * * $links = get_linkobjects(1); * if ($links) { * foreach ($links as $link) { * echo '
  • '.$link->link_name.'
    '.$link->link_description.'
  • '; * } * } * * Fields are: * * - link_id * - link_url * - link_name * - link_image * - link_target * - link_category * - link_description * - link_visible * - link_owner * - link_rating * - link_updated * - link_rel * - link_notes * * @since 1.0.1 * @deprecated 2.1.0 Use get_bookmarks() * @see get_bookmarks() * * @param int $category The category to use. If no category supplied uses all * @param string $orderby the order to output the links. E.g. 'id', 'name', 'url', * 'description', or 'rating'. Or maybe owner. If you start the name with an * underscore the order will be reversed. You can also specify 'rand' as the * order which will return links in a random order. * @param int $limit Limit to X entries. If not specified, all entries are shown. * @return array */ function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); $links = get_bookmarks( array( 'category' => $category, 'orderby' => $orderby, 'limit' => $limit ) ) ; $links_array = array(); foreach ($links as $link) $links_array[] = $link; return $links_array; } /** * Gets the links associated with category 'cat_name' and display rating stars/chars. * * @since 0.71 * @deprecated 2.1.0 Use get_bookmarks() * @see get_bookmarks() * * @param string $cat_name The category name to use. If no match is found uses all * @param string $before The html to output before the link * @param string $after The html to output after the link * @param string $between The html to output between the link/image and its description. Not used if no image or show_images is true * @param bool $show_images Whether to show images (if defined). * @param string $orderby the order to output the links. E.g. 'id', 'name', 'url', * 'description', or 'rating'. Or maybe owner. If you start the name with an * underscore the order will be reversed. You can also specify 'rand' as the * order which will return links in a random order. * @param bool $show_description Whether to show the description if show_images=false/not defined * @param int $limit Limit to X entries. If not specified, all entries are shown. * @param int $show_updated Whether to show last updated timestamp */ function get_linksbyname_withrating($cat_name = "noname", $before = '', $after = '
    ', $between = " ", $show_images = true, $orderby = 'id', $show_description = true, $limit = -1, $show_updated = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); get_linksbyname($cat_name, $before, $after, $between, $show_images, $orderby, $show_description, true, $limit, $show_updated); } /** * Gets the links associated with category n and display rating stars/chars. * * @since 0.71 * @deprecated 2.1.0 Use get_bookmarks() * @see get_bookmarks() * * @param int $category The category to use. If no category supplied uses all * @param string $before The html to output before the link * @param string $after The html to output after the link * @param string $between The html to output between the link/image and its description. Not used if no image or show_images == true * @param bool $show_images Whether to show images (if defined). * @param string $orderby The order to output the links. E.g. 'id', 'name', 'url', * 'description', or 'rating'. Or maybe owner. If you start the name with an * underscore the order will be reversed. You can also specify 'rand' as the * order which will return links in a random order. * @param bool $show_description Whether to show the description if show_images=false/not defined. * @param int $limit Limit to X entries. If not specified, all entries are shown. * @param int $show_updated Whether to show last updated timestamp */ function get_links_withrating($category = -1, $before = '', $after = '
    ', $between = " ", $show_images = true, $orderby = 'id', $show_description = true, $limit = -1, $show_updated = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, true, $limit, $show_updated); } /** * Gets the auto_toggle setting. * * @since 0.71 * @deprecated 2.1.0 * * @param int $id The category to get. If no category supplied uses 0 * @return int Only returns 0. */ function get_autotoggle($id = 0) { _deprecated_function( __FUNCTION__, '2.1.0' ); return 0; } /** * Lists categories. * * @since 0.71 * @deprecated 2.1.0 Use wp_list_categories() * @see wp_list_categories() * * @param int $optionall * @param string $all * @param string $sort_column * @param string $sort_order * @param string $file * @param bool $list * @param int $optiondates * @param int $optioncount * @param int $hide_empty * @param int $use_desc_for_title * @param bool $children * @param int $child_of * @param int $categories * @param int $recurse * @param string $feed * @param string $feed_image * @param string $exclude * @param bool $hierarchical * @return false|null */ function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=false, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=false) { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_list_categories()' ); $query = compact('optionall', 'all', 'sort_column', 'sort_order', 'file', 'list', 'optiondates', 'optioncount', 'hide_empty', 'use_desc_for_title', 'children', 'child_of', 'categories', 'recurse', 'feed', 'feed_image', 'exclude', 'hierarchical'); return wp_list_cats($query); } /** * Lists categories. * * @since 1.2.0 * @deprecated 2.1.0 Use wp_list_categories() * @see wp_list_categories() * * @param string|array $args * @return false|null|string */ function wp_list_cats($args = '') { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_list_categories()' ); $r = wp_parse_args( $args ); // Map to new names. if ( isset($r['optionall']) && isset($r['all'])) $r['show_option_all'] = $r['all']; if ( isset($r['sort_column']) ) $r['orderby'] = $r['sort_column']; if ( isset($r['sort_order']) ) $r['order'] = $r['sort_order']; if ( isset($r['optiondates']) ) $r['show_last_update'] = $r['optiondates']; if ( isset($r['optioncount']) ) $r['show_count'] = $r['optioncount']; if ( isset($r['list']) ) $r['style'] = $r['list'] ? 'list' : 'break'; $r['title_li'] = ''; return wp_list_categories($r); } /** * Deprecated method for generating a drop-down of categories. * * @since 0.71 * @deprecated 2.1.0 Use wp_dropdown_categories() * @see wp_dropdown_categories() * * @param int $optionall * @param string $all * @param string $orderby * @param string $order * @param int $show_last_update * @param int $show_count * @param int $hide_empty * @param bool $optionnone * @param int $selected * @param int $exclude * @return string */ function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc', $show_last_update = 0, $show_count = 0, $hide_empty = 1, $optionnone = false, $selected = 0, $exclude = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_dropdown_categories()' ); $show_option_all = ''; if ( $optionall ) $show_option_all = $all; $show_option_none = ''; if ( $optionnone ) $show_option_none = __('None'); $vars = compact('show_option_all', 'show_option_none', 'orderby', 'order', 'show_last_update', 'show_count', 'hide_empty', 'selected', 'exclude'); $query = add_query_arg($vars, ''); return wp_dropdown_categories($query); } /** * Lists authors. * * @since 1.2.0 * @deprecated 2.1.0 Use wp_list_authors() * @see wp_list_authors() * * @param bool $optioncount * @param bool $exclude_admin * @param bool $show_fullname * @param bool $hide_empty * @param string $feed * @param string $feed_image * @return null|string */ function list_authors($optioncount = false, $exclude_admin = true, $show_fullname = false, $hide_empty = true, $feed = '', $feed_image = '') { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_list_authors()' ); $args = compact('optioncount', 'exclude_admin', 'show_fullname', 'hide_empty', 'feed', 'feed_image'); return wp_list_authors($args); } /** * Retrieves a list of post categories. * * @since 1.0.1 * @deprecated 2.1.0 Use wp_get_post_categories() * @see wp_get_post_categories() * * @param int $blogid Not Used * @param int $post_ID * @return array */ function wp_get_post_cats($blogid = '1', $post_ID = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_get_post_categories()' ); return wp_get_post_categories($post_ID); } /** * Sets the categories that the post id belongs to. * * @since 1.0.1 * @deprecated 2.1.0 * @deprecated Use wp_set_post_categories() * @see wp_set_post_categories() * * @param int $blogid Not used * @param int $post_ID * @param array $post_categories * @return bool|mixed */ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array()) { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_set_post_categories()' ); return wp_set_post_categories($post_ID, $post_categories); } /** * Retrieves a list of archives. * * @since 0.71 * @deprecated 2.1.0 Use wp_get_archives() * @see wp_get_archives() * * @param string $type * @param string $limit * @param string $format * @param string $before * @param string $after * @param bool $show_post_count * @return string|null */ function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_get_archives()' ); $args = compact('type', 'limit', 'format', 'before', 'after', 'show_post_count'); return wp_get_archives($args); } /** * Returns or Prints link to the author's posts. * * @since 1.2.0 * @deprecated 2.1.0 Use get_author_posts_url() * @see get_author_posts_url() * * @param bool $echo * @param int $author_id * @param string $author_nicename Optional. * @return string|null */ function get_author_link($echo, $author_id, $author_nicename = '') { _deprecated_function( __FUNCTION__, '2.1.0', 'get_author_posts_url()' ); $link = get_author_posts_url($author_id, $author_nicename); if ( $echo ) echo $link; return $link; } /** * Print list of pages based on arguments. * * @since 0.71 * @deprecated 2.1.0 Use wp_link_pages() * @see wp_link_pages() * * @param string $before * @param string $after * @param string $next_or_number * @param string $nextpagelink * @param string $previouspagelink * @param string $pagelink * @param string $more_file * @return string */ function link_pages($before='
    ', $after='
    ', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_link_pages()' ); $args = compact('before', 'after', 'next_or_number', 'nextpagelink', 'previouspagelink', 'pagelink', 'more_file'); return wp_link_pages($args); } /** * Get value based on option. * * @since 0.71 * @deprecated 2.1.0 Use get_option() * @see get_option() * * @param string $option * @return string */ function get_settings($option) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_option()' ); return get_option($option); } /** * Print the permalink of the current post in the loop. * * @since 0.71 * @deprecated 1.2.0 Use the_permalink() * @see the_permalink() */ function permalink_link() { _deprecated_function( __FUNCTION__, '1.2.0', 'the_permalink()' ); the_permalink(); } /** * Print the permalink to the RSS feed. * * @since 0.71 * @deprecated 2.3.0 Use the_permalink_rss() * @see the_permalink_rss() * * @param string $deprecated */ function permalink_single_rss($deprecated = '') { _deprecated_function( __FUNCTION__, '2.3.0', 'the_permalink_rss()' ); the_permalink_rss(); } /** * Gets the links associated with category. * * @since 1.0.1 * @deprecated 2.1.0 Use wp_list_bookmarks() * @see wp_list_bookmarks() * * @param string $args a query string * @return null|string */ function wp_get_links($args = '') { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_list_bookmarks()' ); if ( strpos( $args, '=' ) === false ) { $cat_id = $args; $args = add_query_arg( 'category', $cat_id, $args ); } $defaults = array( 'after' => '
    ', 'before' => '', 'between' => ' ', 'categorize' => 0, 'category' => '', 'echo' => true, 'limit' => -1, 'orderby' => 'name', 'show_description' => true, 'show_images' => true, 'show_rating' => false, 'show_updated' => true, 'title_li' => '', ); $r = wp_parse_args( $args, $defaults ); return wp_list_bookmarks($r); } /** * Gets the links associated with category by id. * * @since 0.71 * @deprecated 2.1.0 Use get_bookmarks() * @see get_bookmarks() * * @param int $category The category to use. If no category supplied uses all * @param string $before the html to output before the link * @param string $after the html to output after the link * @param string $between the html to output between the link/image and its description. * Not used if no image or show_images == true * @param bool $show_images whether to show images (if defined). * @param string $orderby the order to output the links. E.g. 'id', 'name', 'url', * 'description', or 'rating'. Or maybe owner. If you start the name with an * underscore the order will be reversed. You can also specify 'rand' as the order * which will return links in a random order. * @param bool $show_description whether to show the description if show_images=false/not defined. * @param bool $show_rating show rating stars/chars * @param int $limit Limit to X entries. If not specified, all entries are shown. * @param int $show_updated whether to show last updated timestamp * @param bool $echo whether to echo the results, or return them instead * @return null|string */ function get_links($category = -1, $before = '', $after = '
    ', $between = ' ', $show_images = true, $orderby = 'name', $show_description = true, $show_rating = false, $limit = -1, $show_updated = 1, $echo = true) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); $order = 'ASC'; if ( substr($orderby, 0, 1) == '_' ) { $order = 'DESC'; $orderby = substr($orderby, 1); } if ( $category == -1 ) //get_bookmarks uses '' to signify all categories $category = ''; $results = get_bookmarks(array('category' => $category, 'orderby' => $orderby, 'order' => $order, 'show_updated' => $show_updated, 'limit' => $limit)); if ( !$results ) return; $output = ''; foreach ( (array) $results as $row ) { if ( !isset($row->recently_updated) ) $row->recently_updated = false; $output .= $before; if ( $show_updated && $row->recently_updated ) $output .= get_option('links_recently_updated_prepend'); $the_link = '#'; if ( !empty($row->link_url) ) $the_link = esc_url($row->link_url); $rel = $row->link_rel; if ( '' != $rel ) $rel = ' rel="' . $rel . '"'; $desc = esc_attr(sanitize_bookmark_field('link_description', $row->link_description, $row->link_id, 'display')); $name = esc_attr(sanitize_bookmark_field('link_name', $row->link_name, $row->link_id, 'display')); $title = $desc; if ( $show_updated ) if (substr($row->link_updated_f, 0, 2) != '00') $title .= ' ('.__('Last updated') . ' ' . date(get_option('links_updated_date_format'), $row->link_updated_f + (get_option('gmt_offset') * HOUR_IN_SECONDS)) . ')'; if ( '' != $title ) $title = ' title="' . $title . '"'; $alt = ' alt="' . $name . '"'; $target = $row->link_target; if ( '' != $target ) $target = ' target="' . $target . '"'; $output .= ''; if ( $row->link_image != null && $show_images ) { if ( strpos($row->link_image, 'http') !== false ) $output .= "link_image\" $alt $title />"; else // If it's a relative path $output .= "link_image\" $alt $title />"; } else { $output .= $name; } $output .= ''; if ( $show_updated && $row->recently_updated ) $output .= get_option('links_recently_updated_append'); if ( $show_description && '' != $desc ) $output .= $between . $desc; if ($show_rating) { $output .= $between . get_linkrating($row); } $output .= "$after\n"; } // end while if ( !$echo ) return $output; echo $output; } /** * Output entire list of links by category. * * Output a list of all links, listed by category, using the settings in * $wpdb->linkcategories and output it as a nested HTML unordered list. * * @since 1.0.1 * @deprecated 2.1.0 Use wp_list_bookmarks() * @see wp_list_bookmarks() * * @param string $order Sort link categories by 'name' or 'id' */ function get_links_list($order = 'name') { _deprecated_function( __FUNCTION__, '2.1.0', 'wp_list_bookmarks()' ); $order = strtolower($order); // Handle link category sorting $direction = 'ASC'; if ( '_' == substr($order,0,1) ) { $direction = 'DESC'; $order = substr($order,1); } if ( !isset($direction) ) $direction = ''; $cats = get_categories(array('type' => 'link', 'orderby' => $order, 'order' => $direction, 'hierarchical' => 0)); // Display each category if ( $cats ) { foreach ( (array) $cats as $cat ) { // Handle each category. // Display the category name echo '
  • ' . apply_filters('link_category', $cat->name ) . "

    \n\t
      \n"; // Call get_links() with all the appropriate params get_links($cat->term_id, '
    • ', "
    • ", "\n", true, 'name', false); // Close the last category echo "\n\t
    \n
  • \n"; } } } /** * Show the link to the links popup and the number of links. * * @since 0.71 * @deprecated 2.1.0 * * @param string $text the text of the link * @param int $width the width of the popup window * @param int $height the height of the popup window * @param string $file the page to open in the popup window * @param bool $count the number of links in the db */ function links_popup_script($text = 'Links', $width=400, $height=400, $file='links.all.php', $count = true) { _deprecated_function( __FUNCTION__, '2.1.0' ); } /** * Legacy function that retrieved the value of a link's link_rating field. * * @since 1.0.1 * @deprecated 2.1.0 Use sanitize_bookmark_field() * @see sanitize_bookmark_field() * * @param object $link Link object. * @return mixed Value of the 'link_rating' field, false otherwise. */ function get_linkrating( $link ) { _deprecated_function( __FUNCTION__, '2.1.0', 'sanitize_bookmark_field()' ); return sanitize_bookmark_field('link_rating', $link->link_rating, $link->link_id, 'display'); } /** * Gets the name of category by id. * * @since 0.71 * @deprecated 2.1.0 Use get_category() * @see get_category() * * @param int $id The category to get. If no category supplied uses 0 * @return string */ function get_linkcatname($id = 0) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_category()' ); $id = (int) $id; if ( empty($id) ) return ''; $cats = wp_get_link_cats($id); if ( empty($cats) || ! is_array($cats) ) return ''; $cat_id = (int) $cats[0]; // Take the first cat. $cat = get_category($cat_id); return $cat->name; } /** * Print RSS comment feed link. * * @since 1.0.1 * @deprecated 2.5.0 Use post_comments_feed_link() * @see post_comments_feed_link() * * @param string $link_text */ function comments_rss_link($link_text = 'Comments RSS') { _deprecated_function( __FUNCTION__, '2.5.0', 'post_comments_feed_link()' ); post_comments_feed_link($link_text); } /** * Print/Return link to category RSS2 feed. * * @since 1.2.0 * @deprecated 2.5.0 Use get_category_feed_link() * @see get_category_feed_link() * * @param bool $echo * @param int $cat_ID * @return string */ function get_category_rss_link($echo = false, $cat_ID = 1) { _deprecated_function( __FUNCTION__, '2.5.0', 'get_category_feed_link()' ); $link = get_category_feed_link($cat_ID, 'rss2'); if ( $echo ) echo $link; return $link; } /** * Print/Return link to author RSS feed. * * @since 1.2.0 * @deprecated 2.5.0 Use get_author_feed_link() * @see get_author_feed_link() * * @param bool $echo * @param int $author_id * @return string */ function get_author_rss_link($echo = false, $author_id = 1) { _deprecated_function( __FUNCTION__, '2.5.0', 'get_author_feed_link()' ); $link = get_author_feed_link($author_id); if ( $echo ) echo $link; return $link; } /** * Return link to the post RSS feed. * * @since 1.5.0 * @deprecated 2.2.0 Use get_post_comments_feed_link() * @see get_post_comments_feed_link() * * @return string */ function comments_rss() { _deprecated_function( __FUNCTION__, '2.2.0', 'get_post_comments_feed_link()' ); return esc_url( get_post_comments_feed_link() ); } /** * An alias of wp_create_user(). * * @since 2.0.0 * @deprecated 2.0.0 Use wp_create_user() * @see wp_create_user() * * @param string $username The user's username. * @param string $password The user's password. * @param string $email The user's email. * @return int The new user's ID. */ function create_user($username, $password, $email) { _deprecated_function( __FUNCTION__, '2.0.0', 'wp_create_user()' ); return wp_create_user($username, $password, $email); } /** * Unused function. * * @deprecated 2.5.0 */ function gzip_compression() { _deprecated_function( __FUNCTION__, '2.5.0' ); return false; } /** * Retrieve an array of comment data about comment $comment_ID. * * @since 0.71 * @deprecated 2.7.0 Use get_comment() * @see get_comment() * * @param int $comment_ID The ID of the comment * @param int $no_cache Whether to use the cache (cast to bool) * @param bool $include_unapproved Whether to include unapproved comments * @return array The comment data */ function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { _deprecated_function( __FUNCTION__, '2.7.0', 'get_comment()' ); return get_comment($comment_ID, ARRAY_A); } /** * Retrieve the category name by the category ID. * * @since 0.71 * @deprecated 2.8.0 Use get_cat_name() * @see get_cat_name() * * @param int $cat_ID Category ID * @return string category name */ function get_catname( $cat_ID ) { _deprecated_function( __FUNCTION__, '2.8.0', 'get_cat_name()' ); return get_cat_name( $cat_ID ); } /** * Retrieve category children list separated before and after the term IDs. * * @since 1.2.0 * @deprecated 2.8.0 Use get_term_children() * @see get_term_children() * * @param int $id Category ID to retrieve children. * @param string $before Optional. Prepend before category term ID. * @param string $after Optional, default is empty string. Append after category term ID. * @param array $visited Optional. Category Term IDs that have already been added. * @return string */ function get_category_children( $id, $before = '/', $after = '', $visited = array() ) { _deprecated_function( __FUNCTION__, '2.8.0', 'get_term_children()' ); if ( 0 == $id ) return ''; $chain = ''; /** TODO: consult hierarchy */ $cat_ids = get_all_category_ids(); foreach ( (array) $cat_ids as $cat_id ) { if ( $cat_id == $id ) continue; $category = get_category( $cat_id ); if ( is_wp_error( $category ) ) return $category; if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) { $visited[] = $category->term_id; $chain .= $before.$category->term_id.$after; $chain .= get_category_children( $category->term_id, $before, $after ); } } return $chain; } /** * Retrieves all category IDs. * * @since 2.0.0 * @deprecated 4.0.0 Use get_terms() * @see get_terms() * * @link https://codex.wordpress.org/Function_Reference/get_all_category_ids * * @return object List of all of the category IDs. */ function get_all_category_ids() { _deprecated_function( __FUNCTION__, '4.0.0', 'get_terms()' ); if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category' ) ) { $cat_ids = get_terms( 'category', array('fields' => 'ids', 'get' => 'all') ); wp_cache_add( 'all_category_ids', $cat_ids, 'category' ); } return $cat_ids; } /** * Retrieve the description of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's description. */ function get_the_author_description() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'description\')' ); return get_the_author_meta('description'); } /** * Display the description of the author of the current post. * * @since 1.0.0 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_description() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'description\')' ); the_author_meta('description'); } /** * Retrieve the login name of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's login name (username). */ function get_the_author_login() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'login\')' ); return get_the_author_meta('login'); } /** * Display the login name of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_login() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'login\')' ); the_author_meta('login'); } /** * Retrieve the first name of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's first name. */ function get_the_author_firstname() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'first_name\')' ); return get_the_author_meta('first_name'); } /** * Display the first name of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_firstname() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'first_name\')' ); the_author_meta('first_name'); } /** * Retrieve the last name of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's last name. */ function get_the_author_lastname() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'last_name\')' ); return get_the_author_meta('last_name'); } /** * Display the last name of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_lastname() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'last_name\')' ); the_author_meta('last_name'); } /** * Retrieve the nickname of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's nickname. */ function get_the_author_nickname() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'nickname\')' ); return get_the_author_meta('nickname'); } /** * Display the nickname of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_nickname() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'nickname\')' ); the_author_meta('nickname'); } /** * Retrieve the email of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's username. */ function get_the_author_email() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'email\')' ); return get_the_author_meta('email'); } /** * Display the email of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_email() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'email\')' ); the_author_meta('email'); } /** * Retrieve the ICQ number of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's ICQ number. */ function get_the_author_icq() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'icq\')' ); return get_the_author_meta('icq'); } /** * Display the ICQ number of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_icq() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'icq\')' ); the_author_meta('icq'); } /** * Retrieve the Yahoo! IM name of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's Yahoo! IM name. */ function get_the_author_yim() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'yim\')' ); return get_the_author_meta('yim'); } /** * Display the Yahoo! IM name of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_yim() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'yim\')' ); the_author_meta('yim'); } /** * Retrieve the MSN address of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's MSN address. */ function get_the_author_msn() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'msn\')' ); return get_the_author_meta('msn'); } /** * Display the MSN address of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_msn() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'msn\')' ); the_author_meta('msn'); } /** * Retrieve the AIM address of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The author's AIM address. */ function get_the_author_aim() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'aim\')' ); return get_the_author_meta('aim'); } /** * Display the AIM address of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta('aim') * @see the_author_meta() */ function the_author_aim() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'aim\')' ); the_author_meta('aim'); } /** * Retrieve the specified author's preferred display name. * * @since 1.0.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @param int $auth_id The ID of the author. * @return string The author's display name. */ function get_author_name( $auth_id = false ) { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'display_name\')' ); return get_the_author_meta('display_name', $auth_id); } /** * Retrieve the URL to the home page of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string The URL to the author's page. */ function get_the_author_url() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'url\')' ); return get_the_author_meta('url'); } /** * Display the URL to the home page of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_url() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'url\')' ); the_author_meta('url'); } /** * Retrieve the ID of the author of the current post. * * @since 1.5.0 * @deprecated 2.8.0 Use get_the_author_meta() * @see get_the_author_meta() * * @return string|int The author's ID. */ function get_the_author_ID() { _deprecated_function( __FUNCTION__, '2.8.0', 'get_the_author_meta(\'ID\')' ); return get_the_author_meta('ID'); } /** * Display the ID of the author of the current post. * * @since 0.71 * @deprecated 2.8.0 Use the_author_meta() * @see the_author_meta() */ function the_author_ID() { _deprecated_function( __FUNCTION__, '2.8.0', 'the_author_meta(\'ID\')' ); the_author_meta('ID'); } /** * Display the post content for the feed. * * For encoding the html or the $encode_html parameter, there are three possible * values. '0' will make urls footnotes and use make_url_footnote(). '1' will * encode special characters and automatically display all of the content. The * value of '2' will strip all HTML tags from the content. * * Also note that you cannot set the amount of words and not set the html * encoding. If that is the case, then the html encoding will default to 2, * which will strip all HTML tags. * * To restrict the amount of words of the content, you can use the cut * parameter. If the content is less than the amount, then there won't be any * dots added to the end. If there is content left over, then dots will be added * and the rest of the content will be removed. * * @since 0.71 * * @deprecated 2.9.0 Use the_content_feed() * @see the_content_feed() * * @param string $more_link_text Optional. Text to display when more content is available but not displayed. * @param int $stripteaser Optional. Default is 0. * @param string $more_file Optional. * @param int $cut Optional. Amount of words to keep for the content. * @param int $encode_html Optional. How to encode the content. */ function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) { _deprecated_function( __FUNCTION__, '2.9.0', 'the_content_feed()' ); $content = get_the_content($more_link_text, $stripteaser); /** * Filters the post content in the context of an RSS feed. * * @since 0.71 * * @param string $content Content of the current post. */ $content = apply_filters('the_content_rss', $content); if ( $cut && !$encode_html ) $encode_html = 2; if ( 1== $encode_html ) { $content = esc_html($content); $cut = 0; } elseif ( 0 == $encode_html ) { $content = make_url_footnote($content); } elseif ( 2 == $encode_html ) { $content = strip_tags($content); } if ( $cut ) { $blah = explode(' ', $content); if ( count($blah) > $cut ) { $k = $cut; $use_dotdotdot = 1; } else { $k = count($blah); $use_dotdotdot = 0; } /** @todo Check performance, might be faster to use array slice instead. */ for ( $i=0; $i<$k; $i++ ) $excerpt .= $blah[$i].' '; $excerpt .= ($use_dotdotdot) ? '...' : ''; $content = $excerpt; } $content = str_replace(']]>', ']]>', $content); echo $content; } /** * Strip HTML and put links at the bottom of stripped content. * * Searches for all of the links, strips them out of the content, and places * them at the bottom of the content with numbers. * * @since 0.71 * @deprecated 2.9.0 * * @param string $content Content to get links * @return string HTML stripped out of content with links at the bottom. */ function make_url_footnote( $content ) { _deprecated_function( __FUNCTION__, '2.9.0', '' ); preg_match_all( '/(.+?)<\/a>/', $content, $matches ); $links_summary = "\n"; for ( $i = 0, $c = count( $matches[0] ); $i < $c; $i++ ) { $link_match = $matches[0][$i]; $link_number = '['.($i+1).']'; $link_url = $matches[2][$i]; $link_text = $matches[4][$i]; $content = str_replace( $link_match, $link_text . ' ' . $link_number, $content ); $link_url = ( ( strtolower( substr( $link_url, 0, 7 ) ) != 'http://' ) && ( strtolower( substr( $link_url, 0, 8 ) ) != 'https://' ) ) ? get_option( 'home' ) . $link_url : $link_url; $links_summary .= "\n" . $link_number . ' ' . $link_url; } $content = strip_tags( $content ); $content .= $links_summary; return $content; } /** * Retrieve translated string with vertical bar context * * Quite a few times, there will be collisions with similar translatable text * found in more than two places but with different translated context. * * In order to use the separate contexts, the _c() function is used and the * translatable string uses a pipe ('|') which has the context the string is in. * * When the translated string is returned, it is everything before the pipe, not * including the pipe character. If there is no pipe in the translated text then * everything is returned. * * @since 2.2.0 * @deprecated 2.9.0 Use _x() * @see _x() * * @param string $text Text to translate * @param string $domain Optional. Domain to retrieve the translated text * @return string Translated context string without pipe */ function _c( $text, $domain = 'default' ) { _deprecated_function( __FUNCTION__, '2.9.0', '_x()' ); return before_last_bar( translate( $text, $domain ) ); } /** * Translates $text like translate(), but assumes that the text * contains a context after its last vertical bar. * * @since 2.5.0 * @deprecated 3.0.0 Use _x() * @see _x() * * @param string $text Text to translate * @param string $domain Domain to retrieve the translated text * @return string Translated text */ function translate_with_context( $text, $domain = 'default' ) { _deprecated_function( __FUNCTION__, '2.9.0', '_x()' ); return before_last_bar( translate( $text, $domain ) ); } /** * Legacy version of _n(), which supports contexts. * * Strips everything from the translation after the last bar. * * @since 2.7.0 * @deprecated 3.0.0 Use _nx() * @see _nx() * * @param string $single The text to be used if the number is singular. * @param string $plural The text to be used if the number is plural. * @param int $number The number to compare against to use either the singular or plural form. * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. * Default 'default'. * @return string The translated singular or plural form. */ function _nc( $single, $plural, $number, $domain = 'default' ) { _deprecated_function( __FUNCTION__, '2.9.0', '_nx()' ); return before_last_bar( _n( $single, $plural, $number, $domain ) ); } /** * Retrieve the plural or single form based on the amount. * * @since 1.2.0 * @deprecated 2.8.0 Use _n() * @see _n() */ function __ngettext() { _deprecated_function( __FUNCTION__, '2.8.0', '_n()' ); $args = func_get_args(); return call_user_func_array('_n', $args); } /** * Register plural strings in POT file, but don't translate them. * * @since 2.5.0 * @deprecated 2.8.0 Use _n_noop() * @see _n_noop() */ function __ngettext_noop() { _deprecated_function( __FUNCTION__, '2.8.0', '_n_noop()' ); $args = func_get_args(); return call_user_func_array('_n_noop', $args); } /** * Retrieve all autoload options, or all options if no autoloaded ones exist. * * @since 1.0.0 * @deprecated 3.0.0 Use wp_load_alloptions()) * @see wp_load_alloptions() * * @return array List of all options. */ function get_alloptions() { _deprecated_function( __FUNCTION__, '3.0.0', 'wp_load_alloptions()' ); return wp_load_alloptions(); } /** * Retrieve HTML content of attachment image with link. * * @since 2.0.0 * @deprecated 2.5.0 Use wp_get_attachment_link() * @see wp_get_attachment_link() * * @param int $id Optional. Post ID. * @param bool $fullsize Optional, default is false. Whether to use full size image. * @param array $max_dims Optional. Max image dimensions. * @param bool $permalink Optional, default is false. Whether to include permalink to image. * @return string */ function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) { _deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_link()' ); $id = (int) $id; $_post = get_post($id); if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) ) return __('Missing Attachment'); if ( $permalink ) $url = get_attachment_link($_post->ID); $post_title = esc_attr($_post->post_title); $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims); return "$innerHTML"; } /** * Retrieve icon URL and Path. * * @since 2.1.0 * @deprecated 2.5.0 Use wp_get_attachment_image_src() * @see wp_get_attachment_image_src() * * @param int $id Optional. Post ID. * @param bool $fullsize Optional, default to false. Whether to have full image. * @return array Icon URL and full path to file, respectively. */ function get_attachment_icon_src( $id = 0, $fullsize = false ) { _deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_image_src()' ); $id = (int) $id; if ( !$post = get_post($id) ) return false; $file = get_attached_file( $post->ID ); if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) { // We have a thumbnail desired, specified and existing $src_file = basename($src); } elseif ( wp_attachment_is_image( $post->ID ) ) { // We have an image without a thumbnail $src = wp_get_attachment_url( $post->ID ); $src_file = & $file; } elseif ( $src = wp_mime_type_icon( $post->ID ) ) { // No thumb, no image. We'll look for a mime-related icon instead. $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' ); $src_file = $icon_dir . '/' . basename($src); } if ( !isset($src) || !$src ) return false; return array($src, $src_file); } /** * Retrieve HTML content of icon attachment image element. * * @since 2.0.0 * @deprecated 2.5.0 Use wp_get_attachment_image() * @see wp_get_attachment_image() * * @param int $id Optional. Post ID. * @param bool $fullsize Optional, default to false. Whether to have full size image. * @param array $max_dims Optional. Dimensions of image. * @return false|string HTML content. */ function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) { _deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_image()' ); $id = (int) $id; if ( !$post = get_post($id) ) return false; if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) ) return false; list($src, $src_file) = $src; // Do we need to constrain the image? if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) { $imagesize = getimagesize($src_file); if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) { $actual_aspect = $imagesize[0] / $imagesize[1]; $desired_aspect = $max_dims[0] / $max_dims[1]; if ( $actual_aspect >= $desired_aspect ) { $height = $actual_aspect * $max_dims[0]; $constraint = "width='{$max_dims[0]}' "; $post->iconsize = array($max_dims[0], $height); } else { $width = $max_dims[1] / $actual_aspect; $constraint = "height='{$max_dims[1]}' "; $post->iconsize = array($width, $max_dims[1]); } } else { $post->iconsize = array($imagesize[0], $imagesize[1]); $constraint = ''; } } else { $constraint = ''; } $post_title = esc_attr($post->post_title); $icon = "$post_title"; return apply_filters( 'attachment_icon', $icon, $post->ID ); } /** * Retrieve HTML content of image element. * * @since 2.0.0 * @deprecated 2.5.0 Use wp_get_attachment_image() * @see wp_get_attachment_image() * * @param int $id Optional. Post ID. * @param bool $fullsize Optional, default to false. Whether to have full size image. * @param array $max_dims Optional. Dimensions of image. * @return false|string */ function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) { _deprecated_function( __FUNCTION__, '2.5.0', 'wp_get_attachment_image()' ); $id = (int) $id; if ( !$post = get_post($id) ) return false; if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims)) return $innerHTML; $innerHTML = esc_attr($post->post_title); return apply_filters('attachment_innerHTML', $innerHTML, $post->ID); } /** * Retrieves bookmark data based on ID. * * @since 2.0.0 * @deprecated 2.1.0 Use get_bookmark() * @see get_bookmark() * * @param int $bookmark_id ID of link * @param string $output Optional. Type of output. Accepts OBJECT, ARRAY_N, or ARRAY_A. * Default OBJECT. * @param string $filter Optional. How to filter the link for output. Accepts 'raw', 'edit', * 'attribute', 'js', 'db', or 'display'. Default 'raw'. * @return object|array Bookmark object or array, depending on the type specified by `$output`. */ function get_link( $bookmark_id, $output = OBJECT, $filter = 'raw' ) { _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmark()' ); return get_bookmark($bookmark_id, $output, $filter); } /** * Performs esc_url() for database or redirect usage. * * @since 2.3.1 * @deprecated 2.8.0 Use esc_url_raw() * @see esc_url_raw() * * @param string $url The URL to be cleaned. * @param array $protocols An array of acceptable protocols. * @return string The cleaned URL. */ function sanitize_url( $url, $protocols = null ) { _deprecated_function( __FUNCTION__, '2.8.0', 'esc_url_raw()' ); return esc_url_raw( $url, $protocols ); } /** * Checks and cleans a URL. * * A number of characters are removed from the URL. If the URL is for displaying * (the default behaviour) ampersands are also replaced. The 'clean_url' filter * is applied to the returned cleaned URL. * * @since 1.2.0 * @deprecated 3.0.0 Use esc_url() * @see esc_url() * * @param string $url The URL to be cleaned. * @param array $protocols Optional. An array of acceptable protocols. * @param string $context Optional. How the URL will be used. Default is 'display'. * @return string The cleaned $url after the {@see 'clean_url'} filter is applied. */ function clean_url( $url, $protocols = null, $context = 'display' ) { if ( $context == 'db' ) _deprecated_function( 'clean_url( $context = \'db\' )', '3.0.0', 'esc_url_raw()' ); else _deprecated_function( __FUNCTION__, '3.0.0', 'esc_url()' ); return esc_url( $url, $protocols, $context ); } /** * Escape single quotes, specialchar double quotes, and fix line endings. * * The filter {@see 'js_escape'} is also applied by esc_js(). * * @since 2.0.4 * @deprecated 2.8.0 Use esc_js() * @see esc_js() * * @param string $text The text to be escaped. * @return string Escaped text. */ function js_escape( $text ) { _deprecated_function( __FUNCTION__, '2.8.0', 'esc_js()' ); return esc_js( $text ); } /** * Legacy escaping for HTML blocks. * * @deprecated 2.8.0 Use esc_html() * @see esc_html() * * @param string $string String to escape. * @param string $quote_style Unused. * @param false|string $charset Unused. * @param false $double_encode Whether to double encode. Unused. * @return string Escaped `$string`. */ function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) { _deprecated_function( __FUNCTION__, '2.8.0', 'esc_html()' ); if ( func_num_args() > 1 ) { // Maintain back-compat for people passing additional arguments. $args = func_get_args(); return call_user_func_array( '_wp_specialchars', $args ); } else { return esc_html( $string ); } } /** * Escaping for HTML attributes. * * @since 2.0.6 * @deprecated 2.8.0 Use esc_attr() * @see esc_attr() * * @param string $text * @return string */ function attribute_escape( $text ) { _deprecated_function( __FUNCTION__, '2.8.0', 'esc_attr()' ); return esc_attr( $text ); } /** * Register widget for sidebar with backward compatibility. * * Allows $name to be an array that accepts either three elements to grab the * first element and the third for the name or just uses the first element of * the array for the name. * * Passes to wp_register_sidebar_widget() after argument list and backward * compatibility is complete. * * @since 2.2.0 * @deprecated 2.8.0 Use wp_register_sidebar_widget() * @see wp_register_sidebar_widget() * * @param string|int $name Widget ID. * @param callable $output_callback Run when widget is called. * @param string $classname Optional. Classname widget option. Default empty. * @param mixed $params ,... Widget parameters. */ function register_sidebar_widget($name, $output_callback, $classname = '') { _deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_sidebar_widget()' ); // Compat if ( is_array($name) ) { if ( count($name) == 3 ) $name = sprintf($name[0], $name[2]); else $name = $name[0]; } $id = sanitize_title($name); $options = array(); if ( !empty($classname) && is_string($classname) ) $options['classname'] = $classname; $params = array_slice(func_get_args(), 2); $args = array($id, $name, $output_callback, $options); if ( !empty($params) ) $args = array_merge($args, $params); call_user_func_array('wp_register_sidebar_widget', $args); } /** * Serves as an alias of wp_unregister_sidebar_widget(). * * @since 2.2.0 * @deprecated 2.8.0 Use wp_unregister_sidebar_widget() * @see wp_unregister_sidebar_widget() * * @param int|string $id Widget ID. */ function unregister_sidebar_widget($id) { _deprecated_function( __FUNCTION__, '2.8.0', 'wp_unregister_sidebar_widget()' ); return wp_unregister_sidebar_widget($id); } /** * Registers widget control callback for customizing options. * * Allows $name to be an array that accepts either three elements to grab the * first element and the third for the name or just uses the first element of * the array for the name. * * Passes to wp_register_widget_control() after the argument list has * been compiled. * * @since 2.2.0 * @deprecated 2.8.0 Use wp_register_widget_control() * @see wp_register_widget_control() * * @param int|string $name Sidebar ID. * @param callable $control_callback Widget control callback to display and process form. * @param int $width Widget width. * @param int $height Widget height. */ function register_widget_control($name, $control_callback, $width = '', $height = '') { _deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_widget_control()' ); // Compat if ( is_array($name) ) { if ( count($name) == 3 ) $name = sprintf($name[0], $name[2]); else $name = $name[0]; } $id = sanitize_title($name); $options = array(); if ( !empty($width) ) $options['width'] = $width; if ( !empty($height) ) $options['height'] = $height; $params = array_slice(func_get_args(), 4); $args = array($id, $name, $control_callback, $options); if ( !empty($params) ) $args = array_merge($args, $params); call_user_func_array('wp_register_widget_control', $args); } /** * Alias of wp_unregister_widget_control(). * * @since 2.2.0 * @deprecated 2.8.0 Use wp_unregister_widget_control() * @see wp_unregister_widget_control() * * @param int|string $id Widget ID. */ function unregister_widget_control($id) { _deprecated_function( __FUNCTION__, '2.8.0', 'wp_unregister_widget_control()' ); return wp_unregister_widget_control($id); } /** * Remove user meta data. * * @since 2.0.0 * @deprecated 3.0.0 Use delete_user_meta() * @see delete_user_meta() * * @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 = '' ) { _deprecated_function( __FUNCTION__, '3.0.0', 'delete_user_meta()' ); 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) ); clean_user_cache( $user_id ); wp_cache_delete( $user_id, 'user_meta' ); 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 * @deprecated 3.0.0 Use get_user_meta() * @see get_user_meta() * * @param int $user_id User ID * @param string $meta_key Optional. Metadata key. * @return mixed */ function get_usermeta( $user_id, $meta_key = '' ) { _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_meta()' ); 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 * @deprecated 3.0.0 Use update_user_meta() * @see update_user_meta() * * @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 ) { _deprecated_function( __FUNCTION__, '3.0.0', 'update_user_meta()' ); 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') ); elseif ( $cur->meta_value != $meta_value ) $wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key') ); else return false; clean_user_cache( $user_id ); wp_cache_delete( $user_id, 'user_meta' ); 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; } /** * Get users for the site. * * For setups that use the multisite feature. Can be used outside of the * multisite feature. * * @since 2.2.0 * @deprecated 3.1.0 Use get_users() * @see get_users() * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $id Site ID. * @return array List of users that are part of that site ID */ function get_users_of_blog( $id = '' ) { _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' ); global $wpdb; if ( empty( $id ) ) { $id = get_current_blog_id(); } $blog_prefix = $wpdb->get_blog_prefix($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 = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" ); return $users; } /** * Enable/disable automatic general feed link outputting. * * @since 2.8.0 * @deprecated 3.0.0 Use add_theme_support() * @see add_theme_support() * * @param bool $add Optional, default is true. Add or remove links. Defaults to true. */ function automatic_feed_links( $add = true ) { _deprecated_function( __FUNCTION__, '3.0.0', "add_theme_support( 'automatic-feed-links' )" ); if ( $add ) add_theme_support( 'automatic-feed-links' ); else remove_action( 'wp_head', 'feed_links_extra', 3 ); // Just do this yourself in 3.0+ } /** * Retrieve user data based on field. * * @since 1.5.0 * @deprecated 3.0.0 Use get_the_author_meta() * @see get_the_author_meta() * * @param string $field User meta field. * @param false|int $user Optional. User ID to retrieve the field for. Default false (current user). * @return string The author's field from the current author's DB object. */ function get_profile( $field, $user = false ) { _deprecated_function( __FUNCTION__, '3.0.0', 'get_the_author_meta()' ); if ( $user ) { $user = get_user_by( 'login', $user ); $user = $user->ID; } return get_the_author_meta( $field, $user ); } /** * Retrieves the number of posts a user has written. * * @since 0.71 * @deprecated 3.0.0 Use count_user_posts() * @see count_user_posts() * * @param int $userid User to count posts for. * @return int Number of posts the given user has written. */ function get_usernumposts( $userid ) { _deprecated_function( __FUNCTION__, '3.0.0', 'count_user_posts()' ); return count_user_posts( $userid ); } /** * Callback used to change %uXXXX to &#YYY; syntax * * @since 2.8.0 * @access private * @deprecated 3.0.0 * * @param array $matches Single Match * @return string An HTML entity */ function funky_javascript_callback($matches) { return "&#".base_convert($matches[1],16,10).";"; } /** * Fixes JavaScript bugs in browsers. * * Converts unicode characters to HTML numbered entities. * * @since 1.5.0 * @deprecated 3.0.0 * * @global $is_macIE * @global $is_winIE * * @param string $text Text to be made safe. * @return string Fixed text. */ function funky_javascript_fix($text) { _deprecated_function( __FUNCTION__, '3.0.0' ); // Fixes for browsers' JavaScript bugs. global $is_macIE, $is_winIE; if ( $is_winIE || $is_macIE ) $text = preg_replace_callback("/\%u([0-9A-F]{4,4})/", "funky_javascript_callback", $text); return $text; } /** * Checks that the taxonomy name exists. * * @since 2.3.0 * @deprecated 3.0.0 Use taxonomy_exists() * @see taxonomy_exists() * * @param string $taxonomy Name of taxonomy object * @return bool Whether the taxonomy exists. */ function is_taxonomy( $taxonomy ) { _deprecated_function( __FUNCTION__, '3.0.0', 'taxonomy_exists()' ); return taxonomy_exists( $taxonomy ); } /** * Check if Term exists. * * @since 2.3.0 * @deprecated 3.0.0 Use term_exists() * @see term_exists() * * @param int|string $term The term to check * @param string $taxonomy The taxonomy name to use * @param int $parent ID of parent term under which to confine the exists search. * @return mixed Get the term id or Term Object, if exists. */ function is_term( $term, $taxonomy = '', $parent = 0 ) { _deprecated_function( __FUNCTION__, '3.0.0', 'term_exists()' ); return term_exists( $term, $taxonomy, $parent ); } /** * Determines whether the current admin page is generated by a plugin. * * Use global $plugin_page and/or get_plugin_page_hookname() hooks. * * For more information on this and similar theme functions, check out * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ * Conditional Tags} article in the Theme Developer Handbook. * * @since 1.5.0 * @deprecated 3.1.0 * * @global $plugin_page * * @return bool */ function is_plugin_page() { _deprecated_function( __FUNCTION__, '3.1.0' ); global $plugin_page; if ( isset($plugin_page) ) return true; return false; } /** * Update the categories cache. * * This function does not appear to be used anymore or does not appear to be * needed. It might be a legacy function left over from when there was a need * for updating the category cache. * * @since 1.5.0 * @deprecated 3.1.0 * * @return bool Always return True */ function update_category_cache() { _deprecated_function( __FUNCTION__, '3.1.0' ); return true; } /** * Check for PHP timezone support * * @since 2.9.0 * @deprecated 3.2.0 * * @return bool */ function wp_timezone_supported() { _deprecated_function( __FUNCTION__, '3.2.0' ); return true; } /** * Displays an editor: TinyMCE, HTML, or both. * * @since 2.1.0 * @deprecated 3.3.0 Use wp_editor() * @see wp_editor() * * @param string $content Textarea content. * @param string $id Optional. HTML ID attribute value. Default 'content'. * @param string $prev_id Optional. Unused. * @param bool $media_buttons Optional. Whether to display media buttons. Default true. * @param int $tab_index Optional. Unused. * @param bool $extended Optional. Unused. */ function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2, $extended = true) { _deprecated_function( __FUNCTION__, '3.3.0', 'wp_editor()' ); wp_editor( $content, $id, array( 'media_buttons' => $media_buttons ) ); } /** * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users * * @since 3.0.0 * @deprecated 3.3.0 * * @param array $ids User ID numbers list. * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays. */ function get_user_metavalues($ids) { _deprecated_function( __FUNCTION__, '3.3.0' ); $objects = array(); $ids = array_map('intval', $ids); foreach ( $ids as $id ) $objects[$id] = array(); $metas = update_meta_cache('user', $ids); foreach ( $metas as $id => $meta ) { foreach ( $meta as $key => $metavalues ) { foreach ( $metavalues as $value ) { $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value); } } } return $objects; } /** * 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 * @deprecated 3.3.0 * * @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') { _deprecated_function( __FUNCTION__, '3.3.0' ); if ( is_object($user) ) { if ( !isset($user->ID) ) $user->ID = 0; if ( ! ( $user instanceof WP_User ) ) { $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; } /** * Get boundary post relational link. * * Can either be start or end post relational link. * * @since 2.8.0 * @deprecated 3.3.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in a same category. * @param string $excluded_categories Optional. Excluded categories IDs. * @param bool $start Optional, default is true. Whether to display link to first or last post. * @return string */ function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { _deprecated_function( __FUNCTION__, '3.3.0' ); $posts = get_boundary_post($in_same_cat, $excluded_categories, $start); // If there is no post stop. if ( empty($posts) ) return; // Even though we limited get_posts to return only 1 item it still returns an array of objects. $post = $posts[0]; 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->ID); $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 * @deprecated 3.3.0 * * @param string $title Optional. Link title format. * @param bool $in_same_cat Optional. Whether link should be in a same category. * @param string $excluded_categories Optional. Excluded categories IDs. */ function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { _deprecated_function( __FUNCTION__, '3.3.0' ); echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true); } /** * Get site index relational link. * * @since 2.8.0 * @deprecated 3.3.0 * * @return string */ function get_index_rel_link() { _deprecated_function( __FUNCTION__, '3.3.0' ); $link = "\n"; return apply_filters( "index_rel_link", $link ); } /** * Display relational link for the site index. * * @since 2.8.0 * @deprecated 3.3.0 */ function index_rel_link() { _deprecated_function( __FUNCTION__, '3.3.0' ); echo get_index_rel_link(); } /** * Get parent post relational link. * * @since 2.8.0 * @deprecated 3.3.0 * * @param string $title Optional. Link title format. Default '%title'. * @return string */ function get_parent_post_rel_link( $title = '%title' ) { _deprecated_function( __FUNCTION__, '3.3.0' ); 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->ID); $link = "\n"; return apply_filters( "parent_post_rel_link", $link ); } /** * Display relational link for parent item * * @since 2.8.0 * @deprecated 3.3.0 * * @param string $title Optional. Link title format. Default '%title'. */ function parent_post_rel_link( $title = '%title' ) { _deprecated_function( __FUNCTION__, '3.3.0' ); echo get_parent_post_rel_link($title); } /** * Add the "Dashboard"/"Visit Site" menu. * * @since 3.2.0 * @deprecated 3.3.0 * * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. */ function wp_admin_bar_dashboard_view_site_menu( $wp_admin_bar ) { _deprecated_function( __FUNCTION__, '3.3.0' ); $user_id = get_current_user_id(); if ( 0 != $user_id ) { if ( is_admin() ) $wp_admin_bar->add_menu( array( 'id' => 'view-site', 'title' => __( 'Visit Site' ), 'href' => home_url() ) ); elseif ( is_multisite() ) $wp_admin_bar->add_menu( array( 'id' => 'dashboard', 'title' => __( 'Dashboard' ), 'href' => get_dashboard_url( $user_id ) ) ); else $wp_admin_bar->add_menu( array( 'id' => 'dashboard', 'title' => __( 'Dashboard' ), 'href' => admin_url() ) ); } } /** * Checks if the current user belong to a given site. * * @since MU (3.0.0) * @deprecated 3.3.0 Use is_user_member_of_blog() * @see is_user_member_of_blog() * * @param int $blog_id Site ID * @return bool True if the current users belong to $blog_id, false if not. */ function is_blog_user( $blog_id = 0 ) { _deprecated_function( __FUNCTION__, '3.3.0', 'is_user_member_of_blog()' ); return is_user_member_of_blog( get_current_user_id(), $blog_id ); } /** * Open the file handle for debugging. * * @since 0.71 * @deprecated 3.4.0 Use error_log() * @see error_log() * * @link https://secure.php.net/manual/en/function.error-log.php * * @param string $filename File name. * @param string $mode Type of access you required to the stream. * @return false Always false. */ function debug_fopen( $filename, $mode ) { _deprecated_function( __FUNCTION__, '3.4.0', 'error_log()' ); return false; } /** * Write contents to the file used for debugging. * * @since 0.71 * @deprecated 3.4.0 Use error_log() * @see error_log() * * @link https://secure.php.net/manual/en/function.error-log.php * * @param mixed $fp Unused. * @param string $string Message to log. */ function debug_fwrite( $fp, $string ) { _deprecated_function( __FUNCTION__, '3.4.0', 'error_log()' ); if ( ! empty( $GLOBALS['debug'] ) ) error_log( $string ); } /** * Close the debugging file handle. * * @since 0.71 * @deprecated 3.4.0 Use error_log() * @see error_log() * * @link https://secure.php.net/manual/en/function.error-log.php * * @param mixed $fp Unused. */ function debug_fclose( $fp ) { _deprecated_function( __FUNCTION__, '3.4.0', 'error_log()' ); } /** * Retrieve list of themes with theme data in theme directory. * * The theme is broken, if it doesn't have a parent theme and is missing either * style.css and, or index.php. If the theme has a parent theme then it is * broken, if it is missing style.css; index.php is optional. * * @since 1.5.0 * @deprecated 3.4.0 Use wp_get_themes() * @see wp_get_themes() * * @return array Theme list with theme data. */ function get_themes() { _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_themes()' ); global $wp_themes; if ( isset( $wp_themes ) ) return $wp_themes; $themes = wp_get_themes(); $wp_themes = array(); foreach ( $themes as $theme ) { $name = $theme->get('Name'); if ( isset( $wp_themes[ $name ] ) ) $wp_themes[ $name . '/' . $theme->get_stylesheet() ] = $theme; else $wp_themes[ $name ] = $theme; } return $wp_themes; } /** * Retrieve theme data. * * @since 1.5.0 * @deprecated 3.4.0 Use wp_get_theme() * @see wp_get_theme() * * @param string $theme Theme name. * @return array|null Null, if theme name does not exist. Theme data, if exists. */ function get_theme( $theme ) { _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme( $stylesheet )' ); $themes = get_themes(); if ( is_array( $themes ) && array_key_exists( $theme, $themes ) ) return $themes[ $theme ]; return null; } /** * Retrieve current theme name. * * @since 1.5.0 * @deprecated 3.4.0 Use wp_get_theme() * @see wp_get_theme() * * @return string */ function get_current_theme() { _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' ); if ( $theme = get_option( 'current_theme' ) ) return $theme; return wp_get_theme()->get('Name'); } /** * Accepts matches array from preg_replace_callback in wpautop() or a string. * * Ensures that the contents of a `
    ...
    ` HTML block are not * converted into paragraphs or line-breaks. * * @since 1.2.0 * @deprecated 3.4.0 * * @param array|string $matches The array or string * @return string The pre block without paragraph/line-break conversion. */ function clean_pre($matches) { _deprecated_function( __FUNCTION__, '3.4.0' ); if ( is_array($matches) ) $text = $matches[1] . $matches[2] . ""; else $text = $matches; $text = str_replace(array('
    ', '
    ', '
    '), array('', '', ''), $text); $text = str_replace('

    ', "\n", $text); $text = str_replace('

    ', '', $text); return $text; } /** * Add callbacks for image header display. * * @since 2.1.0 * @deprecated 3.4.0 Use add_theme_support() * @see add_theme_support() * * @param callable $wp_head_callback Call on the {@see 'wp_head'} action. * @param callable $admin_head_callback Call on custom header administration screen. * @param callable $admin_preview_callback Output a custom header image div on the custom header administration screen. Optional. */ function add_custom_image_header( $wp_head_callback, $admin_head_callback, $admin_preview_callback = '' ) { _deprecated_function( __FUNCTION__, '3.4.0', 'add_theme_support( \'custom-header\', $args )' ); $args = array( 'wp-head-callback' => $wp_head_callback, 'admin-head-callback' => $admin_head_callback, ); if ( $admin_preview_callback ) $args['admin-preview-callback'] = $admin_preview_callback; return add_theme_support( 'custom-header', $args ); } /** * Remove image header support. * * @since 3.1.0 * @deprecated 3.4.0 Use remove_theme_support() * @see remove_theme_support() * * @return null|bool Whether support was removed. */ function remove_custom_image_header() { _deprecated_function( __FUNCTION__, '3.4.0', 'remove_theme_support( \'custom-header\' )' ); return remove_theme_support( 'custom-header' ); } /** * Add callbacks for background image display. * * @since 3.0.0 * @deprecated 3.4.0 Use add_theme_support() * @see add_theme_support() * * @param callable $wp_head_callback Call on the {@see 'wp_head'} action. * @param callable $admin_head_callback Call on custom background administration screen. * @param callable $admin_preview_callback Output a custom background image div on the custom background administration screen. Optional. */ function add_custom_background( $wp_head_callback = '', $admin_head_callback = '', $admin_preview_callback = '' ) { _deprecated_function( __FUNCTION__, '3.4.0', 'add_theme_support( \'custom-background\', $args )' ); $args = array(); if ( $wp_head_callback ) $args['wp-head-callback'] = $wp_head_callback; if ( $admin_head_callback ) $args['admin-head-callback'] = $admin_head_callback; if ( $admin_preview_callback ) $args['admin-preview-callback'] = $admin_preview_callback; return add_theme_support( 'custom-background', $args ); } /** * Remove custom background support. * * @since 3.1.0 * @deprecated 3.4.0 Use add_custom_background() * @see add_custom_background() * * @return null|bool Whether support was removed. */ function remove_custom_background() { _deprecated_function( __FUNCTION__, '3.4.0', 'remove_theme_support( \'custom-background\' )' ); return remove_theme_support( 'custom-background' ); } /** * Retrieve theme data from parsed theme file. * * @since 1.5.0 * @deprecated 3.4.0 Use wp_get_theme() * @see wp_get_theme() * * @param string $theme_file Theme file path. * @return array Theme data. */ function get_theme_data( $theme_file ) { _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' ); $theme = new WP_Theme( basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) ); $theme_data = array( 'Name' => $theme->get('Name'), 'URI' => $theme->display('ThemeURI', true, false), 'Description' => $theme->display('Description', true, false), 'Author' => $theme->display('Author', true, false), 'AuthorURI' => $theme->display('AuthorURI', true, false), 'Version' => $theme->get('Version'), 'Template' => $theme->get('Template'), 'Status' => $theme->get('Status'), 'Tags' => $theme->get('Tags'), 'Title' => $theme->get('Name'), 'AuthorName' => $theme->get('Author'), ); foreach ( apply_filters( 'extra_theme_headers', array() ) as $extra_header ) { if ( ! isset( $theme_data[ $extra_header ] ) ) $theme_data[ $extra_header ] = $theme->get( $extra_header ); } return $theme_data; } /** * Alias of update_post_cache(). * * @see update_post_cache() Posts and pages are the same, alias is intentional * * @since 1.5.1 * @deprecated 3.4.0 Use update_post_cache() * @see update_post_cache() * * @param array $pages list of page objects */ function update_page_cache( &$pages ) { _deprecated_function( __FUNCTION__, '3.4.0', 'update_post_cache()' ); update_post_cache( $pages ); } /** * Will clean the page in the cache. * * Clean (read: delete) page from cache that matches $id. Will also clean cache * associated with 'all_page_ids' and 'get_pages'. * * @since 2.0.0 * @deprecated 3.4.0 Use clean_post_cache * @see clean_post_cache() * * @param int $id Page ID to clean */ function clean_page_cache( $id ) { _deprecated_function( __FUNCTION__, '3.4.0', 'clean_post_cache()' ); clean_post_cache( $id ); } /** * Retrieve nonce action "Are you sure" message. * * Deprecated in 3.4.1 and 3.5.0. Backported to 3.3.3. * * @since 2.0.4 * @deprecated 3.4.1 Use wp_nonce_ays() * @see wp_nonce_ays() * * @param string $action Nonce action. * @return string Are you sure message. */ function wp_explain_nonce( $action ) { _deprecated_function( __FUNCTION__, '3.4.1', 'wp_nonce_ays()' ); return __( 'Are you sure you want to do this?' ); } /** * Display "sticky" CSS class, if a post is sticky. * * @since 2.7.0 * @deprecated 3.5.0 Use post_class() * @see post_class() * * @param int $post_id An optional post ID. */ function sticky_class( $post_id = null ) { _deprecated_function( __FUNCTION__, '3.5.0', 'post_class()' ); if ( is_sticky( $post_id ) ) echo ' sticky'; } /** * Retrieve post ancestors. * * This is no longer needed as WP_Post lazy-loads the ancestors * property with get_post_ancestors(). * * @since 2.3.4 * @deprecated 3.5.0 Use get_post_ancestors() * @see get_post_ancestors() * * @param WP_Post $post Post object, passed by reference (unused). */ function _get_post_ancestors( &$post ) { _deprecated_function( __FUNCTION__, '3.5.0' ); } /** * Load an image from a string, if PHP supports it. * * @since 2.1.0 * @deprecated 3.5.0 Use wp_get_image_editor() * @see wp_get_image_editor() * * @param string $file Filename of the image to load. * @return resource The resulting image resource on success, Error string on failure. */ function wp_load_image( $file ) { _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' ); if ( is_numeric( $file ) ) $file = get_attached_file( $file ); if ( ! is_file( $file ) ) { /* translators: %s: file name */ return sprintf( __( 'File “%s” doesn’t exist?' ), $file ); } if ( ! function_exists('imagecreatefromstring') ) return __('The GD image library is not installed.'); // Set artificially high because GD uses uncompressed images in memory. wp_raise_memory_limit( 'image' ); $image = imagecreatefromstring( file_get_contents( $file ) ); if ( ! is_resource( $image ) ) { /* translators: %s: file name */ return sprintf( __( 'File “%s” is not an image.' ), $file ); } return $image; } /** * Scale down an image to fit a particular size and save a new copy of the image. * * The PNG transparency will be preserved using the function, as well as the * image type. If the file going in is PNG, then the resized image is going to * be PNG. The only supported image types are PNG, GIF, and JPEG. * * Some functionality requires API to exist, so some PHP version may lose out * support. This is not the fault of WordPress (where functionality is * downgraded, not actual defects), but of your PHP version. * * @since 2.5.0 * @deprecated 3.5.0 Use wp_get_image_editor() * @see wp_get_image_editor() * * @param string $file Image file path. * @param int $max_w Maximum width to resize to. * @param int $max_h Maximum height to resize to. * @param bool $crop Optional. Whether to crop image or resize. * @param string $suffix Optional. File suffix. * @param string $dest_path Optional. New image file path. * @param int $jpeg_quality Optional, default is 90. Image quality percentage. * @return mixed WP_Error on failure. String with new destination path. */ function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) { _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' ); $editor = wp_get_image_editor( $file ); if ( is_wp_error( $editor ) ) return $editor; $editor->set_quality( $jpeg_quality ); $resized = $editor->resize( $max_w, $max_h, $crop ); if ( is_wp_error( $resized ) ) return $resized; $dest_file = $editor->generate_filename( $suffix, $dest_path ); $saved = $editor->save( $dest_file ); if ( is_wp_error( $saved ) ) return $saved; return $dest_file; } /** * Retrieve a single post, based on post ID. * * Has categories in 'post_category' property or key. Has tags in 'tags_input' * property or key. * * @since 1.0.0 * @deprecated 3.5.0 Use get_post() * @see get_post() * * @param int $postid Post ID. * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. * @return WP_Post|null Post object or array holding post contents and information */ function wp_get_single_post( $postid = 0, $mode = OBJECT ) { _deprecated_function( __FUNCTION__, '3.5.0', 'get_post()' ); return get_post( $postid, $mode ); } /** * Check that the user login name and password is correct. * * @since 0.71 * @deprecated 3.5.0 Use wp_authenticate() * @see wp_authenticate() * * @param string $user_login User name. * @param string $user_pass User password. * @return bool False if does not authenticate, true if username and password authenticates. */ function user_pass_ok($user_login, $user_pass) { _deprecated_function( __FUNCTION__, '3.5.0', 'wp_authenticate()' ); $user = wp_authenticate( $user_login, $user_pass ); if ( is_wp_error( $user ) ) return false; return true; } /** * Callback formerly fired on the save_post hook. No longer needed. * * @since 2.3.0 * @deprecated 3.5.0 */ function _save_post_hook() {} /** * Check if the installed version of GD supports particular image type * * @since 2.9.0 * @deprecated 3.5.0 Use wp_image_editor_supports() * @see wp_image_editor_supports() * * @param string $mime_type * @return bool */ function gd_edit_image_support($mime_type) { _deprecated_function( __FUNCTION__, '3.5.0', 'wp_image_editor_supports()' ); if ( function_exists('imagetypes') ) { switch( $mime_type ) { case 'image/jpeg': return (imagetypes() & IMG_JPG) != 0; case 'image/png': return (imagetypes() & IMG_PNG) != 0; case 'image/gif': return (imagetypes() & IMG_GIF) != 0; } } else { switch( $mime_type ) { case 'image/jpeg': return function_exists('imagecreatefromjpeg'); case 'image/png': return function_exists('imagecreatefrompng'); case 'image/gif': return function_exists('imagecreatefromgif'); } } return false; } /** * Converts an integer byte value to a shorthand byte value. * * @since 2.3.0 * @deprecated 3.6.0 Use size_format() * @see size_format() * * @param int $bytes An integer byte value. * @return string A shorthand byte value. */ function wp_convert_bytes_to_hr( $bytes ) { _deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' ); $units = array( 0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB' ); $log = log( $bytes, KB_IN_BYTES ); $power = (int) $log; $size = pow( KB_IN_BYTES, $log - $power ); if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) { $unit = $units[ $power ]; } else { $size = $bytes; $unit = $units[0]; } return $size . $unit; } /** * Formerly used internally to tidy up the search terms. * * @since 2.9.0 * @access private * @deprecated 3.7.0 * * @param string $t Search terms to "tidy", e.g. trim. * @return string Trimmed search terms. */ function _search_terms_tidy( $t ) { _deprecated_function( __FUNCTION__, '3.7.0' ); return trim( $t, "\"'\n\r " ); } /** * Determine if TinyMCE is available. * * Checks to see if the user has deleted the tinymce files to slim down * their WordPress installation. * * @since 2.1.0 * @deprecated 3.9.0 * * @return bool Whether TinyMCE exists. */ function rich_edit_exists() { global $wp_rich_edit_exists; _deprecated_function( __FUNCTION__, '3.9.0' ); if ( ! isset( $wp_rich_edit_exists ) ) $wp_rich_edit_exists = file_exists( ABSPATH . WPINC . '/js/tinymce/tinymce.js' ); return $wp_rich_edit_exists; } /** * Old callback for tag link tooltips. * * @since 2.7.0 * @access private * @deprecated 3.9.0 * * @param int $count Number of topics. * @return int Number of topics. */ function default_topic_count_text( $count ) { return $count; } /** * Formerly used to escape strings before inserting into the DB. * * Has not performed this function for many, many years. Use wpdb::prepare() instead. * * @since 0.71 * @deprecated 3.9.0 * * @param string $content The text to format. * @return string The very same text. */ function format_to_post( $content ) { _deprecated_function( __FUNCTION__, '3.9.0' ); return $content; } /** * Formerly used to escape strings before searching the DB. It was poorly documented and never worked as described. * * @since 2.5.0 * @deprecated 4.0.0 Use wpdb::esc_like() * @see wpdb::esc_like() * * @param string $text The text to be escaped. * @return string text, safe for inclusion in LIKE query. */ function like_escape($text) { _deprecated_function( __FUNCTION__, '4.0.0', 'wpdb::esc_like()' ); return str_replace( array( "%", "_" ), array( "\\%", "\\_" ), $text ); } /** * Determines if the URL can be accessed over SSL. * * Determines if the URL can be accessed over SSL by using the WordPress HTTP API to access * the URL using https as the scheme. * * @since 2.5.0 * @deprecated 4.0.0 * * @param string $url The URL to test. * @return bool Whether SSL access is available. */ function url_is_accessable_via_ssl( $url ) { _deprecated_function( __FUNCTION__, '4.0.0' ); $response = wp_remote_get( set_url_scheme( $url, 'https' ) ); if ( !is_wp_error( $response ) ) { $status = wp_remote_retrieve_response_code( $response ); if ( 200 == $status || 401 == $status ) { return true; } } return false; } /** * Start preview theme output buffer. * * Will only perform task if the user has permissions and template and preview * query variables exist. * * @since 2.6.0 * @deprecated 4.3.0 */ function preview_theme() { _deprecated_function( __FUNCTION__, '4.3.0' ); } /** * Private function to modify the current template when previewing a theme * * @since 2.9.0 * @deprecated 4.3.0 * @access private * * @return string */ function _preview_theme_template_filter() { _deprecated_function( __FUNCTION__, '4.3.0' ); return ''; } /** * Private function to modify the current stylesheet when previewing a theme * * @since 2.9.0 * @deprecated 4.3.0 * @access private * * @return string */ function _preview_theme_stylesheet_filter() { _deprecated_function( __FUNCTION__, '4.3.0' ); return ''; } /** * Callback function for ob_start() to capture all links in the theme. * * @since 2.6.0 * @deprecated 4.3.0 * @access private * * @param string $content * @return string */ function preview_theme_ob_filter( $content ) { _deprecated_function( __FUNCTION__, '4.3.0' ); return $content; } /** * Manipulates preview theme links in order to control and maintain location. * * Callback function for preg_replace_callback() to accept and filter matches. * * @since 2.6.0 * @deprecated 4.3.0 * @access private * * @param array $matches * @return string */ function preview_theme_ob_filter_callback( $matches ) { _deprecated_function( __FUNCTION__, '4.3.0' ); return ''; } /** * Formats text for the rich text editor. * * The {@see 'richedit_pre'} filter is applied here. If $text is empty the filter will * be applied to an empty string. * * @since 2.0.0 * @deprecated 4.3.0 Use format_for_editor() * @see format_for_editor() * * @param string $text The text to be formatted. * @return string The formatted text after filter is applied. */ function wp_richedit_pre($text) { _deprecated_function( __FUNCTION__, '4.3.0', 'format_for_editor()' ); if ( empty( $text ) ) { /** * Filters text returned for the rich text editor. * * This filter is first evaluated, and the value returned, if an empty string * is passed to wp_richedit_pre(). If an empty string is passed, it results * in a break tag and line feed. * * If a non-empty string is passed, the filter is evaluated on the wp_richedit_pre() * return after being formatted. * * @since 2.0.0 * @deprecated 4.3.0 * * @param string $output Text for the rich text editor. */ return apply_filters( 'richedit_pre', '' ); } $output = convert_chars($text); $output = wpautop($output); $output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) ); /** This filter is documented in wp-includes/deprecated.php */ return apply_filters( 'richedit_pre', $output ); } /** * Formats text for the HTML editor. * * Unless $output is empty it will pass through htmlspecialchars before the * {@see 'htmledit_pre'} filter is applied. * * @since 2.5.0 * @deprecated 4.3.0 Use format_for_editor() * @see format_for_editor() * * @param string $output The text to be formatted. * @return string Formatted text after filter applied. */ function wp_htmledit_pre($output) { _deprecated_function( __FUNCTION__, '4.3.0', 'format_for_editor()' ); if ( !empty($output) ) $output = htmlspecialchars($output, ENT_NOQUOTES, get_option( 'blog_charset' ) ); // convert only < > & /** * Filters the text before it is formatted for the HTML editor. * * @since 2.5.0 * @deprecated 4.3.0 * * @param string $output The HTML-formatted text. */ return apply_filters( 'htmledit_pre', $output ); } /** * Retrieve permalink from post ID. * * @since 1.0.0 * @deprecated 4.4.0 Use get_permalink() * @see get_permalink() * * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. * @return string|false */ function post_permalink( $post_id = 0 ) { _deprecated_function( __FUNCTION__, '4.4.0', 'get_permalink()' ); return get_permalink( $post_id ); } /** * Perform a HTTP HEAD or GET request. * * If $file_path is a writable filename, this will do a GET request and write * the file to that path. * * @since 2.5.0 * @deprecated 4.4.0 Use WP_Http * @see WP_Http * * @param string $url URL to fetch. * @param string|bool $file_path Optional. File path to write request to. Default false. * @param int $red Optional. The number of Redirects followed, Upon 5 being hit, * returns false. Default 1. * @return bool|string False on failure and string of headers if HEAD request. */ function wp_get_http( $url, $file_path = false, $red = 1 ) { _deprecated_function( __FUNCTION__, '4.4.0', 'WP_Http' ); @set_time_limit( 60 ); if ( $red > 5 ) return false; $options = array(); $options['redirection'] = 5; if ( false == $file_path ) $options['method'] = 'HEAD'; else $options['method'] = 'GET'; $response = wp_safe_remote_request( $url, $options ); if ( is_wp_error( $response ) ) return false; $headers = wp_remote_retrieve_headers( $response ); $headers['response'] = wp_remote_retrieve_response_code( $response ); // WP_HTTP no longer follows redirects for HEAD requests. if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) { return wp_get_http( $headers['location'], $file_path, ++$red ); } if ( false == $file_path ) return $headers; // GET request - write it to the supplied filename $out_fp = fopen($file_path, 'w'); if ( !$out_fp ) return $headers; fwrite( $out_fp, wp_remote_retrieve_body( $response ) ); fclose($out_fp); clearstatcache(); return $headers; } /** * Whether SSL login should be forced. * * @since 2.6.0 * @deprecated 4.4.0 Use force_ssl_admin() * @see force_ssl_admin() * * @param string|bool $force Optional Whether to force SSL login. Default null. * @return bool True if forced, false if not forced. */ function force_ssl_login( $force = null ) { _deprecated_function( __FUNCTION__, '4.4.0', 'force_ssl_admin()' ); return force_ssl_admin( $force ); } /** * Retrieve path of comment popup template in current or parent template. * * @since 1.5.0 * @deprecated 4.5.0 * * @return string Full path to comments popup template file. */ function get_comments_popup_template() { _deprecated_function( __FUNCTION__, '4.5.0' ); return ''; } /** * Determines whether the current URL is within the comments popup window. * * For more information on this and similar theme functions, check out * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ * Conditional Tags} article in the Theme Developer Handbook. * * @since 1.5.0 * @deprecated 4.5.0 * * @return bool */ function is_comments_popup() { _deprecated_function( __FUNCTION__, '4.5.0' ); return false; } /** * Display the JS popup script to show a comment. * * @since 0.71 * @deprecated 4.5.0 */ function comments_popup_script() { _deprecated_function( __FUNCTION__, '4.5.0' ); } /** * Adds element attributes to open links in new tabs. * * @since 0.71 * @deprecated 4.5.0 * * @param string $text Content to replace links to open in a new tab. * @return string Content that has filtered links. */ function popuplinks( $text ) { _deprecated_function( __FUNCTION__, '4.5.0' ); $text = preg_replace('//i', "", $text); return $text; } /** * The Google Video embed handler callback. * * Deprecated function that previously assisted in turning Google Video URLs * into embeds but that service has since been shut down. * * @since 2.9.0 * @deprecated 4.6.0 * * @return string An empty string. */ function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) { _deprecated_function( __FUNCTION__, '4.6.0' ); return ''; } /** * Retrieve path of paged template in current or parent template. * * @since 1.5.0 * @deprecated 4.7.0 The paged.php template is no longer part of the theme template hierarchy. * * @return string Full path to paged template file. */ function get_paged_template() { _deprecated_function( __FUNCTION__, '4.7.0' ); return get_query_template( 'paged' ); } /** * Removes the HTML JavaScript entities found in early versions of Netscape 4. * * Previously, this function was pulled in from the original * import of kses and removed a specific vulnerability only * existent in early version of Netscape 4. However, this * vulnerability never affected any other browsers and can * be considered safe for the modern web. * * The regular expression which sanitized this vulnerability * has been removed in consideration of the performance and * energy demands it placed, now merely passing through its * input to the return. * * @since 1.0.0 * @deprecated 4.7.0 Officially dropped security support for Netscape 4. * * @param string $string * @return string */ function wp_kses_js_entities( $string ) { _deprecated_function( __FUNCTION__, '4.7.0' ); return preg_replace( '%&\s*\{[^}]*(\}\s*;?|$)%', '', $string ); } /** * Sort categories by ID. * * Used by usort() as a callback, should not be used directly. Can actually be * used to sort any term object. * * @since 2.3.0 * @deprecated 4.7.0 Use wp_list_sort() * @access private * * @param object $a * @param object $b * @return int */ function _usort_terms_by_ID( $a, $b ) { _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort()' ); if ( $a->term_id > $b->term_id ) return 1; elseif ( $a->term_id < $b->term_id ) return -1; else return 0; } /** * Sort categories by name. * * Used by usort() as a callback, should not be used directly. Can actually be * used to sort any term object. * * @since 2.3.0 * @deprecated 4.7.0 Use wp_list_sort() * @access private * * @param object $a * @param object $b * @return int */ function _usort_terms_by_name( $a, $b ) { _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort()' ); return strcmp( $a->name, $b->name ); } /** * Sort menu items by the desired key. * * @since 3.0.0 * @deprecated 4.7.0 Use wp_list_sort() * @access private * * @global string $_menu_item_sort_prop * * @param object $a The first object to compare * @param object $b The second object to compare * @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b. */ function _sort_nav_menu_items( $a, $b ) { global $_menu_item_sort_prop; _deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort()' ); if ( empty( $_menu_item_sort_prop ) ) return 0; if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) ) return 0; $_a = (int) $a->$_menu_item_sort_prop; $_b = (int) $b->$_menu_item_sort_prop; if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) return 0; elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop ) return $_a < $_b ? -1 : 1; else return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop ); } /** * Retrieves the Press This bookmarklet link. * * @since 2.6.0 * @deprecated 4.9.0 * */ function get_shortcut_link() { _deprecated_function( __FUNCTION__, '4.9.0' ); $link = ''; /** * Filters the Press This bookmarklet link. * * @since 2.6.0 * @deprecated 4.9.0 * * @param string $link The Press This bookmarklet link. */ return apply_filters( 'shortcut_link', $link ); } /** * Ajax handler for saving a post from Press This. * * @since 4.2.0 * @deprecated 4.9.0 */ function wp_ajax_press_this_save_post() { _deprecated_function( __FUNCTION__, '4.9.0' ); if ( is_plugin_active( 'press-this/press-this-plugin.php' ) ) { include( WP_PLUGIN_DIR . '/press-this/class-wp-press-this-plugin.php' ); $wp_press_this = new WP_Press_This_Plugin(); $wp_press_this->save_post(); } else { wp_send_json_error( array( 'errorMessage' => __( 'The Press This plugin is required.' ) ) ); } } /** * Ajax handler for creating new category from Press This. * * @since 4.2.0 * @deprecated 4.9.0 */ function wp_ajax_press_this_add_category() { _deprecated_function( __FUNCTION__, '4.9.0' ); if ( is_plugin_active( 'press-this/press-this-plugin.php' ) ) { include( WP_PLUGIN_DIR . '/press-this/class-wp-press-this-plugin.php' ); $wp_press_this = new WP_Press_This_Plugin(); $wp_press_this->add_category(); } else { wp_send_json_error( array( 'errorMessage' => __( 'The Press This plugin is required.' ) ) ); } } /** * Filter the SQL clauses of an attachment query to include filenames. * * @since 4.7.0 * @deprecated 6.0.3 * @access private * * @param array $clauses An array including WHERE, GROUP BY, JOIN, ORDER BY, * DISTINCT, fields (SELECT), and LIMITS clauses. * @return array The unmodified clauses. */ function _filter_query_attachment_filenames( $clauses ) { _deprecated_function( __FUNCTION__, '6.0.3', 'add_filter( "wp_allow_query_attachment_by_filename", "__return_true" )'); remove_filter( 'posts_clauses', __FUNCTION__ ); return $clauses; } /** * HTTP API: WP_Http class * * @package WordPress * @subpackage HTTP * @since 2.7.0 */ if ( ! class_exists( 'Requests' ) ) { require( ABSPATH . WPINC . '/class-requests.php' ); Requests::register_autoloader(); Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' ); } /** * Core class used for managing HTTP transports and making HTTP requests. * * This class is used to consistently make outgoing HTTP requests easy for developers * while still being compatible with the many PHP configurations under which * WordPress runs. * * Debugging includes several actions, which pass different variables for debugging the HTTP API. * * @since 2.7.0 */ class WP_Http { // Aliases for HTTP response codes. const HTTP_CONTINUE = 100; const SWITCHING_PROTOCOLS = 101; const PROCESSING = 102; const EARLY_HINTS = 103; const OK = 200; const CREATED = 201; const ACCEPTED = 202; const NON_AUTHORITATIVE_INFORMATION = 203; const NO_CONTENT = 204; const RESET_CONTENT = 205; const PARTIAL_CONTENT = 206; const MULTI_STATUS = 207; const IM_USED = 226; const MULTIPLE_CHOICES = 300; const MOVED_PERMANENTLY = 301; const FOUND = 302; const SEE_OTHER = 303; const NOT_MODIFIED = 304; const USE_PROXY = 305; const RESERVED = 306; const TEMPORARY_REDIRECT = 307; const PERMANENT_REDIRECT = 308; const BAD_REQUEST = 400; const UNAUTHORIZED = 401; const PAYMENT_REQUIRED = 402; const FORBIDDEN = 403; const NOT_FOUND = 404; const METHOD_NOT_ALLOWED = 405; const NOT_ACCEPTABLE = 406; const PROXY_AUTHENTICATION_REQUIRED = 407; const REQUEST_TIMEOUT = 408; const CONFLICT = 409; const GONE = 410; const LENGTH_REQUIRED = 411; const PRECONDITION_FAILED = 412; const REQUEST_ENTITY_TOO_LARGE = 413; const REQUEST_URI_TOO_LONG = 414; const UNSUPPORTED_MEDIA_TYPE = 415; const REQUESTED_RANGE_NOT_SATISFIABLE = 416; const EXPECTATION_FAILED = 417; const IM_A_TEAPOT = 418; const MISDIRECTED_REQUEST = 421; const UNPROCESSABLE_ENTITY = 422; const LOCKED = 423; const FAILED_DEPENDENCY = 424; const UPGRADE_REQUIRED = 426; const PRECONDITION_REQUIRED = 428; const TOO_MANY_REQUESTS = 429; const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; const UNAVAILABLE_FOR_LEGAL_REASONS = 451; const INTERNAL_SERVER_ERROR = 500; const NOT_IMPLEMENTED = 501; const BAD_GATEWAY = 502; const SERVICE_UNAVAILABLE = 503; const GATEWAY_TIMEOUT = 504; const HTTP_VERSION_NOT_SUPPORTED = 505; const VARIANT_ALSO_NEGOTIATES = 506; const INSUFFICIENT_STORAGE = 507; const NOT_EXTENDED = 510; const NETWORK_AUTHENTICATION_REQUIRED = 511; /** * Send an HTTP request to a URI. * * Please note: The only URI that are supported in the HTTP Transport implementation * are the HTTP and HTTPS protocols. * * @since 2.7.0 * * @param string $url The request URL. * @param string|array $args { * Optional. Array or string of HTTP request arguments. * * @type string $method Request method. Accepts 'GET', 'POST', 'HEAD', 'PUT', 'DELETE', * 'TRACE', 'OPTIONS', or 'PATCH'. * Some transports technically allow others, but should not be * assumed. Default 'GET'. * @type int $timeout How long the connection should stay open in seconds. Default 5. * @type int $redirection Number of allowed redirects. Not supported by all transports * Default 5. * @type string $httpversion Version of the HTTP protocol to use. Accepts '1.0' and '1.1'. * Default '1.0'. * @type string $user-agent User-agent value sent. * Default 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ). * @type bool $reject_unsafe_urls Whether to pass URLs through wp_http_validate_url(). * Default false. * @type bool $blocking Whether the calling code requires the result of the request. * If set to false, the request will be sent to the remote server, * and processing returned to the calling code immediately, the caller * will know if the request succeeded or failed, but will not receive * any response from the remote server. Default true. * @type string|array $headers Array or string of headers to send with the request. * Default empty array. * @type array $cookies List of cookies to send with the request. Default empty array. * @type string|array $body Body to send with the request. Default null. * @type bool $compress Whether to compress the $body when sending the request. * Default false. * @type bool $decompress Whether to decompress a compressed response. If set to false and * compressed content is returned in the response anyway, it will * need to be separately decompressed. Default true. * @type bool $sslverify Whether to verify SSL for the request. Default true. * @type string sslcertificates Absolute path to an SSL certificate .crt file. * Default ABSPATH . WPINC . '/certificates/ca-bundle.crt'. * @type bool $stream Whether to stream to a file. If set to true and no filename was * given, it will be droped it in the WP temp dir and its name will * be set using the basename of the URL. Default false. * @type string $filename Filename of the file to write to when streaming. $stream must be * set to true. Default null. * @type int $limit_response_size Size in bytes to limit the response to. Default null. * * } * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. * A WP_Error instance upon error. */ public function request( $url, $args = array() ) { $defaults = array( 'method' => 'GET', /** * Filters the timeout value for an HTTP request. * * @since 2.7.0 * @since 5.1.0 The `$url` parameter was added. * * @param int $timeout_value Time in seconds until a request times out. Default 5. * @param string $url The request URL. */ 'timeout' => apply_filters( 'http_request_timeout', 5, $url ), /** * Filters the number of redirects allowed during an HTTP request. * * @since 2.7.0 * @since 5.1.0 The `$url` parameter was added. * * @param int $redirect_count Number of redirects allowed. Default 5. * @param string $url The request URL. */ 'redirection' => apply_filters( 'http_request_redirection_count', 5, $url ), /** * Filters the version of the HTTP protocol used in a request. * * @since 2.7.0 * @since 5.1.0 The `$url` parameter was added. * * @param string $version Version of HTTP used. Accepts '1.0' and '1.1'. Default '1.0'. * @param string $url The request URL. */ 'httpversion' => apply_filters( 'http_request_version', '1.0', $url ), /** * Filters the user agent value sent with an HTTP request. * * @since 2.7.0 * @since 5.1.0 The `$url` parameter was added. * * @param string $user_agent WordPress user agent string. * @param string $url The request URL. */ 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $url ), /** * Filters whether to pass URLs through wp_http_validate_url() in an HTTP request. * * @since 3.6.0 * @since 5.1.0 The `$url` parameter was added. * * @param bool $pass_url Whether to pass URLs through wp_http_validate_url(). Default false. * @param string $url The request URL. */ 'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false, $url ), 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt', 'stream' => false, 'filename' => null, 'limit_response_size' => null, ); // Pre-parse for the HEAD checks. $args = wp_parse_args( $args ); // By default, Head requests do not cause redirections. if ( isset( $args['method'] ) && 'HEAD' == $args['method'] ) { $defaults['redirection'] = 0; } $r = wp_parse_args( $args, $defaults ); /** * Filters the arguments used in an HTTP request. * * @since 2.7.0 * * @param array $r An array of HTTP request arguments. * @param string $url The request URL. */ $r = apply_filters( 'http_request_args', $r, $url ); // The transports decrement this, store a copy of the original value for loop purposes. if ( ! isset( $r['_redirection'] ) ) { $r['_redirection'] = $r['redirection']; } /** * Filters whether to preempt an HTTP request's return value. * * Returning a non-false value from the filter will short-circuit the HTTP request and return * early with that value. A filter should return either: * * - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements * - A WP_Error instance * - boolean false (to avoid short-circuiting the response) * * Returning any other value may result in unexpected behaviour. * * @since 2.9.0 * * @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false. * @param array $r HTTP request arguments. * @param string $url The request URL. */ $pre = apply_filters( 'pre_http_request', false, $r, $url ); if ( false !== $pre ) { return $pre; } if ( function_exists( 'wp_kses_bad_protocol' ) ) { if ( $r['reject_unsafe_urls'] ) { $url = wp_http_validate_url( $url ); } if ( $url ) { $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) ); } } $arrURL = @parse_url( $url ); if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { return new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); } if ( $this->block_request( $url ) ) { return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); } // If we are streaming to a file but no filename was given drop it in the WP temp dir // and pick its name using the basename of the $url if ( $r['stream'] ) { if ( empty( $r['filename'] ) ) { $r['filename'] = get_temp_dir() . basename( $url ); } // Force some settings if we are streaming to a file and check for existence and perms of destination directory $r['blocking'] = true; if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) { return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); } } if ( is_null( $r['headers'] ) ) { $r['headers'] = array(); } // WP allows passing in headers as a string, weirdly. if ( ! is_array( $r['headers'] ) ) { $processedHeaders = WP_Http::processHeaders( $r['headers'] ); $r['headers'] = $processedHeaders['headers']; } // Setup arguments $headers = $r['headers']; $data = $r['body']; $type = $r['method']; $options = array( 'timeout' => $r['timeout'], 'useragent' => $r['user-agent'], 'blocking' => $r['blocking'], 'hooks' => new WP_HTTP_Requests_Hooks( $url, $r ), ); // Ensure redirects follow browser behaviour. $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) ); // Validate redirected URLs. if ( function_exists( 'wp_kses_bad_protocol' ) && $r['reject_unsafe_urls'] ) { $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) ); } if ( $r['stream'] ) { $options['filename'] = $r['filename']; } if ( empty( $r['redirection'] ) ) { $options['follow_redirects'] = false; } else { $options['redirects'] = $r['redirection']; } // Use byte limit, if we can if ( isset( $r['limit_response_size'] ) ) { $options['max_bytes'] = $r['limit_response_size']; } // If we've got cookies, use and convert them to Requests_Cookie. if ( ! empty( $r['cookies'] ) ) { $options['cookies'] = WP_Http::normalize_cookies( $r['cookies'] ); } // SSL certificate handling if ( ! $r['sslverify'] ) { $options['verify'] = false; $options['verifyname'] = false; } else { $options['verify'] = $r['sslcertificates']; } // All non-GET/HEAD requests should put the arguments in the form body. if ( 'HEAD' !== $type && 'GET' !== $type ) { $options['data_format'] = 'body'; } /** * Filters whether SSL should be verified for non-local requests. * * @since 2.8.0 * @since 5.1.0 The `$url` parameter was added. * * @param bool $ssl_verify Whether to verify the SSL connection. Default true. * @param string $url The request URL. */ $options['verify'] = apply_filters( 'https_ssl_verify', $options['verify'], $url ); // Check for proxies. $proxy = new WP_HTTP_Proxy(); if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { $options['proxy'] = new Requests_Proxy_HTTP( $proxy->host() . ':' . $proxy->port() ); if ( $proxy->use_authentication() ) { $options['proxy']->use_authentication = true; $options['proxy']->user = $proxy->username(); $options['proxy']->pass = $proxy->password(); } } // Avoid issues where mbstring.func_overload is enabled mbstring_binary_safe_encoding(); try { $requests_response = Requests::request( $url, $headers, $data, $type, $options ); // Convert the response into an array $http_response = new WP_HTTP_Requests_Response( $requests_response, $r['filename'] ); $response = $http_response->to_array(); // Add the original object to the array. $response['http_response'] = $http_response; } catch ( Requests_Exception $e ) { $response = new WP_Error( 'http_request_failed', $e->getMessage() ); } reset_mbstring_encoding(); /** * Fires after an HTTP API response is received and before the response is returned. * * @since 2.8.0 * * @param array|WP_Error $response HTTP response or WP_Error object. * @param string $context Context under which the hook is fired. * @param string $class HTTP transport used. * @param array $r HTTP request arguments. * @param string $url The request URL. */ do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url ); if ( is_wp_error( $response ) ) { return $response; } if ( ! $r['blocking'] ) { return array( 'headers' => array(), 'body' => '', 'response' => array( 'code' => false, 'message' => false, ), 'cookies' => array(), 'http_response' => null, ); } /** * Filters the HTTP API response immediately before the response is returned. * * @since 2.9.0 * * @param array $response HTTP response. * @param array $r HTTP request arguments. * @param string $url The request URL. */ return apply_filters( 'http_response', $response, $r, $url ); } /** * Normalizes cookies for using in Requests. * * @since 4.6.0 * * @param array $cookies Array of cookies to send with the request. * @return Requests_Cookie_Jar Cookie holder object. */ public static function normalize_cookies( $cookies ) { $cookie_jar = new Requests_Cookie_Jar(); foreach ( $cookies as $name => $value ) { if ( $value instanceof WP_Http_Cookie ) { $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes() ); } elseif ( is_scalar( $value ) ) { $cookie_jar[ $name ] = new Requests_Cookie( $name, $value ); } } return $cookie_jar; } /** * Match redirect behaviour to browser handling. * * Changes 302 redirects from POST to GET to match browser handling. Per * RFC 7231, user agents can deviate from the strict reading of the * specification for compatibility purposes. * * @since 4.6.0 * * @param string $location URL to redirect to. * @param array $headers Headers for the redirect. * @param string|array $data Body to send with the request. * @param array $options Redirect request options. * @param Requests_Response $original Response object. */ public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) { // Browser compat if ( $original->status_code === 302 ) { $options['type'] = Requests::GET; } } /** * Validate redirected URLs. * * @since 4.7.5 * * @throws Requests_Exception On unsuccessful URL validation * @param string $location URL to redirect to. */ public static function validate_redirects( $location ) { if ( ! wp_http_validate_url( $location ) ) { throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' ); } } /** * Tests which transports are capable of supporting the request. * * @since 3.2.0 * * @param array $args Request arguments * @param string $url URL to Request * * @return string|false Class name for the first transport that claims to support the request. False if no transport claims to support the request. */ public function _get_first_available_transport( $args, $url = null ) { $transports = array( 'curl', 'streams' ); /** * Filters which HTTP transports are available and in what order. * * @since 3.7.0 * * @param array $transports Array of HTTP transports to check. Default array contains * 'curl', and 'streams', in that order. * @param array $args HTTP request arguments. * @param string $url The URL to request. */ $request_order = apply_filters( 'http_api_transports', $transports, $args, $url ); // Loop over each transport on each HTTP request looking for one which will serve this request's needs. foreach ( $request_order as $transport ) { if ( in_array( $transport, $transports ) ) { $transport = ucfirst( $transport ); } $class = 'WP_Http_' . $transport; // Check to see if this transport is a possibility, calls the transport statically. if ( ! call_user_func( array( $class, 'test' ), $args, $url ) ) { continue; } return $class; } return false; } /** * Dispatches a HTTP request to a supporting transport. * * Tests each transport in order to find a transport which matches the request arguments. * Also caches the transport instance to be used later. * * The order for requests is cURL, and then PHP Streams. * * @since 3.2.0 * @deprecated 5.1.0 Use WP_Http::request() * @see WP_Http::request() * * @param string $url URL to Request * @param array $args Request arguments * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error */ private function _dispatch_request( $url, $args ) { static $transports = array(); $class = $this->_get_first_available_transport( $args, $url ); if ( ! $class ) { return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); } // Transport claims to support request, instantiate it and give it a whirl. if ( empty( $transports[ $class ] ) ) { $transports[ $class ] = new $class; } $response = $transports[ $class ]->request( $url, $args ); /** This action is documented in wp-includes/class-http.php */ do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); if ( is_wp_error( $response ) ) { return $response; } /** This filter is documented in wp-includes/class-http.php */ return apply_filters( 'http_response', $response, $args, $url ); } /** * Uses the POST HTTP method. * * Used for sending data that is expected to be in the body. * * @since 2.7.0 * * @param string $url The request URL. * @param string|array $args Optional. Override the defaults. * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error */ public function post( $url, $args = array() ) { $defaults = array( 'method' => 'POST' ); $r = wp_parse_args( $args, $defaults ); return $this->request( $url, $r ); } /** * Uses the GET HTTP method. * * Used for sending data that is expected to be in the body. * * @since 2.7.0 * * @param string $url The request URL. * @param string|array $args Optional. Override the defaults. * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error */ public function get( $url, $args = array() ) { $defaults = array( 'method' => 'GET' ); $r = wp_parse_args( $args, $defaults ); return $this->request( $url, $r ); } /** * Uses the HEAD HTTP method. * * Used for sending data that is expected to be in the body. * * @since 2.7.0 * * @param string $url The request URL. * @param string|array $args Optional. Override the defaults. * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error */ public function head( $url, $args = array() ) { $defaults = array( 'method' => 'HEAD' ); $r = wp_parse_args( $args, $defaults ); return $this->request( $url, $r ); } /** * Parses the responses and splits the parts into headers and body. * * @since 2.7.0 * * @param string $strResponse The full response string * @return array Array with 'headers' and 'body' keys. */ public static function processResponse( $strResponse ) { $res = explode( "\r\n\r\n", $strResponse, 2 ); return array( 'headers' => $res[0], 'body' => isset( $res[1] ) ? $res[1] : '', ); } /** * Transform header string into an array. * * If an array is given then it is assumed to be raw header data with numeric keys with the * headers as the values. No headers must be passed that were already processed. * * @since 2.7.0 * * @param string|array $headers * @param string $url The URL that was requested * @return array Processed string headers. If duplicate headers are encountered, * Then a numbered array is returned as the value of that header-key. */ public static function processHeaders( $headers, $url = '' ) { // Split headers, one per array element. if ( is_string( $headers ) ) { // Tolerate line terminator: CRLF = LF (RFC 2616 19.3). $headers = str_replace( "\r\n", "\n", $headers ); /* * Unfold folded header fields. LWS = [CRLF] 1*( SP | HT ) , * (RFC 2616 2.2). */ $headers = preg_replace( '/\n[ \t]/', ' ', $headers ); // Create the headers array. $headers = explode( "\n", $headers ); } $response = array( 'code' => 0, 'message' => '', ); /* * If a redirection has taken place, The headers for each page request may have been passed. * In this case, determine the final HTTP header and parse from there. */ for ( $i = count( $headers ) - 1; $i >= 0; $i-- ) { if ( ! empty( $headers[ $i ] ) && false === strpos( $headers[ $i ], ':' ) ) { $headers = array_splice( $headers, $i ); break; } } $cookies = array(); $newheaders = array(); foreach ( (array) $headers as $tempheader ) { if ( empty( $tempheader ) ) { continue; } if ( false === strpos( $tempheader, ':' ) ) { $stack = explode( ' ', $tempheader, 3 ); $stack[] = ''; list( , $response['code'], $response['message']) = $stack; continue; } list($key, $value) = explode( ':', $tempheader, 2 ); $key = strtolower( $key ); $value = trim( $value ); if ( isset( $newheaders[ $key ] ) ) { if ( ! is_array( $newheaders[ $key ] ) ) { $newheaders[ $key ] = array( $newheaders[ $key ] ); } $newheaders[ $key ][] = $value; } else { $newheaders[ $key ] = $value; } if ( 'set-cookie' == $key ) { $cookies[] = new WP_Http_Cookie( $value, $url ); } } // Cast the Response Code to an int $response['code'] = intval( $response['code'] ); return array( 'response' => $response, 'headers' => $newheaders, 'cookies' => $cookies, ); } /** * Takes the arguments for a ::request() and checks for the cookie array. * * If it's found, then it upgrades any basic name => value pairs to WP_Http_Cookie instances, * which are each parsed into strings and added to the Cookie: header (within the arguments array). * Edits the array by reference. * * @since 2.8.0 * * @param array $r Full array of args passed into ::request() */ public static function buildCookieHeader( &$r ) { if ( ! empty( $r['cookies'] ) ) { // Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances. foreach ( $r['cookies'] as $name => $value ) { if ( ! is_object( $value ) ) { $r['cookies'][ $name ] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value, ) ); } } $cookies_header = ''; foreach ( (array) $r['cookies'] as $cookie ) { $cookies_header .= $cookie->getHeaderValue() . '; '; } $cookies_header = substr( $cookies_header, 0, -2 ); $r['headers']['cookie'] = $cookies_header; } } /** * Decodes chunk transfer-encoding, based off the HTTP 1.1 specification. * * Based off the HTTP http_encoding_dechunk function. * * @link https://tools.ietf.org/html/rfc2616#section-19.4.6 Process for chunked decoding. * * @since 2.7.0 * * @param string $body Body content * @return string Chunked decoded body on success or raw body on failure. */ public static function chunkTransferDecode( $body ) { // The body is not chunked encoded or is malformed. if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) { return $body; } $parsed_body = ''; // We'll be altering $body, so need a backup in case of error. $body_original = $body; while ( true ) { $has_chunk = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $body, $match ); if ( ! $has_chunk || empty( $match[1] ) ) { return $body_original; } $length = hexdec( $match[1] ); $chunk_length = strlen( $match[0] ); // Parse out the chunk of data. $parsed_body .= substr( $body, $chunk_length, $length ); // Remove the chunk from the raw data. $body = substr( $body, $length + $chunk_length ); // End of the document. if ( '0' === trim( $body ) ) { return $parsed_body; } } } /** * Block requests through the proxy. * * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will * prevent plugins from working and core functionality, if you don't include api.wordpress.org. * * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true in your wp-config.php * file and this will only allow localhost and your site to make requests. The constant * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains * are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted. * * @since 2.8.0 * @link https://core.trac.wordpress.org/ticket/8927 Allow preventing external requests. * @link https://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS * * @staticvar array|null $accessible_hosts * @staticvar array $wildcard_regex * * @param string $uri URI of url. * @return bool True to block, false to allow. */ public function block_request( $uri ) { // We don't need to block requests, because nothing is blocked. if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) { return false; } $check = parse_url( $uri ); if ( ! $check ) { return true; } $home = parse_url( get_option( 'siteurl' ) ); // Don't block requests back to ourselves by default. if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) { /** * Filters whether to block local requests through the proxy. * * @since 2.8.0 * * @param bool $block Whether to block local requests through proxy. * Default false. */ return apply_filters( 'block_local_requests', false ); } if ( ! defined( 'WP_ACCESSIBLE_HOSTS' ) ) { return true; } static $accessible_hosts = null; static $wildcard_regex = array(); if ( null === $accessible_hosts ) { $accessible_hosts = preg_split( '|,\s*|', WP_ACCESSIBLE_HOSTS ); if ( false !== strpos( WP_ACCESSIBLE_HOSTS, '*' ) ) { $wildcard_regex = array(); foreach ( $accessible_hosts as $host ) { $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); } $wildcard_regex = '/^(' . implode( '|', $wildcard_regex ) . ')$/i'; } } if ( ! empty( $wildcard_regex ) ) { return ! preg_match( $wildcard_regex, $check['host'] ); } else { return ! in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it. } } /** * Used as a wrapper for PHP's parse_url() function that handles edgecases in < PHP 5.4.7. * * @deprecated 4.4.0 Use wp_parse_url() * @see wp_parse_url() * * @param string $url The URL to parse. * @return bool|array False on failure; Array of URL components on success; * See parse_url()'s return values. */ protected static function parse_url( $url ) { _deprecated_function( __METHOD__, '4.4.0', 'wp_parse_url()' ); return wp_parse_url( $url ); } /** * Converts a relative URL to an absolute URL relative to a given URL. * * If an Absolute URL is provided, no processing of that URL is done. * * @since 3.4.0 * * @param string $maybe_relative_path The URL which might be relative * @param string $url The URL which $maybe_relative_path is relative to * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned. */ public static function make_absolute_url( $maybe_relative_path, $url ) { if ( empty( $url ) ) { return $maybe_relative_path; } if ( ! $url_parts = wp_parse_url( $url ) ) { return $maybe_relative_path; } if ( ! $relative_url_parts = wp_parse_url( $maybe_relative_path ) ) { return $maybe_relative_path; } // Check for a scheme on the 'relative' url if ( ! empty( $relative_url_parts['scheme'] ) ) { return $maybe_relative_path; } $absolute_path = $url_parts['scheme'] . '://'; // Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url if ( isset( $relative_url_parts['host'] ) ) { $absolute_path .= $relative_url_parts['host']; if ( isset( $relative_url_parts['port'] ) ) { $absolute_path .= ':' . $relative_url_parts['port']; } } else { $absolute_path .= $url_parts['host']; if ( isset( $url_parts['port'] ) ) { $absolute_path .= ':' . $url_parts['port']; } } // Start off with the Absolute URL path. $path = ! empty( $url_parts['path'] ) ? $url_parts['path'] : '/'; // If it's a root-relative path, then great. if ( ! empty( $relative_url_parts['path'] ) && '/' == $relative_url_parts['path'][0] ) { $path = $relative_url_parts['path']; // Else it's a relative path. } elseif ( ! empty( $relative_url_parts['path'] ) ) { // Strip off any file components from the absolute path. $path = substr( $path, 0, strrpos( $path, '/' ) + 1 ); // Build the new path. $path .= $relative_url_parts['path']; // Strip all /path/../ out of the path. while ( strpos( $path, '../' ) > 1 ) { $path = preg_replace( '![^/]+/\.\./!', '', $path ); } // Strip any final leading ../ from the path. $path = preg_replace( '!^/(\.\./)+!', '', $path ); } // Add the Query string. if ( ! empty( $relative_url_parts['query'] ) ) { $path .= '?' . $relative_url_parts['query']; } return $absolute_path . '/' . ltrim( $path, '/' ); } /** * Handles HTTP Redirects and follows them if appropriate. * * @since 3.7.0 * * @param string $url The URL which was requested. * @param array $args The Arguments which were used to make the request. * @param array $response The Response of the HTTP request. * @return false|object False if no redirect is present, a WP_HTTP or WP_Error result otherwise. */ public static function handle_redirects( $url, $args, $response ) { // If no redirects are present, or, redirects were not requested, perform no action. if ( ! isset( $response['headers']['location'] ) || 0 === $args['_redirection'] ) { return false; } // Only perform redirections on redirection http codes. if ( $response['response']['code'] > 399 || $response['response']['code'] < 300 ) { return false; } // Don't redirect if we've run out of redirects. if ( $args['redirection']-- <= 0 ) { return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); } $redirect_location = $response['headers']['location']; // If there were multiple Location headers, use the last header specified. if ( is_array( $redirect_location ) ) { $redirect_location = array_pop( $redirect_location ); } $redirect_location = WP_Http::make_absolute_url( $redirect_location, $url ); // POST requests should not POST to a redirected location. if ( 'POST' == $args['method'] ) { if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) { $args['method'] = 'GET'; } } // Include valid cookies in the redirect process. if ( ! empty( $response['cookies'] ) ) { foreach ( $response['cookies'] as $cookie ) { if ( $cookie->test( $redirect_location ) ) { $args['cookies'][] = $cookie; } } } return wp_remote_request( $redirect_location, $args ); } /** * Determines if a specified string represents an IP address or not. * * This function also detects the type of the IP address, returning either * '4' or '6' to represent a IPv4 and IPv6 address respectively. * This does not verify if the IP is a valid IP, only that it appears to be * an IP address. * * @link http://home.deds.nl/~aeron/regex/ for IPv6 regex * * @since 3.7.0 * * @param string $maybe_ip A suspected IP address * @return integer|bool Upon success, '4' or '6' to represent a IPv4 or IPv6 address, false upon failure */ public static function is_ip_address( $maybe_ip ) { if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $maybe_ip ) ) { return 4; } if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) { return 6; } return false; } }