Making WordPress.org

Changeset 7867


Ignore:
Timestamp:
11/16/2018 10:46:15 PM (7 years ago)
Author:
iandunn
Message:

WordCamp Canonical Years: Apply coding standards.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wc-canonical-years/wc-canonical-years.php

    r7866 r7867  
    11<?php
     2
    23/*
    34 * Plugin Name: WordCamp.org Canonical Years
     
    78
    89class WordCamp_Canonical_Years_Plugin {
    9     function __construct() {
     10    /**
     11     * Constructor.
     12     */
     13    public function __construct() {
    1014        add_action( 'init', array( $this, 'init' ) );
    1115    }
    1216
    13     function init() {
     17    /**
     18     * Initialize plugin
     19     */
     20    public function init() {
    1421        // Only on the home page.
    15         if ( isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] == '/' )
     22        if ( isset( $_SERVER['REQUEST_URI'] ) && '/' === $_SERVER['REQUEST_URI'] ) {
    1623            add_action( 'wp_head', array( $this, 'wp_head' ), 9 );
     24        }
    1725
    1826        // WordPress will print rel=conanical for singular posts by default, we don't want that.
     
    2432     * WordCamp in the same city as the current site.
    2533     */
    26     function wp_head() {
     34    public function wp_head() {
    2735        global $wpdb;
    2836
    2937        $matches = array();
    3038
    31         // match xxxx.city.wordcamp.org
    32         if ( ! preg_match( '/^([0-9]{4})+\.((.+)\.wordcamp\.(lo|dev|test|org))$/i', $_SERVER['HTTP_HOST'], $matches ) )
     39        // Match `xxxx.city.wordcamp.org` pattern.
     40        if ( ! preg_match( '/^([0-9]{4})+\.((.+)\.wordcamp\.(lo|dev|test|org))$/i', $_SERVER['HTTP_HOST'], $matches ) ) {
    3341            return;
     42        }
    3443
    3544        $wordcamp = get_wordcamp_post();
     
    3948         * In rare cases, the site for next year's camp will be created before this year's camp is over. When that
    4049         * happens, we should wait to add the canonical link until after the current year's camp is over.
     50         *
     51         * This won't prevent the link from being added to past years, but that edge case isn't significant enough
     52         * to warrant the extra complexity.
    4153         */
    4254        if ( $end_date && time() < ( (int) $end_date + DAY_IN_SECONDS ) ) {
     
    4557
    4658        $current_domain = $matches[0];
    47         $city_domain = $matches[2];
     59        $city_domain    = $matches[2];
    4860
    4961        $latest_domain = $wpdb->get_var( $wpdb->prepare( "
     
    5870        ) );
    5971
    60         if ( $latest_domain != $current_domain && $latest_domain )
    61             printf( '<link rel="canonical" href="%s" />' . "\n", trailingslashit( esc_url( $latest_domain ) ) );
     72        if ( $latest_domain !== $current_domain && $latest_domain ) {
     73            printf(
     74                '<link rel="canonical" href="%s" />' . "\n",
     75                esc_url( trailingslashit( $latest_domain ) )
     76            );
     77        }
    6278    }
    6379}
    6480
    6581// Initialize the plugin.
    66 new WordCamp_Canonical_Years_Plugin;
     82$GLOBALS['wc_canonical_years'] = new WordCamp_Canonical_Years_Plugin();
Note: See TracChangeset for help on using the changeset viewer.