Ejemplo n.º 1
0
function amp_frontend_add_canonical()
{
    if (false === apply_filters('amp_frontend_show_canonical', true)) {
        return;
    }
    $amp_url = amp_get_permalink(get_queried_object_id());
    printf('<link rel="amphtml" href="%s" />', esc_url($amp_url));
}
Ejemplo n.º 2
0
function amp_admin_get_preview_permalink()
{
    /**
     * Filter the post type to retrieve the latest of for use in the AMP template customizer.
     *
     * @param string $post_type Post type slug. Default 'post'.
     */
    $post_type = (string) apply_filters('amp_customizer_post_type', 'post');
    if (!post_type_supports($post_type, 'amp')) {
        return;
    }
    $post_ids = get_posts(array('post_status' => 'publish', 'post_type' => $post_type, 'posts_per_page' => 1, 'fields' => 'ids'));
    if (empty($post_ids)) {
        return false;
    }
    $post_id = $post_ids[0];
    return amp_get_permalink($post_id);
}
 /**
  * Purge Post
  * Flush the post
  *
  * @since 1.0
  * @param array $postId the ID of the post to be purged
  * @access public
  */
 public function purgePost($postId)
 {
     // If this is a valid post we want to purge the post,
     // the home page and any associated tags and categories
     $validPostStatus = array("publish", "trash");
     $thisPostStatus = get_post_status($postId);
     // array to collect all our URLs
     $listofurls = array();
     if (get_permalink($postId) == true && in_array($thisPostStatus, $validPostStatus)) {
         // If this is a post with a permalink AND it's published or trashed,
         // we're going to add a ton of things to flush.
         // Category purge based on Donnacha's work in WP Super Cache
         $categories = get_the_category($postId);
         if ($categories) {
             foreach ($categories as $cat) {
                 array_push($listofurls, get_category_link($cat->term_id));
             }
         }
         // Tag purge based on Donnacha's work in WP Super Cache
         $tags = get_the_tags($postId);
         if ($tags) {
             foreach ($tags as $tag) {
                 array_push($listofurls, get_tag_link($tag->term_id));
             }
         }
         // Author URL
         array_push($listofurls, get_author_posts_url(get_post_field('post_author', $postId)), get_author_feed_link(get_post_field('post_author', $postId)));
         // Archives and their feeds
         $archiveurls = array();
         if (get_post_type_archive_link(get_post_type($postId)) == true) {
             array_push($listofurls, get_post_type_archive_link(get_post_type($postId)), get_post_type_archive_feed_link(get_post_type($postId)));
         }
         // Post URL
         array_push($listofurls, get_permalink($postId));
         // Also clean URL for trashed post.
         if ($thisPostStatus == "trash") {
             $trashpost = get_permalink($postId);
             $trashpost = str_replace("__trashed", "", $trashpost);
             array_push($listofurls, $trashpost, $trashpost . 'feed/');
         }
         // Add in AMP permalink if Automattic's AMP is installed
         if (function_exists('amp_get_permalink')) {
             array_push($listofurls, amp_get_permalink($postId));
         }
         // Regular AMP url for posts
         array_push($listofurls, get_permalink($postId) . 'amp/');
         // Feeds
         array_push($listofurls, get_bloginfo_rss('rdf_url'), get_bloginfo_rss('rss_url'), get_bloginfo_rss('rss2_url'), get_bloginfo_rss('atom_url'), get_bloginfo_rss('comments_rss2_url'), get_post_comments_feed_link($postId));
         // Home Page and (if used) posts page
         array_push($listofurls, $this->the_home_url() . '/');
         if (get_option('show_on_front') == 'page') {
             // Ensure we have a page_for_posts setting to avoid empty URL
             if (get_option('page_for_posts')) {
                 array_push($listofurls, get_permalink(get_option('page_for_posts')));
             }
         }
     } else {
         // We're not sure how we got here, but bail instead of processing anything else.
         return;
     }
     // Now flush all the URLs we've collected provided the array isn't empty
     if (!empty($listofurls)) {
         foreach ($listofurls as $url) {
             array_push($this->purgeUrls, $url);
         }
     }
     // Filter to add or remove urls to the array of purged urls
     // @param array $purgeUrls the urls (paths) to be purged
     // @param int $postId the id of the new/edited post
     $this->purgeUrls = apply_filters('vhp_purge_urls', $this->purgeUrls, $postId);
 }
 public function purge_post($postId)
 {
     // If this is a valid post we want to purge the post, the home page and any associated tags & cats
     // If not, purge everything on the site.
     $validPostStatus = array('publish', 'trash');
     $thisPostStatus = get_post_status($postId);
     // If this is a revision, stop.
     if (get_permalink($postId) !== true && !in_array($thisPostStatus, $validPostStatus)) {
         return;
     } else {
         // array to collect all our URLs
         $listofurls = array();
         // Category purge based on Donnacha's work in WP Super Cache
         $categories = get_the_category($postId);
         if ($categories) {
             foreach ($categories as $cat) {
                 array_push($listofurls, get_category_link($cat->term_id));
             }
         }
         // Tag purge based on Donnacha's work in WP Super Cache
         $tags = get_the_tags($postId);
         if ($tags) {
             foreach ($tags as $tag) {
                 array_push($listofurls, get_tag_link($tag->term_id));
             }
         }
         // Author URL
         array_push($listofurls, get_author_posts_url(get_post_field('post_author', $postId)), get_author_feed_link(get_post_field('post_author', $postId)));
         // Archives and their feeds
         $archiveurls = array();
         if (get_post_type_archive_link(get_post_type($postId)) == true) {
             array_push($listofurls, get_post_type_archive_link(get_post_type($postId)), get_post_type_archive_feed_link(get_post_type($postId)));
         }
         // Post URL
         array_push($listofurls, get_permalink($postId));
         // Feeds
         array_push($listofurls, get_bloginfo_rss('rdf_url'), get_bloginfo_rss('rss_url'), get_bloginfo_rss('rss2_url'), get_bloginfo_rss('atom_url'), get_bloginfo_rss('comments_rss2_url'), get_post_comments_feed_link($postId));
         // Home Page and (if used) posts page
         array_push($listofurls, home_url('/'));
         if (get_option('show_on_front') == 'page') {
             array_push($listofurls, get_permalink(get_option('page_for_posts')));
         }
         // If Automattic's AMP is installed, add AMP permalink
         if (function_exists('amp_get_permalink')) {
             array_push($listofurls, amp_get_permalink($postId));
         }
         // Now flush all the URLs we've collected
         foreach ($listofurls as $url) {
             array_push($this->purgeUrls, $url);
         }
     }
     // Filter to add or remove urls to the array of purged urls
     // @param array $purgeUrls the urls (paths) to be purged
     // @param int $postId the id of the new/edited post
     $this->purgeUrls = apply_filters('vcaching_purge_urls', $this->purgeUrls, $postId);
     $this->purge_cache();
 }