This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generate_uuid(){ | |
$charid = md5(uniqid(rand(), true)); | |
$uuid = substr($charid, 0, 8) . "-" | |
.substr($charid, 8, 4) . "-" | |
.substr($charid,12, 4) . "-" | |
.substr($charid,16, 4) . "-" | |
.substr($charid,20,12); | |
return $uuid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function generate_uuid() { | |
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', | |
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), | |
mt_rand( 0, 0xffff ), | |
mt_rand( 0, 0x0fff ) | 0x4000, | |
mt_rand( 0, 0x3fff ) | 0x8000, | |
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Person { | |
private $name; | |
private $age; | |
private $id; | |
function __construct( $name, $age ) { | |
$this->name = $name; | |
$this->age = $age; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the hash of the current git HEAD | |
* @param str $branch The git branch to check | |
* @return mixed Either the hash or a boolean false | |
*/ | |
function get_current_git_commit( $branch = 'master' ) | |
{ | |
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) { | |
return $hash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Connection | |
{ | |
protected $link; | |
private $dsn, $username, $password; | |
public function __construct($dsn, $username, $password) | |
{ | |
$this->dsn = $dsn; | |
$this->username = $username; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
THESITE= "SITE-NAME" | |
THEDB="DATABASE-NAME" | |
THEDBUSER="DATABASE-USER" | |
THEDBPW="DATABASE-USER-PASSWORD" | |
THEDATE=`date +%d%m%y%H%M` | |
# export database | |
mysqldump -u $THEDBUSER -p${THEDBPW} $THEDB | gzip > /var/www/_backups/dbbackup_${THEDB}_${THEDATE}.bak.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', 'example_session_start', 1 ); | |
add_action( 'wp_login', 'example_session_regenerate' ); | |
add_action( 'wp_logout', 'example_session_end' ); | |
function example_session_start() { | |
if ( !session_id() ) { | |
session_save_path( '/mnt/data/www/example.com/sessions' ); | |
session_name( uniqid( 'example-', true ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); | |
/* | |
Plugin Name: Plugin x | |
*/ | |
add_action( 'wp_footer', 'example_plugin_name' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Render template | |
function tpl_set($template_name, $template_data = array()){ | |
if(stristr($template_name, '.php') === FALSE) { | |
$template_name = $template_name . '.php'; | |
} | |
// Create variables for each of sent data index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Activate WordPress Maintenance Mode | |
function maintenance_mode(){ | |
if(!current_user_can('edit_themes') || !is_user_logged_in()){ | |
wp_die('<h1 style="color:red">Website under Maintenance</h1><br />We are performing scheduled maintenance. We will be back online shortly!'); | |
} | |
} | |
add_action('get_header', 'maintenance_mode'); |