Skip to content

Instantly share code, notes, and snippets.

View elvismdev's full-sized avatar
🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@elvismdev
elvismdev / FindMultipleGenesFromFile.java
Last active July 4, 2023 05:30
A Java small class to find all the genes from a DNA string stored in a plain text file. The library edu.duke is a dependency for the class to work, it should be added into the Java IDE to compile with no errors. Download link http://www.dukelearntoprogram.com/downloads/archives/courserajava.jar
/**
* Find all the genes from a DNA string file and using StorageResource class.
*
* @author (Elvis Morales)
* @version (1.0)
*/
import edu.duke.*;
import java.io.File;
@elvismdev
elvismdev / require-post-title.php
Last active November 2, 2022 12:08
Require post title at backend WordPress editor
<?php
add_action( 'edit_form_advanced', 'force_post_title' );
function force_post_title( $post ) {
// List of post types that we want to require post titles for.
$post_types = array(
'post',
'report',
// 'event',
@elvismdev
elvismdev / single-author.php
Created October 19, 2017 04:40
Combine tax_query and meta_query in WP_Query()
<?php
/**
* This is a kind of rare combination of arguments for WP_Query(), needed in some very special cases.
* This is an already tested snippet code that works!
*/
// Bring post from the global context (if not present already).
global $post;
// Define the post_type's to query for.
$post_types = array( 'event', 'post', 'book' );
@elvismdev
elvismdev / jenkins_wpsvn_deploy.sh
Last active August 30, 2022 18:35 — forked from BFTrick/deploy.sh
Deploy from Jenkins to WordPress.org SVN
# In your Jenkins job configuration, select "Add build step > Execute shell", and paste this script contents.
# Replace `______your-plugin-name______`, `______your-wp-username______` and `______your-wp-password______` as needed.
# main config
WP_ORG_USER="______your-wp-username______" # your WordPress.org username
WP_ORG_PASS="______your-wp-password______" # your WordPress.org password
PLUGINSLUG="______your-plugin-name______"
CURRENTDIR=`pwd`
MAINFILE="______your-plugin-name______.php" # this should be the name of your main php file in the wordpress plugin
<?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 / sum_total_orders_revenue.php
Last active November 3, 2021 10:35
SUM up all values from table column - Doctrine QueryBuilder.
<?php
// Sum all values from order_total column in completed orders, and return.
$qb = $em->createQueryBuilder();
$qb = $qb
->select( 'SUM(e.orderTotal) as totalRevenue' )
->from( '[Vendor]\[Package]\Entity\Orders', 'e' )
->where( $qb->expr()->andX(
$qb->expr()->eq( 'e.orderStatus', ':status' ),
// $qb->expr()->in( 'e.state', array( 'queued', 'confirmed' ) )
@elvismdev
elvismdev / wp-cfm-ssot.php
Created September 10, 2019 06:15
Example `wpcfm_is_ssot` filter to conditionally set WP-CFM bundles files as SSOT when running on Pantheon live environment.
<?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 September 9, 2019 19:44
Example usage filter `wpcfm_is_ssot`
<?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 September 9, 2019 15:13
Example usage filter `wpcfm_multi_env` to disable multi-environment feature in Pantheon
<?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 September 9, 2019 14:15
Example usage filter `wpcfm_current_env`
<?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;