Skip to content

Instantly share code, notes, and snippets.

View adeel-raza's full-sized avatar

Adeel adeel-raza

View GitHub Profile
@adeel-raza
adeel-raza / fix-wordpress-permissions.sh
Created April 22, 2016 11:29 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@adeel-raza
adeel-raza / dl-file.php
Created July 5, 2016 11:51 — forked from hakre/dl-file.php
Wordpress login to download uploaded files
<?php
/*
* dl-file.php
*
* Protect uploaded files with login.
*
* @link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* @author hakre <http://hakre.wordpress.com/>
* @license GPL-3.0+
@adeel-raza
adeel-raza / uploads-remote-nginx-apache.md
Last active October 4, 2016 10:56 — forked from rahilwazir/uploads-remote-nginx-apache.md
Map uploads dir on local system to remote server

Nginx

Put this within server { ... } block of your vhost

location ~ "^(.*)/your_uploads_folder/(.*)$" {
    if (!-e $request_filename) {
        return 302 http://yourlivesite.com$request_uri;
    }
}
@adeel-raza
adeel-raza / check-if-on-backend-in-WP.php
Created October 19, 2016 15:23
Load content based on the condition that whether its the WP backend or frontend
<?php
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
// run Backend only code here
} else {
// Frontend code here, this will include the ajax calls
}
@adeel-raza
adeel-raza / textbox-range-limit.js
Created April 6, 2017 15:35
Limit the range of a numeric textbox with Jquery
jQuery("#textbox_id").on("keypress", function(e){
var currentChar = parseInt(String.fromCharCode(e.keyCode), 10);
if(!isNaN(currentChar)){
var nextValue = elem.val() + currentChar; //It's a string concatenation, not an addition
if(parseInt(nextValue, 10) <= 20) return true;
}
return false;
});
@adeel-raza
adeel-raza / parse-csv-as-associate-array.php
Created May 5, 2017 09:57
Parse a CSV as an associate array with column names as keys and row as values
$csv = array_map("str_getcsv", file("file1.csv",FILE_SKIP_EMPTY_LINES));
$keys = array_shift($csv);
foreach ($csv as $i=>$row) {
$csv[$i] = array_combine($keys, $row);
}
@adeel-raza
adeel-raza / date-comparison.php
Created May 13, 2017 08:05
Compare 2 dates and find the difference in days between them
<?php
$match_date = \DateTime::createFromFormat("Y-m-d H:i:s", $date_1);
$match_date->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison
$today = new \DateTime(); // This object represents current date/time
$today->setTime( 0, 0, 0 ); // reset time part, to prevent partial comparison
$diff = $today->diff( $match_date );
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval
@adeel-raza
adeel-raza / wp_mail_smtp.php
Created May 13, 2017 13:23 — forked from butlerblog/wp_config.php
Configure WordPress wp_mail function to send through SMTP server http://b.utler.co/Y3
/**
* This function will connect wp_mail to your authenticated
* SMTP server. This improves reliability of wp_mail, and
* avoids many potential problems.
*
* Author: Chad Butler
* Author URI: http://butlerblog.com
*
* For more information and instructions, see:
* http://b.utler.co/Y3
$fileName = 'Billing-Summary.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$fh = @fopen( 'php://output', 'w' );
<?php
# RegEx For Eval Removal: \s+(eval\(base64.*?\))\);
exit;
function back_to_for_slash($str) {
return str_replace('\\', '/', $str);
}
$current_dir = back_to_for_slash(dirname(__FILE__) . '/public_html');
$directory = $current_dir;