Skip to content

Instantly share code, notes, and snippets.

View jtsternberg's full-sized avatar
😎
Awesome Motive-ing

Justin Sternberg jtsternberg

😎
Awesome Motive-ing
View GitHub Profile
@jazzsequence
jazzsequence / cmb2_add_field.sublime-snippet
Last active July 11, 2016 21:21
Sublime Text snippets
<snippet>
<content><![CDATA[
->add_field( array(
'name' => __( '${1:Field Name}', '${2:textdomain}' ),
'id' => \$prefix . '${3:field_id}',
'type' => '${4:cmb2_field_type}',
'desc' => __( '${5:Description of the field.}', '${2:textdomain}' ),
${6:'options' =>} ${7:${8:array of options or callback function},}
${9:'attributes' =>} ${10:${11:array of attributes},}
${12:'default' =>} ${13:'${14:default_value}',}

CMB2 Canned Issue Response

Unfortunately, we can't support every person's specific or custom implementations for CMB2. Github issues are reserved for confirmed bug reports and occasional feature requests. Please review the CONTRIBUTING.md for support suggestions. Please also review the additional resources listed at the bottom of that document, as the solution you're looking for may already be present.

CMB2 Taxonomy field canned response

The taxonomy fields are not intended to provide an arbitrary list of terms to pick from, but are intended to be a replacement for the default taxonomy metaboxes. I.e. they are meant to set the taxonomy terms on an object. Any other use of these types will be hacky and/or buggy. I suggest looking at building a custom field type for this: https://github.com/WebDevStudios/CMB2/wiki/Tips-&-Tricks#a-dropdown-for-taxonomy-terms-which-does-not-set-the-term-on-the-post

CMB2 wrong PR response

Thank you for

@jtsternberg
jtsternberg / gtc_list_item_add_excerpt.php
Last active January 17, 2017 03:21
Add excerpt to results from Google Analytics Top Content Widget
<?php
/**
* Add the post excerpt to the results in the Google Analytics Top Content Widget.
*
* @param string $item_html The item html.
* @param array $page The page result object from Google Analytics.
* @param WP_Post|null $wppost The WordPress post object (if we have it).
*
* @return string The modified item html.
*/
var Circle = {
radius : 0,
create : function(radius) {
// Creating prototypal linkage using Object.create
var obj = Object.create(this);
obj.radius = radius;
return obj;
},
area : function() {
@jtsternberg
jtsternberg / cmb-toggle-fields.css
Last active May 11, 2017 20:30
hidden-toggle for cmb. Works like the WordPress metabox toggle (but for only a selection of fields)
.advanced-toggle .toggle-label {
cursor: pointer;
display: block;
line-height: 3em;
border-bottom: 1px solid #e9e9e9;
border-left: 1px solid #e9e9e9;
border-right: 1px solid #e9e9e9;
padding-left: .8em;
}
.advanced-toggle .inside .cmb-row {
@aymanfarhat
aymanfarhat / urlobject.js
Last active July 27, 2017 00:04
JS utility function that: - Breaks down url to an object with accessible properties: protocol, parameters object, host, hash, etc... - Converts url parameters to key/value pairs - Convert parameter numeric values to their base types instead of strings - Store multiple values of a parameter in an array - Unescape parameter values
function urlObject(options) {
"use strict";
/*global window, document*/
var url_search_arr,
option_key,
i,
urlObj,
get_param,
key,
@jtsternberg
jtsternberg / post-endpoints.php
Last active September 25, 2017 05:02
Add custom post endpoints and misc. functionality
<?php
/**
* Handly place to define our endpoints all in one spot
* @return array Array of our endpoints
*/
function prefix_custom_endpoints() {
return array(
'portfolio',
'testimonials',
@jtsternberg
jtsternberg / cmb-select-with-optgroups.php
Last active November 15, 2017 20:38
CMB2 select field options overridden with a filter and using optgroups
<?php
function cmb_opt_groups( $args, $defaults, $field_object, $field_types_object ) {
// Only do this for the field we want (vs all select fields)
if ( '_cmb_option_field' != $field_types_object->_id() ) {
return $args;
}
$option_array = array(
'Group 1' => array(
@jtsternberg
jtsternberg / $-cache-with-find.js
Last active January 22, 2018 08:44
jQuery selector cache with reset (original: http://eamann.com/tech/selector-caching-jquery/). If commenting, please ping me on Twitter, same username.
function Selector_Cache() {
var elementCache = {};
var get_from_cache = function( selector, $ctxt, reset ) {
if ( 'boolean' === typeof $ctxt ) {
reset = $ctxt;
$ctxt = false;
}
var cacheKey = $ctxt ? $ctxt.selector + ' ' + selector : selector;
@jtsternberg
jtsternberg / gc-pull-filters.php
Last active January 24, 2018 16:25
Working with the GatherContent pull filters
<?php
/**
* Modify post data when GatherContent does a pull.
*
* @param array $post_data Array of post data to be updated/modified.
* @param GatherContent\Importer\Sync\Pull $pull_object The GC Pull object.
* @param boolean $update Whether this is a post update (vs new). Default: false.
*
* @return array Array of post data to be updated/modified.