Skip to content

Instantly share code, notes, and snippets.

View mboynes's full-sized avatar

Matthew Boynes mboynes

View GitHub Profile
@mboynes
mboynes / codesniffer.ruleset.xml
Created March 20, 2015 15:42
WordPress Codesniffer ruleset starting point
<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards Configuration">
<!-- Set a description for this ruleset. -->
<description>Code standard rules to check against a WordPress Theme.</description>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>inc/cli.php</exclude-pattern>
<!-- Include the WordPress VIP ruleset -->
<rule ref="WordPress-VIP">
@mboynes
mboynes / fieldmanager-demo-1.php
Last active August 29, 2015 14:19
Demo for fieldmanager.org
<?php
// put this in functions.php or an include file
add_action( 'fm_post_post', function() {
$fm = new Fieldmanager_Group( array(
'name' => 'contact_information',
'children' => array(
'name' => new Fieldmanager_Textfield( __( 'Name', 'your-domain' ) ),
'phone_number' => new Fieldmanager_Textfield( __( 'Phone Number', 'your-domain' ) ),
'website' => new Fieldmanager_Link( __( 'Website', 'your-domain' ) ),
),
@mboynes
mboynes / fieldmanager-demo-2.php
Last active August 29, 2015 14:19
Slideshow demo for Fieldmanager.org
<?php
// using Fieldmanager for a slideshow - any number of slides,
// with any number of related links
add_action( 'fm_post_post', function() {
$fm = new Fieldmanager_Group( array(
'name' => 'slideshow',
'limit' => 0,
'label' => __( 'New Slide', 'your-domain' ),
'label_macro' => array( __( 'Slide: %s', 'your-domain' ), 'title' ),
'add_more_label' => __( 'Add another slide', 'your-domain' ),
@mboynes
mboynes / class-fieldmanager-context-termpage.php
Last active October 4, 2016 15:49
Use fieldmanager to create meta boxes on a subpage from a term
<?php
if ( class_exists( 'Fieldmanager_Context_Term' ) ) {
/**
* Use fieldmanager to create meta boxes on a subpage from a term
*/
class Fieldmanager_Context_Termpage extends Fieldmanager_Context_Term {
/**
@mboynes
mboynes / trait-alley-cli-bulk-task.php
Last active November 16, 2022 18:09
WP-CLI methods to iterate over any number of posts efficiently and reliably
<?php
// DEPRECATED. See https://github.com/alleyinteractive/wp-bulk-task as the successor to this trait.
/**
* Chunk up the task when you need to iterate over many posts.
*
* For instance, to iterate over every post on the site and add post meta:
*
* $this->bulk_task( function( $post ) {
@mboynes
mboynes / class-fieldmanager-datasource-cap.php
Created December 8, 2016 19:23
Co-Authors Plus datasource for Fieldmanager
<?php
if ( class_exists( 'Fieldmanager_Datasource' ) ) {
/**
* Custom Fieldmanager Datasource for Co-Authors Plus.
*/
class Fieldmanager_Datasource_CAP extends Fieldmanager_Datasource {
/**
@mboynes
mboynes / demo-datasource-cap.php
Created December 8, 2016 19:24
Demo of Fieldmanager_Datasource_CAP
<?php
require_once( __DIR__ . '/inc/class-fieldmanager-datasource-cap.php' );
add_action( 'fm_post_post', function() {
$fm = new \Fieldmanager_Group( [
'name' => 'byline',
'limit' => 0,
'label' => __( 'Author', 'cap-sandbox' ),
'sortable' => true,
'add_more_label' => __( 'Add a coauthor', 'cap-sandbox' ),
@mboynes
mboynes / jetpack-popular-posts.php
Created March 12, 2018 15:11
Get popular posts using Jetpack
@mboynes
mboynes / ngrok-and-jetpack.md
Created December 20, 2018 02:15 — forked from mjangda/ngrok-and-jetpack.md
How to connect ngrok to your local WordPress environment (props @DanReyLop)

How to develop with Jetpack locally with ngrok

To connect Jetpack in your local installation, you'll need a way for WP.com servers to reach your server. That can be done in a number of different ways:

  • You can open your router's ports and use your public IP
  • You can use some kind of Dynamic DNS provider.

But these options fall short of ngrok, which is a "localhost tunnel". It basically allows the Internet to hit a local port on your machine without worrying about ports or IPs.

As long as ngrok is running, Jetpack / WP.com will be able to communicate with your local site. This will allow remote modules like Site Search and Manage to work.

@mboynes
mboynes / gist:a3f65eb29c8e06ddd8c6cbece0f88ae6
Created May 1, 2019 19:37 — forked from mannieschumpert/gist:8886289
Code Examples from Andrew Nacin's "Current User Can Watch This Talk"
<?php
// If you can edit pages, you can edit widgets
add_filter( 'user_has_cap',
function( $caps ) {
if ( ! empty( $caps['edit_pages'] ) )
$caps['edit_theme_options'] = true;
return $caps;
} );