Skip to content

Instantly share code, notes, and snippets.

View samjco's full-sized avatar

Sam C. samjco

View GitHub Profile
@kcpt-steven-kohlmeyer
kcpt-steven-kohlmeyer / query-hooks.php
Created February 9, 2015 22:51
Virtual URLs to modify query
<?php
function add_custom_query_vars($vars) {
$vars[] = "past_events";
return $vars;
}
// hook add_query_vars function into query_vars
add_filter('query_vars', 'add_custom_query_vars');
@kcpt-steven-kohlmeyer
kcpt-steven-kohlmeyer / redirect-subscriber.php
Created February 9, 2015 21:25
Wordpress: Redirect subscribers from accessing admin.
<?php
global $current_user; // Use global
get_currentuserinfo(); // Make sure global is set, if not set it.
if ( user_can( $current_user, "subscriber" ) ) {
// Disable admin bar for subscribers
show_admin_bar(false);
// Turns all textareas into medium-editors
// requires:
// - Medium-Editor
// - jQuery (can be easily rewritten without)
// - find_with_mutations: https://gist.github.com/hampei/7620643
// - sync_node_html_to_form_field: https://gist.github.com/hampei/7620825
window.textareas_to_medium_editor = function() {
find_with_mutations('form', 'textarea', function(el) {
el.style.display = 'none'; // hide the textarea
editor = $('<div />'); // create editor element
@srikat
srikat / functions.php
Last active July 19, 2017 05:37
How to display Posts from a Category in columns using Display Posts Shortcode. https://sridharkatakam.com/how-to-display-posts-from-a-category-in-columns-using-display-posts-shortcode/
// Register a custom image size for Featured Category images
add_image_size( 'featured-cat-image', 300, 200, true );
/**
* Add Column Classes to Display Posts Shortcodes
* @author Bill Erickson
* @link http://www.billerickson.net/code/add-column-classes-to-display-posts-shortcode
*
* Usage: [display-posts columns="2"]
*
<?php
/**
* Get a field value and send to remote API
*/
add_action( 'caldera_forms_submit_complete', function( $form, $referrer, $process_id ) {
//change your form ID here
if( 'cf123..' != $form[ 'ID' ] ) {
return;
}
@Shelob9
Shelob9 / all-fields.php
Created May 2, 2017 19:09
Get all field IDs or field slugs or field labels from a Caldera Form
<?php
/**
Get all field IDs or field slugs or field labels from a Caldera Form
*/
//Get form config
$form = Caldera_Forms_Forms::get_form( 'CF58c1e0a4d7c27' );
//Get all fields in order
$fields = Caldera_Forms_Forms::get_fields( $form, true );
<?php
/**
* Delete all form configs, but no entries.
*/
$forms = Caldera_Forms_Forms::get_forms( false, true );
foreach ( $forms as $form ){
Caldera_Forms_Forms::delete_form( $form );
}
<?php
add_filter( 'caldera_forms_submission_url', function( $url, $form_id ){
if( 'CF582e6cf914f03' == $form_id ){
$url = 'https://somesite.com/api';
}
return $url;
}, 25, 2 );
<?php
/*
Plugin Name: Custom Caldera Forms Field
*/
add_filter('caldera_forms_get_field_types', 'slug_add_field');
function slug_add_field($fieldtypes){
$fieldtypes['field_name'] = array(
"field" => "Field Name",
@danielpataki
danielpataki / author-removal.php
Last active December 18, 2018 23:10
Modifying Twenty Fifteen
<?php
// Author bio.
if ( is_single() && get_the_author_meta( 'description' ) ) :
get_template_part( 'author-bio' );
endif;
?>