/**
 * Adds custom rewrite rules for the plugin.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function ccp_rewrite_rules()
{
    $project_type = ccp_get_project_post_type();
    $author_slug = ccp_get_author_rewrite_slug();
    // Where to place the rewrite rules.  If no rewrite base, put them at the bottom.
    $after = ccp_get_author_rewrite_base() ? 'top' : 'bottom';
    add_rewrite_rule($author_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?post_type=' . $project_type . '&author_name=$matches[1]&paged=$matches[2]', $after);
    add_rewrite_rule($author_slug . '/([^/]+)/?$', 'index.php?post_type=' . $project_type . '&author_name=$matches[1]', $after);
}
 /**
  * Sets up custom admin menus.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function admin_menu()
 {
     // Create the settings page.
     $this->settings_page = add_submenu_page('edit.php?post_type=' . ccp_get_project_post_type(), esc_html__('Portfolio Settings', 'custom-content-portfolio'), esc_html__('Settings', 'custom-content-portfolio'), apply_filters('ccp_settings_capability', 'manage_options'), 'settings', array($this, 'settings_page'));
     if ($this->settings_page) {
         // Register settings.
         add_action('admin_init', array($this, 'register_settings'));
         // Add help tabs.
         add_action("load-{$this->settings_page}", array($this, 'add_help_tabs'));
     }
 }
/**
 * Filters the Breadcrumb Trail plugin arguments.  We're basically just telling it to show the
 * `portfolio_category` taxonomy when viewing single portfolio projects.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $args
 * @return array
 */
function ccp_breadcrumb_trail_args($args)
{
    $project_type = ccp_get_project_post_type();
    $project_base = ccp_get_project_rewrite_base();
    if (false === strpos($project_base, '%') && !isset($args['post_taxonomy'][$project_type])) {
        $args['post_taxonomy'][$project_type] = ccp_get_category_taxonomy();
    }
    return $args;
}
/**
 * Adds custom bulk post updated messages on the manage projects screen.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $messages
 * @param  array  $counts
 * @return array
 */
function ccp_bulk_post_updated_messages($messages, $counts)
{
    $type = ccp_get_project_post_type();
    $messages[$type]['updated'] = _n('%s project updated.', '%s projects updated.', $counts['updated'], 'custom-content-portfolio');
    $messages[$type]['locked'] = _n('%s project not updated, somebody is editing it.', '%s projects not updated, somebody is editing them.', $counts['locked'], 'custom-content-portfolio');
    $messages[$type]['deleted'] = _n('%s project permanently deleted.', '%s projects permanently deleted.', $counts['deleted'], 'custom-content-portfolio');
    $messages[$type]['trashed'] = _n('%s project moved to the Trash.', '%s projects moved to the trash.', $counts['trashed'], 'custom-content-portfolio');
    $messages[$type]['untrashed'] = _n('%s project restored from the Trash.', '%s projects restored from the trash.', $counts['untrashed'], 'custom-content-portfolio');
    return $messages;
}
 /**
  * Custom row actions below the post title.
  *
  * @since  1.0.0
  * @access public
  * @param  array   $actions
  * @param  object  $post
  * @return array
  */
 function row_actions($actions, $post)
 {
     $post_type_object = get_post_type_object(ccp_get_project_post_type());
     $project_id = ccp_get_project_id($post->ID);
     if ('trash' === get_post_status($project_id) || !current_user_can($post_type_object->cap->publish_posts)) {
         return $actions;
     }
     $current_url = remove_query_arg(array('project_id', 'ccp_project_notice'));
     // Build text.
     $text = ccp_is_project_sticky($project_id) ? esc_html__('Unstick', 'custom-content-portfolio') : esc_html__('Stick', 'custom-content-portfolio');
     // Build toggle URL.
     $url = add_query_arg(array('project_id' => $project_id, 'action' => 'ccp_toggle_sticky'), $current_url);
     $url = wp_nonce_url($url, "ccp_toggle_sticky_{$project_id}");
     // Add sticky action.
     $actions['sticky'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($url), 'sticky', esc_html($text));
     // Move view action to the end.
     if (isset($actions['view'])) {
         $view_action = $actions['view'];
         unset($actions['view']);
         $actions['view'] = $view_action;
     }
     return $actions;
 }
/**
 * Checks if the current post is a project.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $post_id
 * @return bool
 */
function ccp_is_project($post_id = '')
{
    $post_id = ccp_get_project_id($post_id);
    return apply_filters('ccp_is_project', ccp_get_project_post_type() === get_post_type($post_id), $post_id);
}
/**
 * Register taxonomies for the plugin.
 *
 * @since  0.1.0
 * @access public
 * @return void.
 */
