Skip to content

Instantly share code, notes, and snippets.

@razaanstha
razaanstha / wp-config.php
Created January 16, 2024 13:27
Redirect all of your local WP site medias to remote site; saving local storage and media migration hassle.
<?php
$remote_site = 'https://' . basename(dirname(__FILE__)) . '.com';
// Comment the line above and uncomment the following line if your local site url is not based on directory
// $remote_site = 'https://www.your-remote-site.com';
if (!empty($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['REQUEST_URI']) && preg_match('/^\/wp-content\/uploads\/(.*)$/', $_SERVER['REQUEST_URI'], $matches) && !file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI'])) {
header('Location: ' . $remote_site . '/wp-content/uploads/' . $matches[1]);
exit;
}
@razaanstha
razaanstha / acf-block.php
Created December 6, 2023 16:55
ContentEditable - ACF Block
<?php
/**
* Block: Hero
* --------------------------------
* The hero block for all pages.
*/
$block_data = get_fields();
?>
@razaanstha
razaanstha / getCompanyName.js
Created September 4, 2023 02:58
NEPSE: Get Real Time Stock Price on Google Sheets
/**
* Returns the company name of a NEPSE stock.
*
* @param {string} stockSymbol - The stock symbol to retrieve the company name for.
* @return {string} The company name of the specified stock.
* @customfunction
*/
function getCompanyName(stockSymbol) {
if (!stockSymbol) return '#SYMBOL_MISSING';
const response = UrlFetchApp.fetch("https://nepse-test.vercel.app/api?symbol=" + stockSymbol);
@razaanstha
razaanstha / gist:af10490a09422231094e1cb4ea5a2b2c
Last active August 8, 2023 16:59
Enhancing YouTube and Vimeo Video Embeds for GDPR Compliance in WordPress
add_filter('embed_oembed_html', 'gdpr_compliant_embed_for_youtube_and_vimeo');
function gdpr_compliant_embed_for_youtube_and_vimeo($html)
{
if (preg_match('/src="(.+?)"/', $html, $matches)) {
$source = !empty($matches[1]) ? parse_url($matches[1]) : '';
$host = !empty($source['host']) ? $source['host'] : '';
// For Youtube embedded videos
if ($host && ($host == 'www.youtube.com' || $host == 'youtu.be')) {
$html = str_replace($host, 'www.youtube-nocookie.com', $html);