fireflythemes

Untitled

Mar 11th, 2022
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.62 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Register features CPT
  4.  *
  5.  * @package FireFlyMain
  6.  */
  7.  
  8. function ff_doc_init() {
  9.   register_taxonomy( 'documentation_category',array( 'documentation'), array(
  10.     'hierarchical'      => true,
  11.     'show_ui'           => true,
  12.     'show_admin_column' => true,
  13.     'query_var'         => true,
  14.   ));
  15.  
  16.     $args = array(
  17.         'public'    => true,
  18.         'label'     => esc_html__( 'FF Documentation', 'ff-doc' ),
  19.         'menu_icon' => 'dashicons-media-document',
  20.         'has_archive' => true,
  21.         'hierarchical' => false,
  22.         'supports' => array(
  23.             'title',
  24.             'editor',
  25.             'excerpt',
  26.             'thumbnail',
  27.             'page-attributes',
  28.         ),
  29.         'taxonomies' => array( 'documentation_category'),
  30.     );
  31.     register_post_type( 'documentation', $args );
  32. }
  33. add_action( 'init', 'ff_doc_init' );
  34.  
  35.  
  36. function ff_doc_documentation_category_taxonomy_custom_fields( $term ) {  
  37.     // put the term ID into a variable
  38.     $t_id = $term->term_id;
  39.  
  40.     $ff_doc_menu_order = get_term_meta( $t_id, 'ff_doc_menu_order', true );
  41. ?>  
  42.  
  43. <tr class="form-field">  
  44.     <th scope="row" valign="top">  
  45.         <label for="menu_order">Menu Order</label>  
  46.     </th>  
  47.     <td>  
  48.         <input type="number" name="ff_doc_menu_order" id="ff_doc_menu_order" style="width:80px;" value="<?php echo $ff_doc_menu_order; ?>" />
  49.     </td>  
  50. </tr>  
  51.  
  52. <?php  
  53. }  
  54.  add_action( 'documentation_category_edit_form_fields', 'ff_doc_documentation_category_taxonomy_custom_fields', 10, 2 );  
  55.  
  56. // A callback function to save our extra taxonomy field(s)  
  57. function ff_doc_save_taxonomy_custom_fields( $term_id ) {  
  58.     if ( isset( $_POST['ff_doc_menu_order'] ) ) {
  59.        update_term_meta( $term_id, 'ff_doc_menu_order', absint( $_POST['ff_doc_menu_order'] ) );
  60.     }
  61. }
  62. add_action( 'edited_documentation_category', 'ff_doc_save_taxonomy_custom_fields' );
  63. add_action( 'create_documentation_category', 'ff_doc_save_taxonomy_custom_fields' );
  64.  
  65. function ff_doc_add_menu_order_columns( $columns ) {
  66.     $columns['menu_order'] = 'Menu Order';
  67.     return $columns;
  68. }
  69. add_filter( 'manage_edit-documentation_category_columns', 'ff_doc_add_menu_order_columns' );
  70.  
  71. function ff_doc_add_menu_order_column_content($content,$column_name,$term_id){
  72.     $term= get_term( $term_id, 'documentation_category' );
  73.     switch ($column_name) {
  74.         case 'menu_order':
  75.             //do your stuff here with $term or $term_id
  76.             $content = get_term_meta( $term_id, 'ff_doc_menu_order', true );
  77.             break;
  78.         default:
  79.             break;
  80.     }
  81.     return $content;
  82. }
  83. add_filter( 'manage_documentation_category_custom_column', 'ff_doc_add_menu_order_column_content',10,3 );
  84.  
  85. add_action( 'quick_edit_custom_box', 'quick_edit_add', 10, 2 );
  86.  
  87. /**
  88.  * Add Headline news checkbox to quick edit screen
  89.  *
  90.  * @param string $column_name Custom column name, used to check
  91.  * @param string $post_type
  92.  *
  93.  * @return void
  94.  */
  95. function quick_edit_add( $column_name, $post_type ) {
  96.     if ( 'edit-tags' !== $post_type || 'menu_order' !== $column_name ) {
  97.         return;
  98.     }
  99.  
  100.      // put the term ID into a variable
  101.     $t_id = $term->term_id;
  102.  
  103.     $ff_doc_menu_order = get_term_meta( $t_id, 'ff_doc_menu_order', true );
  104.     ?>
  105.     <fieldset>
  106.         <div class="inline-edit-col">
  107.         <label>
  108.             <span class="title">Menu Order</span>
  109.             <span class="input-text-wrap"><input type="number" name="ff_doc_menu_order" id="ff_doc_menu_order" style="width:80px;" value="<?php echo $ff_doc_menu_order; ?>" /></span>
  110.         </div>
  111.     </fieldset>
  112.     <?php
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment