Skip to content

Instantly share code, notes, and snippets.

View karlazz's full-sized avatar

Karla Leibowitz karlazz

  • herself
  • Walnut Creek, CA
View GitHub Profile
@karlazz
karlazz / gist:8106308
Created December 23, 2013 23:02
Add a post type record to wp-post from command line. Doesn't take content (yet), needs work.
<?php
if (isset($argv[1])) $title = $argv[1]; else { print "Usage php wpinsert TITLE POSTTYPE \n -- POSTTYPE is optional and defaults to page\n"; exit; }
if (isset($argv[2])) $type = $argv[2]; else { print "Post type defaulting to PAGE\n"; $type="page"; }
//required include files
define('WP_DEBUG', false);
require('wp-blog-header.php');
require_once("wp-config.php");
require_once("wp-includes/wp-db.php");
@karlazz
karlazz / gist:8152691
Created December 27, 2013 21:14
Turn on error log for this php script.
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
error_log( "Hello, errors!" );
@karlazz
karlazz / gist:8152703
Created December 27, 2013 21:16
Quickly display multiple values on separate lines.
foreach ($d = array('<br>', self::USER, self::ENDPOINT, $query_string) as $e) {echo $e . $d[0];}
@karlazz
karlazz / gist:9511441
Created March 12, 2014 17:05
How to clear DNS cache on mavericks OS
dscacheutil -flushcache;sudo killall -HUP mDNSResponder
@karlazz
karlazz / gist:4a9feba239d548d54bb5
Created June 25, 2014 22:26
Read from a file into a multi-selector field in gravity forms
/* http://www.gravityhelp.com/documentation/page/Dynamically_Populating_Drop_Down_Fields
*/
add_filter('gform_pre_render_5', 'populate_posts');
function populate_posts($form){
foreach($form['fields'] as &$field){
if( strpos($field['cssClass'], 'multi-selector') === false) /* original had a check for $field['type'] != 'select' */
continue;
@karlazz
karlazz / gist:e207417e5165f49bee1d
Created July 3, 2014 16:41
Some gravity form field manipulations: character counter (requires plugin), field validations, preset form values, post set form value.
<?php
add_action('wp_footer', 'add_char_counter');
function add_char_counter() {
if ( is_page( array( 'add-a-highlight', 'add-a-publication' ) ) ) { ?>
<script src="/wp-content/themes/ameriflux/library/js/textcounter.min.js"></script>
<script type="text/javascript">
jQuery('.amx-title input').textcounter({
max: 250,
countDownText: "Characters Left: "
});
@karlazz
karlazz / gist:019ed5666079ec9a3f9c
Created October 2, 2014 22:17
redirect debug output to debug.log with wordpress
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@karlazz
karlazz / gist:97820f3a17f90f421ca0
Last active September 7, 2016 01:03
WP_ajax basics with nonce security part not tested
// this goes in the page template or where you need it
// make sure that your add_action and your callback are in functions, not in a page template
wp_enqueue_script('karla');
$ajax_nonce = wp_create_nonce( "karla-nonce" );
wp_localize_script('karla','getter',array('ajax_url' => admin_url( 'admin-ajax.php' ),'sugar'=>$_GET['sugar']), 'security'=> $ajax_nonce );
@karlazz
karlazz / gist:aff9c80aa804c12d0f60
Created November 29, 2014 00:24
Create an event handler for jquery from viralpatel.net
(function ($) {
$.each(['show', 'hide'], function (i, ev) {
var el = $.fn[ev];
$.fn[ev] = function () {
this.trigger(ev);
return el.apply(this, arguments);
};
});
})(jQuery);
@karlazz
karlazz / gist:d6330b8192c413259452
Last active August 29, 2015 14:14
enhance wp-config to easily toggle debugging
if (isset($_GET['debug']) ) {
define('WP_DEBUG',true);
if ( $_GET['debug']=='log') {
// Enable Debug logging to the /wp-content/debug.log file
// The web user will have to have write permission to the file
/* uncomment next to use wordpress file default of wp-content/debug.log, make sure of write permission */
//define('WP_DEBUG_LOG', true);
/* or use a file in the wp-content/uploads directory, which should always have write perms on it */
@ini_set('error_log', dirname(__FILE__) . '/wp-content/uploads/debug.log');
// Disable display of errors and warnings