Skip to content

Instantly share code, notes, and snippets.

🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@elvismdev
elvismdev / wp-cfm-ssot.php
Created Sep 10, 2019
Example `wpcfm_is_ssot` filter to conditionally set WP-CFM bundles files as SSOT when running on Pantheon live environment.
View wp-cfm-ssot.php
<?php
/*
Plugin Name: WP-CFM SSOT
Description: Sets WP-CFM bundles as the Single Source of Truth.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
@elvismdev
elvismdev / wp-cfm-ssot.php
Created Sep 9, 2019
Example usage filter `wpcfm_is_ssot`
View wp-cfm-ssot.php
<?php
/*
Plugin Name: WP-CFM SSOT
Description: Sets WP-CFM bundles as the Single Source of Truth for all tracked options.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
@elvismdev
elvismdev / wpcfm_multi_env_disable.php
Last active Sep 9, 2019
Example usage filter `wpcfm_multi_env` to disable multi-environment feature in Pantheon
View wpcfm_multi_env_disable.php
<?php
// wp-content/mu-plugins/wp-cfm-multi-env.php
// ...
// Return empty array to disable multi-environment feature.
function my_wpcfm_multi_env_disable( $environments ) {
return [];
}
add_filter( 'wpcfm_multi_env', 'my_wpcfm_multi_env_disable' );
@elvismdev
elvismdev / wpcfm_current_env.php
Last active Sep 9, 2019
Example usage filter `wpcfm_current_env`
View wpcfm_current_env.php
<?php
// wp-content/mu-plugins/wp-cfm-multi-env.php
// ...
function my_wpcfm_current_env_set( $env ) {
// Detect with your own code logic the current environment the WordPress site is running.
// Generally this will be defined in a constant inside `$_ENV` or `$_SERVER` super-globals.
// ...
$env = 'dev';
return $env;
@elvismdev
elvismdev / wpcfm_multi_env.php
Created Sep 9, 2019
Example usage filter `wpcfm_multi_env`
View wpcfm_multi_env.php
<?php
// wp-content/mu-plugins/wp-cfm-multi-env.php
// ...
function my_wpcfm_multi_env_register( $environments ) {
// Define an array containing the hosting environment names.
// Or detect these with your own code logic if all are available in `$_ENV` or `$_SERVER` super-globals.
// ...
$environments = [
'dev',
@elvismdev
elvismdev / wp-cfm-multi-env.php
Created Sep 9, 2019
Enables configuration management for multiple environments with WP-CFM.
View wp-cfm-multi-env.php
<?php
/*
Plugin Name: WP-CFM Multi-environment
Description: Enables configuration management for multiple environments with WP-CFM.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
View add-redirect.php
<?php
/*
Plugin Name: WP All Import - Redirection AddOn
Description: Add a redirect for each post imported.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
@elvismdev
elvismdev / functions.php
Created Jan 28, 2019
Create valid date format from custom date string.
View functions.php
<?php
function correct_date_string( $str ) {
if ( $str ) {
$date = DateTime::createFromFormat('Y.m.d', $str);
return $date->format('m/d/Y');
} else {
return '';
}
}
@elvismdev
elvismdev / functions.php
Created Jan 28, 2019
Relates a post by title.
View functions.php
<?php
// Relates a post by title.
function rel_post_by_title( $title, $post_type ) {
// If we don't have a title to lookup, then return null;
if ( !$title ) return null;
// Check if related post already exists. If it doesn't then create it.
// Attempt to find page by value.
$page = get_page_by_title( $title, null, $post_type );
@elvismdev
elvismdev / script.js
Created Aug 2, 2018
Replaces a parameter value from a given URL query string.
View script.js
function replaceUrlParam(url, paramName, paramValue) {
if (paramValue == null) {
paramValue = '';
}
var pattern = new RegExp('\\b('+paramName+'=).*?(&|#|$)');
if (url.search(pattern)>=0) {
return url.replace(pattern,'$1' + paramValue + '$2');
}
url = url.replace(/[?#]$/,'');
You can’t perform that action at this time.