/** * Removes a theme from the list of sticky themes. * * @since 1.0.0 * @access public * @param int $theme_id * @return bool */ function thds_remove_sticky_theme($theme_id) { $theme_id = thds_get_theme_id($theme_id); if (thds_is_theme_sticky($theme_id)) { $stickies = thds_get_sticky_themes(); $key = array_search($theme_id, $stickies); if (isset($stickies[$key])) { unset($stickies[$key]); return update_option('thds_sticky_themes', 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']) && 'thds_toggle_sticky' === $_GET['action'] && isset($_GET['theme_id'])) { $theme_id = absint(thds_get_theme_id($_GET['theme_id'])); // Verify the nonce. check_admin_referer("thds_toggle_sticky_{$theme_id}"); if (thds_is_theme_sticky($theme_id)) { thds_remove_sticky_theme($theme_id); } else { thds_add_sticky_theme($theme_id); } // Redirect to correct admin page. $redirect = add_query_arg(array('updated' => 1), remove_query_arg(array('action', 'theme_id', '_wpnonce'))); wp_safe_redirect(esc_url_raw($redirect)); // Always exit for good measure. exit; } return; }
/** * Save theme 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['thds_theme_publish_box']) || !wp_verify_nonce($_POST['thds_theme_publish_box'], 'thds_theme_publish_box_nonce')) { return; } // Is the sticky checkbox checked? $should_stick = !empty($_POST['thds_theme_sticky']); // If checked, add the theme if it is not sticky. if ($should_stick && !thds_is_theme_sticky($post_id)) { thds_add_sticky_theme($post_id); } elseif (!$should_stick && thds_is_theme_sticky($post_id)) { thds_remove_sticky_theme($post_id); } }
/** * Filter the post class. * * @since 1.0.0 * @access public * @param array $classes * @param string $class * @param int $post_id * @return array */ function thds_post_class($classes, $class, $post_id) { if (thds_is_theme($post_id) && thds_is_theme_archive() && thds_is_theme_sticky($post_id) && !is_paged()) { $classes[] = 'sticky'; } return $classes; }