function ccp_register_taxonomies()
{
    // Set up the arguments for the portfolio category taxonomy.
    $cat_args = array('public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'query_var' => ccp_get_category_taxonomy(), 'capabilities' => ccp_get_category_capabilities(), 'labels' => ccp_get_category_labels(), 'rewrite' => array('slug' => ccp_get_category_rewrite_slug(), 'with_front' => false, 'hierarchical' => false, 'ep_mask' => EP_NONE));
    // Set up the arguments for the portfolio tag taxonomy.
    $tag_args = array('public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => false, 'query_var' => ccp_get_tag_taxonomy(), 'capabilities' => ccp_get_tag_capabilities(), 'labels' => ccp_get_tag_labels(), 'rewrite' => array('slug' => ccp_get_tag_rewrite_slug(), 'with_front' => false, 'hierarchical' => false, 'ep_mask' => EP_NONE));
    // Register the taxonomies.
    register_taxonomy(ccp_get_category_taxonomy(), ccp_get_project_post_type(), apply_filters('ccp_category_taxonomy_args', $cat_args));
    register_taxonomy(ccp_get_tag_taxonomy(), ccp_get_project_post_type(), apply_filters('ccp_tag_taxonomy_args', $tag_args));
}
/**
 * If a theme supports post formats, limit project to only only the audio, image,
 * gallery, and video formats.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function ccp_post_format_support_filter()
{
    $screen = get_current_screen();
    $project_type = ccp_get_project_post_type();
    // Bail if not on the projects screen.
    if (empty($screen->post_type) || $project_type !== $screen->post_type) {
        return;
    }
    // Check if the current theme supports formats.
    if (current_theme_supports('post-formats')) {
        $formats = get_theme_support('post-formats');
        // If we have formats, add theme support for only the allowed formats.
        if (isset($formats[0])) {
            $new_formats = array_intersect($formats[0], ccp_get_allowed_project_formats());
            // Remove post formats support.
            remove_theme_support('post-formats');
            // If the theme supports the allowed formats, add support for them.
            if ($new_formats) {
                add_theme_support('post-formats', $new_formats);
            }
        }
    }
    // Filter the default post format.
    add_filter('option_default_post_format', 'ccp_default_post_format_filter', 95);
}
 /**
  * Filter on the post author drop-down (used in the "Author" meta box) to only show users
  * of roles that have the correct capability for editing portfolio projects.
  *
  * @since  1.0.0
  * @access public
  * @param  array   $args
  * @param  array   $r
  * @global object  $wp_roles
  * @global object  $post
  * @return array
  */
 function dropdown_users_args($args, $r)
 {
     global $wp_roles, $post;
     // WP version 4.4.0 check. Bail if we can't use the `role__in` argument.
     if (!method_exists('WP_User_Query', 'fill_query_vars')) {
         return $args;
     }
     // Check that this is the correct drop-down.
     if ('post_author_override' === $r['name'] && ccp_get_project_post_type() === $post->post_type) {
         $roles = array();
         // Loop through the available roles.
         foreach ($wp_roles->roles as $name => $role) {
             // Get the edit posts cap.
             $cap = get_post_type_object(ccp_get_project_post_type())->cap->edit_posts;
             // If the role is granted the edit posts cap, add it.
             if (isset($role['capabilities'][$cap]) && true === $role['capabilities'][$cap]) {
                 $roles[] = $name;
             }
         }
         // If we have roles, change the args to only get users of those roles.
         if ($roles) {
             $args['who'] = '';
             $args['role__in'] = $roles;
         }
     }
     return $args;
 }
/**
 * Returns the author portfolio archive URL.
 *
 * @since  1.0.0
 * @access public
 * @param  int     $user_id
 * @global object  $wp_rewrite
 * @global object  $authordata
 * @return string
 */
function ccp_get_author_url($user_id = 0)
{
    global $wp_rewrite, $authordata;
    $url = '';
    // If no user ID, see if there's some author data we can get it from.
    if (!$user_id && is_object($authordata)) {
        $user_id = $authordata->ID;
    }
    // If we have a user ID, build the URL.
    if ($user_id) {
        // Get the author's nicename.
        $nicename = get_the_author_meta('user_nicename', $user_id);
        // Pretty permalinks.
        if ($wp_rewrite->using_permalinks()) {
            $url = home_url(user_trailingslashit(trailingslashit(ccp_get_author_rewrite_slug()) . $nicename));
        } else {
            $url = add_query_arg(array('post_type' => ccp_get_project_post_type(), 'author_name' => $nicename), home_url('/'));
        }
    }
    return apply_filters('ccp_get_author_url', $url, $user_id);
}