Skip to content

Instantly share code, notes, and snippets.

Avatar
🍕
Working hard reviewing and deploying code

Scott Kingsley Clark sc0ttkclark

🍕
Working hard reviewing and deploying code
View GitHub Profile
@sc0ttkclark
sc0ttkclark / pods-blocks-examples.php
Last active Aug 22, 2020
Pods Blocks API examples for register a custom block type or a custom block collection. Screencast: https://share.skc.dev/12uJvZL1
View pods-blocks-examples.php
<?php
/**
* Want a quick overview and live demo? Check out the screencast here: https://share.skc.dev/12uJvZL1
*/
/**
* Example 1: Registering a custom block type.
*/
add_action( 'pods_blocks_api_init', 'register_my_custom_block_type' );
@sc0ttkclark
sc0ttkclark / 1-readme.md
Last active Aug 8, 2020
Filter the relationship field to allow for selecting multiple post types or multiple taxonomies.
View 1-readme.md

These filters will automatically tell Pods relationship fields to support multiple post types or taxonomies instead of just being tied to one. This is done by changing the default where clause used by Pods to determine what kind of content is returned for the various areas of input (selects, checkboxes, list fields, ajax autocomplete, etc). This is by far the simplest way to customize a related field, but it also has it's drawbacks (see notes below).

Important notes

You must relate the relationship field itself to a NON-POD, any post type not created or extended by Pods will do. The same goes for taxonomies. Don't worry, this doesn't mean you are unable to relate your field to any other Pod, it's just the field setting itself that needs to be set. Your filtering below will handle what it's going to truly be working with from a relationship aspect.

Failing to do this will cause any data you save to not be returned by Pods because when a relationship is related to a Pod it has extra checks to limit

@sc0ttkclark
sc0ttkclark / skc-404.php
Created Jul 3, 2020
My 404 handler for scottkclark.com
View skc-404.php
<?php
/**
* Handle 404's in a way that can trick Slack and other link previews.
*/
function skc_404_handler() {
if ( is_admin() || ! is_404() ) {
return;
}
View rest.json
{
"namespace": "pods/v1",
"routes": {
"/pods/v1": {
"namespace": "pods/v1",
"methods": [
"GET"
],
"endpoints": [
{
View pods-help.php
<?php
//pods: https://imgur.com/a/MflzgtI
$search = sanitize_text_field( $search );
$query = array();
$query[] = 'brand.meta_value = ' . absint( $_REQUEST['brand_id'] );
$query[] = '
d.asset_name LIKE "%' . pods_sanitize_like( $search ) . '%"
OR product_d.sku like "%' . pods_sanitize_like( $search ) . '%"
@sc0ttkclark
sc0ttkclark / event-tickets-support-html-descriptions.php
Last active Oct 8, 2019
Support HTML descriptions on Tickets for the Event Tickets plugin
View event-tickets-support-html-descriptions.php
<?php
// Allow (safe) HTML for ticket descriptions.
add_action( 'tribe_tickets_ticket_add', function( $post_id, $ticket, $data ) {
$ticket->description = isset( $data['ticket_description'] ) ? wp_kses_post( $data['ticket_description'] ) : '';
}, 10, 3 );
@sc0ttkclark
sc0ttkclark / debug-ep.php
Created Feb 26, 2019
ElasticPress debugging code for mu-plugins
View debug-ep.php
<?php
/**
* @param string $type
*
* @return bool
*/
function debug_ep_is_debug( $type = 'normal' ) {
if ( ! empty( $_GET['epdebug'] ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
@sc0ttkclark
sc0ttkclark / custom-pods-shortcode-total-text.php
Last active May 28, 2019
Custom `[pods]` shortcode handling for total text.
View custom-pods-shortcode-total-text.php
<?php
/*
* Ensure total_found() gets calculated right away, because in the [pods] shortcode
* it does other queries after the initial find().
*/
add_filter( 'pods_data_auto_calculate_total_found', '__return_true' );
/**
* Add custom shortcode handling for total text.
@sc0ttkclark
sc0ttkclark / import-example.php
Created Aug 29, 2017
Pods import csv example
View import-example.php
<?php
/**
* Import CSV example for Pods
*
* @param string $file File location
*
* @return true|WP_Error Returns true on success, WP_Error if there was a problem
*/
function my_import_csv( $file ) {
@sc0ttkclark
sc0ttkclark / prospress-command.php
Created Jul 18, 2017
Prospress command example for WP-CLI
View prospress-command.php
<?php
/**
* Prospress command for CLI actions.
*/
class Prospress_Command extends WP_CLI_Command {
/**
* Run scheduler
*
You can’t perform that action at this time.