Skip to content

Instantly share code, notes, and snippets.

View alvarogois's full-sized avatar

Alvaro Gois dos Santos alvarogois

View GitHub Profile
@webdados
webdados / sanitize_file_name.php
Created September 10, 2020 11:00
Sanitize WordPress uploaded file names
<?php
add_filter( 'sanitize_file_name', 'my_sanitize_file_name' );
function my_sanitize_file_name( $filename ) {
$original_chars = array(
'/А/','/Б/','/В/','/Г/', // cyrillic alphabet
'/Д/','/Е/','/Ж/','/З/','/И/',
'/Й/','/К/','/Л/','/М/','/Н/',
'/О/','/П/','/Р/','/С/','/Т/',
@webdados
webdados / redirect_if_not_logged_in.php
Created January 6, 2020 13:48
Poor guy's Private WordPress Website - Redirect a user to the login form if he's not logged in
<?php
add_action( 'template_redirect', 'redirect_if_not_logged_in' );
function redirect_if_not_logged_in() {
if ( ! is_user_logged_in() ) wp_redirect( wp_login_url( $_SERVER['REQUEST_URI'] ) );
}
@webdados
webdados / old_posts_warning.php
Last active January 14, 2019 15:22
Add a warning to WordPress posts over one year old
<?php
add_filter( 'the_content', 'old_posts_warning' );
function old_posts_warning( $content ) {
if ( is_singular( 'post' ) ) {
global $post;
$past_date = date_i18n( 'Y-m-d H:i:s', strtotime( '-1 year' ) );
if ( $post->post_date < $past_date ) {
$content = '<p><strong>This content is over one year old. It may not be updated.</strong></p>' . $content;
}
}
@nicooprat
nicooprat / custom-callback.php
Created October 22, 2018 17:22
Create an ACF block with Sage 9 & Blade
function my_acf_block_render_callback( $block ) {
$slug = str_replace('acf/', '', $block['name']);
$block['slug'] = $slug;
$block['classes'] = implode(' ', [$block['slug'], $block['className'], $block['align']]);
echo \App\template("blocks/${slug}", ['block' => $block]);
}
@webdados
webdados / remove_wc_add_to_cart_message_html.php
Created March 1, 2018 17:22
Remove WooCommerce "Added to cart" message
<?php
/* Removes the "added to cart" message and "continue shopping" link after a product was added to the cart and the user was redirected to the cart page */
add_filter( 'wc_add_to_cart_message_html', 'remove_wc_add_to_cart_message_html' );
function remove_wc_add_to_cart_message_html( $message ) {
$message = '';
return $message;
}
?>
@webdados
webdados / resizeandcanvasto1200.jsx
Last active April 26, 2020 17:26
Automatic resize a folder of images into the same square size on Adobe Photoshop. Just right click the file and open it with Photoshop.
//Marco Almeida - Webdados
#target photoshop
app.bringToFront();
app.preferences.rulerUnits = Units.PIXELS;
gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );
@webdados
webdados / cancelled_order_add_customer_email.php
Last active December 16, 2017 03:33
WooCommerce Cancelled orders sent to client also
<?php
add_filter( 'woocommerce_email_recipient_cancelled_order', 'cancelled_order_add_customer_email', 10, 2 );
function cancelled_order_add_customer_email( $recipient, $order ) {
if ( $order ) {
return $recipient . ',' . ( version_compare( WC_VERSION, '3.0', '>=' ) ? $order->get_billing_email() : $order->billing_email );
} else {
return $recipient;
}
}
@kevinwhoffman
kevinwhoffman / resources-web-developers-designers.md
Last active January 26, 2024 21:20
Resources for Web Developers and Designers

Resources for Web Developers and Designers

This is an incomplete list of resources including courses and individuals who publish content that has helped me grow as a web developer and designer. Many of these resources are WordPress-specific as that is my current area of specialization. This list will grow over time. If you've got something to add, send me a link @kevinwhoffman and I'll check it out!

Course Providers

@generatepress
generatepress / gist:7f324df1ee32bf389cc2e476739875dd
Last active November 10, 2017 18:31
Add support for Lifter LMS plugin
if ( ! function_exists( 'generate_lifterlms_start' ) ) :
/**
* Add LifterLMS starting wrappers
*/
add_action('lifterlms_before_main_content', 'generate_lifterlms_start', 10);
function generate_lifterlms_start()
{ ?>
<div id="primary" <?php generate_content_class();?>>
<main id="main" <?php generate_main_class(); ?>>
<?php do_action('generate_before_main_content'); ?>
@webdados
webdados / percentage_woocommerce_sale_flash.php
Last active March 22, 2019 08:03
Discount percentage on the WooCommerce "on sale" badge
<?php
add_filter( 'woocommerce_sale_flash', 'percentage_woocommerce_sale_flash', 10, 3 );
function percentage_woocommerce_sale_flash( $html, $post, $product ) {
if ( $html!='' ) {
$perc = round( 100 - ( $product->sale_price * 100 / $product->regular_price ) );
if ( $perc>0 ) $html = '<span class="onsale">-'.$perc.'%</span>';
}
return $html;
}