Skip to content

Instantly share code, notes, and snippets.

View maxkostinevich's full-sized avatar
🚧
Work in progress

Max Kostinevich maxkostinevich

🚧
Work in progress
View GitHub Profile
@maxkostinevich
maxkostinevich / newvhost.cmd
Last active August 29, 2015 14:27
Shell script to create new Virtual Host on WAMP for Windows and XAMPP on Ubuntu.
:: Create new Virtual Host for WAMP SERVER
:: IMPORTANT!!! Run this script as Administrator
:: IMPORTANT!!! Make sure that variable vhosts_path is configured properly
@ECHO OFF
:: Path to the Apache VHosts file
SET vhosts_path=D:\work\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
:: Path to the WWW Directory
SET www_path=D:\work\wamp\www
SET www_path_unix=D:/work/wamp/www
@maxkostinevich
maxkostinevich / move-wp.sql
Created August 17, 2015 09:48
Move WordPress installation
UPDATE wp_options SET option_value = replace(option_value, 'http://OLDDOMAIN', 'http://NEWDOMAIN') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://OLDDOMAIN','http://NEWDOMAIN');
UPDATE wp_posts SET post_content = replace(post_content, 'http://OLDDOMAIN', 'http://NEWDOMAIN');
@maxkostinevich
maxkostinevich / functions.php
Last active August 29, 2015 14:27
Logger for WP plugins
<?php
/**
* Simple logger for WordPress plugins
* Author: Max Kostinevich
* Author URI: https://maxkostinevich.com
* Version: 1.0.0
* License: MIT
* 2015 (c) Max Kostinevich
*/
@maxkostinevich
maxkostinevich / functions.php
Created August 14, 2015 06:43
Convert multi-line string to UL-list
<?php
/*
* Convert multi-line string to UL-list
* 1. Explode the multi-line string ($string) into array by the new line symbol ("\n")
* 2. Convert the array back into the string using "implode" function and append the ul and li tags.
*/
function str_to_list($str){
return '<ul><li>' .implode('</li><li>', explode("\n", $str)). '</li></ul>';
}
@maxkostinevich
maxkostinevich / functions.php
Created July 30, 2015 16:02
Create Image from any friendly format
/**
* Create Image from any friendly format
*
* Return: Image Resource
*/
function imageCreateFromAny($filepath) {
$type = exif_imagetype($filepath); // [] if you don't have exif you could use getImageSize()
$allowedTypes = array(
1, // [] gif
2, // [] jpg
@maxkostinevich
maxkostinevich / app.js
Created July 15, 2015 16:20
Javascript Image preview before it uploaded to server
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
@maxkostinevich
maxkostinevich / functions.php
Created July 15, 2015 08:08
Restrict access to WP-Admin dashboard in WordPress
<?php
// RESTRICT ACCESS TO WP-ADMIN DASHBOARD
function restrict_admin_access(){
if( !current_user_can( 'edit_posts' ) ) {
wp_redirect( home_url() );
die();
}
}
add_action( 'admin_init', restrict_admin_access, 1 );
?>
@maxkostinevich
maxkostinevich / functions.php
Last active August 29, 2015 14:23
Get user IP Address
<?php
/* Get user IP Address */
function getUserIP() {
$IPAddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$IPAddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$IPAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$IPAddress = $_SERVER['HTTP_X_FORWARDED'];
@maxkostinevich
maxkostinevich / .htaccess
Created February 27, 2015 08:44
Force HTTPS for main domain
# Force HTTPS for the main domain
# Replace DOMAIN.COM with your domain name
RewriteEngine On
RewriteCond %{HTTPS} off
# Only redirect to https if the main domain (not subdomain) is matched
# case-insensitively in HTTP_HOST
RewriteCond %{HTTP_HOST} ^DOMAINNAME\.COM$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Disable force HTTPS for subdomains