Skip to content

Instantly share code, notes, and snippets.

View elvismdev's full-sized avatar
🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@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 / 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 / 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>
@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
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 ) {
<?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
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()";
@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(/[?#]$/,'');