| 1 |
<?php |
| 2 |
|
| 3 |
class WPUPG_Giveaway { |
| 4 |
|
| 5 |
public function __construct() |
| 6 |
{ |
| 7 |
$now = new DateTime(); |
| 8 |
$giveaway_start = new DateTime( '2017-11-16 10:00:00', new DateTimeZone( 'Europe/Brussels' ) ); |
| 9 |
$giveaway_end = new DateTime( '2017-11-24 10:00:00', new DateTimeZone( 'Europe/Brussels' ) ); |
| 10 |
|
| 11 |
if ( $giveaway_start < $now && $now < $giveaway_end ) { |
| 12 |
add_action( 'admin_menu', array( $this, 'add_submenu_page' ), 99 ); |
| 13 |
add_action( 'admin_notices', array( $this, 'giveaway_notice' ) ); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
public function add_submenu_page() |
| 18 |
{ |
| 19 |
add_submenu_page( 'edit.php?post_type=' . WPUPG_POST_TYPE, 'Giveaway', '~ Plugin Giveaway! ~', 'manage_options', 'wpupg_giveaway', array( $this, 'page_template' ) ); |
| 20 |
} |
| 21 |
|
| 22 |
public function page_template() { |
| 23 |
echo '<div class="wrap">'; |
| 24 |
echo '<h1>Plugin Giveaway</h1>'; |
| 25 |
echo '<a class="e-widget no-button" href="https://gleam.io/dY9yY/black-friday-2017" rel="nofollow">Black Friday Giveaway 2017</a>'; |
| 26 |
echo '<script type="text/javascript" src="https://js.gleam.io/e.js" async="true"></script>'; |
| 27 |
echo '</div>'; |
| 28 |
} |
| 29 |
|
| 30 |
public function giveaway_notice() |
| 31 |
{ |
| 32 |
$screen = get_current_screen(); |
| 33 |
|
| 34 |
if ( 'edit-wpupg_grid' === $screen->id ) { |
| 35 |
echo '<div class="updated" style="padding: 10px;">'; |
| 36 |
echo '<strong>Feeling lucky?</strong> Win plugins in our <a href="' . esc_url( admin_url( 'edit.php?post_type=' . WPUPG_POST_TYPE . '&page=wpupg_giveaway' ) ) . '" target="_blank">Black Friday Giveaway</a>!'; |
| 37 |
echo '</div>'; |
| 38 |
} |
| 39 |
} |
| 40 |
} |