Advertisement
Guest User

category-posts-in-custom-menu.php

a guest
Jul 29th, 2014
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 28.88 KB | None | 0 0
  1. <?php
  2. /*
  3.     Plugin Name: Category Posts in Custom Menu
  4.     Plugin URI: http://blog.dianakoenraadt.nl
  5.     Description: This plugin replaces selected Category links / Post Tag links / Custom taxonomy links in a Custom Menu by a list of their posts/pages.
  6.     Version: 0.9.5
  7.     Author: Diana Koenraadt
  8.     Author URI: http://www.dianakoenraadt.nl
  9.     License: GPL2
  10. */
  11.  
  12. /*  Copyright 2012 Diana Koenraadt (email : diana at dianakoenraadt dot nl)
  13.  
  14.     This program is free software; you can redistribute it and/or modify
  15.     it under the terms of the GNU General Public License, version 2, as
  16.     published by the Free Software Foundation.
  17.  
  18.     This program is distributed in the hope that it will be useful,
  19.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.     GNU General Public License for more details.
  22.  
  23.     You should have received a copy of the GNU General Public License
  24.     along with this program; if not, write to the Free Software
  25.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  26. */
  27.  
  28. require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); // Load all the nav menu interface functions
  29.  
  30. $CurrentVer = phpversion();
  31.  
  32. // Use version_compare because closures are not supported in PHP 5.2 or below
  33. // http://wordpress.org/support/topic/unexpected-t_function-1
  34. if (version_compare($CurrentVer, '5.3.0') == -1)
  35. {
  36.     require('cpcm-functions52.php');   
  37. }
  38. else
  39. {
  40.     require('cpcm-functions.php');     
  41. }
  42.  
  43.  
  44. new CPCM_Manager;
  45.  
  46. class CPCM_Manager {
  47.  
  48.     function __construct()
  49.     {
  50.         add_action( 'admin_enqueue_scripts', array( &$this, 'cpmp_wp_admin_nav_menus_css' ) );
  51.         add_filter( 'wp_edit_nav_menu_walker', array( &$this, 'cpcm_edit_nav_menu_walker' ), 1, 2 );
  52.         add_filter( 'wp_nav_menu_objects', array( &$this, 'cpcm_replace_taxonomy_by_posts' ), 1, 2 );
  53.         add_action( 'wp_update_nav_menu_item', array( &$this, 'cpcm_update_nav_menu_item' ), 1, 3 );
  54.     } // function
  55.  
  56.     function CPCM_Manager()
  57.     {
  58.         $this->__construct();
  59.  
  60.     } // function
  61.    
  62.     static function cpmp_uninstall() {
  63.         // We're uninstalling, so delete all custom fields on nav_menu_items that the CPCM plugin added
  64.         $all_nav_menu_items = get_posts('numberposts=-1&post_type=nav_menu_item&post_status=any');
  65.  
  66.         foreach( $all_nav_menu_items as $nav_menu_item) {
  67.             delete_post_meta($nav_menu_item->ID, 'cpcm-unfold');
  68.             //exclude post
  69.             delete_post_meta($nav_menu_item->ID, 'cpcm-exclude');
  70.             delete_post_meta($nav_menu_item->ID, 'cpcm-orderby');
  71.             delete_post_meta($nav_menu_item->ID, 'cpcm-order');
  72.             delete_post_meta($nav_menu_item->ID, 'cpcm-item-count');
  73.             delete_post_meta($nav_menu_item->ID, 'cpcm-item-titles');
  74.             delete_post_meta($nav_menu_item->ID, 'cpcm-remove-original-item');
  75.         }
  76.     } // function
  77.  
  78.     /*
  79.     * Add CSS for div.cpmp-description to nav-menus.php
  80.     */
  81.     function cpmp_wp_admin_nav_menus_css($hook){
  82.         // Check the hook so that the .css is only added to the .php file where we need it
  83.         if( 'nav-menus.php' != $hook )
  84.                 return;
  85.         wp_register_style( 'cpmp_wp_admin_nav_menus_css', plugins_url( 'cpmp_wp_admin_nav_menus.css' , __FILE__ ) );
  86.         wp_enqueue_style( 'cpmp_wp_admin_nav_menus_css' );
  87.     } // function
  88.  
  89.     /*
  90.     * Extend Walker_Nav_Menu_Edit and use the extended class (CPCM_Walker_Nav_Menu_Edit) to add controls to nav-menus.php,
  91.     * specifically a div is added with class="cpmp-description". Everything else in this extended class is unchanged with
  92.     * respect to the parent class.
  93.     *
  94.     * Note that this extension of Walker_Nav_Menu_Edit is required because there are no hooks in its start_el method.
  95.     * If hooks are provided in later versions of wordpress, the plugin needs to be updated to use these hooks, that would be
  96.     * much better.
  97.     */
  98.     function cpcm_edit_nav_menu_walker( $walker_name, $menu_id ) {
  99.         if ( class_exists ( 'CPCM_Walker_Nav_Menu_Edit' ) ) {
  100.                 return 'CPCM_Walker_Nav_Menu_Edit';
  101.         }
  102.         return 'Walker_Nav_Menu_Edit';
  103.     } // function
  104.  
  105.     function replace_placeholders( $post, $string )
  106.     {
  107.         $custom_field_keys = get_post_custom_keys($post->ID);
  108.         foreach ( (array)$custom_field_keys as $key => $value ) {
  109.             $valuet = trim($value);
  110.             if ( '_' == $valuet{0} )
  111.             continue;
  112.             $meta = get_post_meta($post->ID, $valuet, true);
  113.             $valuet_str = str_replace(' ', '_', $valuet);
  114.             // Check if post_myfield occurs
  115.             if (substr_count($string, "%post_" . $valuet_str) > 0)
  116.             {
  117.                 if (is_string($meta))
  118.                 {
  119.                     $string = str_replace( "%post_" . $valuet_str, $meta, $string);
  120.                 }
  121.             }
  122.         }
  123.        
  124.         $userdata = get_userdata($post->post_author);
  125.         $string = str_replace( "%post_author",  $userdata ? $userdata->data->display_name : '', $string);
  126.  
  127.         $thumb_image = wp_get_attachment_thumb_url( get_post_thumbnail_id($post->ID) );
  128.         $string = str_replace( "%post_feat_image_thumb",    $thumb_image, $string); // deprecated
  129.         $string = str_replace( "%post_featured_image_thumb_url",    $thumb_image, $string);
  130.         if (trim($thumb_image) == true)
  131.         {
  132.             $string = str_replace( "%post_featured_image_thumb",    "<img src=\"" . $thumb_image . "\" />", $string);
  133.         }
  134.        
  135.         $featured_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
  136.         $string = str_replace( "%post_feat_image",  $featured_image, $string); // deprecated
  137.         $string = str_replace( "%post_featured_image_url",  $featured_image, $string);
  138.         if (trim($featured_image) == true)
  139.         {
  140.             $string = str_replace( "%post_featured_image",  "<img src=\"" . $featured_image . "\" />", $string);
  141.         }
  142.  
  143.         $string = str_replace( "%post_title",   $post->post_title,  $string);
  144.         $string = str_replace( "%post_excerpt",     $post->post_excerpt,    $string);
  145.         $string = str_replace( "%post_url",     get_permalink($post->ID),   $string);
  146.  
  147.         $string = replace_dates($post, $string);
  148.  
  149.         $string = str_replace( "%post_comment_count",   $post->comment_count,   $string);
  150.        
  151.         // Remove remaining %post_ occurrences.
  152.         $pattern = "/" . "((\((?P<lbrack>(\S*))))?" . "\%post_\w+(?P<brackets>(\(((?P<inner>[^\(\)]*)|(?P>brackets))\)))" . "(((?P<rbrack>(\S*))\)))?" . "/";
  153.         $string = preg_replace($pattern, '', $string);
  154.        
  155.         $pattern = "/%post_\w+(?P<brackets>(\(((?P<inner>[^\(\)]*)|(?P>brackets))\)))?/";
  156.         $string = preg_replace($pattern, '', $string);         
  157.        
  158.         $pattern = "/%post_\w+(\(\w*\))?/";
  159.         $string = preg_replace($pattern, '', $string);
  160.        
  161.         return $string;
  162.     }
  163.    
  164.     /*
  165.     * Build the menu structure for display: Augment taxonomies (category, tags or custom taxonomies) that have been marked as such, by their posts. Optionally: remove original menu item.
  166.     */
  167.     function cpcm_replace_taxonomy_by_posts( $sorted_menu_items, $args ) {
  168.         $result = array();    
  169.         $inc = 0;
  170.         foreach ( (array) $sorted_menu_items as $key => $menu_item ) {
  171.        
  172.             $menu_item->menu_order = $menu_item->menu_order + $inc;
  173.        
  174.             // Augment taxonomy object with a list of its posts: Append posts to $result
  175.             // Optional: Remove the taxonomy object/original menu item itself.
  176.             if ( $menu_item->type == 'taxonomy' && (get_post_meta($menu_item->db_id, "cpcm-unfold", true) == '1')) {                   
  177.                 $query_arr = array();
  178.  
  179.                 $query_arr['tax_query'] = array(array('taxonomy'=>$menu_item->object,
  180.                 'field'=>'id',
  181.                 'terms'=>$menu_item->object_id
  182.                 ));
  183.  
  184.                 // If cpcm-unfold is true, the following custom fields exist:
  185.                 $query_arr['order'] = get_post_meta($menu_item->db_id, "cpcm-order", true);
  186.                 //exclude post
  187.                 $query_arr['exclude'] = get_post_meta($menu_item->db_id, "cpcm-exclude", true);
  188.                 $query_arr['orderby'] = get_post_meta($menu_item->db_id, "cpcm-orderby", true);
  189.                 $query_arr['numberposts'] = get_post_meta($menu_item->db_id, "cpcm-item-count", true); // default value of -1 returns all posts
  190.                
  191.                 // Support for custom post types
  192.                 $tag = get_taxonomy($menu_item->object);
  193.                 $query_arr['post_type'] = $tag->object_type;
  194.  
  195.                 $posts = get_posts( $query_arr );
  196.                
  197.                 // Decide whether the original item needs to be preserved.
  198.                 $remove_original_item = get_post_meta($menu_item->db_id, "cpcm-remove-original-item", true);
  199.                 $menu_item_parent = $menu_item->menu_item_parent;
  200.                 switch ($remove_original_item) {
  201.                     case "always":
  202.                         $inc -= 1;
  203.                         break;
  204.                     case "only if empty":
  205.                         if (empty($posts))
  206.                         {
  207.                             $inc -= 1;
  208.                         }
  209.                         else
  210.                         {
  211.                             array_push($result,$menu_item);
  212.                             $menu_item_parent = $menu_item->db_id;
  213.                         }
  214.                         break;
  215.                     case "never":
  216.                         array_push($result,$menu_item);
  217.                         $menu_item_parent = $menu_item->db_id;
  218.                         break;
  219.                 }
  220.                
  221.                 if (is_numeric($query_arr['numberposts']) && $query_arr['numberposts'] == '0')
  222.                 {
  223.                     continue;
  224.                 }
  225.  
  226.                 foreach( (array) $posts as $pkey => $post ) {
  227.                     // Decorate the posts with the required data for a menu-item.
  228.                     if($query_arr['exclude']==="1" && get_the_category($post->ID)[0]->parent!==0){
  229.                         unset($posts[$pkey]);
  230.                         continue;
  231.                     }
  232.                     $post = wp_setup_nav_menu_item( $post );
  233.                     $post->menu_item_parent = $menu_item_parent; // Set to parent of taxonomy item.
  234.  
  235.                     // Transfer properties from the old menu item to the new one
  236.                     $post->target = $menu_item->target;
  237.                     //$post->classes = $menu_item->classes; // Don't copy the classes, because this will also copy the 'active' CSS class too all siblings of the selected menu item. http://wordpress.org/support/topic/active-css-class
  238.                    
  239.                     $post->xfn = $menu_item->xfn;
  240.                     $post->description = $menu_item->description;
  241.  
  242.                     // Set the title of the new menu item
  243.                     $post->title = get_post_meta($menu_item->db_id, "cpcm-item-titles", true);
  244.  
  245.                     // Replace the placeholders in the title by the properties of the post
  246.                     $post->title = $this->replace_placeholders($post, $post->title);
  247.  
  248.                     $inc += 1;
  249.                    
  250.                     $post->menu_order = $menu_item->menu_order + $inc;
  251.                 }
  252.                 // Append the new menu_items to the menu array that we're building.
  253.                 $result = array_merge( $result, $posts );
  254.                
  255.                 // Apply _wp_menu_item_classes_by_context not only to the $posts array, but to the whole result array so that the classes for the original menu items are regenerated as well. Solves: http://wordpress.org/support/topic/issue-with-default-wordpress-sidebar-menu and http://wordpress.org/support/topic/menu-do-not-include-the-current-menu-parent-class
  256.                 // Extend the items with classes.
  257.                 _wp_menu_item_classes_by_context( $result );
  258.             } else {
  259.                 // Treat other objects as usual, but note that the position
  260.                 // of elements in the array changes.
  261.                 array_push($result,$menu_item);
  262.             }
  263.         }
  264.  
  265.         unset( $sorted_menu_items );
  266.         return $result;
  267.     } // function
  268.  
  269.     function __empty($string){
  270.         $string = trim($string);
  271.         if(!is_numeric($string)) return empty($string);
  272.         return FALSE;
  273.     }
  274.  
  275.     /*
  276.     * Store the entered data in nav-menus.php by inspecting the $_POST variable again.
  277.     */
  278.     function cpcm_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
  279.         // Only inspect the values if the $_POST variable contains data (the wp_update_nav_menu_item filter is applied in three other places, without a $_POST action)
  280.         if ( ! empty( $_POST['menu-item-db-id'] ) ) {
  281.             update_post_meta( $menu_item_db_id, 'cpcm-unfold', (!empty( $_POST['menu-item-cpcm-unfold'][$menu_item_db_id]) ) );
  282.             //exclude post
  283.             update_post_meta( $menu_item_db_id, 'cpcm-exclude', (!empty( $_POST['menu-item-cpcm-exclude'][$menu_item_db_id]) ) );
  284.             update_post_meta( $menu_item_db_id, 'cpcm-orderby', (empty( $_POST['menu-item-cpcm-orderby'][$menu_item_db_id]) ? "none" : $_POST['menu-item-cpcm-orderby'][$menu_item_db_id]) );
  285.             update_post_meta( $menu_item_db_id, 'cpcm-order', (empty( $_POST['menu-item-cpcm-order'][$menu_item_db_id]) ? "DESC" : $_POST['menu-item-cpcm-order'][$menu_item_db_id]) );
  286.             update_post_meta( $menu_item_db_id, 'cpcm-item-count', (int) ($this->__empty( $_POST['menu-item-cpcm-item-count'][$menu_item_db_id]) ? "-1" : $_POST['menu-item-cpcm-item-count'][$menu_item_db_id]) );
  287.             update_post_meta( $menu_item_db_id, 'cpcm-item-titles', (empty( $_POST['menu-item-cpcm-item-titles'][$menu_item_db_id]) ? "%post_title" : $_POST['menu-item-cpcm-item-titles'][$menu_item_db_id]) );
  288.             update_post_meta( $menu_item_db_id, 'cpcm-remove-original-item', (empty( $_POST['menu-item-cpcm-remove-original-item'][$menu_item_db_id]) ? "always" : $_POST['menu-item-cpcm-remove-original-item'][$menu_item_db_id]) );
  289.         } // if
  290.     } // function
  291.  
  292. } // class
  293.  
  294. class CPCM_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit  {
  295.     function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
  296.         global $_wp_nav_menu_max_depth;
  297.         $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
  298.  
  299.         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  300.  
  301.         ob_start();
  302.         $item_id = esc_attr( $item->ID );
  303.         $removed_args = array(
  304.             'action',
  305.             'customlink-tab',
  306.             'edit-menu-item',
  307.             'menu-item',
  308.             'page-tab',
  309.             '_wpnonce',
  310.         );
  311.  
  312.         $original_title = '';
  313.         if ( $item->type == 'taxonomy' ) {
  314.             $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
  315.             if ( is_wp_error( $original_title ) )
  316.                 $original_title = false;
  317.         } elseif ( 'post_type' == $item->type ) {
  318.             $original_object = get_post( $item->object_id );
  319.             $original_title = $original_object->post_title;
  320.         }
  321.  
  322.         $classes = array(
  323.             'menu-item menu-item-depth-' . $depth,
  324.             'menu-item-' . esc_attr( $item->object ),
  325.             'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
  326.         );
  327.  
  328.         $title = $item->title;
  329.  
  330.         if ( ! empty( $item->_invalid ) ) {
  331.             $classes[] = 'menu-item-invalid';
  332.             /* translators: %s: title of menu item which is invalid */
  333.             $title = sprintf( __( '%s (Invalid)' ), $item->title );
  334.         } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
  335.             $classes[] = 'pending';
  336.             /* translators: %s: title of menu item in draft status */
  337.             $title = sprintf( __('%s (Pending)'), $item->title );
  338.         }
  339.  
  340.         $title = empty( $item->label ) ? $title : $item->label;
  341.  
  342.         ?>
  343.         <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?> ">
  344.             <dl class="menu-item-bar">
  345.                 <dt class="menu-item-handle">
  346.                     <span class="item-title"><?php echo esc_html( $title ); ?></span>
  347.                     <span class="item-controls">
  348.                         <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
  349.                         <span class="item-order hide-if-js">
  350.                             <a href="<?php
  351.                                 echo wp_nonce_url(
  352.                                     add_query_arg(
  353.                                         array(
  354.                                             'action' => 'move-up-menu-item',
  355.                                             'menu-item' => $item_id,
  356.                                         ),
  357.                                         remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  358.                                     ),
  359.                                     'move-menu_item'
  360.                                 );
  361.                             ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">&#8593;</abbr></a>
  362.                             |
  363.                             <a href="<?php
  364.                                 echo wp_nonce_url(
  365.                                     add_query_arg(
  366.                                         array(
  367.                                             'action' => 'move-down-menu-item',
  368.                                             'menu-item' => $item_id,
  369.                                         ),
  370.                                         remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  371.                                     ),
  372.                                     'move-menu_item'
  373.                                 );
  374.                             ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">&#8595;</abbr></a>
  375.                         </span>
  376.                         <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php
  377.                             echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
  378.                         ?>"><?php _e( 'Edit Menu Item' ); ?></a>
  379.                     </span>
  380.                 </dt>
  381.             </dl>
  382.  
  383.             <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>">
  384.                 <?php if( 'custom' == $item->type ) : ?>
  385.                     <p class="field-url description description-wide">
  386.                         <label for="edit-menu-item-url-<?php echo $item_id; ?>">
  387.                             <?php _e( 'URL' ); ?><br />
  388.                             <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
  389.                         </label>
  390.                     </p>
  391.                 <?php endif; ?>
  392.                 <p class="description description-thin">
  393.                     <label for="edit-menu-item-title-<?php echo $item_id; ?>">
  394.                         <?php _e( 'Navigation Label' ); ?><br />
  395.                         <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
  396.                     </label>
  397.                 </p>
  398.                 <p class="description description-thin">
  399.                     <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
  400.                         <?php _e( 'Title Attribute' ); ?><br />
  401.                         <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
  402.                     </label>
  403.                 </p>
  404.                 <p class="field-link-target description">
  405.                     <label for="edit-menu-item-target-<?php echo $item_id; ?>">
  406.                         <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
  407.                         <?php _e( 'Open link in a new window/tab' ); ?>
  408.                     </label>
  409.                 </p>
  410.                 <p class="field-css-classes description description-thin">
  411.                     <label for="edit-menu-item-classes-<?php echo $item_id; ?>">
  412.                         <?php _e( 'CSS Classes (optional)' ); ?><br />
  413.                         <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
  414.                     </label>
  415.                 </p>
  416.                 <p class="field-xfn description description-thin">
  417.                     <label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
  418.                         <?php _e( 'Link Relationship (XFN)' ); ?><br />
  419.                         <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
  420.                     </label>
  421.                 </p>
  422.                 <p class="field-description description description-wide">
  423.                     <label for="edit-menu-item-description-<?php echo $item_id; ?>">
  424.                         <?php _e( 'Description' ); ?><br />
  425.                         <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea>
  426.                         <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
  427.                     </label>
  428.                 </p>
  429.  
  430.                 <?php /* BEGIN CATEGORY POSTS IN CUSTOM MENU */ if( $item->type == 'taxonomy' ) : ?>
  431.                     <div class="cpmp-description">
  432.                         <p class="field-cpcm-unfold description description-wide">
  433.                             <label for="edit-menu-item-cpcm-unfold-<?php echo $item_id; ?>">
  434.                                 <input type="checkbox" id="edit-menu-item-cpcm-unfold-<?php echo $item_id; ?>" class="edit-menu-item-cpcm-unfold" name="menu-item-cpcm-unfold[<?php echo $item_id; ?>]" <?php checked( get_post_meta($item_id, "cpcm-unfold", true), true )  ?> /> Create submenu containing links to posts<?php if ('Category' == $item->type_label) echo ' in this category'; else if (('Tag' == $item->type_label) || ('Post Tag' == $item->type_label)) echo ' with this tag'; else echo ' in this taxonomy'; ?>.
  435.                             </label>
  436.                         </p>
  437.                         <!-- exclude sub category -->
  438.                         <?php if ('Category' == $item->type_label) { ?>
  439.                         <p class="field-cpcm-exclude description description-wide">
  440.                             <label for="edit-menu-item-cpcm-exclude-<?php echo $item_id; ?>">
  441.                                 <input type="checkbox" id="edit-menu-item-cpcm-exclude-<?php echo $item_id; ?>" class="edit-menu-item-cpcm-exclude" name="menu-item-cpcm-exclude[<?php echo $item_id; ?>]" <?php checked( get_post_meta($item_id, "cpcm-exclude", true), true )  ?> /> Exclude posts from sub categories (top level only).
  442.                             </label>
  443.                         </p>
  444.                         <?php }; ?>
  445.                         <!-- // -->
  446.                         <p class="field-cpcm-item-count description description-thin">
  447.                             <label for="edit-menu-item-cpcm-item-count-<?php echo $item_id; ?>">
  448.                                 <?php _e( 'Number of Posts' ); ?><br />
  449.                                 <input type="text" id="edit-menu-item-cpcm-item-count-<?php echo $item_id; ?>" class="widefat code edit-menu-item-cpcm-item-count" name="menu-item-cpcm-item-count[<?php echo $item_id; ?>]" value="<?php $item_count = get_post_meta($item_id, "cpcm-item-count", true); echo $item_count != '' ? $item_count : '-1'; ?>" />
  450.                             </label>
  451.                         </p>
  452.                         <p class="field-cpcm-orderby description description-thin">
  453.                             <label for="edit-menu-item-cpcm-orderby-<?php echo $item_id; ?>">
  454.                                 <?php _e( 'Order By' ); ?><br />
  455.                                 <select id="edit-menu-item-cpcm-orderby-<?php echo $item_id; ?>" class="widefat edit-menu-item-cpcm-orderby" name="menu-item-cpcm-orderby[<?php echo $item_id; ?>]">
  456.                                     <option value="none" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "none" )  ?>><?php _e('None'); ?></option>
  457.                                     <option value="ID" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "ID" )  ?>><?php _e('ID'); ?></option>
  458.                                     <option value="author" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "author" )  ?>><?php _e('Author'); ?></option>
  459.                                     <option value="title" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "title" )  ?>><?php _e('Title'); ?></option>
  460.                                     <option value="date" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "date" )  ?>><?php _e('Date'); ?></option>
  461.                                     <option value="modified" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "modified" )  ?>><?php _e('Last Modified'); ?></option>
  462.                                     <option value="parent" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "parent" )  ?>><?php _e('Post/Page Parent ID'); ?></option>
  463.                                     <option value="rand" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "rand" )  ?>><?php _e('Random Order'); ?></option>
  464.                                     <option value="comment_count" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "comment_count" )  ?>><?php _e('Number of Comments'); ?></option>
  465.                                     <option value="menu_order" <?php selected( get_post_meta($item_id, "cpcm-orderby", true), "menu_order" ) ?>><?php _e('Menu Order'); ?></option>
  466.                                 </select>
  467.                             </label>
  468.                         </p>
  469.                         <p class="field-cpcm-order description description-thin">
  470.                             <label for="edit-menu-item-cpcm-order-<?php echo $item_id; ?>">
  471.                                 <?php _e( 'Order' ); ?><br />
  472.                                 <select id="edit-menu-item-cpcm-order-<?php echo $item_id; ?>" class="widefat edit-menu-item-cpcm-order" name="menu-item-cpcm-order[<?php echo $item_id; ?>]">
  473.                                     <option value="DESC" <?php selected( get_post_meta($item_id, "cpcm-order", true), "DESC" )  ?>><?php _e('Descending'); ?></option>
  474.                                     <option value="ASC" <?php selected( get_post_meta($item_id, "cpcm-order", true), "ASC" )  ?>><?php _e('Ascending'); ?></option>
  475.                                 </select>
  476.                             </label>
  477.                         </p>
  478.                         <p class="field-cpcm-remove-original-item description description-thin">
  479.                             <label for="edit-menu-item-cpcm-remove-original-item-<?php echo $item_id; ?>">
  480.                                 <?php _e( 'Remove original menu item' ); ?><br />
  481.                                 <select id="edit-menu-item-cpcm-remove-original-item-<?php echo $item_id; ?>" class="widefat edit-menu-item-cpcm-remove-original-item" name="menu-item-cpcm-remove-original-item[<?php echo $item_id; ?>]">
  482.                                     <option value="always" <?php selected( get_post_meta($item_id, "cpcm-remove-original-item", true), "always" )  ?>><?php _e('Always'); ?></option>
  483.                                     <option value="only if empty" <?php selected( get_post_meta($item_id, "cpcm-remove-original-item", true), "only if empty" )  ?>><?php _e('Only if there are no posts'); ?></option>
  484.                                     <option value="never" <?php selected( get_post_meta($item_id, "cpcm-remove-original-item", true), "never" )  ?>><?php _e('Never'); ?></option>
  485.                                 </select>
  486.                             </label>
  487.                         </p>
  488.                         <p class="field-cpcm-item-titles description description-wide">
  489.                             <label for="edit-menu-item-cpcm-item-titles-<?php echo $item_id; ?>">
  490.                                 <?php _e( 'Post Navigation Label' ); ?><br />
  491.                                 <textarea id="edit-menu-item-cpcm-item-titles-<?php echo $item_id; ?>" class="widefat code edit-menu-item-cpcm-item-titles" name="menu-item-cpcm-item-titles[<?php echo $item_id; ?>]" rows="4"><?php $item_titles = get_post_meta($item_id, "cpcm-item-titles", true); echo $item_titles != '' ? esc_attr( $item_titles ) : '%post_title' ?></textarea>
  492.                                 <span class="description"><?php _e('The navigation label for generated post links may be customized using wildcars such as: %post_title, %post_author, %post_my_field (for custom field \'my field\' or \'my_field\'). See documentation.'); ?></span>
  493.                             </label>
  494.                         </p>
  495.                     </div>
  496.                 <?php endif; /* CATEGORY POSTS IN CUSTOM MENU END */ ?>
  497.  
  498.                 <div class="menu-item-actions description-wide submitbox">
  499.                     <?php if( 'custom' != $item->type && $original_title !== false ) : ?>
  500.                         <p class="link-to-original">
  501.                             <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
  502.                         </p>
  503.                     <?php endif; ?>
  504.                     <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php
  505.                     echo wp_nonce_url(
  506.                         add_query_arg(
  507.                             array(
  508.                                 'action' => 'delete-menu-item',
  509.                                 'menu-item' => $item_id,
  510.                             ),
  511.                             remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
  512.                         ),
  513.                         'delete-menu_item_' . $item_id
  514.                     ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ) );
  515.                         ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a>
  516.                 </div>
  517.  
  518.                 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
  519.                 <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
  520.                 <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
  521.                 <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
  522.                 <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
  523.                 <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
  524.             </div><!-- .menu-item-settings-->
  525.             <ul class="menu-item-transport"></ul>
  526.         <?php
  527.         $output .= ob_get_clean();
  528.     } // function
  529. } // class
  530.  
  531. // Register the uninstall hook. Should be done after the class has been defined.
  532. register_uninstall_hook( __FILE__, array( 'CPCM_Manager', 'cpmp_uninstall' ) );
  533.  
  534. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement