Skip to content

Instantly share code, notes, and snippets.

@clarklab
clarklab / block-whitelist.php
Created January 28, 2020 19:05
WordPress whitelist Gutenberg blocks
<?php
/**
* Block whitelist
* Only allow certain blocks to be used
*/
add_filter( 'allowed_block_types', 'our_allowed_block_types' );
function our_allowed_block_types( $allowed_blocks ) {
@clarklab
clarklab / blocks.php
Created January 27, 2020 18:13
WordPress Gutenberg block use only once
<?php
// ... the rest of your file here
acf_register_block_type(array(
'name' => 'hero',
'title' => __('Hero'),
'description' => __('A custom hero block.'),
'render_template' => 'template-parts/blocks/hero/hero.php',
'category' => 'formatting',
@clarklab
clarklab / block-helpers.php
Last active August 3, 2021 15:58
Wordpress check if block is used first
<?php
/**
* Block helpers
* add special classes when certain blocks appear, put this in your functions.php file or include it somewhere
*/
// add block classes in body and post class
function blocks_body_class( $classes ) {
global $post;
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="List Posts From WordPress Using REST API With cURL In PHP">
<title>WordPress REST API</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
DJI Osmo Mobile http://amzn.to/2tgSBDL ($292)
DJI Osmo High Capacity Battery http://amzn.to/2tgJz9v ($42)
DJI Osmo Base http://amzn.to/2sbfVlT ($14)
DJI Osmo Tripod http://amzn.to/2tgtvVk ($55)
DJI Osmo Stick http://amzn.to/2sbNOTH ($64)
Total Retail $467
Sale Price $325
@clarklab
clarklab / get-shorty.php
Created March 30, 2017 15:07
Get first X words of WordPress post
// toss this in your functions.php (or elsewhere)
function get_shorty($count = 15){
global $post;
$str = get_the_content();
$str = implode(' ', array_slice(explode(' ', $str), 0, $count));
return $str.'...';
}
@clarklab
clarklab / shortcodes-in-ACF.php
Last active April 9, 2019 13:22
Shortcodes with Advanced Custom Fields
add_filter('acf/format_value/type=textarea', 'do_shortcode');
@clarklab
clarklab / rwd-summit-notes.md
Created March 12, 2015 17:18
RWD Summit Notes

Intro

  • find me on twitter, codepen
  • heckle me on Twitter, use the hashtag
  • a little bit about myself
  • worked on the web for over a decade now
  • just left a gig at TheZebra.com
    • a team of about 2 dozen
    • was there about 2 years
    • lone designer, lots of engineers
  • made me think about our process
@clarklab
clarklab / gist:243b58bd42dfba214b1f
Last active August 29, 2015 14:16
WordPress comment hacks
//start by checking for a couple of key pieces of info
$current_user = wp_get_current_user();
$private_comments = get_post_meta($post->ID, 'private_comments', true);
$meta_lock = get_post_meta($post->ID, 'meta_lock', true);
$time_lock = get_post_meta($post->ID, 'time_lock', true);
//if the post has the custom field 'meta_lock'
if ($meta_lock) {
//check the current user for that meta field
$user_meta_key = get_user_meta($current_user->ID, $meta_lock, true);
@clarklab
clarklab / rsvp.php
Last active December 12, 2015 08:49 — forked from technosailor/gist:1771566
Updated to function as a simple RSVP button with facepile (list of avatars from confirmed users).
<?php
class wordup_session_rsvp {
function __construct()
{
$this->hooks();
}
function hooks()