Skip to content

Instantly share code, notes, and snippets.

@davilera
Created November 12, 2015 08:19
Show Gist options
  • Save davilera/cd56291946761039dd8d to your computer and use it in GitHub Desktop.
Save davilera/cd56291946761039dd8d to your computer and use it in GitHub Desktop.
<?php
/**
* This function creates all the relevant pages for our plugin.
* These pages appear in the Dashboard.
*
* @since 0.1
*/
public function create_nelioab_admin_pages() {
$nelioab_menu = 'nelioab-dashboard';
// Main menu
// ----------------------------------------------------------------------
add_menu_page(
__( 'Nelio A/B Testing', 'nelioab' ),
__( 'Nelio A/B Testing', 'nelioab' ),
'edit_posts',
$nelioab_menu,
null,
null,
NelioABSettings::get_menu_location() . '.000023510' // 2N.3E.5L.1I.0O
);
// Dashboard page
// ----------------------------------------------------------------------
require_once( NELIOAB_ADMIN_DIR . '/dashboard-page-controller.php' );
add_submenu_page( $nelioab_menu,
__( 'Dashboard', 'nelioab' ),
__( 'Dashboard', 'nelioab' ),
'edit_posts',
'nelioab-dashboard',
array( 'NelioABDashboardPageController', 'build' ) );
// Experiments pages (depending on the action, we show one or another)
// ----------------------------------------------------------------------
$the_action = NULL;
if ( isset( $_GET['action'] ) )
$the_action = $_GET['action'];
switch ( $the_action ) {
case 'edit':
require_once( NELIOAB_ADMIN_DIR . '/select-exp-edition-page-controller.php' );
$page_to_build = array( 'NelioABSelectExpEditionPageController', 'build' );
break;
case 'progress':
require_once( NELIOAB_ADMIN_DIR . '/select-exp-progress-page-controller.php' );
$page_to_build = array( 'NelioABSelectExpProgressPageController', 'build' );
break;
default:
require_once( NELIOAB_ADMIN_DIR . '/experiments-page-controller.php' );
$page_to_build = array( 'NelioABExperimentsPageController', 'build' );
break;
}
add_submenu_page( $nelioab_menu,
__( 'Experiments', 'nelioab' ),
__( 'Experiments', 'nelioab' ),
'edit_posts',
'nelioab-experiments',
$page_to_build );
// Creating Experiment; (depending on the type, we show one form or another)
// ----------------------------------------------------------------------
require_once( NELIOAB_ADMIN_DIR . '/select-exp-creation-page-controller.php' );
add_action( 'admin_head', array( $this, 'add_css_for_creation_page' ) );
add_action( 'admin_head', array( $this, 'add_css_for_themes' ) );
$page_to_build = array( 'NelioABSelectExpCreationPageController', 'build' );
add_submenu_page( $nelioab_menu,
__( 'Add Experiment', 'nelioab' ),
__( 'Add Experiment', 'nelioab' ),
'edit_posts',
'nelioab-add-experiment',
$page_to_build );
// Either Free Trial or My Account page
// ----------------------------------------------------------------------
if ( NelioABAccountSettings::is_using_free_trial() ) {
$label = __( 'Free Trial', 'nelioab' );
} else {
$label = __( 'My Account', 'nelioab' );
}
require_once( NELIOAB_ADMIN_DIR . '/account-page-controller.php' );
add_submenu_page( $nelioab_menu,
$label,
$label,
'manage_options',
'nelioab-account',
array( 'NelioABAccountPageController', 'build' ) );
// Settings page
// ----------------------------------------------------------------------
require_once( NELIOAB_ADMIN_DIR . '/settings-page-controller.php' );
add_submenu_page( $nelioab_menu,
__( 'Settings', 'nelioab' ),
__( 'Settings', 'nelioab' ),
'manage_options',
'nelioab-settings',
array( 'NelioABSettingsPageController', 'build' ) );
// Help
// ----------------------------------------------------------------------
add_submenu_page( $nelioab_menu,
__( 'Help', 'nelioab' ),
__( 'Help', 'nelioab' ),
'edit_posts',
'nelioab-help' );
global $submenu;
if ( isset( $submenu['nelioab-dashboard'] ) ) {
for ( $i = 0; $i < count( $submenu['nelioab-dashboard'] ); ++$i ) {
if ( 'nelioab-help' == $submenu['nelioab-dashboard'][$i][2] ) {
$submenu['nelioab-dashboard'][$i][2] = 'http://support.nelioabtesting.com/support/home';
break;
}
}
}
// OTHER PAGES (not included in the menu)
// CSS Editing
// ----------------------------------------------------------------------
require_once( NELIOAB_ADMIN_DIR . '/views/content/css-edit.php' );
add_submenu_page( NULL,
__( 'CSS Edit', 'nelioab' ),
__( 'CSS Edit', 'nelioab' ),
'edit_posts',
'nelioab-css-edit',
array( 'NelioABCssEditPage', 'build' ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment