Skip to content

Instantly share code, notes, and snippets.

@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 ) {
@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 / 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 / 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.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 / php_scripts_with_wp.php
Last active December 30, 2021 13:45
Run php scripts from the command line with full access to WordPress functions.
<?php
/**
* A utility script to load WordPress to run
* php scripts directly from the command line.
*/
if ( php_sapi_name() !== 'cli' ) {
die( "This script is meant to be run from the command line" );
}
@rocketgeek
rocketgeek / api.php
Last active July 12, 2022 13:48
admin API with new functions for custom user views
<?php
/**
* WP-Members Admin API Functions
*
* This file is part of the WP-Members plugin by Chad Butler
* You can find out more about this plugin at https://rocketgeek.com
* Copyright (c) 2006-2022 Chad Butler
* WP-Members(tm) is a trademark of butlerblog.com
*
* @package WP-Members
@rocketgeek
rocketgeek / rm.bash
Created September 3, 2022 14:42
remove all but a single file in a directory using ssh
# No dirs:
rm -- !(file.txt)
# If dirs:
rm -rf -- !(file.txt)
# If extglob is not enabled:
shopt -s extglob
@rocketgeek
rocketgeek / create_wp_site.bat
Last active November 8, 2022 14:24
batch file: create/delete wordpress site in xampp
:: This is for spinning up installs for dev work, so don't consider this for
:: production applications. It creates everything off a single entry variable
:: so that you don't have to mess with unnecessary details. The site name and
:: username are the same (a single input), as are the database and db user.
:: The passwords for the initial WP user and the db user are generic "pass".
:: PHP, WP-CLI, and MYSQL all need to be path environment variables.
:: If you get errors that indicate something is not recognized as an internal
:: or external command, make sure you have these in your PATH.
@rocketgeek
rocketgeek / class-wp-members-pwd-reset.php
Created December 13, 2022 16:45
Potential update to password reset to add WP error to WP-Members error object if the user object contains an error.
<?php
/**
* An object class for WP-Members Password Reset.
*
* @since 3.3.5
* @since 3.3.8 Rebuild processing to utilize WP native functions and user_activation_key.
*/
class WP_Members_Pwd_Reset {
/**