Skip to content

Instantly share code, notes, and snippets.

View jondcampbell's full-sized avatar

Jon Campbell jondcampbell

View GitHub Profile
@chriscct7
chriscct7 / gist:d7d077afb01011b1839d
Last active January 24, 2024 04:20
Plugins that need to be updated to be ready for the move to PHP 5 constructors

Important Notice for WordPress Plugins Using PHP 4 Style Constructors

The ability to use PHP 4 style constructors is getting removed from PHP. Without an update, many plugins will eventually no longer work (this is PHP breaking this backwards compatibility, not WordPress)

One of the more common uses of the PHP 4 style constructor (as opposed to PHP 5 style __construct() ) are plugins with widgets calling WP_Widget::WP_Widget() and/or parent::WP_Widget() and/or {object}->WP_Widget()

Note: Starting in WordPress 4.3, regardless of the PHP version in use on a server, WordPress will throw a deprecated notice when one of the PHP 4 style constructors is called specifically for widgets.

Basically instead of doing these:

@maxrice
maxrice / wc-local-pickup-plus-remove-pickup-location.php
Created June 9, 2015 18:48
WooCommerce Local Pickup Plus - Remove pickup location action
function wc_local_pickup_plus_remove_pickup_location() {
$methods = WC()->shipping->load_shipping_methods();
if ( isset( $methods['local_pickup_plus'] ) ) {
remove_action( 'woocommerce_after_template_part', array( $methods['local_pickup_plus'], 'review_order_shipping_pickup_location' ), 10, 4 );
}
}
add_action( 'wc_shipping_local_pickup_plus_init', 'wc_local_pickup_plus_remove_pickup_location' );
@aaroneaton
aaroneaton / Navigation.php
Last active March 7, 2017 19:10
Using the Zurb Foundation Top Bar with WordPress menus
<?php
class Navigation {
public function __construct() {
// Move the navigation to the header element
remove_action( 'genesis_after_header', 'genesis_do_nav' );
remove_action( 'genesis_site_title', 'genesis_seo_site_title' );
// remove_action( 'genesis_header', )
@thoronas
thoronas / gist:2876f159404b7547d89b
Last active August 29, 2015 14:24
Function for uploading images from URL to WordPress. Thanks to Andrew Norcross for help with this.
<?php
function upload_external_image( $post_id, $img_url ) {
// load media handlers
require_once( ABSPATH . 'wp-admin' . '/includes/image.php' );
require_once( ABSPATH . 'wp-admin' . '/includes/file.php' );
require_once( ABSPATH . 'wp-admin' . '/includes/media.php' );
// create a temp file
$temp_file = download_url( $img_url );
// Change the column widths to match your site
@media #{$large-up} {
.content-sidebar .content-sidebar-wrap {
main {
@include grid-column(9);
}
aside.sidebar-primary {
@include grid-column(3);
}
@spivurno
spivurno / gw-gravity-forms-populate-field-value-into-subsequent-field.php
Created November 16, 2015 02:46
Gravity Wiz // Gravity Forms // Populate Field Value from One Page to Field in Subsequent Page
/**
* Gravity Wiz // Gravity Forms // Populate Field from One Page to Field in Subsequent Page
* http://gravitywiz.com/
*/
// update "1074" to the ID of your form
add_filter( 'gform_pre_render_1074', function( $form ) {
foreach( $form['fields'] as &$field ) {
// update "2" to the field ID on the later page
@wesbos
wesbos / gist:0d5572a29e4f5688a1c8
Last active September 1, 2023 17:59
Handy list of widths to target in a responsive website
320
321
322
323
324
325
326
327
328
329
@spivurno
spivurno / gp-preview-submission-display-filename.php
Created March 14, 2017 13:36
Gravity Perks // GP Preview Submission // Display Filename for File Upload Fields
<?php
/**
* Gravity Perks // GP Preview Submission // Display Filename for File Upload Fields
* http://gravitywiz.com/documentation/gravity-forms-preview-submission/
*/
add_filter( 'gpps_special_merge_tags_value_fileupload', function( $value, $field, $input_id, $modifier, $form, $entry ) {
if( ! $field->multipleFiles ) {
$input_name = 'input_' . str_replace( '.', '_', $field->id );
$file_info = GFFormsModel::get_temp_filename( $form['id'], $input_name );
@jtsternberg
jtsternberg / recursive-array-calculate.php
Last active December 28, 2017 23:48
Recursively calculate totals from an array of arrays (with matching keys, etc)
<?php
/**
* Calculate totals from a nested array. Handles nested recursion.
* Uses first nested array as the "pattern" for building the totals array.
*
* @param array $to_count The multi-dimensional array to calculate the totals for.
*
* @return array The array of totals.
*/
function calculate_array_totals( $to_count ) {

Familiar Tools

A way for me to remember what my go-to libraries and utilities are.

PHP

Working with APIs

  • HTTP Requests - Guzzle
  • Logging - Monolog

JavaScript

VueJS