Skip to content

Commit

Permalink
Merge pull request #81 from Parsely/bugfix/archive-page-canonicals
Browse files Browse the repository at this point in the history
Bugfix/archive page canonicals
  • Loading branch information
joshuarrrr authored Jan 30, 2018
2 parents e08c14b + f373aaf commit 5faee42
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions wp-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://www.parsely.com/
Description: This plugin makes it a snap to add Parse.ly tracking code to your WordPress blog.
Author: Mike Sukmanowsky ( mike@parsely.com )
Version: 1.12
Version: 1.12.1
Requires at least: 4.0.0
Author URI: http://www.parsely.com/
License: GPL2
Expand Down Expand Up @@ -37,7 +37,7 @@ class Parsely {
/**
* @codeCoverageIgnoreStart
*/
const VERSION = '1.12';
const VERSION = '1.12.1';
const MENU_SLUG = 'parsely'; // Defines the page param passed to options-general.php
const MENU_TITLE = 'Parse.ly'; // Text to be used for the menu as seen in Settings sub-menu
const MENU_PAGE_TITLE = 'Parse.ly > Settings'; // Text shown in <title></title> when the settings screen is viewed
Expand Down Expand Up @@ -189,7 +189,10 @@ public function initialize_settings() {
'option_key' => 'meta_type',
'help_text' => $h,
// filter Wordpress taxonomies under the hood that should not appear in dropdown
'select_options' => array( 'json_ld' => 'json_ld', 'repeated_metas' => 'repeated_metas' ),
'select_options' => array(
'json_ld' => 'json_ld',
'repeated_metas' => 'repeated_metas',
),
'requires_recrawl' => true,
'multiple' => false,
)
Expand Down Expand Up @@ -601,38 +604,22 @@ public function insert_parsely_page() {
} elseif ( in_array( get_post_type(), $parsely_options['track_page_types'], true ) && 'publish' === $post->post_status ) {
$parsely_page['headline'] = $this->get_clean_parsely_page_value( get_the_title() );
$parsely_page['url'] = $this->get_current_url( 'post' );
} elseif ( is_author() ) {
// TODO: why can't we have something like a WP_User object for all the other cases? Much nicer to deal with than functions
$author = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
$parsely_page['headline'] = $this->get_clean_parsely_page_value( 'Author - ' . $author->data->display_name );
$parsely_page['url'] = $current_url;
} elseif ( is_category() ) {
$category = get_the_category();
$category = $category[0];
$parsely_page['headline'] = $this->get_clean_parsely_page_value( $category->name );
$parsely_page['url'] = $current_url;
} elseif ( is_date() ) {
if ( is_year() ) {
$parsely_page['headline'] = 'Yearly Archive - ' . get_the_time( 'Y' );
} elseif ( is_month() ) {
$parsely_page['headline'] = 'Monthly Archive - ' . get_the_time( 'F, Y' );
} elseif ( is_day() ) {
$parsely_page['headline'] = 'Daily Archive - ' . get_the_time( 'F jS, Y' );
} elseif ( is_time() ) {
$parsely_page['headline'] = 'Hourly, Minutely, or Secondly Archive - ' . get_the_time( 'F jS g:i:s A' );
}
$parsely_page['url'] = $current_url;
} elseif ( is_tag() ) {
$tag = single_tag_title( '', false );
if ( empty( $tag ) ) {
$tag = single_term_title( '', false );
}
$parsely_page['headline'] = $this->get_clean_parsely_page_value( 'Tagged - ' . $tag );
$parsely_page['url'] = $current_url;
} elseif ( is_front_page() ) {
}
if ( is_front_page() ) {
$parsely_page['headline'] = $this->get_clean_parsely_page_value( get_bloginfo( 'name', 'raw' ) );
$parsely_page['url'] = home_url();
$parsely_page['url'] = get_home_url();
$parsely_page['@type'] = 'WebPage';
}
if ( is_archive() ) {
$parsely_page['@type'] = 'WebPage';
$parsely_page['url'] = $this->get_current_url();
if ( is_author() ) {
$parsely_page['headline'] = $this->get_clean_parsely_page_value( 'Author - ' . $author->data->display_name );
} else {
$parsely_page['headline'] = get_the_archive_title();
}
}

$parsely_page = apply_filters( 'after_set_parsely_page', $parsely_page, $post, $parsely_options );
include( 'parsely-parsely-page.php' );
return $parsely_page;
Expand Down Expand Up @@ -1037,10 +1024,12 @@ private function get_current_url( $post = 'nonpost' ) {
return $canonical;
}
$page_url = site_url( null, $scheme );
if ( 80 !== intval( $_SERVER['SERVER_PORT'] ) || 443 !== intval( $_SERVER['SERVER_PORT'] ) ) {
$page_url .= ':' . esc_url( wp_unslash( $_SERVER['SERVER_PORT'] ) );

$port_number = intval( $_SERVER['SERVER_PORT'] );
if ( 80 !== $port_number && 443 !== $port_number ) {
$page_url .= ':' . $port_number;
}
$page_url .= esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) );
$page_url .= esc_html( wp_unslash( $_SERVER['REQUEST_URI'] ) );
return $page_url;
}

Expand Down

0 comments on commit 5faee42

Please sign in to comment.