Skip to content

Instantly share code, notes, and snippets.

@wesrice
wesrice / gist:1551880
Created January 2, 2012 19:58
ACF Reciprocal Relationship Functionality
<?php
function update_value( $post_id, $field, $value ){
// Check to see if there are any old relationships
if( parent::get_value( $post_id, $field ) !== '' ){
// If so, find out what needs to be added or deleted
$old_value = explode( ',', parent::get_value( $post_id, $field ) );
$new_value = explode( ',', $value );
@wesrice
wesrice / random-repeater.php
Created February 27, 2012 16:02
Return a random row of data from an ACF repeater field
<?php
// Get the repeater field
$repeater = get_field( 'repeater_field_name' );
// Get a random rows. Change the second parameter in array_rand() to how many rows you want.
$random_rows = array_rand( $repeater, 2 );
// Loop through the random rows if more than one is returned
if( is_array( $random_rows ) ){
@wesrice
wesrice / wp-config-snippet.php
Created March 5, 2012 03:28
WordPress Database settings for working in multiple environments
<?php
/* Replace database connection information in wp-config.php */
// Get the host
$host = $_SERVER['HTTP_HOST'];
if( $host === 'local.website.com' || $host === 'localhost:8888' ){
// ** MySQL settings - You can get this info from your web host ** //
@wesrice
wesrice / gist:2378760
Created April 13, 2012 17:49
My default wp-config.php and why WP_UPLOAD_PATH and WP_UPLOAD_URL are logical constants
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
@wesrice
wesrice / wp-config.php
Created September 19, 2012 15:35
Multi-environment wp-config
// Get the host
$host = $_SERVER['HTTP_HOST'];
// Define the site base
$site_base = 'example.com';
// WP subdirectory
$wp_subdirectory = '';
if( $host === 'local.' . $site_base || $host === 'localhost:8888' ){
@wesrice
wesrice / gist:7725501
Created November 30, 2013 22:36
Kyle Problem
<?php
$types = explode( ",", $_GET['types'] );
foreach( $workoutmoves AS $workoutmove ):
?>
<li>
<input class="check_box" type="checkbox" <?php in_array( $workoutmove->slug, $types ) ? 'checked' : ''; ?> value="<?php echo $workoutmove->slug; ?>"> <?php echo $workoutmove->name; ?>
</li>
<?php endforeach; ?>
craft()->on('entries.saveEntry', function(Event $event) {
$entry = $event->params['entry'];
if( $event->params['entry']->sectionId == 4 ) {
craft()->request->redirect( '/admin/nameofplugin' );
}
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2014, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license Craft License Agreement
@wesrice
wesrice / _base.twig
Last active October 2, 2019 18:02
Sample Modular Templating for Craft CMS - Inspired by principles from https://smacss.com/.
<!DOCTYPE html>
<head>
{# Base #}
{% includeCssFile 'layouts/base/css/base.css' %}
{% includeJsFile 'layouts/base/js/base.js' %}
{# Header #}
{% includeCssFile 'modules/header/css/header.css' %}
{% includeJsFile 'modules/header/js/header.js' %}
@wesrice
wesrice / AbstractEntity.php
Last active August 4, 2021 22:02
Self Validating Value Objects and Entities (Laravel Implementation)
<?php
abstract class AbstractEntity extends AbstractValueObject
{
/**
* Offset Set
*
* @param mixed $offset
* @param mixed $value
*