Skip to content

Instantly share code, notes, and snippets.

View elvismdev's full-sized avatar
🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@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 / wp-ctrl-addthis-sidebar.php
Last active July 6, 2017 06:13
Controls the display of the AddThis Sharing Sidebar style using the show/hide Addthis sharing radio buttons in admin post add/edit page. When using the plugin Share Buttons by AddThis for WordPress (https://wordpress.org/plugins/addthis/), this code snippet aims to resolve this problem described here https://wordpress.org/support/topic/include-a…
<?php
/**
* Controls the display of the AddThis Sharing Sidebar style using the
* show/hide Addthis sharing radio buttons in admin post add/edit page.
*/
add_action( 'wp', 'ctrl_addthis_sidebar' );
function ctrl_addthis_sidebar() {
if ( get_post_meta( get_the_ID(), '_at_widget', true ) == 0 ) {
global $AddThis_addjs_sharing_button_plugin;
remove_action( 'wp_footer', array( $AddThis_addjs_sharing_button_plugin, 'output_script' ) );
@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
@elvismdev
elvismdev / array_dechunk.php
Last active June 16, 2017 05:28
De-chunks an array, opposite of array_chunk() http://php.net/manual/en/function.array-chunk.php
function array_dechunk( $array ) {
return array_reduce( $array, function ( $carry, $item ) {
return array_merge( $carry, $item );
}, [] );
}
@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 / acf_filter_choice.php
Last active August 11, 2017 21:30
WordPress ACF - Remove / override the choices for a radio, checkbox and select fields.
<?php
/**
* Removes custom style selector for non Administrator user roles.
* Uses acf/load_field filter https://www.advancedcustomfields.com/resources/acf-load_field/
*
* @param array $field
* @return array
*/
function acf_filter_radio_choices( $field ) {
@elvismdev
elvismdev / addthis_share_array.php
Created August 16, 2017 08:26
WordPress AddThis plugin - Override URL and Title to share via addthis_share variable https://www.addthis.com/academy/the-addthis_share-variable/
<?php
add_filter( 'addthis_share_array', function ( $addthis_share ) {
$addthis_share['title'] = 'My custom title';
$addthis_share['url'] = 'http://example.com/my-custom-title';
return $addthis_share;
});
@elvismdev
elvismdev / addthis_layers_array.php
Last active August 21, 2017 04:43
WordPress AddThis plugin (v6+) - Output and control programmatically the AddThis floating sidebar with it's "Smart Layers API": https://www.addthis.com/academy/smart-layers-api/
<?php
/**
* Output an AddThis floating share sidebar to the left with selected services.
*
* Notice 'desktop' and 'mobile' parameters, they take a Boolean data type as value, meaning it can be used to
* allow a more dynamic control and display of the sharing sidebar.
*
* More options to play with can be found here in the docs: https://www.addthis.com/academy/smart-layers-api/
* Just notice to convert the JSON format in the examples to PHP's array() format
@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 / 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>