Skip to content

Instantly share code, notes, and snippets.

@sang4lv
sang4lv / weixin
Last active December 18, 2015 01:19
<?php
class Weixin {
public function __construct($postStr) {
if( !empty($_GET['echostr']) && $this->check_signature() ) {
echo $_GET['echostr'];
return;
}
if( empty($postStr) ) {
add_filter( 'walker_nav_menu_start_el', 'antu_modify_menu', 10, 2 );
function antu_modify_menu( $output, $item ) {
if($item->url == "#") {
$link = get_latest_post($item->xfn);
$output = str_replace('href="#"', 'href="' . $link . '"', $output);
return $output;
} else {
return $output;
@sang4lv
sang4lv / disable_update
Created July 23, 2013 12:46
Disable Wordpress Core, Plugins, and Themes Update
<?php
//Disable Theme Updates
# 2.8 to 3.0:
remove_action( 'load-themes.php', 'wp_update_themes' );
remove_action( 'load-update.php', 'wp_update_themes' );
remove_action( 'admin_init', '_maybe_update_themes' );
remove_action( 'wp_update_themes', 'wp_update_themes' );
add_filter( 'pre_transient_update_themes', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_themes' );
@sang4lv
sang4lv / gist:6088370
Created July 26, 2013 12:05
Settings API
<?php
//Options Page Configuration
function admin_init_callback() {
register_setting( 'msp_settings', 'msp_duration' );
add_settings_section( 'msp_settings', __('Multisite Posts Configuration'), false, 'general' );
add_settings_field( 'msp_duration', __('Cache Duration'), array($this, 'msp_settings_callback'), 'general', 'msp_settings', array(
"id" => "msp_duration",
@sang4lv
sang4lv / scraper
Last active December 20, 2015 13:29
Node JS Webpage Scraper
var url = require("url");
var http = require("http");
var jsdom = require("jsdom");
var request = require("request");
var server = http.createServer( function( top_request, top_response ) {
var pathname = top_request.url.split("/");
var uri_path = "";
if( "author" === pathname[1] &&
pathname[2] ) {
@sang4lv
sang4lv / gist:6203849
Created August 11, 2013 07:20
Error on Scraper
root@angelawang:/var/www/node/scraper# node main.js
/var/www/node/scraper/main.js:16
if(err) throw err;
^
Error: Invalid URI "undefined"
at Request.init (/var/www/node/scraper/node_modules/request/index.js:205:24)
at new Request (/var/www/node/scraper/node_modules/request/index.js:124:8)
at Function.request [as get] (/var/www/node/scraper/node_modules/request/index.js:1275:11)
at Server.<anonymous> (/var/www/node/scraper/main.js:12:10)
@sang4lv
sang4lv / attachMediaFromUrl.php
Created August 11, 2013 12:21
Insert file to media library and attach it to post
<?php
function attachMediaFromUrl( $url, $post_id = 0, $file_type = null ) {
//Fetch Media And Set Path
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$upload_dir = wp_upload_dir();
$file_name = basename( $url );
$image_data = @file_get_contents( $url );
$file = wp_mkdir_p( $upload_dir['path'] ) ? $upload_dir['path'] : $upload_dir['basedir'];
$file .= '/' . $file_name;
@sang4lv
sang4lv / gist:6208716
Created August 12, 2013 06:55
Remove Version No
<?php
add_filter( 'style_loader_src', 'idu_remove_version_no', 9999 );
add_filter( 'script_loader_src', 'idu_remove_version_no', 9999 );
//Hack to get rid of the bloody automatic version no
function idu_remove_version_no($src) {
if ( strpos( $src, 'ver=' ) ) {
$src = remove_query_arg( 'ver', $src );
}
<?php
class Idu_Taxonomy {
function __construct($taxonomy) {
$this->taxonomy = $taxonomy;
$this->taxonomy["singular"] = $this->prepare_name($taxonomy["singular"]);
$this->taxonomy["plural"] = $this->prepare_name($taxonomy["plural"]);
if("tax" == $taxonomy["type"]) {
@sang4lv
sang4lv / main.js
Last active December 21, 2015 00:19
URL Shortener
var mongoose = require('mongoose');
var http = require('http');
mongoose.connect("mongodb://localhost/shortener");
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
var urlSchema = mongoose.Schema({
slug: String,