Skip to content

Commit

Permalink
Added option to add the chapter-slug to the URL line and cleaned up t…
Browse files Browse the repository at this point in the history
…he archive tab
  • Loading branch information
Frumph committed Oct 26, 2014
1 parent 67a6446 commit 6d3d84f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 8 deletions.
5 changes: 3 additions & 2 deletions ceo-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
'enable_transcripts_in_comic_posts',
'enable_motion_artist_support',
'enable_hoverbox',
'disable_cal_rewrite_rules',
'allow_comics_to_have_categories'
) as $key) {
if (!isset($_REQUEST[$key])) $_REQUEST[$key] = 0;
Expand Down Expand Up @@ -97,7 +96,9 @@
}

foreach (array(
'include_comics_in_blog_archive'
'include_comics_in_blog_archive',
'disable_cal_rewrite_rules',
'enable_chapter_in_url'
) as $key) {
if (!isset($_REQUEST[$key])) $_REQUEST[$key] = 0;
$ceo_options[$key] = (bool)( $_REQUEST[$key] == 1 ? true : false );
Expand Down
67 changes: 66 additions & 1 deletion comiceasel.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,69 @@ function ceo_initialize_post_types() {
}
}

if (ceo_pluginfo('enable_chapter_in_url')) {
add_action( 'registered_post_type', 'ceo_add_post_types_rewrite', 1, 2 );
add_filter( 'post_type_link', 'ceo_filter_post_type_link', 1, 2 );
}

/**
* Add the numeric permalink structure to bbPress topics and replies.
*
* @author Nashwan Doaqan
*/
function ceo_add_post_types_rewrite( $post_type, $args ) {
if ( 'comic' === $post_type ) {
add_rewrite_tag( "%chapter_name%", '(.+?)', "post_type=comic&chapters=" );
add_permastruct( $post_type, "{$args->rewrite['slug']}/%chapter_name%/%postname%", $args->rewrite );
}
}

/**
* Change bbPress post types links.
*
* @author Nashwan Doaqan
*/
function ceo_filter_post_type_link( $post_link , $_post ) {
global $wp_rewrite;
if ( empty( $_post ) )
return $post_link;
if ( 'comic' === $_post->post_type ) {
$post_link = $wp_rewrite->get_extra_permastruct( $_post->post_type );
if ( strpos( $post_link, '%chapter_name%' ) !== FALSE ) {
$chapter = get_the_terms( $_post->ID, 'chapters' );
if (is_array($chapter)) {
$chapter = reset( $chapter );
$chapter_name = ceo_get_taxonomy_parents_names( $chapter->term_id, 'chapters', '/', TRUE );
$post_link = str_replace( "%chapter_name%", untrailingslashit( $chapter_name ), $post_link );
} else return;
}
$post_link = str_replace( "%postname%", $_post->post_name, $post_link );
$post_link = home_url( user_trailingslashit( $post_link ) );
}
return $post_link;
}

function ceo_get_taxonomy_parents_names( $id, $taxonomy, $separator = '/', $nicename = false, $visited = array() ) {
$chain = '';
$parent = get_term( $id, $taxonomy );
if ( is_wp_error( $parent ) || ! $parent )return $parent;

if ( $nicename )
$name = $parent->slug;
else
$name = $parent->name;

if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
$visited[] = $parent->parent;
$chain .= ceo_get_taxonomy_parents_names( $parent->parent, $taxonomy, $separator, $nicename, $visited );
}
if ( ! empty( $name ) ) {
$chain .= $name.$separator;
}

return $chain;
}

if (!defined('CEO_FEATURE_DISABLE_REWRITE_RULES') && !ceo_pluginfo('disable_cal_rewrite_rules'))
add_action('generate_rewrite_rules', 'ceo_datearchives_rewrite_rules');

Expand Down Expand Up @@ -408,7 +471,8 @@ function ceo_load_options($reset = false) {
'disable_cal_rewrite_rules' => false,
'chapter_on_home' => 0,
'allow_comics_to_have_categories' => false,
'enable_nav_above_comic' => false
'enable_nav_above_comic' => false,
'enable_chapter_in_url' => false
) as $field => $value) {
$ceo_config[$field] = $value;
}
Expand Down Expand Up @@ -461,6 +525,7 @@ function ceo_pluginfo($whichinfo = null) {
$ceo_options['db_version'] = '1.7';
$ceo_options['chapter_type_slug_name'] = 'chapter';
$ceo_options['chapter_type_name_plural'] = 'chapters';
$ceo_options['enable_chapter_in_url'] = false;
update_option('comiceasel-config', $ceo_options);
}
$ceo_coreinfo = wp_upload_dir();
Expand Down
19 changes: 14 additions & 5 deletions options/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<?php wp_nonce_field('update-options') ?>

<div class="comiceasel-options">

<div style='color: #b00;font-size: 16px;text-align:center;background-color: #efefef;padding: 5px;border: solid 2px #000;font-weight: 700;'><?php _e('IMPORTANT - If you change any of the settings on this page from the default, go to settings -> permalink and click SAVE so that the permalink structure can be recognized by WordPress','comiceasel'); ?></div>
<br />
<table class="widefat">
<thead>
<tr>
Expand All @@ -22,12 +23,22 @@
</tr>
<tr>
<?php if (!isset($ceo_options['disable_cal_rewrite_rules'])) $ceo_options['disable_cal_rewrite_rules'] = false; ?>
<th scope="row"><label for="disable_cal_rewrite_rules"><?php _e('Disable the regeneration of the rewrite rules so numerical slugs get turned into dates?','comiceasel'); ?></label></th>
<th scope="row"><label for="disable_cal_rewrite_rules"><?php _e('Disable the the rewrite rules so numerical slugs do not get turned into dates?','comiceasel'); ?></label></th>
<td>
<input id="disable_cal_rewrite_rules" name="disable_cal_rewrite_rules" type="checkbox" value="1" <?php checked(true, $ceo_options['disable_cal_rewrite_rules']); ?> />
</td>
<td>
<?php _e('This option disables the url line from interpreting numerical numbers as dates.','comiceasel'); ?>
<?php _e('This option disables the url line from interpreting numerical numbers as dates. ex. /comic/2014/ ','comiceasel'); ?>
</td>
</tr>
<tr class="alternate">
<?php if (!isset($ceo_options['enable_chapter_in_url'])) $ceo_options['enable_chapter_in_url'] = false; ?>
<th scope="row"><label for="enable_chapter_in_url"><?php _e('Allow the URL to also denote the chapter?','comiceasel'); ?></label></th>
<td>
<input id="enable_chapter_in_url" name="enable_chapter_in_url" type="checkbox" value="1" <?php checked(true, $ceo_options['enable_chapter_in_url']); ?> />
</td>
<td>
<?php _e('Allows the chapter that the comic is in to show up in the URL of the comic. ex: /comic/chapter-slug/postname/','comiceasel'); ?>
</td>
</tr>
</table>
Expand Down Expand Up @@ -56,7 +67,6 @@
<td>
<?php _e('Default: "comic" changing this will modify the permalink name for the /comic/ how it is addressed in the url. This is a slug name, no slashes or spaces allowed; only alpha characters and a single word.','comiceasel'); ?><br />
<br />
<span style='color: #b00;'><?php _e('IMPORTANT - If you change this from the default remember to go to settings -> permalink and click SAVE so that the permalink structure can be recognized by WordPress','comiceasel'); ?></span>
</td>
</tr>
<tr>
Expand All @@ -77,7 +87,6 @@
<td>
<?php _e('Default: "chapter" changing this will modify the permalink name for the /chapter/ how it is addressed in the url. This is a slug name, no slashes or spaces allowed; only alpha characters and a single word.','comiceasel'); ?><br />
<br />
<span style='color: #b00;'><?php _e('IMPORTANT - If you change this from the default remember to go to settings -> permalink and click SAVE so that the permalink structure can be recognized by WordPress','comiceasel'); ?></span>
</td>
</tr>
<tr class="alternate">
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ The comic navigation widget is only seen if you have the comic sidebar's enabled
* the column for the all comics now uses the name chosen for the taxonomy
* change the way the comment value is displayed in the navigation to better support disqus and other 3rd party comment systems
* Comic sidebars now default to being enabled on new installations
* option to add chapter_slug to the URL, replacement for the use of the custom post type permalinks plugin

= 1.7.7.1 =
* fixed bug where you couldn't save the facebook image size
Expand Down

0 comments on commit 6d3d84f

Please sign in to comment.