Skip to content

Instantly share code, notes, and snippets.

View fahdi's full-sized avatar

Fahad Murtaza fahdi

View GitHub Profile
@fahdi
fahdi / home.php
Created November 30, 2013 22:29 — forked from slambert/home.php
<?php get_header() ?>
<!-- generated with home.php -->
<div id="home-banner">
<?php putRevSlider("tsleadin") ?>
</div><!-- #home-banner-->
<div id="home-container">
@fahdi
fahdi / functions.php
Created December 13, 2013 10:42
Add this code to your Wordpress theme's functions file. This will add two new fields to Wordpress registration form, first and last name.
<?php
//1. Add a new form element...
add_action('register_form','saratoga_register_form');
function saratoga_register_form (){
$first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
?>
<p>
<label for="first_name"><?php _e('First Name','saratoga') ?><br />
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
</p>
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
@fahdi
fahdi / code.php
Created December 31, 2013 04:44 — forked from anonymous/code.php
<?php
add_action( 'user_profile_update_errors', 'validate_field' );
function validate_field(&$errors, $update = null, &$user = null)
{
if($user->has_cap('s2member_level2')) { // Custom fields only display to business accounts
// Nested if to check for field(s)
if ($_POST['exp_years']=='' or $_POST['exp_years']==NULL) // Change to check for empty or any regular expression.
@fahdi
fahdi / scale_me_not_add_to_functions.php
Created December 31, 2013 17:37
How to crop uploaded images instead of scaling them Would you like to crop your thumbnails instead of scaling them? If yes, I have a very handy snippet for you today. Just read on and enjoy! Just add the code below to your functions.php file:
<?php
// Standard Size Thumbnail
if(false === get_option("thumbnail_crop")) {
add_option("thumbnail_crop", "1"); }
else {
update_option("thumbnail_crop", "1");
}
// Medium Size Thumbnail
@fahdi
fahdi / date_arithmetic.php
Created July 18, 2014 00:43
Some date arithmetic code I wrote nearly a decade ago. Use at your own risk!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
echo date("M-d-Y", mktime(0, 0, 0, 12, 32, 1997))."<br/>";
@fahdi
fahdi / frontpage.php
Created July 28, 2014 09:48
Advanced custom fields sorting
<?php
if ( have_rows( 'repeater_field', $order_id ) ) :
while ( have_rows( 'repeater_field', $order_id ) ) : the_row();
$type = get_sub_field( 'type', $order_id );
if( $type === 'tekst' ): ?>
<div id="customerMessageTxt">
<?php the_sub_field($type, $order_id); ?>
</div>
<?php
$terms = get_terms('focus15', array(
'exclude' => array(16, 20, 22, 25, 27, 28, 30, 4, 33 ), //* Enter ID's of parent categories to exclude from list
'hide_empty' => 0 ) );
if($terms)
{
echo '<ul>';
foreach($terms as $term)
{
ps xmo rss=,pmem=,comm= | while read rss pmem comm; ((n++<5)); do
size="$[rss/1024]";
short=$[4-${#size}];
size="(${size}M)";
i=0;
while ((i++ < short)); do size=" $size"; done;
pmem="${pmem%%.*}"
if (($pmem >= 20)); then color=$'\e[31m';