Skip to content

Instantly share code, notes, and snippets.

View mboynes's full-sized avatar

Matthew Boynes mboynes

View GitHub Profile
@mboynes
mboynes / fieldmanager-module-post-limits.js
Created March 1, 2022 16:06
Limit POST data on fieldmanager repeating groups
'use strict';
jQuery(function ($) {
var $form = $('form#post');
if ($form.length && $('.fm-modules-wrapper').length) {
$form.submit(function (e) {
var $modules = $('.fm-modules-wrapper .fm-modules:not(.fmjs-proto)');
if ($modules.length) {
// Remove all protos to start.
@mboynes
mboynes / class-product.php
Created December 14, 2021 20:40
Product demo model for Mantle with GraphQL fields
<?php
/**
* Product class file.
*
* @package App\Models
*/
namespace App\Models;
use Mantle\Contracts\Database\Registrable;
diff --git a/resources/js/app.js b/resources/js/app.js
index 01b8468..8c93dcc 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -7,6 +7,10 @@
require('./bootstrap');
window.Vue = require('vue');
+window.Vue.prototype.authorize = function(handler) {
+ const { user } = window.App;
@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;
} );
@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 / jetpack-popular-posts.php
Created March 12, 2018 15:11
Get popular posts using Jetpack
@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 / 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 / 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-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 {
/**