• I’m using a plugin (posts expire) that exclude posts with specific “end date” (custom field) from being displayed.

    How can I override this plugin for certain categories/pages/posts? I assume this can be done with remove_filter or remove_action hooks?

    <?php
    /*
    Plugin Name: Posts Expire
    Description: Adds an expiry date to posts.
    Author: Michael O'Connell
    Version: 1.02
    Author URI: https://wunder-ful.com/
    
    	This plugin is released under version 2 of the GPL:
    	https://www.opensource.org/licenses/gpl-license.php
    */
    class posts_expire
    {
    	function posts_expire()
    	{
    		global $wpdb;
    		if ( !get_settings('posts_have_end_date') )
    		{
    			$wpdb->query("ALTER TABLE <code>$wpdb->posts</code> ADD <code>post_end_date</code> DATE AFTER <code>post_date</code>");
    			update_option('posts_have_end_date', 1);
    		}
    
    		add_filter('posts_where', array(&$this, 'add_where_clause'));
    		add_filter('posts_orderby', array(&$this, 'add_orderby')); //bypass orderby safety check
    		add_action('simple_edit_form', array(&$this, 'add_end_date_input'));
    		add_action('edit_form_advanced', array(&$this, 'add_end_date_input'));
    		add_action('edit_page_form', array(&$this, 'add_end_date_input'));
    		add_action('save_post', array(&$this, 'add_update_statement'));
    	}
    
    	function add_where_clause($where)
    	{
    		if(get_settings('show_expired_posts') || is_admin() || is_single())
    			return $where;
    
    		//exclude nulls when getting a list of posts that expire soon
    		$include_nulls = !($_GET['orderby'] == 'post_end_date');	
    
    		$now = date('Y-m-d') . ' 23:59:59'; //timezone not taken into consideration...
    
    		$where = $where . " AND (post_end_date >= '$now'";
    		if($include_nulls)
    			$where = $where . ' OR  post_end_date IS NULL';
    		$where = $where . ')';
    
    		return $where;
    	}
    
    	function add_orderby($orderby)
    	{
    		if($_GET['orderby'] == 'post_end_date')
    			return '<code>post_end_date</code> ASC';
    		else
    			return $orderby;
    	}
    
    	function add_end_date_input()
    	{
    		$end_date = get_end_date();
    		echo "<div>Enter a end date (yyyy-mm-dd): <input type='text' name='end_date' value='$end_date'></input></div>";
    	}
    
    	function add_update_statement($post_ID)
    	{
    		global $wpdb;
    
    		$end_date = $_POST['end_date'];
    
    		if($end_date)
    			$wpdb->query("UPDATE <code>$wpdb->posts</code> SET <code>post_end_date</code> = '$end_date' WHERE <code>ID</code> =$post_ID LIMIT 1 ;");
    		else //remove existing end date if user blanks field
    			$wpdb->query("UPDATE <code>$wpdb->posts</code> SET <code>post_end_date</code> = NULL WHERE <code>ID</code> =$post_ID LIMIT 1 ;");
    	}
    }
    
    $posts_expire =& new posts_expire();
    
    function the_end_date($prefix = '')
    {
    	$end_date = mysql2date(get_settings('date_format'),get_end_date());
    
    	if(!$prefix)
    		$prefix = __('Expires ');
    
    	if(function_exists('get_begin_date') && get_begin_date())
    		$prefix = ', ' . $prefix;
    
    	if($end_date)
    		echo $prefix . $end_date;
    	else
    		echo __('Expiration Unknown');
    }
    
    function get_end_date()
    {
    	global $post;
    	return $post->post_end_date;
    }
    ?>
  • The topic ‘remove_filter or remove_action ?’ is closed to new replies.