Skip to content

Instantly share code, notes, and snippets.

@danieliser
danieliser / prevent-post-delete.php
Created March 2, 2015 08:36
Prevent users from deleting a specific page, post or CPT in WordPress.
function prevent_default_theme_deletion($allcaps, $caps, $args) {
$post_id = 123;
if ( isset( $args[0] ) && isset( $args[2] ) && $args[2] == $post_id && $args[0] == 'delete_post' ) {
$allcaps[ $caps[0] ] = false;
}
return $allcaps;
}
add_filter ('user_has_cap', 'prevent_default_theme_deletion', 10, 3);
@danieliser
danieliser / es5.js
Last active February 27, 2024 23:11
Convert Hex Color to rgba with opacity
/**
* ECMA2015
*/
function convertHex(hexCode, opacity = 1){
var hex = hexCode.replace('#', '');
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
@danieliser
danieliser / subscribe-to-download-popup-maker-ninja-forms.js
Last active July 20, 2023 04:15
Javascript used to set the value of a hidden form field inside a popup based on the url of a click trigger.
(function ($) {
var popupID = 123,
hiddenFieldSelector = '#nf-field-1';
$(document).on('pumBeforeOpen', '#pum-'+popupID, function () {
var trigger = $.fn.popmake.last_open_trigger[0],
field = $(hiddenFieldSelector);
if (trigger && "" !== trigger.href) {
field.val(trigger.href);
@danieliser
danieliser / functions.php
Last active April 13, 2023 16:48
Fetch Active Install Count from WordPress Plugins API
<?php
function get_plugin_install_count( $plugin ) {
$api = plugins_api( 'plugin_information', array(
'slug' => 'popup-maker',
'fields' => array( 'active_installs' => true )
) );
if( ! is_wp_error( $api ) ) {
return $api->active_installs;
}
@danieliser
danieliser / functions.php
Last active April 13, 2023 16:48
Plugins API Active Install Count Shortcode for WordPress
<?php
function plugin_install_count_shortcode( $atts ) {
$a = shortcode_atts( array(
'plugin' => NULL,
), $atts );
if( ! $a['plugin'] ) {
return;
}
@danieliser
danieliser / hide-header-footer-in-iframe.css
Last active April 12, 2023 11:11
Automatically hide elements on your site if its loaded in an iframe. JavaScript is used to detect when in a frame and add a class to the <html> element. CSS can then be used to hide or show elements.
@danieliser
danieliser / Set Cookie on Form Submit and Close
Last active February 1, 2023 03:44 — forked from rgadon107/Set Cookie on Form Submit and Close
Custom function to pass in a jQuery script to set a cookie via manual JS during 'on_click' trigger event and on form close.
@danieliser
danieliser / pm-mc4wp-close-popup-after-submit.js
Last active December 8, 2022 22:54
Popup Maker: Close any popup after successful AJAX submission for Mailchimp for WordPress plugin.
jQuery(document).on('subscribe.mc4wp','.popmake-content .mc4wp-form', function() {
var $popup = PUM.getPopup(this);
$popup.trigger('pumSetCookie');
setTimeout(function () {
$popup.popmake('close');
}, 5000); // 5 seconds
});
@danieliser
danieliser / rename-plugins-after-update.php
Last active November 28, 2022 18:40
This code works to update addon/extension plugin slugs during update from a premapped list. Code likely needs to be run in separate plugin/theme/mu-plugin/drop-in.
<?php
/**
* This code works to update addon/extension plugin slugs during update from a premapped list.
*
* Code likely needs to be run in separate plugin/theme/mu-plugin/drop-in.
*
* Tested Working On:
* - Single Site: Updates Page - Singe Plugin.
@danieliser
danieliser / password-pages.php
Last active November 21, 2022 03:49
Examples of how to add custom conditions to Popup Maker v1.4+.
<?php
/**
* Conditions are applied to popups based on the current page being viewing.
*
* Ex. Show Popup if the current page is ____ (AND/OR) ____
*
*
* All Conditions should return false by default AND only true if 100% matched.
*