/** * 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; }
/** * Callback function for handling post status changes. * * @since 1.0.0 * @access public * @return void */ public function handler() { // Checks if the sticky toggle link was clicked. if (isset($_GET['action']) && 'ccp_toggle_sticky' === $_GET['action'] && isset($_GET['project_id'])) { $project_id = absint(ccp_get_project_id($_GET['project_id'])); // Verify the nonce. check_admin_referer("ccp_toggle_sticky_{$project_id}"); if (ccp_is_project_sticky($project_id)) { ccp_remove_sticky_project($project_id); } else { ccp_add_sticky_project($project_id); } // Redirect to correct admin page. $redirect = add_query_arg(array('updated' => 1), remove_query_arg(array('action', 'project_id', '_wpnonce'))); wp_safe_redirect(esc_url_raw($redirect)); // Always exit for good measure. exit; } return; }
/** * Save project details settings on post save. * * @since 1.0.0 * @access public * @param int $post_id * @return void */ public function update($post_id) { $this->manager->update($post_id); // Verify the nonce. if (!isset($_POST['ccp_project_publish_box']) || !wp_verify_nonce($_POST['ccp_project_publish_box'], 'ccp_project_publish_box_nonce')) { return; } // Is the sticky checkbox checked? $should_stick = !empty($_POST['ccp_project_sticky']); // If checked, add the project if it is not sticky. if ($should_stick && !ccp_is_project_sticky($post_id)) { ccp_add_sticky_project($post_id); } elseif (!$should_stick && ccp_is_project_sticky($post_id)) { ccp_remove_sticky_project($post_id); } }