Skip to content

Instantly share code, notes, and snippets.

@rocketgeek
rocketgeek / class-wp-members.php
Last active October 7, 2021 14:17
new is_blocked for individual post checking
<?php // do not include this line. Replace the function is_blocked() in class-wp-members.php with the below:
/**
* Determines if content should be blocked.
*
* This function was originally stand alone in the core file and
* was moved to the WP_Members class in 3.0.
*
* @since 3.0.0
* @since 3.3.0 Added $post_id
@rocketgeek
rocketgeek / extract_html_atts.php
Created August 4, 2021 14:10
Extract "data-" attributes from WooCommerce HTML tags
<?php
// Extraction utility for getting attributes from HTML tag.
function extract_html_atts( $string, $prefix = "data-" ) {
$start = 0;
$end = 0;
while( strpos( $string, $prefix, $end ) ) {
$start = strpos( $string, $prefix, $start )+strlen( $prefix );
$end = strpos( $string, '"', $start )-1;
@rocketgeek
rocketgeek / class-wp-members-forms.php
Last active March 11, 2021 22:24
Fixes issue with WooCommerce My Account reg form that duplicates last WP-Members field label
<?php
/**
This is not longer the most recent set of changes.
See new gist for additional changes:
https://gist.github.com/rocketgeek/6e8329aeaf0f1de26b618bd7d5dc2fe8
**/
@rocketgeek
rocketgeek / wp-php-cli.php
Created October 27, 2020 14:51
Simple framework for running WP imports via command line
<?php
/**
* A framework for using the command line for big
* WordPress import projects.
*/
// Identify that script must run from command line.
if (php_sapi_name() !== 'cli') {
die("This script is meant to be run from the command line");
}
@rocketgeek
rocketgeek / html_to_obj.php
Created July 10, 2019 12:43
Convert HTML DOM to JSON
<?php
// https://stackoverflow.com/questions/23062537/how-to-convert-html-to-json-using-php
function html_to_obj( $html ) {
$dom = new DOMDocument();
$dom->loadHTML( $html );
return element_to_obj( $dom->documentElement );
}
function element_to_obj( $element ) {