From f57ea825ddf86d84a678fa4213efd620d17ad084 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 8 Jul 2016 10:50:34 -0400 Subject: [PATCH] Added event name as page title to event detail page. --- index.php | 6 +++--- setup/frontHooks.php | 38 ++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/index.php b/index.php index ed50200..136e4c4 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM Members Database Events * Plugin URI: http://www.gaslightmedia.com/ * Description: Gaslight Media Members Database. - * Version: 1.2.17 + * Version: 1.2.18 * Author: Chuck Scott * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -20,7 +20,7 @@ * @package glmMembersDatabaseEventsAddOn * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.2.17 + * @version 1.2.18 */ /* @@ -38,7 +38,7 @@ * so that we're sure the other add-ons see an up to date * version from this plugin. */ -define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.2.17'); +define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.2.18'); define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.18'); // This is the minimum version of the GLM Members DB plugin require for this plugin. diff --git a/setup/frontHooks.php b/setup/frontHooks.php index ec30ef9..de47a2a 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -53,26 +53,36 @@ if ( ! isset( $rules['('.$this->config['settings']['canonical_event_page'].')/([ * * The code below checks if we're on a event detail page and if so returns the event slug so that * can be added to the URL. The matching apply_filters is in the main plugin in setup/frontHooks.php. + * + * We're also going to set the page title to the event name in here while we're at it. */ -add_filter('glm_rel_canonical_slug', function($detailSlug) { +if (strpos(GLM_MEMBERS_PLUGIN_CURRENT_URL, $this->config['settings']['canonical_event_page']) > 0) { - // If another add-on already supplied the detail slug, then just return that. - if ($detailSlug != false) { - return $detailSlug; - } + // Parse out only the event slug from the current URL + $m = array(); + preg_match('|.*/'.$this->config['settings']['canonical_event_page'].'/([^/]*).*|', GLM_MEMBERS_PLUGIN_CURRENT_URL, $m ); + $GLOBALS['glmDetailSlug'] = $m[1]; - // Check if the page is a event-detail page use the correct - if (strpos(GLM_MEMBERS_PLUGIN_CURRENT_URL, $this->config['settings']['canonical_event_page']) > 0) { + // Return the current event slug to the glm_rel_canonical_slug filter for use in the canonical page link. + add_filter('glm_rel_canonical_slug', function($detailSlug) { - // Parse out only the event slug and use that - $m = array(); - preg_match('|.*/'.$this->config['settings']['canonical_event_page'].'/([^/]*).*|', GLM_MEMBERS_PLUGIN_CURRENT_URL, $m ); - $detailSlug = $m[1]; + // If another add-on already supplied the detail slug, then just return that. + if ($detailSlug != false) { + return $detailSlug; + } + return $GLOBALS['glmDetailSlug']; - } + }); - return $detailSlug; -}); + // Get the event name for use in the page title + global $wpdb; + $GLOBALS['glmEventName'] = $wpdb->get_var( "SELECT name FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE name_slug = '".$GLOBALS['glmDetailSlug']."'" ); + + // Set the page title to the event name + add_filter('wp_title', function() { + return $GLOBALS['glmEventName']; + }); +} // Add eventslug query var add_filter('query_vars', function($vars) { -- 2.17.1