Advertisement
onlineth

Show Specific Content Based on Month

Jun 19th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Content Based on Month
  4. Description: Displays 1 of 2 sets of content every 2 months and switches automatically. Also provides an expiration shortcode.
  5. Author: Onlineth
  6. Version: Beta
  7. */
  8. /*
  9. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  10. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  11. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  12. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  13. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  14. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  15. THE SOFTWARE.
  16.  */
  17. function content_set1( $atts, $contenttext1 = null ) {
  18.     $date = date('F');
  19.     switch ($date) {
  20.         case 'January':
  21.         case 'Febuary':
  22.         case 'May':
  23.         case 'June':
  24.         case 'September':
  25.         case 'October':
  26.             return $contenttext1;
  27.     }
  28. }
  29. function content_set2( $atts, $contenttext2 = null ) {
  30.     $date = date('F');
  31.     switch ($date) {
  32.         case 'March':
  33.         case 'April':
  34.         case 'July':
  35.         case 'August':
  36.         case 'November':
  37.         case 'December':
  38.             return $contenttext2;
  39.     }
  40. }
  41. function lastdaymonth(){
  42.     $month = date('m');
  43.     if ($month % 2 == 0) {
  44.         return (new DateTime())->format("m/d/Y");
  45.     } else {
  46.         return (new DateTime("+1 month"))->format("m/d/Y");
  47.     }
  48. }
  49. add_shortcode('expiration', 'lastdaymonth');
  50. add_shortcode('content1', 'content_set1');
  51. add_shortcode('content2', 'content_set2');
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement