Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vienhoang
vienhoang / gist:04a3e843266f92413409
Created August 7, 2014 17:51
WordPress: Plugin comment
<?php
/*
Plugin Name: Movies Post Type
Plugin URI: http://vienhoang.com
Description: Offers a method for managing a movie collection.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / gist:242bb9e3cf0ea33e595e
Created August 9, 2014 13:43
PHP: Add url to text
function add_url_to_text( $text ) {
// Look for anything that is not a space, i = case insensitive, m = multiple line
$text = preg_replace('/(http[^s])+/im', '<a href="$1">$1</a>', $text );
return $text;
}
@vienhoang
vienhoang / messenger.php
Created August 11, 2014 16:21
WordPress: Custom widget
<?php
/*
Plugin Name: Messenger Widget
Plugin URI: http://vienhoang.com
Description: Display any messages.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / movies_post_type.php
Created August 11, 2014 16:22
WordPress: Custom post type
<?php
/*
Plugin Name: Movies Post Type
Plugin URI: http://vienhoang.com
Description: Offers a method for managing a movie collection.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / movies_post_type_shortcode.php
Created August 11, 2014 16:22
WordPress: Custom post type shortcode
<?php
add_shortcode( 'vh_movies', function() {
$loop = new WP_Query(
array(
'post_type' => 'vh_movie',
'orderby' => 'title'
)
);
if ( $loop->have_posts() ) {
@vienhoang
vienhoang / index.php
Created August 11, 2014 16:23
WordPress: Custom shortcode
<?php
/*
Plugin Name: Twitter Shower
Plugin URI: http://vienhoang.com
Description: Display message.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / vh_cron.php
Created August 11, 2014 16:23
WordPress: Custom cron job
<?php
/*
Plugin Name: VH Cron
Plugin URI: http://vienhoang.com
Description: Demo for running WP Cron Jobs
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / vh_filter.php
Created August 11, 2014 16:24
WordPress: Create custom filter
<?php
/*
Plugin Name: VH Filter
Plugin URI: http://vienhoang.com
Description: Filter the content.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / vh_options.php
Created August 11, 2014 16:24
WordPress: Create custom options page
<?php
/*
Plugin Name: VH Options
Plugin URI: http://vienhoang.com
Description: Options page for a theme.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / gist:e4c7dec93bd3e1c259ce
Created August 11, 2014 16:44
PHP: Break out of foreach func
function limiting($num) {
$fruits = array('bananas', 'apples', 'pear');
foreach ( $fruits as $v ) {
if ( $num-- === 0) {
break;
}