| 1 |
<?php |
| 2 |
|
| 3 |
class Poll_Maker_Ays_Welcome { |
| 4 |
|
| 5 |
/** |
| 6 |
* Hidden welcome page slug. |
| 7 |
* |
| 8 |
* @since 4.6.4 |
| 9 |
*/ |
| 10 |
const SLUG = 'poll-maker-getting-started'; |
| 11 |
|
| 12 |
/** |
| 13 |
* Primary class constructor. |
| 14 |
* |
| 15 |
* @since 4.6.4 |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
add_action( 'plugins_loaded', [ $this, 'hooks' ] ); |
| 19 |
} |
| 20 |
|
| 21 |
public function hooks() { |
| 22 |
add_action( 'admin_menu', [ $this, 'register' ] ); |
| 23 |
add_action( 'admin_head', [ $this, 'hide_menu' ] ); |
| 24 |
add_action( 'admin_init', [ $this, 'redirect' ], 9999 ); |
| 25 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] ); |
| 26 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Register the pages to be used for the Welcome screen (and tabs). |
| 31 |
* |
| 32 |
* These pages will be removed from the Dashboard menu, so they will |
| 33 |
* not actually show. Sneaky, sneaky. |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
*/ |
| 37 |
public function register() { |
| 38 |
|
| 39 |
add_dashboard_page( |
| 40 |
esc_html__( 'Welcome to Poll Maker', "poll-maker" ), |
| 41 |
esc_html__( 'Welcome to Poll Maker', "poll-maker" ), |
| 42 |
'manage_options', |
| 43 |
self::SLUG, |
| 44 |
[ $this, 'output' ] |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Removed the dashboard pages from the admin menu. |
| 50 |
* |
| 51 |
* This means the pages are still available to us, but hidden. |
| 52 |
* |
| 53 |
* @since 4.6.4 |
| 54 |
*/ |
| 55 |
public function hide_menu() { |
| 56 |
|
| 57 |
remove_submenu_page( 'index.php', self::SLUG ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Welcome screen redirect. |
| 62 |
* |
| 63 |
* This function checks if a new install or update has just occurred. If so, |
| 64 |
* then we redirect the user to the appropriate page. |
| 65 |
* |
| 66 |
* @since 4.6.4 |
| 67 |
*/ |
| 68 |
public function redirect() { |
| 69 |
|
| 70 |
$current_page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
| 71 |
|
| 72 |
// Check if we are already on the welcome page. |
| 73 |
if ( $current_page === self::SLUG ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
$first_activation = get_option('ays_poll_maker_first_time_activation_page', false); |
| 78 |
|
| 79 |
if (isset($_GET['page']) && strpos($_GET['page'], POLL_MAKER_AYS_NAME) !== false && $first_activation) { |
| 80 |
wp_safe_redirect( admin_url( 'index.php?page=' . self::SLUG ) ); |
| 81 |
exit; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Enqueue custom CSS styles for the welcome page. |
| 87 |
* |
| 88 |
* @since 4.6.4 |
| 89 |
*/ |
| 90 |
public function enqueue_styles() { |
| 91 |
wp_enqueue_style( |
| 92 |
'poll-maker-ays-welcome-css', |
| 93 |
POLL_MAKER_AYS_ADMIN_URL . '/css/poll-maker-ays-welcome.css', |
| 94 |
array(), false, 'all'); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Register the JavaScript for the welcome page. |
| 99 |
* |
| 100 |
* @since 4.6.4 |
| 101 |
*/ |
| 102 |
public function enqueue_scripts() { |
| 103 |
|
| 104 |
wp_enqueue_script( 'poll-maker-ays-welcome', POLL_MAKER_AYS_ADMIN_URL . '/js/poll-maker-ays-welcome.js', array('jquery'), false, true); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Getting Started screen. Shows after first install. |
| 109 |
* |
| 110 |
* @since 1.0.0 |
| 111 |
*/ |
| 112 |
public function output() { |
| 113 |
?> |
| 114 |
<style> |
| 115 |
#wpcontent { |
| 116 |
padding-left: 0 !important; |
| 117 |
position: relative; |
| 118 |
} |
| 119 |
</style> |
| 120 |
<div id="poll-maker-welcome"> |
| 121 |
|
| 122 |
<div class="poll-maker-welcome-container"> |
| 123 |
|
| 124 |
<div class="poll-maker-welcome-intro"> |
| 125 |
|
| 126 |
<div class="poll-maker-welcome-logo"> |
| 127 |
<img src="<?php echo POLL_MAKER_AYS_ADMIN_URL; ?>/images/icons/poll-maker-logo.png" alt="<?php echo __( 'Poll Maker Logo', "poll-maker" ); ?>"> |
| 128 |
</div> |
| 129 |
|
| 130 |
<div class="poll-maker-welcome-close"> |
| 131 |
<a href="<?php echo admin_url( 'admin.php?page=' . POLL_MAKER_AYS_NAME ) ?> "> |
| 132 |
<img src="<?php echo POLL_MAKER_AYS_ADMIN_URL; ?>/images/icons/close.svg" alt="<?php echo __( 'Close', "poll-maker" ); ?>"> |
| 133 |
</a> |
| 134 |
</div> |
| 135 |
<div class="poll-maker-welcome-block"> |
| 136 |
<h1><?php echo __( 'Welcome to Poll Maker', "poll-maker" ); ?></h1> |
| 137 |
<h6><?php echo __( 'Thank you for choosing Poll Maker - the best poll and survey plugin for WordPress.', "poll-maker" ); ?></h6> |
| 138 |
</div> |
| 139 |
|
| 140 |
<a href="#" class="play-video" title="<?php esc_attr_e( 'Watch how to create your first poll', "poll-maker" ); ?>"> |
| 141 |
<img src="<?php echo POLL_MAKER_AYS_ADMIN_URL; ?>/images/ays-poll-welcome-video.png" alt="<?php echo __( 'Watch how to create your first poll', "poll-maker" ); ?>" class="poll-maker-welcome-video-thumbnail"> |
| 142 |
</a> |
| 143 |
|
| 144 |
<div class="poll-maker-welcome-block"> |
| 145 |
|
| 146 |
<div class="poll-maker-welcome-button-wrap poll-maker-clear"> |
| 147 |
<div class="poll-maker-welcome-left"> |
| 148 |
<a href="<?php echo esc_url( admin_url( 'admin.php?page=' . POLL_MAKER_AYS_NAME . "&action=add") ); ?>" class="poll-maker-btn poll-maker-btn-block poll-maker-btn-lg poll-maker-btn-orange"> |
| 149 |
<?php echo __( 'Create Your First Poll', "poll-maker" ); ?> |
| 150 |
</a> |
| 151 |
</div> |
| 152 |
<div class="poll-maker-welcome-right"> |
| 153 |
<a href="<?php echo 'https://ays-pro.com/wordpress-poll-maker-user-manual'; ?>" |
| 154 |
class="poll-maker-btn poll-maker-btn-block poll-maker-btn-lg poll-maker-btn-grey" target="_blank" rel="noopener noreferrer"> |
| 155 |
<?php echo __( 'Documentation', "poll-maker" ); ?> |
| 156 |
</a> |
| 157 |
</div> |
| 158 |
</div> |
| 159 |
|
| 160 |
</div> |
| 161 |
|
| 162 |
</div> |
| 163 |
</div> |
| 164 |
</div> |
| 165 |
<?php |
| 166 |
update_option('ays_poll_maker_first_time_activation_page', false); |
| 167 |
} |
| 168 |
} |
| 169 |
new Poll_Maker_Ays_Welcome(); |