Skip to content

Instantly share code, notes, and snippets.

@xafarali
xafarali / add_woocom_setting_page.php
Last active November 6, 2015 01:38
Add Options to Woocomm Setting Page
add_filter( 'woocommerce_general_settings', 'add_order_number_start_setting' );
/*
woocommerce_general_settings
woocommerce_catalog_settings
woocommerce_page_settings
woocommerce_inventory_settings
woocommerce_tax_settings
woocommerce_shipping_settings
woocommerce_payment_gateways_settings
// Random Generator
function gen_rand(length, type ) {
var mode = type || 0;
/*
* @length , Length of Random output
* @type , Mode of Random Generator
0 = mixed string mode
1 = digits
2 = string
@xafarali
xafarali / number_pattern.php
Created January 1, 2015 00:01
Replace Numbers with Pattern
$num = 123;
$format = 'ABC-####-09';
print preg_replace('/(#+)/e', 'str_pad($num, strlen("$1"), 0, STR_PAD_LEFT)', $format);
@xafarali
xafarali / zoom_all.js
Last active August 29, 2015 14:11
Google Map , zoom to bound
// map: an instance of google.maps.Map object
// latlng: an array of google.maps.LatLng objects
// latlng: needs lat, long as interger , so must parse them to interger first.
var latlngbounds = new google.maps.LatLngBounds();
for (var i = 0; i < latlng.length; i++) {
latlngbounds.extend(latlng[i]);
}
map.fitBounds(latlngbounds);
@xafarali
xafarali / tax_with_nested_slug
Last active August 29, 2015 14:11
Custom Post type with taxonomy and Nested Slug
// <url><posttype_slug><taxonomy>
function my_custom_post_work() {
$labels = array(
'name' => _x( 'Work', 'post type general name' ),
'singular_name' => _x( 'Work', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Work' ),
'edit_item' => __( 'Edit Work' ),
'new_item' => __( 'New Work' ),
'all_items' => __( 'All Work' ),
@xafarali
xafarali / image_caption.php
Created July 9, 2013 01:28
Image Caption Alt and Description
<?php
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $image->post_content;
//$img_path = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ),'full') ;
?>
@xafarali
xafarali / check_child.php
Created July 8, 2013 21:49
Check all set of child page for given page
/* -----------------------------------------------------
* Page - Checks child subset to enable widget in sidebar
-------------------------------------------------- */
function has_page_child_set( $page_check ) {
global $post;
//global $page_check;
//$page_check = $name;
@xafarali
xafarali / post_term_1.php
Created June 19, 2013 01:18
Get Post by Taxanomy terms
<?php
$args = array(
'post_type'=> 'services',
'areas' => 'painting',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
@xafarali
xafarali / improved_wp_excerpt.php
Created June 16, 2013 22:35
Great except, IMPROVED!!
function improved_trim_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]&gt;', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
$text = strip_tags($text, '<p>');
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
@xafarali
xafarali / string_replace.php
Created June 16, 2013 16:56
String Relace
function str_lreplace($needle, $replace, $haystack)
{
/*
int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )
Find the numeric position of the last occurrence of needle in the haystack string.
*/
$pos = strrpos($haystack, $needle);
if($pos !== false)
{
$subject = substr_replace($haystack, $replace, $pos, strlen($needle));