Skip to content

Instantly share code, notes, and snippets.

View taricco's full-sized avatar

Tim in Seattle taricco

  • Seattle, WA
View GitHub Profile
<?php
/*
Plugin Name: Global Styles Builder for GenerateBlocks
Plugin URI: https://timtaricco.com
Description: A plugin to create and manage global styles for GenerateBlocks.
Version: 07.23.24
Author: Tim Taricco
Author URI: https://timtaricco.com
License: GPL2
*/
/*** Instructions Panel for Posts ***/
function wsv_post_instructions_panel() {
add_meta_box(
'wsv-post-instructions-panel',
'Post Instructions',
'wsv_post_instructions_panel_display_callback',
'post',
'side',
'high'
);
/*** Redirect logged in users from Login page to Dashboard automatically ***/
add_action('template_redirect', 'redirect_logged_in_users');
function redirect_logged_in_users() {
// Check if the user is logged in
if (is_user_logged_in()) {
// Get the current URL
$current_url = home_url($_SERVER['REQUEST_URI']);
// Define the URL to check
/*** Remove frontend WordPress admin bar for users other than Administrators ***/
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
/*** Redirect to homepage on logout ***/
add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : home_url();
$location = str_replace('&amp;', '&', wp_logout_url($redirect_to));
header("Location: $location");
exit();
}
Facebook: https://www.facebook.com/sharer.php?u=[insert-post-url]
Twitter: https://twitter.com/share?text=[insert-post-title]&url=[insert-post-url]&via=@taricco
LinkedIn: https://www.linkedin.com/shareArticle?url=[insert-post-url]&title=[insert-post-title]
/** Insert post URL: [insert-post-url] **/
function insert_post_url_shortcode() {
// Check if it's a single post, page, or attachment
if (is_singular()) {
return get_permalink();
}
// Add taxonomy filter dropdowns to the Resources CPT admin page
function wsv_resources_category_filter() {
global $typenow;
if ($typenow == 'resources') {
$taxonomies = array('resource-type');
if (!empty($taxonomies)) {
foreach ($taxonomies as $taxonomy) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
/***
1 - Find and replace cpt_name with CPT name using underscore
2 - Find and replace cpt-name with CPT name using a dash (if CPT name uses a dash)
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
/* Load editor notice for CPT */
function wsv_cpt_name_notice_script() {
// Ensure we are on the admin screen to prevent errors on the front end
if (is_admin()) {
// Get the current screen object
/*** Set default editor content for Video CPT using a specific Local Pattern
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function add_or_replace_content_with_gb_template_for_video_posts($data, $postarr) {
// Only target the 'video' post type
if ($data['post_type'] == 'video') {
// Define your gblocks_templates Post ID
$gb_template_post_id = 5593; // Replace 5501 with your actual gblocks_templates Post ID
// Get the content of the gblocks_templates post
$gb_template_post = get_post($gb_template_post_id);
/*** TODAY VERSION - Custom function for making the /matchday/ URL redirect to the next upcoming match URL
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_action('template_redirect', 'redirect_to_next_match');
function redirect_to_next_match() {
if (is_page('matchday')) { // Check if the current page is /matchday/
$today = date('Ymd'); // Get today's date in ACF's preferred format.
$args = array(
'post_type' => 'match', // Your custom post type.
'posts_per_page' => 1, // We only need the next match.
'meta_key' => 'match_date', // The ACF field key for the match date.