Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save githubutilities/5a47df549b54ded682d8 to your computer and use it in GitHub Desktop.

Select an option

Save githubutilities/5a47df549b54ded682d8 to your computer and use it in GitHub Desktop.
Wordpress Cheatsheet

Wordpress CheatSheet

Wordpress is a simple CMS(Content Management System) which can be used as a blog page.

Wordpress Database Hacks

  • change theme from database

change template ,stylesheet and current_theme rows under wp_options table(a key-value option table). Note: change their value to default to restore previous state. Refer here or here if you want more detail info.

Wordpress folder structure

  • wp-contents--plugins, themes, uploaded files
  • wp-admin--admin tools, it also acts as a sandbox to fix problems in case we mess things up
  • wp-includes--assets. e.g. you can file version info about wordpress under wp-includes/version.php

Reference

Wordpres management

  • /wp-admin/upgrade.php--upgrade wordpress while preserving data
  • /wp-admin/install.php--install wordpress
  • /wp-admin/--access to admin panel
  • /wp-login.php--login to wordpress

Reference

Wordpress for SAE

by default, SAE has Anti Leech feature enabled. Add your site domain name to the whitelist of SAE Storage Service to avoid 403 forbidden or 401 unauthorized errors.

Change Favicon

Use All in one Favicon Plugin. For MORE.

Remove Wordpress logo

add the following code to functions.php to your theme.

/**
 * Remove Wordpress Logo
 */
add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );

function remove_wp_logo( $wp_admin_bar ) {
	$wp_admin_bar->remove_node( 'wp-logo' );
}

Remove Leave a Reply

Delete <? php comments_template(); ?> in page.php and so on.

Other interesting plugins

Connecting SAE MySQL database

In wp-config.php change the following.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', SAE_MYSQL_DB);

/** MySQL database username */
define('DB_USER', SAE_MYSQL_USER);

/** MySQL database password */
define('DB_PASSWORD', SAE_MYSQL_PASS);

/** MySQL hostname */
define('DB_HOST', SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT);

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         hash_hmac('sha1', SAE_ACCESSKEY . 'AUTH_KEY', SAE_SECRETKEY ));
define('SECURE_AUTH_KEY',  hash_hmac('sha1', SAE_ACCESSKEY . 'SECURE_AUTH_KEY', SAE_SECRETKEY ));
define('LOGGED_IN_KEY',    hash_hmac('sha1', SAE_ACCESSKEY . 'LOGGED_IN_KEY', SAE_SECRETKEY ));
define('NONCE_KEY',        hash_hmac('sha1', SAE_ACCESSKEY . 'NONCE_KEY', SAE_SECRETKEY ));
define('AUTH_SALT',        hash_hmac('sha1', SAE_ACCESSKEY . 'AUTH_SALT', SAE_SECRETKEY ));
define('SECURE_AUTH_SALT', hash_hmac('sha1', SAE_ACCESSKEY . 'SECURE_AUTH_SALT', SAE_SECRETKEY ));
define('LOGGED_IN_SALT',   hash_hmac('sha1', SAE_ACCESSKEY . 'LOGGED_IN_SALT', SAE_SECRETKEY ));
define('NONCE_SALT',       hash_hmac('sha1', SAE_ACCESSKEY . 'NONCE_SALT', SAE_SECRETKEY ));

Fixing Image Upload Error Due to SAE File Permission

in funtion.php

function wp_mkdir_p( $target ) {
  $wrapper = null;

  if ( substr($target, 0, 10) == 'saestor://' ) {
    return true;
  }
  $target = str_replace( '//', '/', $target );

  // // Strip the protocol.
  // if( wp_is_stream( $target ) ) {
  // 	list( $wrapper, $target ) = explode( '://', $target, 2 );
  // }

  // // From php.net/mkdir user contributed notes.
  // $target = str_replace( '//', '/', $target );

  // // Put the wrapper back on the target.
  // if( $wrapper !== null ) {
  // 	$target = $wrapper . '://' . $target;
  // }
  ...
}
function wp_upload_dir( $time = null ) {
  ...
  $dir = 'saestor://'.SAE_STORAGE.SAE_DIR;
  $url = 'http://'.$_SERVER['HTTP_APPNAME'].'-'.SAE_STORAGE.'.stor.sinaapp.com'.SAE_DIR;
  
  $basedir = $dir;
  $baseurl = $url;
  
  $subdir = '';
  if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
  ...
}

in wp-config.php, add

/** SAE Storage Domain Name */
define('SAE_STORAGE', 'wordpress');

/** file upload path */
define('SAE_DIR','/uploads');

in wp-admin/includes/file.php, comment

  // Set correct file permissions.
  // $stat = stat( dirname( $new_file ));
  // $perms = $stat['mode'] & 0000666;
  // @ chmod( $new_file, $perms );

Testing on wordpress v4.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment