Ok.. I will try and be as detailed as I can with the issue I'm having. Also there is a good chance I am doing something wrong in my php / wordpress code as I've not been using the language for very long.
I have created two wordpress plugins. One is a gallery and one is a page building plugin. Both plugins work fine from the front end and the admin area. The problem occurs when you navigate away from the plugin settings page in the admin area, any other admin area link you navigate to will appear as a blank page, except if you click on the root plugin settings link or the root settings link for the other plugin I have made (works both ways).
Also the issue is not reproduced if you navigate away from either of the plugins root menu. It is only when you are on the Add New / Edit section of the plugin. This area of the plugin is accessing the $wpdb object and is pulling data from the SQL table I have created for each plugin. Also the both Add New / Edit pages are making use of the Media Uploader with the use of wp_equeue_media().
I have tried turning on all manner of logs none of which are reporting / displaying anything. I have tried commenting out the call to $wpdb and wp_equeue_media(). I have tried adjusting the php memory limits and those in wp-config.php. None of this has worked.
Here is the code for the gallery plugin as it is the smaller of the two and they have both been built in a similar way...
This is the main plugin page php
<?php
/**
* Plugin Name: BoxGallery
* Plugin URI: asd
* Description: asd
* Version: 1.0
* Author: asd
* Author URI: asd
* License: GPL2
**/
// GLOBALS
global $boxgal_table_name;
global $boxgal_galleries;
global $toplevel_slug;
// INCLUDES
include('admin/boxgal-admin.php');
function boxgal_init()
{
global $wpdb;
global $boxgal_table_name;
global $boxgal_galleries;
global $toplevel_slug;
$toplevel_slug = 'boxgallery';
$boxgal_table_name = $wpdb->prefix."boxgal";
if($wpdb->get_var("SHOW TABLES LIKE '$boxgal_table_name'") == $boxgal_table_name)
$boxgal_galleries = $wpdb->get_results("SELECT * FROM $boxgal_table_name");
}
add_action('init', 'boxgal_init');
function boxgal_enqueue()
{
wp_enqueue_script('box-slider', plugins_url('/slider/box-slider.js', __FILE__ ));
wp_enqueue_style('box-slider-style', plugins_url('/slider/box-slider-style.css', __FILE__ ));
}
add_action('wp_enqueue_scripts', 'boxgal_enqueue');
function boxgal_install()
{
global $wpdb;
global $boxgal_table_name;
$boxgal_table_name = $wpdb->prefix."boxgal";
if($wpdb->get_var("SHOW TABLES LIKE '$boxgal_table_name'") != $boxgal_table_name) {
$sql = 'CREATE TABLE '.$boxgal_table_name.'(
id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(255),
slug VARCHAR(255),
size_x INTEGER,
size_y INTEGER,
images VARCHAR(255),
trans_type VARCHAR(255),
trans_time INTEGER,
slide_hold INTEGER,
PRIMARY KEY (id))';
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}
register_activation_hook( __FILE__, 'boxgal_install');
function boxgal_shortcode($atts)
{
if (isset($atts['tag'])) {
global $boxgal_galleries;
$tag = $atts['tag'];
$tag_gallery = null;
$tag_gallery_imgs;
foreach ($boxgal_galleries as $gallery) {
if ($tag == $gallery->slug) {
$tag_gallery = $gallery;
$tag_gallery_imgs = explode(",", $tag_gallery->images);
break;
}
}
if ($tag_gallery == null) {
return '<span style="color:#F00;"><b>BoxGallery </b>- Could not find the '.$tag.' gallery. Please check spelling and that the gallery exists.</span>';
}
else
{
$output_html = '<script type="text/javascript">'.
'slideWidth = '.$tag_gallery->size_x.';'.
'slideHeight = '.$tag_gallery->size_y.';'.
'currentTransition = "'.$tag_gallery->trans_type.'";'.
'transitionTime = '.$tag_gallery->trans_time.';'.
'slideHold = '.$tag_gallery->slide_hold.';'.
'</script>';
$output_html .= '<div id="boxslider">';
for($i = 0; $i < count($tag_gallery_imgs); $i++)
{
$attachment = get_post($tag_gallery_imgs[$i]);
$image_attributes = wp_get_attachment_image_src($tag_gallery_imgs[$i], 'full');
$output_html .= '<div class="boxslider_slide" style="background-image: url('.$image_attributes[0].')">'.
'<div class="boxslider_caption">'.
'<p><b>'.$attachment->post_title.'</b></p>'.
'<p>'.$attachment->post_excerpt.'</p>'.
'</div>'.
'</div>';
}
$output_html .= '</div>';
return $output_html;
}
}
else
return '<span style="color:#F00;"><b>BoxGallery </b>- You forgot the tag attribute! i.e. [boxgal tag="gallery_tag"]</span>';
}
add_shortcode('boxgal', 'boxgal_shortcode');
?>
This is the admin include php
<?php
function boxgal_menu()
{
global $toplevel_slug;
add_menu_page('BoxGallery options', 'BoxGallery', 'manage_options', $toplevel_slug, 'boxgal_options');
add_submenu_page($toplevel_slug, 'Add new gallery', 'Add new...', 'manage_options', $toplevel_slug.'_add', 'boxgal_options_addnew');
}
add_action('admin_menu', 'boxgal_menu');
function boxgal_admin_enqueue(){
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
wp_enqueue_script('boxgal-admin', plugins_url('/boxgal-admin.js', __FILE__ ));
}
add_action('admin_enqueue_scripts','boxgal_admin_enqueue');
function boxgal_options()
{
global $wpdb;
global $boxgal_table_name;
global $boxgal_galleries;
global $toplevel_slug;
if (isset($_GET['delid']))
{
$wpdb->delete($boxgal_table_name, array('id' => $_GET['delid']));
$boxgal_galleries = $wpdb->get_results("SELECT * FROM $boxgal_table_name");
}
?>
<div class="wrap">
<h2>BoxGallery</h2>
<table class="widefat" style="margin: 10px 0px 50px 0px;">
<thead>
<tr>
<th>Gallery Name</th>
<th>Gallery Tag</th>
<th>Images</th>
<th>Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Gallery Name</th>
<th>Gallery Tag</th>
<th>Images</th>
<th>Delete</th>
</tr>
</tfoot>
<tbody id="gallery_table">
<?php
foreach ($boxgal_galleries as $gallery) {
$table_row = '';
$table_row .= '<tr>';
$table_row .= '<td><a href="'.admin_url('admin.php').'/?page='.$toplevel_slug.'_add&tag='.$gallery->slug.'">'.$gallery->name.'</a></td>';
$table_row .= '<td>'.$gallery->slug.'</td>';
$gal_imgs = explode(',', $gallery->images);
$table_row .= '<td>';
for($i = 0; $i < count($gal_imgs); $i++)
$table_row .= wp_get_attachment_image($gal_imgs[$i]);
$table_row .= '</td>';
$table_row .= '<td><a href="'.admin_url('admin.php').'/?page='.$toplevel_slug.'&delid='.$gallery->id.'">Delete</a></td>';
$table_row .= '</tr>';
echo $table_row;
}
?>
</tbody>
</table>
</div>
<?php
}
function boxgal_options_addnew()
{
wp_enqueue_media();
$edit_page = isset($_GET['tag']);
if ($edit_page)
{
global $wpdb;
global $boxgal_table_name;
global $boxgal_galleries;
global $toplevel_slug;
$tag = $_GET['tag'];
$tag_gallery = null;
$tag_gallery_imgs;
foreach ($boxgal_galleries as $gallery)
{
if ($tag == $gallery->slug)
{
$tag_gallery = $gallery;
$tag_gallery_imgs = explode(",", $tag_gallery->images);
break;
}
}
}
?>
<script type="text/javascript">
currentImgIds = Array(<?php echo $tag_gallery->images; ?>);
</script>
<div class="wrap">
<?php if (!$edit_page) { ?>
<h2>Add new</h2>
<?php } else { ?>
<h2>Edit "<?php echo $tag_gallery->name; ?>"</h2>
<?php } ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="boxgal_name">Gallery Name:</label></th>
<td><input name="boxgal_name" type="text" id="boxgal_name" value="<?php if($edit_page) echo $tag_gallery->name; ?>" class="regular-text" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="boxgal_slug">Gallery Tag:</label></th>
<td><input name="boxgal_slug" type="text" id="boxgal_slug" value="<?php if($edit_page) echo $tag_gallery->slug; ?>" class="regular-text" />
<p class="description">This is the tag that will be used in the BoxGallery shortcode. This should contain no white-space / spaces.</p></td>
</tr>
<tr valign="top">
<th scope="row"><label for="boxgal_size_x">Size:</label></th>
<td><input name="boxgal_size_x" type="text" id="boxgal_size_x" value="<?php if($edit_page) echo $tag_gallery->size_x; ?>" class="regular-text" style="width: 50px;" /> x
<input name="boxgal_size_y" type="text" id="boxgal_size_y" value="<?php if($edit_page) echo $tag_gallery->size_y; ?>" class="regular-text" style="width: 50px;" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="boxgal_transtype">Transition Type:</label></th>
<td>
<?php
if($edit_page)
$trans_type = $tag_gallery->trans_type;
?>
<select id="boxgal_transtype">
<option <?php if ($edit_page && $trans_type == 'fade') echo 'selected'; ?> value="boxgal_tt_fade">Fade</option>
<option <?php if ($edit_page && $trans_type == 'slide-left') echo 'selected'; ?> value="boxgal_tt_slide-left">Slide Left</option>
<option <?php if ($edit_page && $trans_type == 'slide-right') echo 'selected'; ?> value="boxgal_tt_slide-right">Slide Right</option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="boxgal_tt_time">Transition Time:</label></th>
<td><input name="boxgal_tt_time" type="text" id="boxgal_tt_time" value="<?php if($edit_page) echo $tag_gallery->trans_time; ?>" class="regular-text" style="width: 50px;" />
<p class="description">How long in milliseconds should the transition take?</p></td>
</tr>
<tr valign="top">
<th scope="row"><label for="boxgal_hold_time">Slide Hold:</label></th>
<td><input name="boxgal_hold_time" type="text" id="boxgal_hold_time" value="<?php if($edit_page) echo $tag_gallery->slide_hold; ?>" class="regular-text" style="width: 50px;" />
<p class="description">How long in milliseconds should the slide be on screen for?</p></td>
</tr>
</table>
<div style="margin: 50px 0px 10px 0px;">
<input type="submit" class="button-secondary" id="add_image" value="Add Image" />
</div>
<table class="widefat" style="margin: 10px 0px 50px 0px;">
<thead>
<tr>
<th>Image</th>
<th>Caption</th>
<th>Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Image</th>
<th>Caption</th>
<th>Delete</th>
</tr>
</tfoot>
<tbody id="gallery_table">
<?php if ($edit_page)
{
for($i = 0; $i < count($tag_gallery_imgs); $i++)
{
$attachment = get_post($tag_gallery_imgs[$i]);
echo '<tr>';
echo '<td>'.wp_get_attachment_image($tag_gallery_imgs[$i]).'</td>';
echo '<td>'.$attachment->post_excerpt.'</td>';
echo '<td><a id="'.$tag_gallery_imgs[$i].'" class="boxgal_del" href="#">Delete</a></td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
<input class="button-primary" type="submit" name="save_gallery" value="Save Gallery" id="save_gallery" />
</div>
<?php
}
function boxgal_save_callback()
{
global $wpdb;
global $boxgal_table_name;
global $boxgal_galleries;
$boxgal_name = $_POST['boxgal_name'];
$boxgal_slug = $_POST['boxgal_slug'];
$boxgal_size_x = $_POST['boxgal_size_x'];
$boxgal_size_y = $_POST['boxgal_size_y'];
$boxgal_transtype = $_POST['boxgal_transtype'];
$boxgal_tt_time = $_POST['boxgal_tt_time'];
$boxgal_hold_time = $_POST['boxgal_hold_time'];
$boxgal_img_ids = "";
$img_count = count($_POST['boxgal_img_ids']);
for($i = 0; $i < $img_count; $i++)
{
$boxgal_img_ids .= $_POST['boxgal_img_ids'][$i];
if ($i < $img_count - 1)
$boxgal_img_ids .= ",";
}
$table_id = -1;
foreach ($boxgal_galleries as $gallery)
{
if ($boxgal_slug == $gallery->slug)
{
$table_id = $gallery->id;
break;
}
}
if ($table_id != -1)
{
$wpdb->update($boxgal_table_name, array('name' => $boxgal_name,
'slug' => $boxgal_slug,
'size_x' => $boxgal_size_x,
'size_y' => $boxgal_size_y,
'trans_type' => $boxgal_transtype,
'trans_time' => $boxgal_tt_time,
'slide_hold' => $boxgal_hold_time,
'images' => $boxgal_img_ids), array('id' => $table_id));
}
else
{
$wpdb->insert($boxgal_table_name, array('name' => $boxgal_name,
'slug' => $boxgal_slug,
'size_x' => $boxgal_size_x,
'size_y' => $boxgal_size_y,
'images' => $boxgal_img_ids,
'trans_type' => $boxgal_transtype,
'trans_time' => $boxgal_tt_time,
'slide_hold' => $boxgal_hold_time));
}
echo "Saved";
die();
}
add_action('wp_ajax_boxgal_save', 'boxgal_save_callback');
?>
Thanks for any help anyone may be able to provide!
Dan
wp-config.phpfile, locateWP_DEBUG, change it fromfalsetotrue. Come back with the error. - Ohgodwhy