Skip to content

Instantly share code, notes, and snippets.

@rambuvn
rambuvn / gist:3690013
Created September 10, 2012 09:51
Strip some html tag without strip_tags
function strip_html_tags( $text )
{
$text = preg_replace(
array(
// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
@rambuvn
rambuvn / gist:3792134
Created September 27, 2012 04:22
Check auto save for wordpress save_post action
// check autosave
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || ( defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit']) ) return $post_id
@rambuvn
rambuvn / gist:3904100
Created October 17, 2012 06:56
menu hover on touch-able device
//MENU HOVER ON TOUCH-able DEVICE
if( 'ontouchstart' in document.documentElement ){
var clickable = null;
$('.touchable').each(function(){
var $this = $(this);
if( $this.find('ul.sub-menu').length > 0 ){
$this.find('a:first').unbind('click').bind('touchstart',function(event){
if( clickable != this ){
@rambuvn
rambuvn / gist:3904593
Created October 17, 2012 09:02
my hook, allow all user can edit comment ( subscriber )
//Trick allow user subscriber can edit comment
function nex_update_cap($allcaps){
//print_r($allcaps);
global $comment;
if( !empty($comment) ){
global $current_user;
if( $current_user->ID == $comment->user_id ){
$allcaps['edit_others_posts'] = 1;
$allcaps['edit_published_posts'] = 1;
@rambuvn
rambuvn / gist:3956712
Created October 26, 2012 03:32
new check of wordpress
/*-----------------------------------------------------------------------------------*/
/* Get newest post day of each category
/*-----------------------------------------------------------------------------------*/
if ( !function_exists( 'wallpress_is_new_post' ) ) :
function wallpress_is_new_post( $post_id ) {
//Get newest point of time of each category, must be newest and lessthan 3 days
$categories = get_the_category( $post_id );
foreach ( $categories as $category ) {
$date = wallpress_newest_post_category( $category->cat_ID );
$post_date = get_the_time( 'Y-m-d', $post_id );
@rambuvn
rambuvn / gist:5308525
Created April 4, 2013 07:30
allow to edit comment on the articles which are not theirs
function rb_add_role( $allcaps, $caps, $args ){
global $post;
if( 'edit_comment' == $args[0] ) {
foreach ($caps as $cap) {
if( ! array_key_exists($cap, $allcaps) ) {
$allcaps[$cap] = 1;
}
}
}
return $allcaps;
@rambuvn
rambuvn / gist:5590620
Created May 16, 2013 09:45
developing facebook menu
var ondrag = false,
pointStart = lastPoint = distance = currentTranslate = 0;
$(window).on('mousedown mousemove mouseup touchmove touchstart touchend',function(event){
console.log( event );
switch(event.type) {
case 'touchstart':
case 'mousedown':
ondrag = true;
pointStart = lastPoint = event.pageX || event.originalEvent.touches[0].pageX;
break;
@rambuvn
rambuvn / gist:8416162
Created January 14, 2014 10:14
Twitter Follow to Do Something
<div id="rb-follow-button"></div>
<script>
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
}(document, "script", "twitter-wjs"));
twttr.ready(function(twttr){
/*-----------------------------------------------------------------------------------*/
/* Question Actions
/*-----------------------------------------------------------------------------------*/
add_filter('dwqa_filter_bar','custom_dwqa_question_filter');
function custom_dwqa_question_filter( $tag_field ) {
ob_start();
?>
<div class="filter-by-tags select">
<?php
$selected = get_query_var( 'dwqa-question_tag');
@rambuvn
rambuvn / rb_eta.php
Created February 13, 2014 07:40
Estimate Reading Time For Wordpress
/** Estimate Reading Time
*----------------*/
if( !function_exists('rb_timeline_eta') ) {
function rb_timeline_eta(){
global $post;
$words_per_minute = 270;
$words_per_second = $words_per_minute / 60;
$post_content = $post->post_content;
$word_count = str_word_count(strip_tags($post_content));