Skip to content

Instantly share code, notes, and snippets.

View paulund's full-sized avatar

Paulund paulund

View GitHub Profile
@paulund
paulund / login-to-wordpress-with-email-address.php
Created June 30, 2013 08:57
Function to allow users to login into WordPress using your email address.
<?php
function login_with_email_address($username) {
$user = get_user_by_email($username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address');
@paulund
paulund / secure-uploads-directory.txt
Created June 30, 2013 08:44
Secure the WordPress uploads directory
# Secure /uploads/ directory from unwanted file types
<Files ~ ".*..*">
Order Allow,Deny
Deny from all
</Files>
<FilesMatch ".(jpg|jpeg|jpe|gif|png|tif|tiff)$">
Order Deny,Allow
Allow from all
</FilesMatch>
@paulund
paulund / automatically-set-application-locale.php
Last active March 27, 2019 15:04
Automatically Detect Browser Language With PHP
<?php
$supportedLangs = array('en-GB', 'fr', 'de');
$languages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach($languages as $lang)
{
if(in_array($lang, $supportedLangs))
{
@paulund
paulund / add-option-to-dropdown.js
Created June 25, 2013 18:50
Add and Remove Options in Select using jQuery
$("#selectBox").append('<option value="option6">option6</option>');
@paulund
paulund / example-ltrim-function.php
Last active December 18, 2015 23:19
Examples of using multiple trim functions with PHP
<?php
$string = ' This is an example string ';
echo ltrim($string); // This is display the text This is an example string .
?>
@paulund
paulund / example-curl-request.php
Created June 25, 2013 18:39
Here is an example of a CURL request using PHP.
<?php
$request = "request=string of request";
// Send using curl
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url); // URL to post
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); // headers from above
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT, 8080);
@paulund
paulund / combine-multiple-javascript-files.php
Created June 25, 2013 18:33
A PHP snippet to read multiple javascript files and combine them by changing the content type of the combined files.
<?php
readfile('jquery.js');
readfile('general.js');
readfile('jquery-ui.js');
readfile('page.js');
header('Content-type: text/javascript');
?>
@paulund
paulund / cache-pages-with-php.php
Created June 25, 2013 18:27
Here is a quick code snippet which will allow you to easily cache pages in PHP.
<?php
//cache file
$cachefile = 'cached/'.date('M-d-Y').'.php';
//Total time the file will be cached in seconds set to 10 hours
$cachetime = 36000;
//If the cache file already exists and the cache file is over 10hours old then display the cache file
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
include($cachefile);
@paulund
paulund / debug-array-php.php
Last active December 18, 2015 23:19
Debug Array in PHP
<?php
echo '<pre>';
print_r($debug_array);
echo '</pre>';
exit;
@paulund
paulund / delete-all-files-in-folder.php
Last active December 18, 2015 08:49
Delete all files from a directory
<?php
/*
* php delete function that deals with directories recursively
*/
function delete_files($target) {
if(is_dir($target)){
$files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned
foreach( $files as $file )
{