Skip to content

Instantly share code, notes, and snippets.

Jany Martelli Jany-M

Block or report user

Report or block Jany-M

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Jany-M
Jany-M / wp_ics.php
Last active Jan 17, 2020 — forked from jakebellacera/ICS.php
[WP] Generate a downloadable .ics file from any WordPress post or custom post type
View wp_ics.php
<?php
/*
For a better understanding of ics requirements and time formats
please check https://gist.github.com/jakebellacera/635416
*/
// Add a custom endpoint "calendar"
function add_calendar_feed(){
add_feed('calendar', 'export_ics');
@Jany-M
Jany-M / WP_flush_cache_and_transients.php
Last active Jan 14, 2020
[WordPress] Flush Object Cache (Memcached) & Transients - Admin buttons
View WP_flush_cache_and_transients.php
<?php
// Flush Cache from Admin bar
function flush_memcache_button() {
global $wp_admin_bar;
// If User isnt even logged in or if admin bar is disabled
if ( !is_user_logged_in() || !is_admin_bar_showing() )
return false;
@Jany-M
Jany-M / wc_dynamic_saleprice.php
Created Jan 10, 2020
[WP][WooCommerce] Calculate sale price dynamically / programmatically based on taxonomy term custom field % (also works for Facebook Catalog feed)
View wc_dynamic_saleprice.php
<?php
// Backend
function wc_custom_dynamic_sale_price( $sale_price, $product ) {
$id = $product->get_id();
$tax = get_the_terms($id,'product_cat');
$regular_price = wc_format_decimal( $product->get_price() );
$discount_total = 0;
foreach ($tax as $term){
$disc_single = get_field('sale_value', $term->taxonomy . '_' . $term->term_id);
@Jany-M
Jany-M / .htaccess
Last active Dec 22, 2019
[WP] htacces for best security & caching settings
View .htaccess
####################################################
#
# MIMETYPES
#
####################################################
AddType video/mp4 mp4 m4v
AddType audio/mp4 m4a
AddType video/ogg ogv
@Jany-M
Jany-M / expires.conf
Last active Dec 22, 2019
[Apache] mod_expires conf
View expires.conf
# etc/httpd/conf.d/expires.conf
# https://support.plesk.com/hc/en-us/articles/115001711985-How-to-enable-leverage-browser-caching-in-Plesk
# https://support.plesk.com/hc/en-us/articles/213380049-How-to-enable-gzip-compression-on-nginx-on-Plesk-server
LoadModule expires_module modules/mod_expires.so
ExpiresActive on
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
@Jany-M
Jany-M / google_map_api3_multiple_locations_infowindow_with_html_gallery.js
Last active Dec 21, 2019
Google Maps API3 - Multiple markers and Infowindow with custom content and gallery, using Geocode
View google_map_api3_multiple_locations_infowindow_with_html_gallery.js
@Jany-M
Jany-M / remove_admin_menu_items.php
Created Dec 17, 2019
[WP] Edit WordPress admin menu (backend) - Remove items/pages and sub-items/sub-pages, including Customizer
View remove_admin_menu_items.php
<?php
// Remove items from menu for Editors
function remove_admin_menu_items() {
if(current_user_can('editor') && !current_user_can('administrator')) {
// Remove menu items
// Tools
remove_menu_page( 'tools.php' );
@Jany-M
Jany-M / manage_paragraphs.php
Last active Nov 26, 2019
[WP][PHP] Split first paragraph from main content, display it elsewhere
View manage_paragraphs.php
<?php
// Grab the first paragraph, show it where you need it, then take the rest of the content and remove the first paragraph and show it elsewhere
// The script uses WordPress functions/content but can be used in any PHP script, just replace the WP functions
// First Paragraph
global $post;
$p1 = wpautop( $post->post_content );
$p1 = substr( $p1, 0, strpos( $p1, '</p>' ) + 4 );
//$p1 = strip_tags($p1, '<a><strong><em><h3><h2><i>'); // in case you need to remove some tags, add the ones you want to KEEP here
@Jany-M
Jany-M / greyscale_colorize_wp_post_images.php
Last active Nov 14, 2019
[WP] Colorize (after greyscale), depending on post type, a post image (either feat, parsed or external) and save it as new to uploads
View greyscale_colorize_wp_post_images.php
<?php
// This script assumes we are in a Post Loop
// Get the image you need however you like, I use https://github.com/Jany-M/WP-Imager
$image_orig = wp_imager($img_w, $img_h, 3, '', true, '', true, null, null, true);
// Check for image headers to avoid Error 400 - if all images come always from same server/site you dont need this
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
$ch = curl_init ($image_orig);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@Jany-M
Jany-M / WP_gists_as_wordpress_posts.php
Last active Nov 14, 2019
[WordPress] Display Gists as if they were real WordPress Posts (without saving them to database)
View WP_gists_as_wordpress_posts.php
<?php
// This will display Gists as if they were real WP posts, so you can display them mixed with real ones too
// This will NOT add the Gists as real posts in your DB, you won't see them in your backend
/* --------------------------------------
|
| Real Posts Loop
|
|---------------------------------------*/
You can’t perform that action at this time.