Skip to content

Instantly share code, notes, and snippets.

View bboyvanz's full-sized avatar

G Van bboyvanz

  • Saigon
View GitHub Profile
@chrisguitarguy
chrisguitarguy / comments-example.php
Created September 21, 2011 21:44
How to add custom fields to WordPress comments
<?php
/*
Plugin Name: Add Extra Comment Fields
Plugin URI: http://pmg.co/category/wordpress
Description: An example of how to add, save and edit extra comment fields in WordPress
Version: n/a
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: MIT
*/
@iNamik
iNamik / replace_tags.php
Last active June 4, 2024 19:01
Simple PHP Function to Replace Tags in a String (i.e. "Hello, {{there}}" => "Hello, world")
<?php
/**
* replace_tags replaces tags in the source string with data from the tags map.
* The tags are identified by being wrapped in '{{' and '}}' i.e. '{{tag}}'.
* You may also space your tags like `{{ tag }}` for better readability.
* If a tag value is not present in the tags map, it is replaced with an empty
* string.
* @param string $string A string containing 1 or more tags wrapped in '{{}}'
* @param array $tags A map of key-value pairs used to replace tags.
@TechFounder
TechFounder / style.css
Created June 27, 2016 03:05
Buddha bless your code to be bug free
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@tomhazledine
tomhazledine / calculate_reading_time.php
Created November 16, 2016 08:30
Calculate Reading Time (for WordPress content)
<?php
/**
* READING TIME
*
* Calculate an approximate reading-time for a post.
*
* @param string $content The content to be measured.
* @return integer Reading-time in seconds.
*/
function reading_time( $content ) {
@mi-ca
mi-ca / bandcamp.embed.php
Last active November 12, 2021 03:36
Bandcamp Embed - YouTube Embed & SoundCloud Embed : PHP Classes to auto embed and grab links from Bandcamp, Youtube and Soundcloud
<?php
/**
* Analyse a string , grab Bandcamp links and replace them by embed player
* You may change the html code of the player in buildEmbed method
*
* @author Michael CAILLET <a href="https://mi-ca.ch">mi-ca.ch</a>
* @version 1.0
* @uses $bc=new BandCampEmbed($string);
* echo $bc->getEmbededText();
* // OR
@ybagheri
ybagheri / phpDownload.php
Created February 27, 2018 08:01
PHP Download remote resource URL file image video zip pdf doc xls
<?php
/*
PHP Download Image Or File From URL
I’ll show you 3 php functions that download a particular file (ex: image,video,zip,pdf,doc,xls,etc) from a remote resource (via a valid URL) then save to your server.
Depending on your current php.ini settings, some functions may not work; therefore, let try which function is best for you.
Note: please ensure the folder you want to store the downloaded file is existed and has write permission for everyone or the web process.
Download file from URL with PHP
<?php
/*
Function to import image from URL to WordPress media library and assign to a post
@params
$post_id - The post ID for which you need to assign the uploaded image as featured image
$image_url - The external image URL which needs to be imported to WordPress media library
*/
function import_featured_image_from_url( $post_id = '', $image_url ='' ) {
//Check both post_id and image_url is not empty
if($post_id == '' || $image_url == '') {