/** * Removes a project from the list of sticky projects. * * @since 1.0.0 * @access public * @param int $project_id * @return bool */ function ccp_remove_sticky_project($project_id) { $project_id = ccp_get_project_id($project_id); if (ccp_is_project_sticky($project_id)) { $stickies = ccp_get_sticky_projects(); $key = array_search($project_id, $stickies); if (isset($stickies[$key])) { unset($stickies[$key]); return update_option('ccp_sticky_projects', array_unique($stickies)); } } return false; }
/** * Filter on `the_posts` for the project archive. Moves sticky posts to the top of * the project archive list. * * @since 1.0.0 * @access public * @param array $posts * @param object $query * @return array */ function ccp_posts_sticky_filter($posts, $query) { // Allow devs to filter when to show sticky projects. $show_stickies = apply_filters('ccp_show_stickies', $query->is_main_query() && !is_admin() && ccp_is_project_archive() && !is_paged()); // If we should show stickies, let's get them. if ($show_stickies) { remove_filter('the_posts', 'ccp_posts_sticky_filter'); $posts = ccp_add_stickies($posts, ccp_get_sticky_projects()); } return $posts; }
/** * Add custom views (status list). * * @since 1.0.0 * @access public * @param array $views * @return array */ public function views($views) { $count = count(ccp_get_sticky_projects()); if (0 < $count) { $post_type = ccp_get_project_post_type(); $noop = _n('Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $count, 'custom-content-portfolio'); $text = sprintf($noop, number_format_i18n($count)); $views['sticky'] = sprintf('<a href="%s">%s</a>', add_query_arg(array('post_type' => $post_type, 'sticky' => 1), admin_url('edit.php')), $text); } return $views; }
/** * Conditional check to see if a project has the "sticky" type. * * @since 1.0.0 * @access public * @param int $project_id * @return bool */ function ccp_is_project_sticky($project_id = 0) { $project_id = ccp_get_project_id($project_id); return apply_filters('ccp_is_project_sticky', in_array($project_id, ccp_get_sticky_projects()), $project_id); }