/** * Register taxonomies for the plugin. * * @since 0.1.0 * @access public * @return void. */ function ccp_register_taxonomies() { /* Get the plugin settings. */ $settings = get_option('plugin_custom_content_portfolio', ccp_get_default_settings()); /* Set up the arguments for the portfolio taxonomy. */ $args = array('public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => false, 'query_var' => 'portfolio', 'capabilities' => array('manage_terms' => 'manage_portfolio', 'edit_terms' => 'manage_portfolio', 'delete_terms' => 'manage_portfolio', 'assign_terms' => 'edit_portfolio_items'), 'rewrite' => array('slug' => !empty($settings['portfolio_base']) ? "{$settings['portfolio_root']}/{$settings['portfolio_base']}" : $settings['portfolio_root'], 'with_front' => false, 'hierarchical' => false, 'ep_mask' => EP_NONE), 'labels' => array('name' => __('Portfolios', 'custom-content-portfolio'), 'singular_name' => __('Portfolio', 'custom-content-portfolio'), 'menu_name' => __('Portfolios', 'custom-content-portfolio'), 'name_admin_bar' => __('Portfolio', 'custom-content-portfolio'), 'search_items' => __('Search Portfolios', 'custom-content-portfolio'), 'popular_items' => __('Popular Portfolios', 'custom-content-portfolio'), 'all_items' => __('All Portfolios', 'custom-content-portfolio'), 'edit_item' => __('Edit Portfolio', 'custom-content-portfolio'), 'view_item' => __('View Portfolio', 'custom-content-portfolio'), 'update_item' => __('Update Portfolio', 'custom-content-portfolio'), 'add_new_item' => __('Add New Portfolio', 'custom-content-portfolio'), 'new_item_name' => __('New Portfolio Name', 'custom-content-portfolio'), 'separate_items_with_commas' => __('Separate portfolios with commas', 'custom-content-portfolio'), 'add_or_remove_items' => __('Add or remove portfolios', 'custom-content-portfolio'), 'choose_from_most_used' => __('Choose from the most used portfolios', 'custom-content-portfolio'))); /* Register the 'portfolio' taxonomy. */ register_taxonomy('portfolio', array('portfolio_item'), $args); }
/** * Registers post types needed by the plugin. * * @since 0.1.0 * @access public * @return void */ function ccp_register_post_types() { /* Get the plugin settings. */ $settings = get_option('plugin_custom_content_portfolio', ccp_get_default_settings()); /* Set up the arguments for the portfolio item post type. */ $args = array('description' => '', 'public' => true, 'publicly_queryable' => true, 'show_in_nav_menus' => false, 'show_in_admin_bar' => true, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 12, 'menu_icon' => CCP_URI . 'images/menu-icon.png', 'can_export' => true, 'delete_with_user' => false, 'hierarchical' => false, 'has_archive' => $settings['portfolio_root'], 'query_var' => 'portfolio_item', 'capability_type' => 'portfolio_item', 'map_meta_cap' => true, 'capabilities' => array('edit_post' => 'edit_portfolio_item', 'read_post' => 'read_portfolio_item', 'delete_post' => 'delete_portfolio_item', 'create_posts' => 'create_portfolio_items', 'edit_posts' => 'edit_portfolio_items', 'edit_others_posts' => 'manage_portfolio', 'publish_posts' => 'manage_portfolio', 'read_private_posts' => 'read', 'read' => 'read', 'delete_posts' => 'manage_portfolio', 'delete_private_posts' => 'manage_portfolio', 'delete_published_posts' => 'manage_portfolio', 'delete_others_posts' => 'manage_portfolio', 'edit_private_posts' => 'edit_portfolio_items', 'edit_published_posts' => 'edit_portfolio_items'), 'rewrite' => array('slug' => !empty($settings['portfolio_item_base']) ? "{$settings['portfolio_root']}/{$settings['portfolio_item_base']}" : $settings['portfolio_root'], 'with_front' => false, 'pages' => true, 'feeds' => true, 'ep_mask' => EP_PERMALINK), 'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail'), 'labels' => array('name' => __('Portfolio Items', 'custom-content-portfolio'), 'singular_name' => __('Portfolio Item', 'custom-content-portfolio'), 'menu_name' => __('Portfolio', 'custom-content-portfolio'), 'name_admin_bar' => __('Portfolio Item', 'custom-content-portfolio'), 'add_new' => __('Add New', 'custom-content-portfolio'), 'add_new_item' => __('Add New Portfolio Item', 'custom-content-portfolio'), 'edit_item' => __('Edit Portfolio Item', 'custom-content-portfolio'), 'new_item' => __('New Portfolio Item', 'custom-content-portfolio'), 'view_item' => __('View Portfolio Item', 'custom-content-portfolio'), 'search_items' => __('Search Portfolio', 'custom-content-portfolio'), 'not_found' => __('No portfolio items found', 'custom-content-portfolio'), 'not_found_in_trash' => __('No portfolio items found in trash', 'custom-content-portfolio'), 'all_items' => __('Portfolio Items', 'custom-content-portfolio'), 'archive_title' => __('Portfolio', 'custom-content-portfolio'))); /* Register the portfolio item post type. */ register_post_type('portfolio_item', $args); }
/** * Returns a plugin setting. * * @since 1.0.0 * @access public * @param string $setting * @return mixed */ function ccp_get_setting($setting) { $defaults = ccp_get_default_settings(); $settings = wp_parse_args(get_option('ccp_settings', $defaults), $defaults); return isset($settings[$setting]) ? $settings[$setting] : false; }
/** * Filters the 'breadcrumb_trail_items' hook from the Breadcrumb Trail plugin and the script version * included in the Hybrid Core framework. At best, this is a neat hack to add the portfolio to the * single view of portfolio items based off the '%portfolio%' rewrite tag. At worst, it's potentially * a huge management nightmare in the long term. A better solution is definitely needed baked right * into Breadcrumb Trail itself that takes advantage of its built-in features for figuring out this type * of thing. * * @since 0.1.0 * @access public * @param array $items * @return array */ function ccp_breadcrumb_trail_items($items) { if (is_singular('portfolio_item')) { $settings = get_option('plugin_custom_content_portfolio', ccp_get_default_settings()); if (false !== strpos($settings['portfolio_item_base'], '%portfolio%')) { $post_id = get_queried_object_id(); $terms = get_the_terms($post_id, 'portfolio'); if (!empty($terms)) { usort($terms, '_usort_terms_by_ID'); $term = get_term($terms[0], 'portfolio'); $term_id = $term->term_id; $parents = array(); while ($term_id) { /* Get the parent term. */ $term = get_term($term_id, 'portfolio'); /* Add the formatted term link to the array of parent terms. */ $parents[] = '<a href="' . get_term_link($term, 'portfolio') . '" title="' . esc_attr($term->name) . '">' . $term->name . '</a>'; /* Set the parent term's parent as the parent ID. */ $term_id = $term->parent; } $items = array_splice($items, 0, -1); $items = array_merge($items, array_reverse($parents)); $items[] = single_post_title('', false); } } } return $items; }
/** * Adds plugin settings. At the moment, this function isn't being used because we're waiting for a bug fix * in core. For more information, see: http://core.trac.wordpress.org/ticket/9296 * * @since 0.1.0 * @access public * @return void */ function ccp_plugin_settings() { /* Register settings for the 'permalink' screen in the admin. */ register_setting('permalink', 'plugin_custom_content_portfolio', 'ccp_validate_settings'); /* Adds a new settings section to the 'permalink' screen. */ add_settings_section('ccp-permalink', __('Portfolio Settings', 'custom-content-portfolio'), 'ccp_permalink_section', 'permalink'); /* Get the plugin settings. */ $settings = get_option('plugin_ccp', ccp_get_default_settings()); add_settings_field('ccp-root', __('Portfolio archive', 'custom-content-portfolio'), 'ccp_root_field', 'permalink', 'ccp-permalink', $settings); add_settings_field('ccp-base', __('Portfolio taxonomy slug', 'custom-content-portfolio'), 'ccp_base_field', 'permalink', 'ccp-permalink', $settings); add_settings_field('ccp-item-base', __('Portfolio item slug', 'custom-content-portfolio'), 'ccp_item_base_field', 'permalink', 'ccp-permalink', $settings); }