Skip to content

Instantly share code, notes, and snippets.

View marklchaves's full-sized avatar
🏄‍♂️

mark l chaves marklchaves

🏄‍♂️
View GitHub Profile
@marklchaves
marklchaves / popup_name_sc.php
Last active September 29, 2022 22:38
Make a shortcode for a popup's name (not the title)
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Make a shortcode for a popup's name (not the title)
*
* Note: The popup's internal name is actually the CPT's title.
* The internal name is different from the popup's title.
*
* The popup's title is optional. If you enter a popup title,
* it displays as the heading of your popup (external title).
@marklchaves
marklchaves / set_never_see_again_cookie.php
Last active March 10, 2022 23:41
Example for Manually Setting a Cookie for a Popup Maker Popup
@marklchaves
marklchaves / avada-make-weekday-tab-active.php
Last active March 24, 2022 22:49
Make Today's Weekday Tab Active in the Avada WordPress Theme
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_action('wp_footer', function () {
// Only do for a post called Weekday Tabs just to avoid page bloat. Change to your
// post or page (is_page()) or remove this check if wanted.
if (!is_single('weekday-tabs')) return; ?>
<script>
(function() {
// Init some consts.
const weekDays = [
"Monday",
@marklchaves
marklchaves / popup-maker-test-rest-api-call.php
Last active June 29, 2022 11:12
Check if adblockers like Ghostery block Popup Maker REST API calls
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_action( 'wp_footer', function () { ?>
<script>
(function () {
function testRestApi(url, cb) {
jQuery.ajax({
url: url,
dataType: "text",
type: "GET",
@marklchaves
marklchaves / open_delayed_popup_after_cookie_confirmation.php
Last active February 25, 2022 04:24
Open a Delayed Popup After Cookie Confirmation
@marklchaves
marklchaves / add-favorite-menu-items-to-top-right-menubar.php
Created February 22, 2022 03:49
Put my go-to menu items in the top-right admin toolbar ;-)
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_action('admin_bar_menu', function(WP_Admin_Bar $admin_bar) {
// Plugins
$admin_bar->add_menu( array(
'id' => 'my-plugins',
'parent' => 'top-secondary',
'title' => 'Plugins',
'href' => 'plugins.php',
'meta' => array(
@marklchaves
marklchaves / popup-maker-run-pum-debug.js
Created February 22, 2022 03:23
This tacks on pum_debug=true to a URL to run the Popup Maker debugger
javascript:window.location.search += '&pum_debug=true';
@marklchaves
marklchaves / popup-maker-display-list-of-popups-dropdown.js
Created February 22, 2022 03:18
Chrome snippet to display a dropdown list of all Popup Maker popups loaded on a page
// https://docs.wppopupmaker.com/article/512-popup-maker-debug-tools
javascript: (function($) {
var $select = $('<select>').attr('id', 'pum-popup-select').css({
zIndex: 9999999999999999,
position: 'fixed',
top: 0,
right: 0
}).on('change', function() {
PUM.open($select.val());
$(this).remove();
@marklchaves
marklchaves / content-control-disable-if-elementor-live-preview.php
Last active June 28, 2022 06:49
Disable Content Controls if Elementor Preview Mode is Active
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Disable Content Control if Elementor Preview Mode is Active
*
* References:
* - https://code.elementor.com/methods/elementor-preview-is_preview_mode/
* - https://ralphjsmit.com/elementor-check-active/
*/
@marklchaves
marklchaves / filter_product_query_on_attribute_and_role.php
Last active February 23, 2022 22:45
Filter the WooCommerce product query based on logged-in role and product attribute.
<?php // Ignore this first line when copying to your child theme's functions.php file.
function filter_product_query_on_attribute_and_role($tax_query, $query)
{
// Step 1: Filter the role.
if (wp_get_current_user()->roles[0] != 'wholesale') return $tax_query; // Logged-in except wholesale can see.
// More examples:
// 1. Filter all roles except for wholesale.
// if ( wp_get_current_user()->roles[0] == 'wholesale' ) return $tax_query; // Only a logged-in wholesale role can see.