Skip to content

Instantly share code, notes, and snippets.

@shazdeh
shazdeh / gist:47b8b518cdf3a79d6705a3b6064ec0ca
Last active December 2, 2023 06:02
Find closest larger image size that matches $width and $height
<?php
function find_nearest_image_size( $attachment_id, $width, $height ) : string {
$image_meta = wp_get_attachment_metadata( $attachment_id );
$size = '';
if ( ! empty( $image_meta['sizes'] ) ) {
$last_pixel_count = 0;
foreach ( $image_meta['sizes'] as $key => $value ) {
/* image size is smaller than what we need, skip */
if ( $width > $value['width'] || $height > $value['height'] ) {
@shazdeh
shazdeh / install.php
Last active October 5, 2021 01:50
Run install.php to download and install latest version of WP
<?php
$ch = curl_init();
$source = "https://wordpress.org/latest.zip";
curl_setopt( $ch, CURLOPT_URL, $source );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$data = curl_exec ( $ch );
curl_close ( $ch );
/* save as wordpress.zip */
@shazdeh
shazdeh / gist:7868242
Created December 9, 2013 06:35
WooCommerce: Show the saved percentage on the sale products in the the sale flash
<?php
function custom_product_sale_flash( $output, $post, $product ) {
$percent = ( ( $product->regular_price - $product->get_price() ) / $product->regular_price ) * 100;
return '<span class="onsale">' . __( 'Save:', 'themify' ) . round( $percent ) . '% </span>';
}
add_filter( 'woocommerce_sale_flash', 'custom_product_sale_flash', 11, 3 );
@shazdeh
shazdeh / velvet-blues-update-urls.php
Created June 10, 2017 00:05
Velvet Blues Update URLs
<?php
/*
Plugin Name: Velvet Blues Update URLs
Plugin URI: http://www.velvetblues.com/web-development-blog/wordpress-plugin-update-urls/
Description: This plugin <strong>updates all urls in your website</strong> by replacing old urls with new urls. To get started: 1) Click the "Activate" link to the left of this description, and 2) Go to your <a href="tools.php?page=velvet-blues-update-urls.php">Update URLs</a> page to use it.
Author: VelvetBlues.com
Author URI: http://www.velvetblues.com/
Author Email: info@velvetblues.com
Version: 3.2.7
License: GPLv2 or later
@shazdeh
shazdeh / Fix
Last active June 9, 2017 00:10
Fix Velvet Blues Update URLs bug
<?php
global $wpdb;
$wpdb->query( "UPDATE {$wpdb->postmeta} SET meta_value = Replace( meta_value, \"\n\", '' ) WHERE meta_key = '_themify_builder_settings_json'" );
function custom_post_row_actions_https( $actions ) {
if( isset( $actions['themify-builder'] ) ) {
$actions['themify-builder'] = str_replace( 'http://', 'https://', $actions['themify-builder'] );
}
return $actions;
}
add_filter( 'post_row_actions', 'custom_post_row_actions_https', 100 );
add_filter( 'page_row_actions', 'custom_post_row_actions_https', 100 );
function tf_start_buffer() {
ob_start();
}
add_action( 'wp_head', 'tf_start_buffer', 1 );
function tf_end_buffer() {
$output = ob_get_clean();
if( preg_match( '/class=\"themify_builder_row/', $output ) ) {
$output = str_replace(
'<meta name="builder-styles-css" content="" id="builder-styles-css">',
function themify_audio_player_module() {
/**
* Category list
* @var array
*/
$categories = array_merge(
array(
'off' => array(
'name' => __( 'Disable Audio Player', 'themify' ),
@shazdeh
shazdeh / functions.php
Last active March 30, 2016 18:35
Parallax Child theme
<?php
function custom_enqueue_scripts() {
wp_deregister_style( 'google-fonts' );
wp_enqueue_style( 'google-fonts', themify_https_esc('http://fonts.googleapis.com/css'). '?family=Crete+Round|Vidaloka|Alice');
}
add_action( 'wp_enqueue_scripts', 'custom_enqueue_scripts', 12 );
@shazdeh
shazdeh / gist:8585694
Created January 23, 2014 19:57
Parallax: display header slider controller buttons at the bottom of header
#gallery-controller .slider .slides {
position: absolute;
bottom: 100px;
top: auto !important;
left: 50% !important;
overflow: hidden;
width: 100px !important;
margin-left: -50px !important;
}
#gallery-controller .caroufredsel_wrapper,