Skip to content

Instantly share code, notes, and snippets.

View elvismdev's full-sized avatar
🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@elvismdev
elvismdev / wpcfm_multi_env.php
Created September 9, 2019 13:16
Example usage filter `wpcfm_multi_env`
<?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 September 9, 2019 13:01
Enables configuration management for multiple environments with WP-CFM.
<?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;
}
@elvismdev
elvismdev / functions.php
Created January 28, 2019 12:09
Create valid date format from custom date string.
<?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 January 28, 2019 11:05
Relates a post by title.
<?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 August 2, 2018 23:00
Replaces a parameter value from a given URL query string.
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(/[?#]$/,'');
@elvismdev
elvismdev / functions.php
Created July 27, 2018 10:33
WordPress: Remove parent dropdown selector from hierarchical taxonomy.
<?php
function remove_tax_parent_dropdown() {
$screen = get_current_screen();
if ( 'region' == $screen->taxonomy ) {
if ( 'edit-tags' == $screen->base ) {
$parent = "$('label[for=parent]').parent()";
} elseif ( 'term' == $screen->base ) {
$parent = "$('label[for=parent]').parent().parent()";
<?php
add_filter( 'facetwp_query_args', function( $query_args, $class ) {
$query_args['post__not_in'] = [ 239 ];
return $query_args;
}, 10, 2 );
@elvismdev
elvismdev / functions.php
Last active July 18, 2018 00:26
WordPress: Exclude the most recent post from the main query without braking pagination.
<?php
// ...
/**
* Tweak Archive pages queries.
* @param object $query
* @return object
*/
function tweak_archives( $query ) {
@elvismdev
elvismdev / services.yaml
Created February 22, 2018 18:13
Symfony parameters config key example
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
# My application specific parameters.
app.gpu_qty: # The number of GPU cards each mining rig has.
rukia: 12
zangetsu: 4
app.gpu_share: 3 # How many GPU cards the two rig shares to divide profits.
@elvismdev
elvismdev / functions.php
Created January 11, 2018 21:38
JS alert/confirmation pop-up before permanently erase all content items in the WordPress trash.
<?php
function trash_empty_confirmation() { ?>
<script type="text/javascript">
(function($) {
$('[id=delete_all]').click(function(e){
return confirm( "Are you sure you want to permanently erase all content items in the Trash ?" );
});
})( jQuery );
</script>