Skip to content

Instantly share code, notes, and snippets.

@joecue
Created March 12, 2021 21:12
Show Gist options
  • Save joecue/ec2a98d9680cf5d46b8eed944cc9f801 to your computer and use it in GitHub Desktop.
Save joecue/ec2a98d9680cf5d46b8eed944cc9f801 to your computer and use it in GitHub Desktop.
Custom Form within WordPress Admin Dashboard Custom Menu Page
<?php
//Check for hidden field value and select appropriate API field needed
if( $_POST['action'] == 'filterdates' ){
check_admin_referer( 'filter-date', '_wpnonce_filter-date' );
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances";
$currentYear = date("Y");
switch( $_POST['month'] ){
case 'January':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=1/1/" . $currentYear . "&instanceStart_to=1/31/". $currentYear;
break;
case 'February':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=2/1/" . $currentYear . "&instanceStart_to=2/28/". $currentYear;
break;
case 'March':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=3/1/" . $currentYear . "&instanceStart_to=3/31/". $currentYear;
break;
case 'April':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=4/1/" . $currentYear . "&instanceStart_to=4/30/". $currentYear;
break;
case 'May':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=5/1/" . $currentYear . "&instanceStart_to=5/31/". $currentYear;
break;
case 'June':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=6/1/" . $currentYear . "&instanceStart_to=6/30/". $currentYear;
break;
case 'July':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=7/1/" . $currentYear . "&instanceStart_to=7/31/". $currentYear;
break;
case 'August':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=8/1/" . $currentYear . "&instanceStart_to=8/31/". $currentYear;
break;
case 'September':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=9/1/" . $currentYear . "&instanceStart_to=9/30/". $currentYear;
break;
case 'October':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=10/1/" . $currentYear . "&instanceStart_to=10/31/". $currentYear;
break;
case 'November':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=11/1/" . $currentYear . "&instanceStart_to=11/30/". $currentYear;
break;
case 'December':
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances&instanceStart_from=12/1/" . $currentYear . "&instanceStart_to=12/31/". $currentYear;
break;
}
}else{
$requestUrl = $sDomain ."/api/v3/events?\$expand=instances";
}
?>
<!-- form for filtering view -->
<form id="dates-filter" method="POST" action="">
<div class="tablenav top">
<div class="alignleft actions bulkactions">
<select name="month" id="month">
<option value="">Choose a Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<?php wp_nonce_field( 'filter-date', '_wpnonce_filter-date' ) ?>
<input name="action" type="hidden" value="filterdates" />
<input type="submit" id="filterDate" class="button action" value="Filter Dates">
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment