Skip to content

Instantly share code, notes, and snippets.

View paulmiller3000's full-sized avatar

Paul Miller paulmiller3000

View GitHub Profile
@paulmiller3000
paulmiller3000 / gist:d3cc3be7632e14c6c2f26d0b9592802e
Last active December 3, 2020 13:18
bsd-strong-post-index.js
/*
This page demonstrates how to save WordPress settings through the Settings API from React.
It won't function on its own due to dependencies; it is an excerpt from a soon-to-be-published
plugin. It simply serves as an example.
Lines 62-76 demonstrate how to retrieve options.
Lines 133-169, in combination with state, demonstrate how to update options.
Inspired by:
https://www.codeinwp.com/blog/plugin-options-page-gutenberg/
<?php
function bsd_tup_plugin_options_page() {
?>
<div class='wrap'>
<h1><?php _e('BSD Team and User Profiles', 'bsd-team-user-profiles' ); ?></h1>
<div id='poststuff'>
<div id='post-body' class='metabox-holder columns-2'>
<!-- Content -->
<?php
/**
* WordPress pagination with consecutive page numbers, arrows, and an ellipses
* Style rules tested with Elementor on the Twenty-Twenty theme. YMMV.
* Example:
* « Previous 1 2 3 4 … 436 Next »
*
* PHP Code Source: https://wordpress.stackexchange.com/a/327711
*/
?>
@paulmiller3000
paulmiller3000 / bsd_get_taxonomy_terms_as_string.php
Last active September 5, 2020 14:19
Get all terms for a taxonomy assigned to a WordPress post, returning them as a comma-delimited string.
/*
* Use Case: A taxonomy named "Specialty" assigned to a post has several terms.
* The user needs to receive them back like this: "landlord representation, real estate, tenant representation".
*
* Call it like this:
* $term_list = bsd_get_taxonomy_terms_as_string( 'bsd-specialty', 1035 );
* Where bsd-specialty is the taxonomy slug and 1035 is the post ID.
*/
public function bsd_get_taxonomy_terms_as_string( $taxonomy_name, $object_id ) {
@paulmiller3000
paulmiller3000 / quick_view_pro_display_acf_google_map
Last active February 23, 2020 19:04
Function to display Advanced Custom Fields Google Map in Quick View Pro modal
/*
* Display a map (saved from Advanced Custom Fields) in Quick View Pro modal
* Documentation: https://battlestardigital.com/adding-advanced-custom-fields-google-maps-to-woocommerce-quick-view-pro/
* HTML Source: https://www.advancedcustomfields.com/resources/google-map/
*/
private function bsd_qvp_display_map( $map) {
if ( $map ) {
?>
<div id="map" class="acf-map">
<div class="marker" data-lat="<?php echo esc_attr($map['lat']); ?>" data-lng="<?php echo esc_attr($map['lng']); ?>"></div>
@paulmiller3000
paulmiller3000 / functions.php
Last active February 18, 2020 18:08
Register Advanced Custom Fields for WooCommerce with the WordPress API
<?php
/*
* Register ACF fields to WordPress API
* Tutorial: https://battlestardigital.com/wp-admin/post.php?post=2838&action=edit
*/
add_action( 'rest_api_init', 'bsd_register_acf_with_api' );
function bsd_register_acf_with_api() {
if (!function_exists('get_fields')) return;
@paulmiller3000
paulmiller3000 / return-two-values-to-es6-function.html
Created December 10, 2019 19:11
How to Return Two Values to a Function in ES6
<!DOCTYPE html>
<html>
<head>
<title>How to Return Two Values to a Function in ES6</title>
</head>
<body>
<div class='container'>
<form action='#' onsubmit='funFunction();return false'>
<select name='vehicle-selector' id='vehicle-selector' required />
<option value='BaseStar'>BaseStar</option>
@paulmiller3000
paulmiller3000 / class-extend-woocommerce-stripe-webhook-handler.php
Created December 7, 2019 11:50
Extend WC_Stripe_Webhook_Handler to override the check_for_webhook function
<?php
/**
* Extend WC_Stripe_Webhook_Handler and override the check_for_webhook function
*
*/
if (!class_exists('My_Stripe_Webhook_Handler')) :
class My_Stripe_Webhook_Handler extends WC_Stripe_Webhook_Handler {
@paulmiller3000
paulmiller3000 / parse-url-for-woo.js
Created October 23, 2019 13:53
Parse URL for WooCommerce
document.addEventListener('DOMContentLoaded', function() {
const currentUrl = window.location.pathname;
let parentCategory = false;
let productName = currentUrl.substr(18, (currentUrl.length - 18));
let slashCount = productName.match(/\//g);
// Count the number of slashes. If 1, this is a parent category
slashCount = slashCount ? slashCount.length : 0;
<?php
/**
* Displays a table in the WC Settings page
*
* @link https://paulmiller3000.com
* @since 1.0.0
*
* @package P3k_Galactica
* @subpackage P3k_Galactica/admin
*