WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type UI
[resolved] Patch to add "rewrite=>with_front" functionality (6 posts)

  1. MarcGuay
    Member
    Posted 1 year ago #

    I needed this feature in my version of CPT UI. Here's a simple patch to add it. Hopefully it will be added to the released version, I don't see a reason not to.

    Cheerios
    Marc

    Index: custom-post-type-ui.php
    ===================================================================
    --- custom-post-type-ui.php	(revision 651445)
    +++ custom-post-type-ui.php	(working copy)
    @@ -128,7 +128,7 @@
     				'capability_type' => $cpt_post_type["capability_type"],
     				'hierarchical' => get_disp_boolean($cpt_post_type["hierarchical"]),
     				'exclude_from_search' => $cpt_exclude_from_search,
    -				'rewrite' => array('slug' => $cpt_rewrite_slug),
    +				'rewrite' => array('slug' => $cpt_rewrite_slug, 'with_front' => $cpt_post_type["rewrite_with_front"] ),
     				'query_var' => get_disp_boolean($cpt_post_type["query_var"]),
     				'description' => esc_html($cpt_post_type["description"]),
     				'menu_position' => $cpt_menu_position,
    @@ -178,7 +178,7 @@
     				'label' => $cpt_label,
     				'show_ui' => get_disp_boolean($cpt_tax_type["show_ui"]),
     				'query_var' => get_disp_boolean($cpt_tax_type["query_var"]),
    -				'rewrite' => array('slug' => $cpt_rewrite_slug),
    +				'rewrite' => array('slug' => $cpt_rewrite_slug, 'with_front' => $cpt_tax_type["rewrite_with_front"] ),
     				'singular_label' => $cpt_singular_label,
     				'labels' => $cpt_labels
     			) );
    @@ -553,6 +553,7 @@
                         <th><?php _e('Show UI', 'cpt-plugin');?></th>
                         <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                         <th><?php _e('Rewrite', 'cpt-plugin');?></th>
    +                    <th><?php _e('Rewrite With Front', 'cpt-plugin' );?></th>
                         <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                         <th><?php _e('Total Published', 'cpt-plugin');?></th>
                         <th><?php _e('Total Drafts', 'cpt-plugin');?></th>
    @@ -568,6 +569,7 @@
                         <th><?php _e('Show UI', 'cpt-plugin');?></th>
                         <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                         <th><?php _e('Rewrite', 'cpt-plugin');?></th>
    +                    <th><?php _e('Rewrite With Front', 'cpt-plugin' );?></th>
                         <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                         <th><?php _e('Total Published', 'cpt-plugin');?></th>
                         <th><?php _e('Total Drafts', 'cpt-plugin');?></th>
    @@ -597,6 +599,7 @@
                     <td valign="top"><?php echo disp_boolean($cpt_post_type["show_ui"]); ?></td>
                     <td valign="top"><?php echo disp_boolean($cpt_post_type["hierarchical"]); ?></td>
                     <td valign="top"><?php echo disp_boolean($cpt_post_type["rewrite"]); ?></td>
    +                <td valign="top"><?php echo disp_boolean($cpt_post_type["rewrite_with_front"]); ?></td>
                     <td valign="top"><?php echo $rewrite_slug; ?></td>
                     <td valign="top"><?php echo $cpt_counts->publish; ?></td>
                     <td valign="top"><?php echo $cpt_counts->draft; ?></td>
    @@ -663,7 +666,7 @@
     						$custom_post_type .= 	'\'show_in_menu\' => ' .$cpt_show_in_menu .',';
     						$custom_post_type .= 	'\'capability_type\' => \''.$cpt_post_type["capability_type"].'\',';
     						$custom_post_type .= 	'\'hierarchical\' => '.disp_boolean($cpt_post_type["hierarchical"]).',';
    -						$custom_post_type .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_post_type["rewrite_slug"]. '\'),';
    +						$custom_post_type .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_post_type["rewrite_slug"]. '\', \'with_front\' => \'' .$cpt_post_type["rewrite_with_front"]. '\'),';
     						$custom_post_type .= 	'\'query_var\' => '. disp_boolean($cpt_post_type["query_var"]).',';
    
     						if ( $cpt_post_type["has_archive"] ) {
    @@ -822,6 +825,7 @@
                     <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                     <th><?php _e('Show UI', 'cpt-plugin');?></th>
                     <th><?php _e('Rewrite', 'cpt-plugin');?></th>
    +                <th><?php _e('Rewrite With Front', 'cpt-plugin');?></th>
                     <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                     </tr>
                 </thead>
    @@ -835,6 +839,7 @@
                     <th><?php _e('Hierarchical', 'cpt-plugin');?></th>
                     <th><?php _e('Show UI', 'cpt-plugin');?></th>
                     <th><?php _e('Rewrite', 'cpt-plugin');?></th>
    +                <th><?php _e('Rewrite With Front', 'cpt-plugin');?></th>
                     <th><?php _e('Rewrite Slug', 'cpt-plugin');?></th>
                     </tr>
                 </tfoot>
    @@ -869,6 +874,7 @@
                     <td valign="top"><?php echo disp_boolean($cpt_tax_type["hierarchical"]); ?></td>
                     <td valign="top"><?php echo disp_boolean($cpt_tax_type["show_ui"]); ?></td>
                     <td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite"]); ?></td>
    +                <td valign="top"><?php echo disp_boolean($cpt_tax_type["rewrite_with_front"]); ?></td>
                     <td valign="top"><?php echo $rewrite_slug; ?></td>
                 </tr>
             	<tr>
    @@ -905,7 +911,7 @@
                                     $custom_tax .= 	'\'label\' => \''.$cpt_label.'\',';
                                     $custom_tax .= 	'\'show_ui\' => '.disp_boolean($cpt_tax_type["show_ui"]).',';
                                     $custom_tax .= 	'\'query_var\' => '. disp_boolean($cpt_tax_type["query_var"]).',';
    -				$custom_tax .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_tax_type["rewrite_slug"]. '\'),';
    +				$custom_tax .= 	'\'rewrite\' => array(\'slug\' => \'' .$cpt_tax_type["rewrite_slug"]. '\', \'with_front\' => \'' .$cpt_tax_type["rewrite_with_front"]. '\'),';
                                     $custom_tax .= 	'\'singular_label\' => \''.$cpt_singular_label.'\'';
                                     $custom_tax .= ') );';
    
    @@ -961,6 +967,7 @@
     	$cpt_capability = $cpt_options[$editType]["capability_type"];
     	$cpt_hierarchical = $cpt_options[$editType]["hierarchical"];
     	$cpt_rewrite = $cpt_options[$editType]["rewrite"];
    +    $cpt_rewrite_with_front = $cpt_options[$editType]["rewrite_with_front"];
     	$cpt_rewrite_slug = $cpt_options[$editType]["rewrite_slug"];
     	$cpt_query_var = $cpt_options[$editType]["query_var"];
     	$cpt_description = $cpt_options[$editType]["description"];
    @@ -996,6 +1003,7 @@
     	$cpt_tax_showui = $cpt_options[$editTax]["show_ui"];
     	$cpt_tax_query_var = $cpt_options[$editTax]["query_var"];
     	$cpt_tax_rewrite = $cpt_options[$editTax]["rewrite"];
    +	$cpt_tax_rewrite_with_front = $cpt_options[$editTax]["rewrite_with_front"];
     	$cpt_tax_rewrite_slug = $cpt_options[$editTax]["rewrite_slug"];
     	$cpt_tax_labels = $cpt_options[$editTax][0];
     	$cpt_post_types = $cpt_options[$editTax][1];
    @@ -1225,6 +1233,16 @@
                         </tr>
    
                         <tr valign="top">
    +                    <th scope="row"><?php _e('Rewrite With Front', 'cpt-plugin') ?></th>
    +                    <td>
    +                        <SELECT name="cpt_custom_post_type[rewrite_with_front]" tabindex="8">
    +                            <OPTION value="0" <?php If (isset($cpt_rewrite_with_front)) { If ($cpt_rewrite_with_front == 0 && $cpt_rewrite_with_front != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
    +                            <OPTION value="1" <?php If (isset($cpt_rewrite_with_front)) { If ($cpt_rewrite_with_front == 1 || is_null($cpt_rewrite_with_front)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
    +                        </SELECT> <a href="#" title="" style="cursor: help;">?</a> (default: True)
    +                    </td>
    +                    </tr>
    +
    +                    <tr valign="top">
                         <th scope="row"><?php _e('Custom Rewrite Slug', 'cpt-plugin') ?></th>
                         <td><input type="text" name="cpt_custom_post_type[rewrite_slug]" tabindex="9" value="<?php If (isset($cpt_rewrite_slug)) { echo esc_attr($cpt_rewrite_slug); } ?>" /> <a href="#" title="Custom Post Type Rewrite Slug" style="cursor: help;">?</a> (default: post type name)</td>
                         </tr>
    @@ -1469,6 +1487,15 @@
                         </tr>
    
                         <tr valign="top">
    +                    <th scope="row"><?php _e('Rewrite With Front', 'cpt-plugin') ?></th>
    +                    <td>
    +                        <SELECT name="cpt_custom_tax[rewrite_with_front]" tabindex="28">
    +                            <OPTION value="0" <?php If (isset($cpt_tax_rewrite_with_front)) { If ($cpt_tax_rewrite_with_front == 0 && $cpt_tax_rewrite_with_front != '') { echo 'selected="selected"'; } } ?>>False</OPTION>
    +                            <OPTION value="1" <?php If (isset($cpt_tax_rewrite_with_front)) { If ($cpt_tax_rewrite_with_front == 1 || is_null($cpt_tax_rewrite_with_front)) { echo 'selected="selected"'; } }Else{ echo 'selected="selected"'; } ?>>True</OPTION>
    +                        </SELECT> <a href="#" title="" style="cursor: help;">?</a> (default: True)
    +                    </td>
    +                    </tr><br />
    +                    <tr valign="top">
                         <th scope="row"><?php _e('Custom Rewrite Slug', 'cpt-plugin') ?></th>
                         <td><input type="text" name="cpt_custom_tax[rewrite_slug]" tabindex="9" value="<?php If (isset($cpt_tax_rewrite_slug)) { echo esc_attr($cpt_tax_rewrite_slug); } ?>" /> <a href="#" title="Custom Taxonomy Rewrite Slug" style="cursor: help;">?</a> (default: taxonomy name)</td>
                         </tr>

    http://wordpress.org/extend/plugins/custom-post-type-ui/

  2. dhavaljani
    Member
    Posted 1 year ago #

    Thanks Brad for a great plugin. I agree with MarcGuay as I needed that option too and I found lot of posts and questions about how to add "rewrite=>with_front" functionality and even a fork of this plugin http://stephennomura.com/blog/enhanced-version-of-custom-post-types-ui but I would rather that it was in original plugin as its already installed and being used on the site.

    MarcGuay Can you provide some details on how to apply this patch?

    Thanks.

  3. Michael Beckwith
    Member
    Plugin Author

    Posted 1 year ago #

    Making parameters for all of the options available to the register functions will be a priority for the next release. Not sure why it wasn't part of the original.

  4. eliot.eshelman
    Member
    Posted 11 months ago #

    Thanks for this excellent plugin!

    I'm using version 0.8 and see that "rewrite=>with_front" is supported for custom post types.

    Can I inquire as to why support was not added for setting with_front on custom taxonomies? I've temporarily patched the version on my site.

  5. Michael Beckwith
    Member
    Plugin Author

    Posted 11 months ago #

    eliot.esheiman

    didn't realize it was available for taxonomies as well. I'll create an issue for it on the associated GitHub repo.

    https://github.com/WebDevStudios/custom-post-type-ui

  6. Michael Beckwith
    Member
    Plugin Author

    Posted 10 months ago #

    Currently scheduled to be a part of 0.9, which is the 2nd-to-next release planned

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.