Skip to content

Instantly share code, notes, and snippets.

View kjohnson's full-sized avatar

Kyle B. Johnson kjohnson

View GitHub Profile
@kjohnson
kjohnson / footer.php
Last active April 17, 2023 09:07
[WIP] AJAX request to load a form dynamically.
@kjohnson
kjohnson / ninja_forms_render_options.php
Created May 1, 2018 14:03
Set the default checked option for a select list field.
<?php
add_filter( 'ninja_forms_render_options', 'my_ninja_forms_render_options', 10, 2 );
function my_ninja_forms_render_options( $options, $settings ){
foreach( $options as &$option ){
if( 'three' == $option[ 'value' ] ){
$option[ 'selected' ] = 1;
}
}
return $options;
@kjohnson
kjohnson / database.php
Created February 17, 2018 03:44
A Heroku PostgreSQL connection for Laravel
<?php
return [
'connections' => [
'heroku_pgsql' => [
'driver' => 'pgsql',
'host' => @parse_url(getenv("DATABASE_URL"))['host'],
'port' => env('DB_PORT', '5432'),
@kjohnson
kjohnson / functions.php
Created July 22, 2017 21:31
Adds a shortcode wrapper for wp_get_attachment_image.
<?php
// ...
/*
* [attachment_image]246[/attachment_image]
*/
add_shortcode( 'attachment_image', 'my_attachment_image' );
function my_attachment_image( $atts, $content = false ){
if( ! $content || ! is_numeric( $content ) ) return;
@kjohnson
kjohnson / functions.php
Last active July 22, 2017 21:32
Adds a shortcode wrapper for wpautop.
<?php
// ...
/*
* [wpautop]Your text/shortcode here[/wpautop]
*/
add_shortcode( 'wpautop', 'my_wpautop_shortcode' );
function my_wpautop_shortcode( $atts, $content ){
@kjohnson
kjohnson / patch.txt
Created May 25, 2017 14:16
Patch for Envira Albums not returning the default `admin_body_class`
diff --git a/includes/admin/metaboxes.php b/includes/admin/metaboxes.php
index e4c02e9..9d093a4 100644
--- a/includes/admin/metaboxes.php
+++ b/includes/admin/metaboxes.php
@@ -149,7 +149,7 @@ class Envira_Albums_Metaboxes {
// Bail if we're not on the Envira Post Type screen.
if ( 'envira_album' !== $screen->post_type ) {
- return;
+ return $body_class;
@kjohnson
kjohnson / _plugin.php
Last active February 13, 2024 11:08
Ninja Forms Custom Merge Tags
<?php
/*
* Register the new merge tag class on the `ninja_forms_loaded` hook.
*/
add_action( 'ninja_forms_loaded', 'my_register_merge_tags' );
function my_register_merge_tags(){
require_once 'class.mergetags.php';
Ninja_Forms()->merge_tags[ 'my_merge_tags' ] = new My_MergeTags();
@kjohnson
kjohnson / index.php
Created March 23, 2017 17:04
An example "Resume" action for emulating the halt/redirect/resume process.
<?php if ( ! defined( 'ABSPATH' ) ) exit;
add_action( 'ninja_forms_register_actions', function( $actions ){
include_once 'resume-action.php';
$actions[ 'resume' ] = new Foo_ResumeAction();
return $actions;
});
<?php
$form_id = 1;
// Check which version of Ninja Forms.
if( ! get_option( 'ninja_forms_load_deprecated', FALSE ) ){
// Ninja Forms THREE.
// Check if Ninja Forms is loaded.
@kjohnson
kjohnson / functions.php
Created February 17, 2017 19:58
Add {all_fields_with_values} merge tag to Email Actions
<?php
//...
add_filter( 'ninja_forms_action_email_message', 'kbj_nf_email__all_fields_with_values', 10, 3 );
function kbj_nf_email__all_fields_with_values( $message, $data, $action_settings ){
if( isset( $data[ 'fields' ] ) && ! empty( $data[ 'fields' ] ) ){
$table = '<table>';
foreach( $data[ 'fields' ] as $field ){
if( ! isset( $field[ 'value' ] ) || empty( $field[ 'value' ] ) ) continue;