Advertisement
Guest User

register-life.ph

a guest
Mar 27th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.86 KB | None | 0 0
  1. <?php
  2. add_action('init', 'life_register');
  3.  
  4. function life_register()
  5. {
  6.     global $avia_config;
  7.  
  8.     $labels = array(
  9.         'name' => _x('Life Items', 'post type general name','avia_framework'),
  10.         'singular_name' => _x('Life Entry', 'post type singular name','avia_framework'),
  11.         'add_new' => _x('Add New', 'life','avia_framework'),
  12.         'add_new_item' => __('Add New Life Entry','avia_framework'),
  13.         'edit_item' => __('Edit Life Entry','avia_framework'),
  14.         'new_item' => __('New Life Entry','avia_framework'),
  15.         'view_item' => __('View Life Entry','avia_framework'),
  16.         'search_items' => __('Search Life Entries','avia_framework'),
  17.         'not_found' =>  __('No Life Entries found','avia_framework'),
  18.         'not_found_in_trash' => __('No Life Entries found in Trash','avia_framework'),
  19.         'parent_item_colon' => ''
  20.     );
  21.  
  22.     $permalinks = get_option('avia_permalink_settings');
  23.     if(!$permalinks) $permalinks = array();    
  24.  
  25.     $permalinks['life_permalink_base'] = empty($permalinks['life_permalink_base']) ? __('life-item', 'avia_framework') : $permalinks['life_permalink_base'];
  26.     $permalinks['life_entries_taxonomy_base'] = empty($permalinks['life_entries_taxonomy_base']) ? __('life_entries', 'avia_framework') : $permalinks['life_entries_taxonomy_base'];
  27.  
  28.     $args = array(
  29.         'labels' => $labels,
  30.         'public' => true,
  31.         'show_ui' => true,
  32.         'capability_type' => 'post',
  33.         'hierarchical' => false,
  34.         'rewrite' => array('slug'=>_x($permalinks['life_permalink_base'],'URL slug','avia_framework'), 'with_front'=>true),
  35.         'query_var' => true,
  36.         'show_in_nav_menus'=> true,
  37.         'taxonomies' => array('post_tag'),
  38.         'supports' => array('title','thumbnail','excerpt','editor','comments')
  39.     );
  40.    
  41.    
  42.     $args = apply_filters('avf_life_cpt_args', $args);
  43.     $avia_config['custom_post']['life']['args'] = $args;
  44.  
  45.     register_post_type( 'life' , $args );
  46.  
  47.  
  48.     $tax_args = array( 
  49.         "hierarchical" => true,
  50.         "label" => "Life Categories",
  51.         "singular_label" => "Life Category",
  52.         "rewrite" => array('slug'=>_x($permalinks['life_entries_taxonomy_base'],'URL slug','avia_framework'), 'with_front'=>true),
  53.         "query_var" => true
  54.     );
  55.  
  56.     $avia_config['custom_taxonomy']['life']['life_entries']['args'] = $tax_args;
  57.  
  58.     register_taxonomy("life_entries", array("life"), $tax_args);
  59.  
  60.     //deactivate the avia_flush_rewrites() function - not required because we rely on the default wordpress permalink settings
  61.     remove_action('wp_loaded', 'avia_flush_rewrites');
  62. }
  63.  
  64.  
  65.  
  66. #life_columns, register_post_type then append _columns
  67. add_filter("manage_edit-life_columns", "prod_edit_columns");
  68. add_filter("manage_edit-post_columns", "post_edit_columns");
  69. add_action("manage_posts_custom_column",  "prod_custom_columns");
  70.  
  71.  
  72.  
  73. /**
  74.  * avia life permalink setting.
  75.  *
  76.  * @access public
  77.  * @return void
  78.  */
  79. if(!function_exists('avia_permalink_settings_init'))
  80. {
  81.     function avia_permalink_settings_init()
  82.     {
  83.         global $avia_config;
  84.        
  85.         if(!empty($avia_config['custom_post']))
  86.         {
  87.             foreach($avia_config['custom_post'] as $cpt => $cpt_args)
  88.             {
  89.                 // Add a section to the permalinks page
  90.                 add_settings_section('avia-permalink', $cpt_args['args']['labels']['singular_name'] . ' ' . __('Settings', 'avia_framework'), 'avia_permalink_settings', 'permalink');
  91.             }
  92.         }
  93.     }
  94.     add_action('admin_init', 'avia_permalink_settings_init');
  95. }
  96.  
  97.  
  98. if(!function_exists('avia_permalink_settings'))
  99. {
  100.     function avia_permalink_settings()
  101.     {
  102.         global $avia_config;
  103.  
  104.         if(!empty($avia_config['custom_post']))
  105.         {
  106.             foreach($avia_config['custom_post'] as $cpt => $cpt_args)
  107.             {          
  108.                 echo wpautop(__('These settings change the permalinks used for the', 'avia_framework') . ' ' . strtolower($cpt_args['args']['labels']['name']) . __('.', 'avia_framework'));
  109.  
  110.                 $permalinks = get_option('avia_permalink_settings');
  111.                 if(!$permalinks) $permalinks = array();
  112.  
  113.                 $permalinks[$cpt.'_permalink_base'] = empty($permalinks[$cpt.'_permalink_base']) ? $cpt_args['args']['rewrite']['slug'] : $permalinks[$cpt.'_permalink_base'];
  114.  
  115.                 if(!empty($avia_config['custom_taxonomy'][$cpt]))
  116.                 {
  117.                     foreach($avia_config['custom_taxonomy'][$cpt] as $tax => $tax_args)
  118.                     {
  119.                         $permalinks[$tax.'_taxonomy_base'] = empty($permalinks[$tax.'_taxonomy_base']) ? $tax_args['args']['rewrite']['slug'] : $permalinks[$tax.'_taxonomy_base'];
  120.                     }
  121.                 }
  122.                 ?>
  123.  
  124.                 <table class="form-table">
  125.                     <tbody>
  126.                     <tr>
  127.                         <th><?php echo $cpt_args['args']['labels']['name'] . ' ' . __('Base', 'avia_framework'); ?></th>
  128.                         <td>
  129.                             <?php $option_id = $cpt.'_permalink_base'; ?>
  130.                             <input name="<?php echo $option_id; ?>" id="<?php echo $option_id; ?>" type="text" value="<?php echo esc_attr($permalinks[$option_id]); ?>" class="regular-text code"> <span class="description"><?php _e( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default instead.', 'avia_framework' ); ?></span>
  131.                         </td>
  132.                     </tr>
  133.  
  134.             <?php
  135.                 if(!empty($avia_config['custom_taxonomy'][$cpt]))
  136.                 {
  137.                     foreach($avia_config['custom_taxonomy'][$cpt] as $tax => $tax_args)
  138.                     {
  139.                 ?>
  140.                         <tr>
  141.                             <th><?php echo $tax_args['args']['label']  . ' ' . __('Base', 'avia_framework'); ?></th>
  142.                             <td>
  143.                                 <?php $option_id = $tax.'_taxonomy_base'; ?>
  144.                                 <input name="<?php echo $option_id; ?>" id="<?php echo $option_id; ?>" type="text" value="<?php echo esc_attr($permalinks[$option_id]); ?>" class="regular-text code"> <span class="description"><?php _e( 'Enter a custom base to use. A base <strong>must</strong> be set or WordPress will use default instead.', 'avia_framework' ); ?></span>
  145.                             </td>
  146.                         </tr>
  147.                 <?php
  148.                     }
  149.                 }
  150.             ?>
  151.                     </tbody>
  152.                 </table>
  153.                
  154.                 <?php
  155.             }
  156.         }
  157.     }
  158. }
  159.  
  160.  
  161. if(!function_exists('avia_permalink_settings_save'))
  162. {
  163.     function avia_permalink_settings_save()
  164.     {
  165.         global $avia_config;
  166.         $permalinks = get_option('avia_permalink_settings');
  167.         if(!$permalinks) $permalinks = array();
  168.  
  169.         if(!empty($avia_config['custom_post']))
  170.         {
  171.             foreach($avia_config['custom_post'] as $cpt => $cpt_args)
  172.             {
  173.                 $option_id = $cpt.'_permalink_base';
  174.  
  175.                 // We need to save the options ourselves; settings api does not trigger save for the permalinks page
  176.                 if(isset($_POST[$option_id]))
  177.                 {
  178.                     $permalinks[$option_id] = untrailingslashit(esc_html($_POST[$option_id]));
  179.                 }
  180.  
  181.                 if(!empty($avia_config['custom_taxonomy'][$cpt]))
  182.                 {
  183.                     foreach($avia_config['custom_taxonomy'][$cpt] as $tax => $tax_args)
  184.                     {
  185.                         $option_id = $tax.'_taxonomy_base';
  186.  
  187.                         if(isset($_POST[$option_id]))
  188.                         {
  189.                             $permalinks[$option_id] = untrailingslashit(esc_html($_POST[$option_id]));
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.  
  195.             update_option('avia_permalink_settings', $permalinks);
  196.         }
  197.     }
  198.     add_action('admin_init', 'avia_permalink_settings_save');
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement