Skip to content

Instantly share code, notes, and snippets.

@dikiyforester
Created November 24, 2018 07:09
Show Gist options
  • Save dikiyforester/9e7ca47e41991544e7882907e7faa81a to your computer and use it in GitHub Desktop.
Save dikiyforester/9e7ca47e41991544e7882907e7faa81a to your computer and use it in GitHub Desktop.
Redirect Expired ClassiPress Ad Listings to Home Page
<?php
/**
* Single Listing view.
*/
class DKF_REL_View_Listing_Single extends APP_View {
/**
* Check if this class should handle the current view.
*
* @return bool
*/
public function condition() {
return is_404();
}
/**
* Redirects Expired and deleted ads to the home page.
*
* @global WP_Query $wp_query
* @global wpdb $wpdb
*/
function template_redirect() {
global $wp_query, $wpdb;
$post = get_post( $wpdb->get_var( $wp_query->request ) );
if ( $post && APP_POST_TYPE === $post->post_type && in_array( $post->post_status, array( 'trash', 'draft' ), true ) ) {
wp_redirect( home_url(), 302 );
die();
}
}
}
<?php
/*
Plugin Name: Redirect Expired Listings
Description: Redirect users to home page or category page when requested listing is expired.
Version: 1.0.0
Author: Artem Frolov
*/
add_action( 'appthemes_init', 'dkf_rel_init' );
function dkf_rel_init() {
if ( ! class_exists( 'APP_View' ) ) {
return;
}
require_once 'class-view-listing-single.php';
new DKF_REL_View_Listing_Single();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment