function mbdb_rewrite_rules($rules) { global $wp_rewrite; $mbdb_options = get_option('mbdb_options'); $new_rules = array(); $taxonomies = mbdb_tax_grid_objects(); //get_object_taxonomies( 'mbdb_book', 'objects' ); foreach ($taxonomies as $name => $taxonomy) { $url = ''; if (array_key_exists('mbdb_book_grid_' . $name . '_slug', $mbdb_options)) { $url = $mbdb_options['mbdb_book_grid_' . $name . '_slug']; } if ($url == '') { $url = $taxonomy->labels->singular_name; } $url = sanitize_title($url); //$new_rules['series/([^/]*)/?$'] = 'mbdb_tax_grid/?x=x&the-taxonomy=mbdb_series&the-term=$matches[1]&post_type=mbdb_tax_grid'; $new_rules[$url . '/([^/]*)/?$'] = 'mbdb_tax_grid/test/?x=x&the-taxonomy=' . $name . '&the-term=$matches[1]&post_type=mbdb_tax_grid'; $pretty_name = str_replace('mbdb_', '', $name); $new_rules['book/' . $pretty_name . '/(.+)/?$'] = 'index.php?post_type=mbdb_book&' . $name . '=' . $wp_rewrite->preg_index(1); //$new_rules['mbdb_series/([^/]*)/?$'] = 'mbdb_tax_grid/test/?x=x&the-taxonomy=mbdb_series&the-term=$matches[1]&post_type=mbdb_tax_grid'; $new_rules[$name . '/([^/]*)/?$'] = 'mbdb_tax_grid/test/?x=x&the-taxonomy=' . $name . '&the-term=$matches[1]&post_type=mbdb_tax_grid'; } if (count($new_rules) > 0) { $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } }
/** * * If any of the tag slugs were changed, the rewrite rules * need to be flushed. * This function runs if ANY of the fields were updated. * * * @since 3.0 * @param [string] $old_value * @param [string] $new_value * * @access public */ function options_updated($old_value, $new_value) { // if any of the tax slugs change, flush the rewrite rules $taxonomies = mbdb_tax_grid_objects(); foreach ($taxonomies as $name => $taxonomy) { if ($old_value['mbdb_book_grid_' . $name . '_slug'] != $new_value['mbdb_book_grid_' . $name . '_slug']) { flush_rewrite_rules(); break; } } }
function mbdb_set_default_tax_grid_slugs() { $taxonomies = mbdb_tax_grid_objects(); //get_object_taxonomies( 'mbdb_book', 'objects' ); $mbdb_options = get_option('mbdb_options'); foreach ($taxonomies as $name => $taxonomy) { if ($mbdb_options['mbdb_book_grid_' . $name . '_slug'] == '') { $reserved_terms = mbdb_wp_reserved_terms(); $slug = sanitize_title($taxonomy->labels->singular_name); if (in_array($slug, $reserved_terms)) { $slug = sanitize_title('book-' . $slug); } $mbdb_options['mbdb_book_grid_' . $name . '_slug'] = $slug; } } update_option('mbdb_options', $mbdb_options); }