• I am second develop a site with wordpress.(only use login/register system).

    Because wordpress with a high memory usage, So I am not using the latest wordpress script and use 3.2.1. Then for a further memory save. I modify wordpress main script for require. here is my custom config script.

    define('DB_NAME', 'wp');
    define('DB_USER', 'root');
    define('DB_PASSWORD', 'root');
    define('DB_HOST', 'localhost');
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');
    define('AUTH_KEY',         'some code');
    define('SECURE_AUTH_KEY',  'some code');
    define('LOGGED_IN_KEY',    'some code');
    define('NONCE_KEY',        'some code');
    define('AUTH_SALT',        'some code');
    define('SECURE_AUTH_SALT', 'some code');
    define('LOGGED_IN_SALT',   'some code');
    define('NONCE_SALT',       'some code');
    define('AUTOSAVE_INTERVAL', 100000000 );
    define('WP_POST_REVISIONS', false);
    $table_prefix  = 'wp_';
    define('WPLANG', '');
    define('WP_DEBUG', false);
    if ( !defined('ABSPATH') )
    	define('ABSPATH', dirname(__FILE__) . '/');
    define( 'WPINC', 'wp-includes' );
    require( ABSPATH . WPINC . '/load.php' );
    require( ABSPATH . WPINC . '/default-constants.php' );
    wp_initial_constants( );
    wp_check_php_mysql_versions();
    @ini_set( 'magic_quotes_runtime', 0 );
    @ini_set( 'magic_quotes_sybase',  0 );
    date_default_timezone_set( 'UTC' );
    wp_unregister_GLOBALS();
    wp_fix_server_vars();
    require( ABSPATH . WPINC . '/functions.php' );
    require( ABSPATH . WPINC . '/class-wp.php' );
    require( ABSPATH . WPINC . '/class-wp-error.php' );
    require( ABSPATH . WPINC . '/plugin.php' );
    require( ABSPATH . WPINC . '/pomo/mo.php' );
    require_wp_db();
    $GLOBALS['table_prefix'] = $table_prefix;
    wp_set_wpdb_vars();
    wp_start_object_cache();
    function wp_kses_normalize_entities($string) {
    	return $string;
    }
    function wp_logout_url($redirect = '') {
    	$args = array( 'action' => 'logout' );
    	if ( !empty($redirect) ) {
    		$args['redirect_to'] = urlencode( $redirect );
    	}
    
    	$logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
    	$logout_url = wp_nonce_url( $logout_url, 'log-out' );
    
    	return apply_filters('logout_url', $logout_url, $redirect);
    }
    function wp_login_url($redirect = '', $force_reauth = false) {
    	$login_url = site_url('wp-login.php', 'login');
    
    	if ( !empty($redirect) )
    		$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
    
    	if ( $force_reauth )
    		$login_url = add_query_arg('reauth', '1', $login_url);
    
    	return apply_filters('login_url', $login_url, $redirect);
    }
    function site_url( $path = '', $scheme = null ) {
    	return get_site_url(null, $path, $scheme);
    }
    function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
    	// should the list of allowed schemes be maintained elsewhere?
    	$orig_scheme = $scheme;
    	if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
    		if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
    			$scheme = 'https';
    		elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
    			$scheme = 'https';
    		elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
    			$scheme = 'https';
    		else
    			$scheme = ( is_ssl() ? 'https' : 'http' );
    	}
    
    	if ( empty( $blog_id ) || !is_multisite() )
    		$url = get_option( 'siteurl' );
    	else
    		$url = get_blog_option( $blog_id, 'siteurl' );
    
    	if ( 'http' != $scheme )
    		$url = str_replace( 'http://', "{$scheme}://", $url );
    
    	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
    		$url .= '/' . ltrim( $path, '/' );
    
    	return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id );
    }
    require( ABSPATH . WPINC . '/formatting.php' );
    require( ABSPATH . WPINC . '/capabilities.php' );
    require( ABSPATH . WPINC . '/query.php' );
    require( ABSPATH . WPINC . '/user.php' );
    require( ABSPATH . WPINC . '/meta.php' );
    wp_cookie_constants( );
    require( ABSPATH . WPINC . '/pluggable.php' );
    wp_set_internal_encoding();
    wp_functionality_constants( );
    wp_magic_quotes();
    do_action( 'sanitize_comment_cookies' );
    $wp_the_query = new WP_Query();
    $wp_query = $wp_the_query;
    $wp = new WP();
    $GLOBALS['wp_roles'] = new WP_Roles();
    $wp->init();
    do_action( 'init' );
    do_action('wp_loaded');

    I remove all the unwanted function, like blog, forum, comment, etc. This just for register and login. Then in the main page, use

    <?php
    include(dirname(__FILE__) .'/costom-config.php');
    ?>
    <!DOCTYPE html>
    ...

    insted of wp_header();

    Such a change will save 60% memory for each page load. I want to ask, is it safe for the login/register system? Thanks.

The topic ‘is it safe for custom require wp main script’ is closed to new replies.