Advertisement
mikelittle

Example query var processing

Feb 22nd, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.67 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Zed1 test
  4. Plugin URI: http://zed1.com/
  5. Description: Test plugin
  6. Author: Mike Little
  7. Version: 0.0.1
  8. Author URI: http://zed1.com/
  9. Author URI: http://zed1.com/
  10. License: GPL2+
  11. */
  12. /*
  13.     Copyright 2011  Mike Little  (email : mike@zed1.com)
  14.  
  15.     This file is part of The Zed1 test  Plugin.
  16.  
  17.     The Zed1 test  Plugin is free software:
  18.     you can redistribute it and/or modify it under the terms of the
  19.     GNU General Public License as published by the Free Software Foundation,
  20.     either version 2 of the License, or (at your option) any later version.
  21.  
  22.     This program is distributed in the hope that it will be useful,
  23.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25.     GNU General Public License for more details.
  26.  
  27.     You should have received a copy of the GNU General Public License
  28.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  29. */
  30.  
  31. define('ZED1_TEST_PLUGIN_NAME', 'zed1_test');
  32. define('ZED1_TEST_PLUGIN_VERSION', '0.0.1');
  33. define('ZED1_TEST_DEBUG', false); //true
  34.  
  35. if (!defined('NL')) define('NL', "\n");
  36.  
  37. new zed1_test();
  38.  
  39. class zed1_test {
  40.     static $my_data;
  41.  
  42.     function zed1_test() {
  43.         return $this->__construct();
  44.     } // end php4 constructor
  45.  
  46.     function __construct() {
  47.         error_log("zed1_test:constructor");
  48.         add_action( 'init', array( 'zed1_test', 'init' ) );
  49.     } // end constructor
  50.  
  51.     static function get_my_data() {
  52.         return self::$my_data;
  53.     } // end get_my_data
  54.  
  55.     static function set_my_data($val) {
  56.         return self::$my_data = $val;
  57.     } // end set_my_data
  58.  
  59.     static function init() {
  60.         error_log("zed1_test:init");
  61.         add_action( 'template_redirect', array( 'zed1_test', 'template_redirect_process_query_vars' ) );
  62.         add_filter( 'wp_title', array( 'zed1_test', 'wp_title_display_my_title' ), 99, 3 ); // we want to be last
  63.         add_filter( 'the_title', array( 'zed1_test', 'the_title_display_my_title' ), 99, 2 ); // we want to be last
  64.         add_filter( 'the_content', array( 'zed1_test', 'the_content_display_results' ), 99 ); // we want to be last
  65.     } // end init
  66.  
  67.     static function template_redirect_process_query_vars() {
  68.         error_log("zed1_test:template_redirect_process_query_vars");
  69.         if ( is_singular()  && isset($_GET['recid'] ) ) {
  70.             //validate everything! It's coming from the nasty outside world
  71.             $recid = intval( $_GET['recid'] );
  72.             // run some code to get the record
  73.             $my_data = array( 'title' => 'the record title ' . $recid ,
  74.                               'content' => 'the records content ' . $recid ,
  75.                             );
  76.             // save it
  77.             self::set_my_data($my_data);
  78.         }
  79.     } // end template_redirect_process_query_vars
  80.  
  81.     static function wp_title_display_my_title( $title, $sep, $seplocation ) {
  82.         error_log("zed1_test:wp_title_display_my_title");
  83.         if ( is_singular() ) {
  84.             $my_data = self::get_my_data();
  85.             if ( ! empty( $my_data ) )
  86.                 $title = '<title>my title: ' . $my_data['title'] . '</title>';
  87.         }
  88.         return $title;
  89.     } // end the_content_display_results
  90.  
  91.     static function the_title_display_my_title( $title, $post_id ) {
  92.         error_log("zed1_test:the_title_display_my_title");
  93.         if ( is_singular() ) {
  94.             $my_data = self::get_my_data();
  95.             if ( ! empty( $my_data ) )
  96.                 $title = 'my title: ' . $my_data['title'] . '</title>';
  97.         }
  98.         return $title;
  99.     } // end the_content_display_results
  100.  
  101.     static function the_content_display_results( $content ) {
  102.         error_log("zed1_test:the_content_display_results");
  103.         if ( is_singular() ) {
  104.             $my_data = self::get_my_data();
  105.             if ( ! empty( $my_data ) )
  106.                 $content = 'my content: ' . $my_data['content'];
  107.         }
  108.         return $content;
  109.     } // end the_content_display_results
  110.  
  111.  
  112. } // end class zed1_test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement