integrating wordpress into existing site
25 Dec
this is more for my reference than anything, but I cover the areas i modified to integrate wordpress in to a clients current site. I’m posting this, mainly to keep me from having to compare files everytime i do a wp upgrade. its by no means a solid tut as there are additional site classes / templates I’ve made to integrate the look / site functionality / security that are also used and not mentioned / documented here. as i said it’s written for myself, so i’m assuming you understand php / wordpress
wp-config.php
on the very first line of config.php include either the db config file, or the site wide control include (file that handles all of the general includes, etc)
set wordpress db config to use the globally defined vars. ex: define(‘DB_NAME’,SITE_DB_NAME);
any additional wordpress only includes should be included at the end of this file.
i also added in a secondary check to see if the current site user is logged in to wordpress, you can gt the current user as follows :
$the_user= wp_get_current_user();
$user_ego=$the_user->user_login;
if the current user is logged in to the actual site, but not into wordpress, i attempt to log them in using a login function in my custom site to wordpress connector class.
wp-db
bottom of file change :
if ( ! isset($wpdb) )
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
to
if ( ! isset($wpdb) ){
global $wpdb;
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
}
this will fix issues you run into when including the wordpress connections into a site / custom class.
Admin Area
open wp-admin/admin.php, setup any globals that are needed to require a vliad user for an area. ex: define(‘REQ_VALID_USER’,true)
wp-config will be included immediately after this. look for the line that says $posts_per_page, and add the something like following to limit access to the actual admin area:
global $current_user;
wp_get_current_user();
if(!empty($current_user)){
if(intval($current_user->user_level)< =WORDPRESS_LIMIT_ACCESS){//this var should be defined in your site wide define file
global $_SERVER;
$url=$_SERVER['REQUEST_URI'];
if(strpos($url,”?”)!==false){
$url=substr($url,0,strpos($url,”?”));
}
if(strpos($url,WORDPRESS_ADMIN)!==false && strpos($url,WORDPRESS_LIMIT_ADMIN_STR)===false){
header(‘location: ‘.WORDPRESS_LIMIT_PAGE) ;
exit;
}
}
}
the above code will check the curent url against the allowed urls for general users in admin, as well as redirect them to they limit page (write post) if they aren’t at the proper level. everyone else will be able to use the admin according to their level.
limiting post categories
either wp-admin/admin-functions.php or wp-admin/include/template.php
look for : function write_nested_categories( $categories ) {
limit categories as needed for general users, but be sure to leave an unmodified version for admin users.
remove nav for general users
replace : require(ABSPATH . ‘wp-admin/menu.php’); with
if(intval($current_user->user_level)>WORDPRESS_LIMIT_ACCESS){
require(ABSPATH . ‘/wp-admin/menu.php’);
}
customise nav header
wp-admin/admin-header.php
peace, sid

