I would appreciate any criticism for the big chunk of code below. What I'm trying to do is query a set of custom posts and return them in a table based on custom fields. It works ... the table is being generated, the right posts are being returned, but after executing a query, all other dashboard pages are blank.
//add menu option
add_action( 'admin_menu', 'my_plugin_menu' );
function my_plugin_menu() {
add_options_page( 'Limitless Options', 'Limitless', 'manage_options', 'limitless', 'my_plugin_options' );
}
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
if( isset($_GET['set']) ) {
//variables
$checkk = array();
$meta = NULL;
$date = NULL;
//validate
$start = ($_GET['start'] != NULL ? $_GET['start'] : false);
$end = ($_GET['end'] != NULL ? $_GET['end'] : false);
$question = ($_GET['question'] != NULL ? $_GET['question'] : false);
$answer = ($_GET['answer'] != NULL ? $_GET['answer'] : false);
$greutate_actuala = ($_GET['greutate_actuala'] != NULL ? $_GET['greutate_actuala'] : false);
$greutate_dorita = ($_GET['greutate_dorita'] != NULL ? $_GET['greutate_dorita'] : false);
$check = ($_GET['check'] != NULL ? $_GET['check'] : false);
$startEx = explode("-", $start);
$endEx = explode("-", $end);
if($greutate_actuala) {
$greutate_a = array(
'key' => 'greutate_actuala',
'value' => $greutate_actuala,
);
}else{
$greutate_a = NULL;
}
if($greutate_dorita) {
$greutate_d = array(
'key' => 'greutate_dorita',
'value' => $greutate_dorita,
);
}else{
$greutate_d = NULL;
}
if($check) {
$checkk = array(
'key' => 'check',
'value' => 1,
);
}
if($question && $answer) {
$meta = array(
'key' => $question,
'value' => $answer,
);
}
if($question && !$answer) {
$meta = array(
'key' => $question,
);
}
if(!$question && $answer){
$meta = array(
'value' => $answer,
);
}
if($start && $end) {
echo "start and end";
$date = array(
'after' => array(
'year' => $startEx[0],
'month' => $startEx[1],
'day' => $startEx[2],
),
'before' => array(
'year' => $endEx[0],
'month' => $endEx[1],
'day' => $endEx[2],
),
'inclusive' => true,
);
}
if($start && !$end) {
echo "start not end";
$date = array(
'year' => $startEx[0],
'month' => $startEx[1],
'day' => $startEx[2],
);
}
$args = array(
'post_type' => 'quiz',
'meta_query' => array(
$meta,
$greutate_a,
$greutate_d,
$checkk,
),
'date_query' => array(
$date
),
);
$loop = new WP_Query( $args );
echo '<table border="1" class="table">
<tr>
<td>Nume</td>
<td>Email</td>
';
for($i=1; $i<=10; $i++) {
echo '<td '.(($_GET['question'] === 'question_'.$i.'') ? 'class="active"' : "").'>Question '.$i.'</td>';
}
echo '<td '.(($greutate_actuala) ? 'class="active"' : "").'>GA</td>
<td '.(($greutate_dorita) ? 'class="active"' : "").'>GD</td>
<td '.(($check) ? 'class="active"' : "").'>Check</td>
</tr>';
while ( $loop->have_posts() ) : $loop->the_post();
echo '<tr>';
echo "<td>".get_post_meta(get_the_ID(), 'name', true)."</td>";
echo "<td>".get_post_meta(get_the_ID(), 'email', true)."</td>";
for($i=1; $i <= 10; $i++) {
echo "<td>".get_post_meta(get_the_ID(), 'question_'.$i.'', true)."</td>";
}
echo "<td>".get_post_meta(get_the_ID(), 'greutate_actuala', true)."</td>";
echo "<td>".get_post_meta(get_the_ID(), 'greutate_dorita', true)."</td>";
echo "<td>".get_post_meta(get_the_ID(), 'check', true)."</td>";
echo '</tr>';
$idArr[] = get_the_ID();
endwhile;
echo '</table>';
if(isset($_POST['csv'])) {
csvDownload($idArr);
}
if(isset($_POST['dl-csv'])) {
email_csv();
}
echo '<form method="post" action="">
<input type="submit" name="csv" value="csv">
</form>
';
if(isset($_POST['csv'])) {
echo '<form method="post" action="">
<p>CSV to: '.get_option( 'admin_email' ).' Add more: <input type="email" name="email"> ex: [email protected], [email protected]</p>
<input type="submit" name="dl-csv" value="Send CSV">
</form>
';
}
}
define('WP_DEBUG', true); define('WP_DEBUG_LOG', true);
in wp-config.php ... but no error log.