Skip to content

Instantly share code, notes, and snippets.

@sblomberg
sblomberg / toplytics-filter.php
Created March 29, 2017 19:25
Toplytics filter suggestion
<?php
// Add filter to determine if certain posts should excluded
add_filter( 'toplytics_exclude_post', 'check_if_topolytics_should_exclude', 10, 2 );
function check_if_topolytics_should_exclude( $should_exclude, $post_id ) {
$excluded_posts = get_peta_excluded_posts();
if ( in_array( $post_id, $excluded_posts ) ) {
$should_exclude = true;
}
return $should_exclude;
@sblomberg
sblomberg / wp-config.php
Created July 27, 2016 18:12
Log plugin activation errors to a file
<?php
// Add this to the bottom of wp-config.php to log plugin activation errors:
add_action( 'activated_plugin','fpt_save_error' );
function fpt_save_error( $tmp_plugin ) {
$out_txt = PHP_EOL . date( "Y/m/d H:i" ) . ' Plugin activation: ' . $tmp_plugin . ' ---messages--->' . PHP_EOL;
$out_txt .= ob_get_contents();
$out_txt .= PHP_EOL . '<---- end plugin activation ---' . PHP_EOL;
file_put_contents( ABSPATH. 'wp-content/uploads/plugin_activation.log', $out_txt, FILE_APPEND );
}
@sblomberg
sblomberg / class-gravity-forms-customizations.php
Last active March 16, 2017 18:32
Enable Gravity Forms honeypot by default
<?php
class Gravity_Forms_Customizations {
public static function init() {
add_action( 'gform_after_save_form', array( __CLASS__, 'enable_honeypot_on_new_form_creation' ), 10, 2 );
}
public static function enable_honeypot_on_new_form_creation( $form, $is_new ) {
if ( $is_new ) {
$form['enableHoneypot'] = true;
@sblomberg
sblomberg / class-wrapping.php
Created July 13, 2016 14:46
Wrapping functions with a class to isolate private functions
<?php
/**
* Wrapping with a class the static way:
*/
Static_Convio_Gravity_Forms_Meta::init();
class Static_Convio_Gravity_Forms_Meta {
public static function init() {
add_action( 'gform_post_update_form_meta', array( __CLASS__, 'pga_gform_post_update_form_meta' ), 10, 3 );
@sblomberg
sblomberg / constructor-vs-static.php
Last active June 6, 2016 19:33
PHP Constructor vs Static Init performance test
<pre>
<?php
ini_set( 'display_errors', 'On' );
error_reporting( E_ALL );
function test_function() {
$test = rand();
return $test;
}

Wordcamp Minneapolis 2016 - Key takeaways

Scaling

Scaling truths, according to Automattic Wordpress VIP dev Matt Perry:

  1. Wordpress is built to scale
  2. Truth #1 doesn't matter if your theme or plugin is not built to scale
  3. Sometimes even fast code is not enough, but it's a good place to start