Skip to content

Instantly share code, notes, and snippets.

@faishal
faishal / README
Last active August 29, 2015 14:13 — forked from westonruter/README
Moved to https://github.com/xwp/vip-quickstart/pull/3
@faishal
faishal / remove-kernal.sh
Created March 9, 2015 14:27
Remove unused kernels in ubuntu
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get purge
<?php
add_action( 'widgets_init', 'nbclatino_top_posts_widget_init' );
function nbclatino_top_posts_widget_init() {
// Check if our vip stats function is available
if ( !function_exists( 'wpcom_vip_get_stats_array' ) && ! function_exists( 'stats_get_csv' ) )
return;
unregister_widget( 'Jetpack_Top_Posts_Widget' );
@faishal
faishal / hook.php
Created June 11, 2013 06:06
Web hook php sample code for activeCollab
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$repos= array();
@faishal
faishal / gist:6102452
Last active December 20, 2015 08:39
List all event bind to element
$._data( $("#foo")[0], "events" );
@faishal
faishal / rtMedia_fix_broken_media_path
Created August 12, 2013 10:36
rtMedia fix broken media path . add function in plugin/theme and call yoursite.com/?fix_broken_media=true
function check_broken_media () {
global $wpdb;
$media_model = new RTMediaModel();
$ob_migration = new RTMediaMigration();
$sql = "select * from wp_postmeta m join wp_posts p on p.ID = m.post_id where meta_value like '%rtMedia%'";
$results = $wpdb->get_results ( $sql );
$upload_path = trim ( get_option ( 'upload_path' ) );
if ( empty ( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
$dir = WP_CONTENT_DIR . '/uploads';
@faishal
faishal / bp_latest_update_fix.php
Created September 2, 2013 06:36
User latest update Fix. add this code in theme/plugin and then call yoursite.com/?bp_latest_update_fix=true
if( ! function_exists ("bp_latest_update_fix" )){
function bp_latest_update_fix () {
global $wpdb;
$sql = "select * from $wpdb->usermeta where meta_key like 'bp_latest_update'";
$results = $wpdb->get_results ( $sql );
foreach ( $results as $row ) {
if ( $meta_value = maybe_unserialize ( $row->meta_value ) ) {
if ( is_array ( $meta_value ) ) {
if ( isset ( $meta_value[ "content" ] ) && strpos ( $meta_value[ "content" ], "update_txt" ) !== false ) {
$data_up = json_decode ( $meta_value[ "content" ] );
@faishal
faishal / auto-crop-image.php
Created January 9, 2014 06:13
Auto crop image using image magic
//Calculate frame ratio
$frame_ratio = ( float ) $frame_w / ( float ) $frame_h ;
//Calculate image ratio
$image_ratio = ( float ) $image_w / ( float ) $image_h ;
//Checking if both ratio are same
if ( round ( $frame_ratio , 2 ) != round ( $image_ratio , 2 ) ) {
@faishal
faishal / force-no-ssl.php
Created April 1, 2016 15:41
Force WordPress front end to http instead of https
add_action( 'template_redirect', 'wpmu_ssl_template_redirect', 1 );
function wpmu_ssl_template_redirect() {
if ( is_ssl() && ! is_admin() ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ), 301 );
exit();
} else {
@faishal
faishal / wpdb-in-query-prepare.php
Last active April 11, 2016 13:07
WPDB In Query Prepare
<?php
global $wpdb;
if ( is_array( $ids ) ) {
$in_str_arr = array_fill( 0, count( $ids ), '%d' );
$in_str = join( ',', $in_str_arr );
$form_id_where = $wpdb->prepare( "ID IN ($in_str)", $ids );
} else {
$form_id_where = $ids> 0 ? $wpdb->prepare( 'ID=%d', $ids ) : '';
}