Skip to content

Instantly share code, notes, and snippets.

View azeemhassni's full-sized avatar

Azeem Hassni azeemhassni

View GitHub Profile
@azeemhassni
azeemhassni / script.js
Last active August 29, 2015 14:01
Email Validation Regular Expression
// ^([0-9a-zA-Z\._])+@([a-zA-Z0-9])+\.([0-9A-Za-z]){2,4}([\.a-zA-Z0-9]){0,3}+$
// example : (jQuery) Javascript
function validateEmail(email){
var pattren = new RegExp("^([0-9a-zA-Z\._])+@([a-zA-Z0-9])+\.([0-9A-Za-z]){2,4}([\.a-zA-Z0-9]){0,3}+$");
if(pttren.test(email)){
return true;
} else
@azeemhassni
azeemhassni / wp_is_tmpl.php
Last active August 29, 2015 14:02
Recognize wordpress template .
<?php
/**
* @param : $template_name
* @Author : Azi Baloch
* Description : this function will recognize that is the wordpress current page
* using N template or not .
* eg . i want to add body id depending on template then i can use this function
* to check the currently being used template
**/
@azeemhassni
azeemhassni / MinutesToTimeString.php
Created June 19, 2014 10:26
Convert Minuts to Time String
<?php
function timeToString($time) {
$t = $time / 60;
$t = number_format($t, 2);
// Result 1.5;
$__t = explode('.', $t);
$m = "0.".$__t[1];
$m * 60;
$m = $m*60;
@azeemhassni
azeemhassni / filter_posts
Created June 20, 2014 14:12
Wordpress Filter Posts
SELECT p.* FROM knr_posts p, knr_term_taxonomy tt, knr_term_relationships tr
WHERE p.ID=tr.`object_id`
AND tt.`term_id`=tr.`term_taxonomy_id`
AND (p.post_type = 'recipe_cpt' OR
AND p.post_status = 'publish'
AND tt.`term_taxonomy_id`=7
@azeemhassni
azeemhassni / datestring.php
Created July 5, 2014 22:42
function get Custom date String
<?php
function customDateString($return = false){
$date = "";
$dayName = date("l");
$dayNumber = date('d');
$monthName = date('F');
$year = date("Y");
$st = array(1,31);
$nd = array(2,22);
@azeemhassni
azeemhassni / select_if_regex.php
Created July 9, 2014 06:31
Select IF Block using Regular Expressions
<?php
$pat = 'if\(.*\)\s?\{\n?(.*\s\n?)+\}'
$matches = array();
$code = 'if($var != $var2) {
// code
}';
$isFound = preg_match($pat,$code,$matches);
@azeemhassni
azeemhassni / wp_get_current_template_name.php
Last active August 29, 2015 14:03
WordPress get Current Template Name
/**
* @param bool $return
* @return mixed
*/
function get_current_template_name($return = FALSE) {
$files = get_included_files();
$result = null;
$e = false;
@azeemhassni
azeemhassni / uns.php
Created August 12, 2014 23:59
Unique Number Sequance
<?php
$g = null;
function generate_unique_name(){
global $g;
if(is_null($g)) {
return $g = (((rand()*rand())+rand()));
}
return ++$g;
@azeemhassni
azeemhassni / center.js
Created August 18, 2014 10:27
jQuery Center element method
// add Center method to jquery
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
$(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
$(window).scrollLeft()) + "px");
return this;
}
@azeemhassni
azeemhassni / wp_num_pagination.php
Last active August 29, 2015 14:08
WordPress Numaric Pagination
<?php
/**
* @param string $pages
* @param int $range
* @param WP_Query|null $custom_query
* @author Azi Baloch <www.azibaloch.com>
*/
function wp_print_numaric_pagination( $pages = '', $range = 4, $custom_query = null) {
global $paged;