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 / 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 );
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Module Name: Plain Text
* Description: Display plain text
*/
class TB_Plain_Text_Module extends Themify_Builder_Module {
function __construct() {
parent::__construct(array(
'name' => __('Plain Text', 'themify'),
@shazdeh
shazdeh / gist:af82edb3870b36cce3f0
Created February 6, 2015 10:32
WP Jalali and Polylang Compatibility
<?php
/*
Plugin Name: WP Jalali and Polylang Compatibility
Description: Disables WP Jalali when Farsi is not the current language.
*/
function wp_jalali_polylang_compat() {
if( ! function_exists( 'pll_current_language' ) || pll_current_language() == 'fa' )
return;