Skip to content

Instantly share code, notes, and snippets.

@jb510
jb510 / snippet.php
Created February 29, 2024 16:34
Add Plugins menu item to top level admin bar in WordPress
<?php
/**
* Customize admin bar items
*
* @since 1.0
* @author Jon Brown
* @global array $wp_admin_bar
*/
function s9_customize_admin_bar_items() {
global $wp_admin_bar;
@jb510
jb510 / snippet.php
Created February 29, 2024 05:48
Add "Manage Patterns" menu item under Pages
<?php
/**
* Adds a menu item to the admin menu for managing patterns
*/
function s9_add_manage_patterns_menu() {
// Check if the current user has the capability to edit pages
if (!current_user_can('edit_pages')) {
return;
}
.yst-grid.yst-gap-6.yst-grid-cols-1.sm\:yst-grid-cols-2.min-\[783px\]\:yst-grid-cols-1.lg\:yst-grid-cols-2.\32 xl\:yst-grid-cols-3.min-\[1800px\]\:yst-grid-cols-4 {
grid-template-columns: repeat(1,minmax(0,1fr))!important;
}
img.yst-w-full {
display: none;
}
.xl\:yst-max-w-3xl.xl\:yst-fixed.xl\:yst-right-8.xl\:yst-w-\[16rem\] {
display: none;
@jb510
jb510 / members-protect-cpt-default-roles.php
Created March 30, 2022 07:15
Members Plugin set default content protection roles by Custom Post Type
<?php
add_filter( 'members_default_post_roles', 's9_members_force_content_protection' );
function s9_members_force_content_protection( $roles ) {
if ( 'minutes' === get_post_type( get_the_ID() ) ) {
$roles = array( 'board_member', 'home_owner' );
}
return $roles;
}
@jb510
jb510 / gist:a4e44167bef2c7f89fb3765066601909
Created March 29, 2022 02:43
WooCommerce Delete Product Images with Product Deletion
<?php
/**
* WooCommerce Delete Product Images with Product Deletion
*
* @since 2.1.0
* @link https://gitlab.com/9seeds/plugins/9s-core-functionality
*
* @author Jon Brown <jb@9seeds.com>
* @copyright Copyright (c) 2022, Jon Brown
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
@jb510
jb510 / gist:7a374a97a378525a15aef4536fd7a5a3
Last active March 16, 2022 05:18
WooCommerce Subscriptions Update All Addresses checked by default and change label adding html link
<?php
// WooCommerce Subscription Update Address Checkbox checked by default
add_filter( 'wcs_update_all_subscriptions_addresses_checked', '__return_true' );
// WooCommerce Subscription Update Address Change Label
add_filter( 'woocommerce_form_field_args', 'my_woocommerce_form_field_args', 10, 3 );
function my_woocommerce_form_field_args( $args, $key, $value ) {
if ( function_exists ('wcs_get_address_type_to_display') && $key == 'update_all_subscriptions_addresses' ) {
@jb510
jb510 / s9_scroll_to_top_on_pagination
Last active January 16, 2022 02:53
FacetWP Scroll to Top on Pagination
// Add FacetWP scroll to top of content on pagination
add_action('wp_head','s9_scroll_to_top_on_pagination');
function s9_scroll_to_top_on_pagination() {
echo <<<END
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if ( FWP.soft_refresh == true ) {
FWP.enable_scroll = true;
} else {
@jb510
jb510 / gist:68c092853a8bcae1c6c5b886a49da97e
Created December 18, 2021 07:01
Register custom taxonomy on woocommerce product and add to REST API
/*
Simple Taxonomy */
add_action( 'init', function() {
register_extended_taxonomy( 'customtax', 'product' ); // This relies on https://github.com/johnbillion/extended-cpts/
} );
//Register taxonomy API for WC
add_action( 'rest_api_init', function() {
register_rest_field('product', 'customtax', array(
@jb510
jb510 / gist:30dd61ad8d25476907dcb164ba4a1e24
Last active May 5, 2024 22:16
Delete WordPress tags MySQL
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );
DELETE FROM wp_term_taxonomy WHERE term_id not IN (SELECT term_id FROM wp_terms);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
@jb510
jb510 / Hide Post Editor Tip about Permalinks being the last part of the URL
Created August 2, 2020 22:57
Hide Post Editor Tip about permalinks being the last part of the URL on the WordPress post editor
<?php
/**
* Hide Post Editor Tip about permalinks
*/
add_action( 'admin_head', 's9_hide_permalink_tip' );
function s9_hide_permalink_tip() {
echo '<style>';
echo '#editor .edit-post-sidebar .editor-post-link .components-base-control + p { display: none; }';
echo '</style>';
}