Skip to content

Instantly share code, notes, and snippets.

<?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);
<?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)) {
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}";
<?php
/**
* Translates a camel case string into a string with underscores (e.g. firstName -&gt; 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);
add_action('init', 'cng_author_base');
function cng_author_base() {
global $wp_rewrite;
$author_slug = 'profile'; // change slug name
$wp_rewrite->author_base = $author_slug;
}
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;}
<?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') ); } ?>
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
@achilles283
achilles283 / Custom WordPress Database Error Page
Created October 16, 2012 14:04
Custom WordPress Database Error Page
<?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
@achilles283
achilles283 / Publish to WP via cURL-XMLRPC
Created October 13, 2012 20:27
Publish a post to WordPress using cURL/XMLRPC
// 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