Skip to content

Instantly share code, notes, and snippets.

@danieliser
danieliser / disable-auto-open-if-GET-value-empty.php
Created September 20, 2015 19:35
Disable auto open for a popup if $_GET parameter is missing or empty.
<?php
add_action( 'popmake_get_the_popup_data_attr', 'my_custom_popup_data_attr', 10, 2 );
function my_custom_popup_data_attr( $data_attr, $popup_id ) {
if ( $popup_id == 123 && empty( $_GET['popup'] ) ) {
unset( $data_attr['meta']['auto_open'] );
}
return $data_attr;
}
@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 / 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 / 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;
@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 / edd-clean-expired-unused-discounts.php
Created June 1, 2016 21:31
Auto clean expired discount codes.
<?php
/*
Plugin Name: Easy Digital Downloads - Clean unused & expired discounts
Version: 1.0
Description: Clears expired & unused discounts in EDD daily.
Author: Daniel Iser
Author URI: http://presspowered.com
Original Author: Danny van Kooten
Original Author URI: http://dvk.co/
@danieliser
danieliser / reorder_wp-admin_submenu_by_custom_order.php
Created January 27, 2016 05:21
This filter and array sorting callback will allow you to set WordPress admin submenu items in specific orders. You can even assign the first or last positions independently. This is used to sort the Popup Maker admin menu and allows extensions to reliably be added between Add New & Settings/Support.
<?php
/**
* Submenu filter function. Tested with Wordpress 4.1.1
* Sort and order submenu positions to match our custom order.
*
* @author Daniel Iser<danieliser@wizardinternetsolutions.com>
*/
function pum_reorder_admin_submenu() {
global $submenu;
@danieliser
danieliser / functions.php
Created March 30, 2016 18:57
Trigger loaded popups using url hashes. EX. URL http://example.com#popmake-123 would trigger popup 123 on page load.
<?php
add_action( 'wp_footer', 'custom_popup_js', 1000 );
function custom_popup_js() { ?>
<script type="text/javascript">
(function ($, document) {
$(document).ready(function () {
var hash = window.location.hash,
selector = $('#'+hash);
if (selector.length) {
selector.popmake('open');