Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Zed1 test
- Plugin URI: http://zed1.com/
- Description: Test plugin
- Author: Mike Little
- Version: 0.0.1
- Author URI: http://zed1.com/
- Author URI: http://zed1.com/
- License: GPL2+
- */
- /*
- Copyright 2011 Mike Little (email : mike@zed1.com)
- This file is part of The Zed1 test Plugin.
- The Zed1 test Plugin is free software:
- you can redistribute it and/or modify it under the terms of the
- GNU General Public License as published by the Free Software Foundation,
- either version 2 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- define('ZED1_TEST_PLUGIN_NAME', 'zed1_test');
- define('ZED1_TEST_PLUGIN_VERSION', '0.0.1');
- define('ZED1_TEST_DEBUG', false); //true
- if (!defined('NL')) define('NL', "\n");
- new zed1_test();
- class zed1_test {
- static $my_data;
- function zed1_test() {
- return $this->__construct();
- } // end php4 constructor
- function __construct() {
- error_log("zed1_test:constructor");
- add_action( 'init', array( 'zed1_test', 'init' ) );
- } // end constructor
- static function get_my_data() {
- return self::$my_data;
- } // end get_my_data
- static function set_my_data($val) {
- return self::$my_data = $val;
- } // end set_my_data
- static function init() {
- error_log("zed1_test:init");
- add_action( 'template_redirect', array( 'zed1_test', 'template_redirect_process_query_vars' ) );
- add_filter( 'wp_title', array( 'zed1_test', 'wp_title_display_my_title' ), 99, 3 ); // we want to be last
- add_filter( 'the_title', array( 'zed1_test', 'the_title_display_my_title' ), 99, 2 ); // we want to be last
- add_filter( 'the_content', array( 'zed1_test', 'the_content_display_results' ), 99 ); // we want to be last
- } // end init
- static function template_redirect_process_query_vars() {
- error_log("zed1_test:template_redirect_process_query_vars");
- if ( is_singular() && isset($_GET['recid'] ) ) {
- //validate everything! It's coming from the nasty outside world
- $recid = intval( $_GET['recid'] );
- // run some code to get the record
- $my_data = array( 'title' => 'the record title ' . $recid ,
- 'content' => 'the records content ' . $recid ,
- );
- // save it
- self::set_my_data($my_data);
- }
- } // end template_redirect_process_query_vars
- static function wp_title_display_my_title( $title, $sep, $seplocation ) {
- error_log("zed1_test:wp_title_display_my_title");
- if ( is_singular() ) {
- $my_data = self::get_my_data();
- if ( ! empty( $my_data ) )
- $title = '<title>my title: ' . $my_data['title'] . '</title>';
- }
- return $title;
- } // end the_content_display_results
- static function the_title_display_my_title( $title, $post_id ) {
- error_log("zed1_test:the_title_display_my_title");
- if ( is_singular() ) {
- $my_data = self::get_my_data();
- if ( ! empty( $my_data ) )
- $title = 'my title: ' . $my_data['title'] . '</title>';
- }
- return $title;
- } // end the_content_display_results
- static function the_content_display_results( $content ) {
- error_log("zed1_test:the_content_display_results");
- if ( is_singular() ) {
- $my_data = self::get_my_data();
- if ( ! empty( $my_data ) )
- $content = 'my content: ' . $my_data['content'];
- }
- return $content;
- } // end the_content_display_results
- } // end class zed1_test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement