Skip to content

Instantly share code, notes, and snippets.

View danieliser's full-sized avatar

Daniel L. Iser danieliser

View GitHub Profile
@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 / pm-ninja-forms-close-popup-after-submit.js
Last active June 8, 2016 04:36
Popup Maker: Close any popup after successful AJAX submission for Ninja Forms.
jQuery('.popmake .ninja-forms-form').on('submitResponse', function(e, response) {
var $popup = jQuery(this).parents('.pum'),
errors = response.errors;
if (errors === false) {
$popup.trigger('pumSetCookie');
setTimeout(function () {
$popup.popmake('close');
}, 5000); // 5 seconds
@danieliser
danieliser / fsconcept-comment-checking.php
Created October 22, 2015 16:24
Freemius Concept: Comment Checking
<?php
global $fs;
$values = array(
'free1' => 'Free 1',
'free2' => 'Free 2',
# if ( $fs->is__premium_only() ) :
'pro1' => 'Pro 1',
'pro2' => 'Pro 2',
# endif;
@danieliser
danieliser / class-chaining-demo.php
Last active November 6, 2015 07:46
A short demo of how you can chain set and get methods. This could be the basis for a plain English PHP library where you functions are very semantic and programming is more like writing sentences than code.
<?php
class Chain_Demo {
private $variable = null;
private $method = 'get';
public function set() {
$this->method = 'set';
return $this;
@danieliser
danieliser / function.php
Last active October 4, 2017 19:31
ReOpen popup 123 when form is submitted. This is needed when the form doesn't support ajax submission. The $_POST key & value will vary based on your form and will need to be replaced.
<?php
add_action( 'wp_footer', 'pum14_popup_reg_form_check', 1000 );
function pum14_popup_reg_form_check() {
if ( isset( $_POST['form_id'] ) && $_POST['form_id'] == 'my_form' ) {
?>
<script type="text/javascript">
PUM.open(123);
</script>
<?php
}
@danieliser
danieliser / csv_to_array.php
Created December 20, 2015 00:03 — forked from jaywilliams/csv_to_array.php
Convert a comma separated file into an associated array.
<?php
/**
* Convert a comma separated file into an associated array.
* The first row should contain the array keys.
*
* Example:
*
* @param string $filename Path to the CSV file
* @param string $delimiter The separator used in the file
* @return array
@danieliser
danieliser / functions.php
Last active September 26, 2016 23:00
This will work with any of the Popup Maker newsletter integration extensions. This will close the popup when the form is submitted successfully.
<?php
add_action( 'wp_footer', 'my_custom_popup_scripts', 500 );
function my_custom_popup_scripts() { ?>
<script type="text/javascript">
(function ($) {
$('.pum_sub_form').on('pumNewsletterSuccess pumNewsletterErrorAlreadySubscribed', function () {
$(this).parents('.popmake').popmake('close');
});
@danieliser
danieliser / metabox-display-fields.php
Created December 21, 2015 06:54
​Replace line 277 of popup-maker/includes/admin/popups/metabox-display-fields.php with
<input type="checkbox" value="1" name="popup_display_position_fixed" id="popup_display_position_fixed" <?php checked( $position_fixed, 1 ); ?>/>
@danieliser
danieliser / array_sort_by_key_custom_user_defined_string_position.php
Last active January 7, 2016 21:57
PHP sort array keys by custom user defined order, placing undefined keys at the back.
<?php
function sort_by_string_position( $a, $b ) {
$num = ' Pages Posts';
$ai = stripos( $num, $a );
$bi = stripos( $num, $b );
// If its not set move it to the end of the line.
if ( ! $ai ) {
$ai = strlen( $num );
}
@danieliser
danieliser / sort_array_by_user_defined_order.php
Last active January 7, 2016 22:20
PHP Sort array by user defined order pushing unknown keys to the end of the list.
<?php
function sort_array_using_array( $a, $b ) {
$order = array(
__( 'First', 'popup-maker' ),
__( 'Second', 'popup-maker' ),
__( 'Third', 'popup-maker' ),
);
$ai = in_array( $a, $order ) ? array_search ( $a, $order ) : count( $order ) + 1;
$bi = in_array( $b, $order ) ? array_search ( $b, $order ) : count( $order ) + 1;