Skip to content

Instantly share code, notes, and snippets.

View jonathanstegall's full-sized avatar

Jonathan Stegall jonathanstegall

View GitHub Profile

local installation of Elasticsearch for WordPress VIP Go infrastructure

Update, 11/2022:

Apparently none of this will work with Elasticsearch versions greater than 8.0. See elastic/homebrew-tap#126 (comment). The alternative seems to be to use Docker, or since it's a big system either way might as well switch to VVV.

Previous instructions

These are basic instructions, and I'm sure could be tightened up.

<?php
add_action( 'object_sync_for_salesforce_push_success', 'save_sf_id_acf', 10, 5 );
function save_sf_id_acf( $op, $response, $synced_object, $object_id, $wordpress_id_field_name ) {
// do things if the save succeeded
// $op is what the plugin did - Create, Update, Upsert, Delete
// $response is what was returned by the $salesforce class. sfapi->response
// $synced_object is an array like this:
/*
$synced_object = array(
docs/*,vendor/*,release/*
@jonathanstegall
jonathanstegall / process-salesforce-user.php
Last active February 1, 2021 15:35
process users in WordPress; delete user with a specific criteria
add_filter( 'object_sync_for_salesforce_pull_object_allowed', 'process_user', 10, 5 );
function process_user( $pull_allowed, $object_type, $object, $sf_sync_trigger, $salesforce_mapping ) {
if ( 'Contact' === $object_type && 'deletion' === $object['LastName'] ) {
$pull_allowed = false;
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if ( is_plugin_active( 'object-sync-for-salesforce/object-sync-for-salesforce.php' ) ) {
$salesforce = Object_Sync_Salesforce::get_instance();
$mapping_object = $salesforce->mappings->get_object_maps(

When a new version of PHP is installed, to keep up with the WordPress VIP Go environment locally we need to do a few things:

  1. pecl install gmagick
  2. If #1 fails with a beta warning, use pecl install channel://pecl.php.net/gmagick-2.0.6RC1 instead (replace with the correct version if necessary)
  3. pecl install memcache
  4. code /usr/local/etc/php/[version]/php.ini to open the ini file. Uncomment the lines extension="gmagick.so" and extension="memcache.so"
  5. valet restart

And to make curl stop complaining about the SSL, do this:

@jonathanstegall
jonathanstegall / ffmpeg.zsh
Created October 7, 2020 21:20
working ffmpeg command for resizing an mov video and converting to mp4
ffmpeg -i 10.04.20.mov -crf 23 -preset medium -movflags +faststart -c:a aac -s 960x540 10.04.20.mp4
@jonathanstegall
jonathanstegall / stories-by-category-and-date.sql
Created July 10, 2020 18:29
get a list of stories that are between a certain date range, and that are in a certain list of categories
SELECT ID, post_date, post_title
FROM wp_posts p
INNER JOIN wp_postmeta m ON p.ID = m.post_id
LEFT JOIN wp_term_relationships r ON (p.ID = r.object_id)
LEFT JOIN wp_term_taxonomy tax ON (r.term_taxonomy_id = tax.term_taxonomy_id)
WHERE post_date >= '2019-06-01' AND post_date < '2020-06-01' AND post_status = 'publish' AND tax.term_id IN (72513, 72511, 72514, 3003, 55565, 55831, 55634, 8389)
GROUP BY p.ID
ORDER BY post_date DESC
;
@jonathanstegall
jonathanstegall / global-mysql-sql-mode.sql
Last active July 29, 2021 18:10
this is required for MySQL to successfully import a WordPress database on Mac OS, at least as of June 2020
set global sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET SQL_MODE='ALLOW_INVALID_DATES';
@jonathanstegall
jonathanstegall / object-sync-for-salesforce-post-status.php
Created May 18, 2020 20:26
developer hook to set a post status using object sync for salesforce
<?php
add_filter( 'object_sync_for_salesforce_pull_params_modify', 'change_pull_params', 10, 6 );
function change_pull_params( $params, $mapping, $object, $sf_sync_trigger, $use_soap, $is_new ) {
$params['post_status'] = array(
'value' => 'publish',
'method_modify' => 'wp_update_post',
'method_read' => 'get_post',
);
return $params;
<?php
/**
* Try to fix broken pre-Drupal urls with special characters if we have saved their posts
* @return array $vars
*/
if ( ! function_exists( 'minnpost_largo_special_character_url_redirect' ) ) :
add_action( 'template_redirect', 'minnpost_largo_special_character_url_redirect' );
function minnpost_largo_special_character_url_redirect() {
// check if is a 404 error
if ( is_404() ) {