Plugins
WordPress Database Backup: Quick Fix
The WordPress Plugin: WordPress Database Backup by Austin Matzko is one of the more intuitive backup plugins currently available and with no stern warnings to scare off the faint of heart it has held its own as a very effective and useful tool. Recently though it has come to our attention that a small issue exists for some users of WordPress 2.8 – 1.9.1 wherein the navigation menu has simply disappeared. This applies to WP-DB-Backup Version 2.2.2. The plugin performs correctly if set prior to an upgrade with scheduled emails arriving on time but with no easy way to make changes or force a manual backup. It was decided that our Clients needed immediate access and so we have written a quick fix and provided a download until the issue is corrected by the author. ( Update: 1/14/10 The author has left a comment and updated the plugin for compatibility with 2.9.1 but issue of a missing settings page seems to still persist )
Although the original issue at hand is a lack of management capabilities, we will be covering two modifications within this tutorial. The first alteration is Rediscovering and Relocating the navigational menu to a more suitable position under the Settings menu and the second alteration will be Granting Permissions to users other than the administrator.
Rediscover and Relocate:
In order to once again use the plugin’s settings page we will relocate the menu by altering the current page_hook from “add_management_page” to one of the many other options available ( see Adding Administration Menus codex ) provided by WordPress for more information. For our purposes we will be moving it to the Settings sub menu by using “add_options_page”. Locate the “wp-db-backup.php” and look for the following line of code on line 593:
function admin_menu() {
$_page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'backup_menu'));
add_action('load-' . $_page_hook, array(&$this, 'admin_load'));
if ( function_exists('add_contextual_help') ) {
$text = $this->help_menu();
add_contextual_help($_page_hook, $text);
}
}
and alter it from “add_management_page” to “add_options_page” effectively moving it from the Edit sub menu to the Settings sub menu which helps to keep the menu structure clean and organized.
function admin_menu() {
$_page_hook = add_options_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), '1', $this->basename, array(&$this, 'backup_menu'));
add_action('load-' . $_page_hook, array(&$this, 'admin_load'));
if ( function_exists('add_contextual_help') ) {
$text = $this->help_menu();
add_contextual_help($_page_hook, $text);
}
}
To complete the move locate this next line of code starting on line 601:
function fragment_menu() {
$page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'build_backup_script'));
add_action('load-' . $page_hook, array(&$this, 'admin_load'));
}
and again alter it from “add_management_page” to “add_options_page”.
function fragment_menu() {
$page_hook = add_options_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'build_backup_script'));
add_action('load-' . $page_hook, array(&$this, 'admin_load'));
}
This completes the Rediscovery and Relocation and at this point it is not necessary to move forward with the next step for Administrative access only. Because we needed to grant permissions to the Backup option for all users other than subscribers we will demonstrate this as well.
Grant Permissions:
In order to grant usage permissions WordPress provides a very intuitive and useful sliding scale ranging from 1 to 10 as well as a myriad of other capabilities specific to a user level to determine the access level of a particular user. For further information on this subject please see the Roles and Capabilities codex provided by WordPress.
Currently WordPress Database Backup utilizes the “import” role granting access by the site Administrator only. We will be making a minor alteration to grant all but subscribers access by using “level_1″. Locate the following function starting on line 592:
function admin_menu() {
$_page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import',
and alter “import” to “level_1″.
function admin_menu() {
$_page_hook = add_options_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'level_1',
Next locate the following function starting on line 601:
function fragment_menu() {
$page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import',
and again alter “import” to “level_1″.
function fragment_menu() {
$page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'level_1',
To complete the user access permissions locate the following on line 1389:
if ( ( $this->wp_secure('fatal', $loc) ) && current_user_can('import') )
$can = $this->verify_nonce($_REQUEST['_wpnonce'], $this->referer_check_key, $loc);
and alter “import” to “level_1″.
if ( ( $this->wp_secure('fatal', $loc) ) && current_user_can('level_1') )
$can = $this->verify_nonce($_REQUEST['_wpnonce'], $this->referer_check_key, $loc);
Please note that any role or capability access can be used. We hope this has been a helpful tutorial and has at least permitted access to the plugin once again.
Installation
- Download the plugin and expand it.
- Copy the d4-backup folder into your plugins folder ( wp-content/plugins ).
- Log-in to the WordPress administration panel and visit the Plugins page.
- Locate the d4-backup plugin and click on the activate link.
- The plugin will attempt to create a directory titled /wp-content/backup-*/ within your WordPress directory.
- It may be necessary to make the "wp-content" folder writable to create this directory.
Make A Donation
Feel free to buy us a cup of coffee and we will continue to improve on and create new plugins.
Austin,
I agree that it is a security risk used in the wrong situation i.e. Subscribers, Authors, etc. This is a situation where WordPress is used as a content management system for a website that is managed by a single user. This particular user has requested that we handle updates to the website while they maintain updates and regular backups due the type of website and the visitors involved. What we have done is limit the client’s admin options while allowing them to maintain a backup of their site when they deem it necessary. Keep in mind that WordPress is not always used as in community situation and therefore this particular modification may come in handy to some.
Could you explain why you would want to modify my plugin to allow those without admin rights to download copies of the database? Sounds like a security risk to me.