Redirect to welcome or update page

This commit is contained in:
Jonathan Labreuille
2015-11-17 20:11:03 +01:00
parent 225be9f3cd
commit fdbd1245e3
7 changed files with 111 additions and 41 deletions

View File

@ -159,23 +159,6 @@ body.mailpoet_modal_opened
margin: 0 margin: 0
text-align: right text-align: right
.mailpoet_button
padding: 3px 15px
border: 1px solid #444
font-weight: normal
cursor: pointer
background-color: #222
color: #cfcfcf
font-size: 1em
.mailpoet_button:hover
background-color: #00aacc
color: #fff
.mailpoet_button:active
background-color: #00ccff
color: #fff
@media screen and (max-width: 782px) @media screen and (max-width: 782px)
#mailpoet_modal_overlay.mailpoet_panel_overlay #mailpoet_modal_overlay.mailpoet_panel_overlay
top: 46px top: 46px

27
lib/Config/Changelog.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace MailPoet\Config;
use \MailPoet\Models\Setting;
class Changelog {
function init() {
add_action(
'admin_init',
array($this, 'setup')
);
}
function setup() {
$version = Setting::getValue('version', null);
if($version === null) {
// new install
Setting::setValue('version', Env::$version);
wp_redirect(admin_url('admin.php?page=mailpoet-welcome'));
exit;
} else if($version !== Env::$version) {
// update
Setting::setValue('version', Env::$version);
wp_redirect(admin_url('admin.php?page=mailpoet-update'));
exit;
}
}
}

View File

@ -24,6 +24,7 @@ class Initializer {
$this->setupWidget(); $this->setupWidget();
$this->setupAnalytics(); $this->setupAnalytics();
$this->setupPermissions(); $this->setupPermissions();
$this->setupChangelog();
} }
function setupDB() { function setupDB() {
@ -104,4 +105,9 @@ class Initializer {
$permissions = new Permissions(); $permissions = new Permissions();
$permissions->init(); $permissions->init();
} }
function setupChangelog() {
$changelog = new Changelog();
$changelog->init();
}
} }

View File

@ -34,7 +34,7 @@ class Menu {
'MailPoet', 'MailPoet',
'manage_options', 'manage_options',
'mailpoet', 'mailpoet',
array($this, 'welcome'), array($this, 'home'),
$this->assets_url . '/img/menu_icon.png', $this->assets_url . '/img/menu_icon.png',
30 30
); );
@ -94,31 +94,42 @@ class Menu {
'mailpoet-export', 'mailpoet-export',
array($this, 'export') array($this, 'export')
); );
// add_submenu_page(
// 'mailpoet',
// __('Newsletter editor'),
// __('Newsletter editor'),
// 'manage_options',
// 'mailpoet-newsletter-editor',
// array($this, 'newletterEditor')
// );
$this->registered_pages();
}
function registered_pages() { add_submenu_page(
global $_registered_pages; null,
$pages = array( __('Welcome'),
'mailpoet-welcome' => array($this, 'welcome'), __('Welcome'),
'mailpoet-form-editor' => array($this, 'formEditor'), 'manage_options',
'mailpoet-newsletter-editor' => array($this, 'newletterEditor') 'mailpoet-welcome',
array($this, 'welcome')
);
add_submenu_page(
null,
__('Update'),
__('Update'),
'manage_options',
'mailpoet-update',
array($this, 'update')
);
add_submenu_page(
null,
__('Form editor'),
__('Form editor'),
'manage_options',
'mailpoet-form-editor',
array($this, 'formEditor')
);
add_submenu_page(
null,
__('Newsletter editor'),
__('Newsletter editor'),
'manage_options',
'mailpoet-newsletter-editor',
array($this, 'newletterEditor')
); );
foreach($pages as $menu_slug => $callback) {
$hookname = get_plugin_page_hookname($menu_slug, null);
if(!empty($hookname)) {
add_action($hookname, $callback);
}
$_registered_pages[$hookname] = true;
}
} }
function home() { function home() {
@ -135,6 +146,15 @@ class Menu {
echo $this->renderer->render('welcome.html', $data); echo $this->renderer->render('welcome.html', $data);
} }
function update() {
$data = array(
'settings' => Setting::getAll(),
'current_user' => wp_get_current_user()
);
echo $this->renderer->render('update.html', $data);
}
function settings() { function settings() {
$settings = Setting::getAll(); $settings = Setting::getAll();

View File

@ -28,6 +28,13 @@ class Setting extends Model {
} }
} }
public static function setValue($key, $value) {
return Setting::createOrUpdate(array(
'name' => $key,
'value' => $value
));
}
public static function getAll() { public static function getAll() {
$settingsCollection = self::findMany(); $settingsCollection = self::findMany();
$settings = array(); $settings = array();

20
views/update.html Normal file
View File

@ -0,0 +1,20 @@
<% extends 'layout.html' %>
<% block content %>
<div id="mailpoet_welcome">
<h2><%= __("What's new") %></h2>
<h3>Settings:</h3>
<%= dump(settings) %>
<h3>Current user:</h3>
<%= dump(current_user) %>
<p>
<a
class="button button-primary"
href="<%= admin_url('admin.php?page=mailpoet') %>"
>Take me to MailPoet</a>
</p>
</div>
<% endblock %>

View File

@ -9,5 +9,12 @@
<h3>Current user:</h3> <h3>Current user:</h3>
<%= dump(current_user) %> <%= dump(current_user) %>
<p>
<a
class="button button-primary"
href="<%= admin_url('admin.php?page=mailpoet') %>"
>Take me to MailPoet</a>
</p>
</div> </div>
<% endblock %> <% endblock %>