Skip to content

Instantly share code, notes, and snippets.

View mrbobbybryant's full-sized avatar

Bobby Bryant mrbobbybryant

View GitHub Profile
@mrbobbybryant
mrbobbybryant / loadmore.js
Last active November 13, 2022 01:58
Example WordPress Rest API pagination abstraction
import queryString from 'query-string';
import { getSpinner } from './components';
/**
* Implementation Example at the very bottom.
*/
export default function( settings ) {
let page = 2;
let buttonContent;
let headers;
@mrbobbybryant
mrbobbybryant / get-image.php
Created March 3, 2017 22:13
Get Custom Image
<?php
/**
* This function will return all the image data (id, url)
* @param $post_id int The post id.
* @param $name string the name of your custom field you used when creating the field.
*
* @return mixed
*/
function get_custom_upload( $post_id, $name ) {
@mrbobbybryant
mrbobbybryant / fizzbuzz.js
Created June 30, 2016 03:18
My answer to the fizzbuzz coding challenge
function divisibleBy3(number) {
return number % 3 === 0;
}
function divisibleBy5(number) {
return number % 5 === 0;
}
function divisibleByBoth(number) {
return divisibleBy3(number) && divisibleBy5(number);
function nodeListMap(data) {
return function(callback) {
return [].map.call( data, callback );
}
}
function nodeListMap(data, callback) {
return [].map.call( data, callback );
}
@mrbobbybryant
mrbobbybryant / random-stuff.js
Created April 3, 2016 22:35
Random js things
/**
* Function converts the user provided query object into an encoded query string.
* @param {Object} argsObj The user provided query object from query method.
* @return {String} The query string portion of the endpoint url.
*/
const buildQuery = (argsObj) => {
let queryString = [];
for (var property in argsObj) {
if (argsObj.hasOwnProperty(property)) {
queryString.push(
<div style="width: 70%; margin: 0 auto;">
<form id="user-post">
<?php wp_nonce_field( basename( __FILE__ ), 'user-submitted-question' ) ?>
<input type="text" id="user-name" name="user-name" placeholder="Name" style="margin-bottom: 10px;">
<input type="text" id="user-email" name="user-email" placeholder="Email" style="margin-bottom: 10px;">
<select name="product" id="product" style="margin-bottom: 10px;">
<option value=""></option>
<option value="hosting">Hosting</option>
<option value="themes">Themes</option>
<option value="plugins">Plugins</option>
$( document).ready( function() {
var userSubmitButton = document.getElementById( 'user-submit-button' );
var adminAjaxRequest = function( formData, action ) {
$.ajax({
type: 'POST',
dataType: 'json',
url: screenReaderText.adminAjax,
data: {
action: action,
@mrbobbybryant
mrbobbybryant / user-data.php
Created February 27, 2016 17:46
code snippet from the User Generated data video
<?php
function register_user_question_content_type() {
$post_labels = array(
'name' => 'User Questions',
'singular_name' => 'User Question',
'add_new' => 'Add New',
'add_new_item' => 'Add New User Question',
'edit' => 'Edit',
'edit_item' => 'Edit User Question',
'new_item' => 'New User Question',
@mrbobbybryant
mrbobbybryant / wp_code_context.php
Last active July 25, 2017 08:40
Allows you to dynamically determine if your code is being used in a plugin or a theme
<?php
function wp_code_context() {
$theme = strpos( __DIR__, 'themes' );
return ( $theme ) ? 'theme' : 'plugin';
}
function get_directory_by_context() {
$context = wp_code_context();
switch( $context ) {
case 'theme':
$local_dir = get_template_directory();
<?php
function read_project_svg_assets( $directory ) {
$files = [];
$path = get_template_directory() . '/library/assets/*.svg';
foreach ( glob( $path ) as $filename ) {
$path_parts = pathinfo( $filename );
$files[] = $path_parts['filename'];
}
$svgs = [];
foreach ( $files as $svg_name ) {