Skip to content

Instantly share code, notes, and snippets.

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

mark l chaves marklchaves

🏄‍♂️
View GitHub Profile
@marklchaves
marklchaves / remove_popup_maker_wpadmin_menu.php
Created March 27, 2025 03:29
Remove Popup Maker from the wp-admin side menu for non-admins.
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_action( 'admin_init', function () {
if ( ! current_user_can( 'manage_options' ) ) {
remove_menu_page( 'edit.php?post_type=popup' ); // Popup Maker
}
} );
/**
 * You can add the PHP code snippet to your child theme's functions.php file
@marklchaves
marklchaves / save_popup_when_toggle_enabled.php
Last active March 19, 2025 12:31
Force a popup to save when you toggle the Enabled button on the All Popups page.
<?php // Ignore this first line when copying to your child theme's functions.php file.
// Test utility
add_action('admin_notices', function() {
// Only show on popup edit screen after saving.
if (!isset($_GET['post']) || get_post_type($_GET['post']) !== 'popup') {
return;
}
// Display the last saved time from a transient.
@marklchaves
marklchaves / launch_popup_after_time_on_site.php
Last active March 3, 2025 10:29
Launch popup after time on site is more than 1 minute (regardless of how many pages visited).
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* This is an example of how to launch a Popup Maker popup after time on site is more
* than 1 minute (regardless of how many pages visited).
*
* Run this action at 500 priority.
*
* Change the popupId value to your popup's ID https://wppopupmaker.com/docs/manage-features-or-options/find-the-popup-id/
*
@marklchaves
marklchaves / close_popup_on_scroll.php
Last active February 20, 2025 04:30
Load custom jQuery in the footer that closes a popup on scroll
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Close a popup on a window scroll event.
*/
function close_popup_on_scroll() { ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
// Set up your constants.
@marklchaves
marklchaves / acf_shortcode_hooks.php
Last active December 24, 2024 06:53
1) Turn on the ACF shortcode if you have a new install of ACF and bypass the non-public post check. 2) If the shortcode doesn't work, use a Popup Maker filter to tack on the popup's ACF if it has one. I.e., use 1 or the other not both.
<?php // Ignore this first line when copying to your child theme's functions.php file.
/** Try using the ACF shortcode first. */
/** Turn on the ACF shortcode as of ACF 6.3.0.
* https://www.advancedcustomfields.com/resources/shortcode/#enabling */
add_action( 'acf/init', 'set_acf_settings' );
function set_acf_settings() {
acf_update_setting( 'enable_shortcode', true );
}
@marklchaves
marklchaves / createCookieBeforeRedirect.js
Last active October 20, 2024 11:55
Create a popup cookie when you click a link but before navigating to that link
jQuery(document).ready(function ($) {
// Listen for the link click, then do stuff.
// Link will be something like <a class="do-something" href="https://myawesomewebsite.xyz/my-redirect-page/">Click me!</a>
$('.do-something').click(function (e) {
e.preventDefault(); // Don't redirect yet.
console.log('Creating the cookie.');
$('#popmake-160').trigger('pumSetCookie'); // Set the cookie first. Change to your cookie name.
@marklchaves
marklchaves / force-vimeo-autoplay-0.js
Created August 23, 2024 11:04
Force autoplay=0 (off) for a Vimeo video that opens in an iframe tag.
(function () {
document.addEventListener("DOMContentLoaded", function () { // Wait for all the contents to load.
const elts = document.querySelectorAll("figure a"); // Select all video gallery links.
if (!elts.length) return; // If nothing, bail early.
[...elts].map((elt) => { // Loop over each link.
elt.addEventListener("click", function (e) { // Listen for a click on each gallery link.
console.log("Got a click on a gallery item.");
setTimeout(function () { // Wait for the iframe b/c it loads dynamically.
console.log("Overwriting the autoplay to 0!");
let iElt = document.querySelector("iframe");
@marklchaves
marklchaves / cf7_set_cookie_on_redirect.php
Last active August 30, 2024 00:38
Force setting a popup cookie on forms redirect for Contact Form 7 (CF7), Gravity Forms, and WPForms
@marklchaves
marklchaves / hideFormAndRedirect.js
Created August 4, 2024 15:42
After submit, hide the Contact Form 7 form so only the success message shows then redirect after 3 seconds
document.addEventListener( 'wpcf7mailsent', function( event ) {
document.querySelectorAll("form.wpcf7-form > :not(.wpcf7-response-output)").forEach(el => {
el.style.display = 'none';
});
// Redirect on submission
setTimeout( () => {
location = '/my-redirect-page/'; // TO DO: Put your URL or slug here.
}, 3000 ); // Wait for 3 seconds to redirect. Change the delay to what you want.
}, false );
@marklchaves
marklchaves / add_font_family_and_size.php
Last active August 19, 2024 00:08
Add Font Family and Custom Font Size Options to TinyMCE
<?php // Ignore this first line when copying to your child theme's functions.php file.
// Turn on font size & font family selects in the classic editor.
add_filter( 'mce_buttons_2', function( $buttons ) {
array_unshift( $buttons, 'fontselect' );
array_unshift( $buttons, 'fontsizeselect' );
return $buttons;
} );
/**