Disables the Genre taxonomy archive in the Novelist plugin.
<?php | |
/** | |
* Plugin Name: Novelist - No Genre Archive | |
* Plugin URI: https://www.nosegraze.com | |
* Description: Removes the genre archive pages and turns the genre list into plain text. | |
* Version: 1.0 | |
* Author: Nose Graze | |
* Author URI: https://www.nosegraze.com | |
* License: GPL2 | |
* | |
* @package novelist-no-genre-archive | |
* @copyright Copyright (c) 2016, Nose Graze Ltd. | |
* @license GPL2+ | |
* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License, version 2, as | |
* published by the Free Software Foundation. | |
* | |
* 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, write to the Free Software | |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
/** | |
* Disable "show in nav menus" and "show tag cloud" features. | |
* | |
* @param array $args | |
* | |
* @since 1.0 | |
* @return array | |
*/ | |
function novelist_disable_genre_taxonomy_features( $args ) { | |
$new_args = array( | |
'public' => false, | |
'show_in_nav_menus' => false, | |
'show_tagcloud' => false, | |
); | |
return wp_parse_args( $new_args, $args ); | |
} | |
add_filter( 'novelist/taxonomy/genre-args', 'novelist_disable_genre_taxonomy_features' ); | |
/** | |
* Modify Genre Query | |
* | |
* If a `novelist-genre` query is being performed then set that to a 404. | |
* | |
* @param WP_Query $query | |
* | |
* @since 1.0 | |
* @return void | |
*/ | |
function novelist_modify_genre_query( $query ) { | |
if ( is_admin() ) { | |
return; | |
} | |
if ( is_tax( 'novelist-genre' ) ) { | |
$query->set_404(); | |
} | |
} | |
add_action( 'pre_get_posts', 'novelist_modify_genre_query' ); | |
/** | |
* Remove Genre Archive Links | |
* | |
* Modifies Novelist_Book::get_genres() | |
* | |
* @param string $genre_list Genre list with links to archives. | |
* @param int $book_id ID of the book we're querying. | |
* | |
* @since 1.0 | |
* @return bool|string False on failure, comma-separated list on success. | |
*/ | |
function novelist_remove_genre_archive_links( $genre_list, $book_id ) { | |
$genres = wp_get_post_terms( $book_id, 'novelist-genre', array( 'fields' => 'names' ) ); | |
if ( ! is_array( $genres ) ) { | |
return false; | |
} | |
return implode( ', ', $genres ); | |
} | |
add_filter( 'novelist/book/get/genre', 'novelist_remove_genre_archive_links', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment