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 arrayToObject($d) { | |
if (is_array($d)) { | |
/* | |
* Return array converted to object | |
* Using __FUNCTION__ (Magic constant) | |
* for recursive call | |
*/ | |
return (object) array_map(__FUNCTION__, $d); |
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 objectToArray($d) { | |
if (is_object($d)) { | |
// Gets the properties of the given object | |
// with get_object_vars function | |
$d = get_object_vars($d); | |
} | |
if (is_array($d)) { |
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
server { | |
index index.php; | |
set $basepath "/var/www"; | |
set $domain $host; | |
# check one name domain for simple application | |
if ($domain ~ "^(.[^.]*)\.dev$") { | |
set $domain $1; | |
set $rootpath "${domain}"; |
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 | |
/** | |
* Translates a camel case string into a string with underscores (e.g. firstName -> first_name) | |
* @param string $str String in camel case format | |
* @return string $str Translated into underscore format | |
*/ | |
function from_camel_case($str) { | |
$str[0] = strtolower($str[0]); | |
$func = create_function('$c', 'return "_" . strtolower($c[1]);'); | |
return preg_replace_callback('/([A-Z])/', $func, $str); |
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
function your_last_login($login) { global $user_ID; $user = get_userdatabylogin($login); update_usermeta($user->ID, 'last_login', current_time('mysql'));}add_action('wp_login','your_last_login');function get_last_login($user_id) { $last_login = get_user_meta($user_id, 'last_login', true); $date_format = get_option('date_format') . ' ' . get_option('time_format'); $the_last_login = mysql2date($date_format, $last_login, false); echo $the_last_login;} |
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 //associating a function to login hook add_action('wp_login', 'set_last_login'); //function for setting the last login function set_last_login($login) { $user = get_userdatabylogin($login); //add or update the last login value for logged in user update_usermeta( $user->ID, 'last_login', current_time('mysql') ); } ?> |
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
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql | |
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql |
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 | |
// Put a file called "db-error.php" directly inside your /wp-content/ folder and WordPress will automatically use that when there is a database connection problem. | |
// custom WordPress database error page | |
header('HTTP/1.1 503 Service Temporarily Unavailable'); | |
header('Status: 503 Service Temporarily Unavailable'); | |
header('Retry-After: 600'); // 1 hour = 3600 seconds | |
// If you wish to email yourself upon an error |
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
// http://www.catswhocode.com/blog/10-awesome-things-to-do-with-curl | |
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8') | |
{ | |
$title = htmlentities($title,ENT_NOQUOTES,$encoding); | |
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding); | |
$content = array( | |
'title'=>$title, | |
'description'=>$body, | |
'mt_allow_comments'=>0, // 1 to allow comments |
NewerOlder