Skip to content

Instantly share code, notes, and snippets.

View polevaultweb's full-sized avatar

Iain Poulson polevaultweb

View GitHub Profile
<?php
/**
* Create a POST Webhook action with one arg, the key of 'cv_file_attach' and value of '{field:cv_file_attach:url}'
* Change the key and value to suit the File Upload field. Change the key in the code below.
*/
add_filter( 'nf_remote_post_args', function ( $args ) {
if ( ! isset( $args['body']['cv_file_attach'] ) ) {
return $args;
}
<?php
add_filter( 'pre_update_option_wp-oauth2-tokens', function ( $value, $old_value ) {
if ( empty( $old_value['google'] ) ) {
// Google not connected
return $value;
}
if ( ! empty( $old_value['google'] ) && ! empty( $value['google'] ) ) {
// Google still connected
return $value;
@polevaultweb
polevaultweb / wpum_resize_avatars.php
Created October 15, 2019 10:32
WP User Manager - Resize avatar uploads to a specific size
<?php
add_filter( 'wpum_upload_file_pre_upload', 'wpum_resize_avatar_images', 10, 2 );
function wpum_resize_avatar_images( $file, $args ) {
if ( ! isset( $args['file_key'] ) || 'user_avatar' !== $args['file_key'] ) {
return $file;
}
$editor = wp_get_image_editor( $file['tmp_name'] );
if ( is_wp_error( $editor ) ) {
@polevaultweb
polevaultweb / redirect_to_account_tab.php
Created October 14, 2019 08:03
Redirect to the account tab after saving the setting in WP User Manager
<?php
add_filter( 'wp_redirect', function ( $location ) {
if ( ! isset( $_POST['wpum_form'] ) || 'profile' !== $_POST['wpum_form'] ) {
return $location;
}
if ( empty( $_POST['_wp_http_referer'] ) ) {
return $location;
}
@polevaultweb
polevaultweb / nf_fu_acf_gallery.php
Created October 2, 2019 10:33
Use Ninja Forms File Upload fields as the source of an ACF Gallery field, when using the Post Creation addon.
@polevaultweb
polevaultweb / nf_fu_acf_gallery.php
Created October 2, 2019 10:33
Use Ninja Forms File Upload fields as the source of an ACF Gallery field, when using the Post Creation addon.
@polevaultweb
polevaultweb / ninja-forms-uploads-dropbox-filename.php
Created July 22, 2019 20:29
Make sure any uploads to Dropbox don't have the random timestamp prefix.
<?php
add_filter( 'ninja_forms_uploads_dropbox_filename', 'my_dropbox_filename', 10, 2 );
function my_dropbox_filename( $filename, $original_filename ) {
return $original_filename;
}
@polevaultweb
polevaultweb / ninja-forms-uploads-debugger.php
Created May 16, 2019 11:16
Debug data about Ninja Forms File Uploads, install as a normal plugin or as an mu-plugin.
<?php
/**
* Plugin Name: Ninja Forms Uploads Debugger
* Plugin URI: https://ninjaforms.com/extensions/file-uploads/
* Description: Debugger plugin
* Version: 3.0
* Author: polevaultweb
* Author URI: https://polevaultweb.com
*/
@polevaultweb
polevaultweb / dbi-woo-slack-command.php
Last active May 15, 2019 12:51
WooCommerce Slack Slash Command WordPress plugin
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'dbi', 'slash-woo/', array(
'methods' => 'POST',
'callback' => 'slack_woo_command',
) );
} );
function slack_woo_command( $request ) {
$command = filter_input( INPUT_POST, 'command', FILTER_SANITIZE_STRING );
<?php
add_filter( 'wpmdb_process_column_as_binary', function( Bool $process_as_binary, stdClass $struct ) {
return ( true == $process_as_binary ) ? true :
in_array( strtolower( trim( $struct->Type ) ), [
'geometry',
'point',
'linestring',
'polygon',
'multipoint',