Skip to content

Instantly share code, notes, and snippets.

View wp-kitten's full-sized avatar

Costin wp-kitten

View GitHub Profile
/*
* Creates and updates the chaser menu depending on the loaded header
* @wpk
*/
(function($){
//TODO: IMPORTANT! UPDATE BEFORE DEPLOYMENT
var SITE_URL = 'http://localhost/bogdan/kallyas_html/';
// whether or not the chaser is visible
@wp-kitten
wp-kitten / gist:ad8da10000afe1d4276c
Created March 4, 2016 14:09
VaultPress - validate IP address
function vaultpress_validate_ip_address( $rxs ) {
$remote_ips = array();
if ( !empty( $_SERVER['REMOTE_ADDR'] ) )
$remote_ips[] = $_SERVER['REMOTE_ADDR'];
if ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
$remote_ips[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
$iprx = '/^([0-9]+\.[0-9]+\.[0-9]+\.)([0-9]+)$/';
@wp-kitten
wp-kitten / gist:238b0d44b641b4469e19
Created February 13, 2016 15:16
WordPress Image Upload in theme or plugin
// Enqueue scripts
wp_enqueue_script( 'jquery' );
wp_enqueue_media();
/*
* Generate the fields
*/
function generateImageUploadFields( $inputName, $buttonName, $previewImageID = '', $buttonValue = '')
@wp-kitten
wp-kitten / gist:7d03535ccefa4e8ebea0
Created January 18, 2016 11:57
WooCommerce: Override the add to cart quantity
add_filter('woocommerce_quantity_input_step', 'wpk_custom_quantity_input_step', 99, 1);
function wpk_custom_quantity_input_step(){
// Return the incrementing step here
return 5;
}
@wp-kitten
wp-kitten / gist:aed14374440a9ca85175
Created October 17, 2015 21:08
admin notice transient
<?php
/**
* Display the admin notice. This is an internal function. Do not call directly. Use uwtAdminNotice() instead.
* @internal
* @param string $type The type: error, updated
* @param string $message The message to display
* @return string
*/
function _uwt_admin_notice($type = 'error', $message = ''){
return '<div class="'.$type.'"><p>'.$message.'</p></div>';
<?php
// v4.7.4
$vc_params_list = array(
// Default
'textfield',
'dropdown',
'textarea_html',
'checkbox',
'posttypes',
@wp-kitten
wp-kitten / gist:99d0902e4579a2421ff6
Created October 10, 2015 19:12
Dynamically set post featured image to existent posts
<?php
/*
* This script will process all images from the specified directory from your server and set them as featured images
* for posts.
*
* 1) Upload all images to wp-content/uploads/DIR_NAME -- Only images should be in that directory!
* 2) Update BHWP_UPLOADS_DIR to match the name of your directory
*/
/*
@wp-kitten
wp-kitten / gist:cef024775684f52129ea
Created October 5, 2015 10:55
WooCommerce - Different prices for users
<?php
/**
* Plugin Name: WC Price
* Plugin URI: http://localhost
* Description: WC set different prices
* Version: 1.0
* Author: kso
* Requires at least: 4.1
* Tested up to: 4.3
*
<?php
$options = array(
'has_tabs' => true,
'css_selector' => '.',
'general' => array(
'title' => 'General options',
'options' => array(
array(
'id' => 'use_custom_style',
'name' => 'Map custom style',
/* actions fired when listing/adding/editing posts or pages */
/* admin_head-(hookname) */
add_action( 'admin_head-post.php', 'admin_head_post_editing' );
add_action( 'admin_head-post-new.php', 'admin_head_post_new' );
add_action( 'admin_head-edit.php', 'admin_head_post_listing' );
function admin_head_post_editing() {
echo 'you are editing a post';
}