Skip to content

Instantly share code, notes, and snippets.

View polevaultweb's full-sized avatar

Iain Poulson polevaultweb

View GitHub Profile
@polevaultweb
polevaultweb / igp_post_title.php
Created June 24, 2020 21:41
Add this to the wp-content/mu-plugins directory (create if doesn't exist)
<?php
function my_igp_post_title( $title ) {
// "car model:", "engine:", "Country & City: and (no. 40)" ie.:
// Title: BMW E46 - M52 - Germany/Bavaria/Hof (no. 40)
$model = trim( get_string_between( $title, 'car model:', 'engine:' ) );
$engine = trim( get_string_between( $title, 'engine:', 'bhp:' ) );
$country = trim( get_string_between( $title, 'country & city:', 'occupation:' ) );
$number = '(no. ' . trim( get_string_between( $title, ' (no.', ')' ) ) . ')';
@polevaultweb
polevaultweb / igp_fix_tags_caption.php
Last active June 18, 2020 20:02
Intagrate - Ensure hashtags are stripped from the caption
<?php
/**
* Get matching hashtag regex.
* Based on https://github.com/ngnpope/twitter-text-php
*
* @return string Regex pattern.
*/
function igp_valid_hashtag_regex() {
$tmp = array();
@polevaultweb
polevaultweb / nf_fu_unique_email_error_fix.php
Last active March 20, 2020 11:57
Ninja Forms File Uploads - temporary fix to ensure file uploads still work after the unique email error is triggered in a form submission
<?php
add_action( 'plugins_loaded', function () {
/**
* Submission class extension so we can access the protected errors property.
*
* Class NF_FU_AJAX_Controllers_Submission
*/
class NF_FU_AJAX_Controllers_Submission extends NF_AJAX_Controllers_Submission {
@polevaultweb
polevaultweb / codeception-dropbox-oauth-login.php
Created February 17, 2020 13:00
Using Codeception to login to Dropbox and approve permissions during oAuth2 login flow.
<?php
$I->waitForText( 'Sign in to Dropbox' );
$I->fillField( 'login_email', $_ENV['DROPBOX_EMAIL'] );
$I->wait( 1 );
$I->fillField( 'login_password', $_ENV['DROPBOX_PASSWORD'] );
$I->click( [ 'class' => 'login-button' ] );
$I->wait( 10 );
if ( $I->seeOnPage( 'Allow' ) ) {
$I->click( 'Allow' );
@polevaultweb
polevaultweb / codeception-google-oauth-login.php
Last active February 17, 2020 12:46
Using Codeception to login to Google and approve permissions during oAuth2 login flow.
<?php
$I->waitForText( 'Sign in with Google' );
$I->fillField('#identifierId', $_ENV['GOOGLE_EMAIL']);
$I->wait(1);
$I->click('#identifierNext');
$I->wait(1);
$I->fillField('password', $_ENV['GOOGLE_PASSWORD']);
$I->wait(1);
$I->click('#passwordNext');
# replace 'file' with the array key you want to extract
SELECT
SUBSTRING_INDEX(
SUBSTRING_INDEX(
SUBSTRING(pm.meta_value, ( INSTR( pm.meta_value, CONCAT( 'file', '";' ) ) + CHAR_LENGTH( 'file') + 1 ) ),
'"', 2 ),
'"', -1 ) as attachment_file
FROM wp_posts p
INNER JOIN wp_postmeta pm
ON p.ID = pm.post_id
<?php
$prefix = 'igp';
$panel = new \TDP\OptionsKit( $prefix );
$panel->set_page_title( __( 'My Plugin Settings' ) );
/**
* Setup the menu for the options panel.
*
<?php
/**
* Generated by the WordPress Option Page generator
* at http://jeremyhixon.com/wp-tools/option-page/
*/
class MyExamplePlugin {
private $my_example_plugin_options;
<?php
add_action( 'add_post_meta', function ( $object_id, $meta_key, $_meta_value ) {
if ( $meta_key !== '_igp_id' ) {
return;
}
$category_id = 11; // Change this to the tag_id
wp_set_post_categories( $object_id, array( $category_id ) );
}, 10, 3 );
@polevaultweb
polevaultweb / prefix-composer-autoloader-namespace.php
Last active October 31, 2024 19:10
Patch file to run after PHP Scoper to ensure the Composer Autoload namespace is prefixed
<?php
/**
* Make sure the Composer\Autoload namespace is prefixed.
* Needs to be run after php-scoper.
*
* `php ./patch-scoper-autoloader-namespace.php MY_PREFIX`
*/
if ( empty( $argv[1] ) ) {
return;