Skip to content

Commit

Permalink
Move Ad Code Manager page under the Tools menu, and only print JS hea…
Browse files Browse the repository at this point in the history
…der vars when we're on the proper page
  • Loading branch information
danielbachhuber committed Jan 16, 2012
1 parent b2bb7a6 commit 3020fef
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions ad-code-manager.php
Expand Up @@ -36,7 +36,7 @@ class Ad_Code_Manager
var $script_url_whitelist = array();
var $title = 'Ad Code Manager';
var $post_type = 'acm-code';
var $plugin_slug = 'acm';
var $plugin_slug = 'ad-code-manager';
var $post_type_labels ;
/**
* Instantiate the plugin
Expand All @@ -47,7 +47,10 @@ function __construct() {
// @todo refactor TODO
add_action( 'init', array( &$this, 'action_init' ) );
add_action( 'admin_init', array( &$this, 'action_admin_init' ) );
add_action( 'admin_menu' , array( &$this, 'display_menu' ) );

// Incorporate the link to our admin menu
add_action( 'admin_menu' , array( $this, 'action_admin_menu' ) );

add_action( 'admin_init', array( &$this, 'get_ad_codes' ) );
add_action( 'admin_init', array( &$this, 'ad_code_edit_actions' ) );
add_action( 'admin_init', array( &$this, 'conditions_edit_actions' ) );
Expand Down Expand Up @@ -93,6 +96,7 @@ function action_admin_init() {
// - Saving the data
// - Loading the ad codes in the database and registering them
// with the plugin using

}

/**
Expand Down Expand Up @@ -295,10 +299,15 @@ function print_json( $data = array() ) {
echo json_encode( $data );
exit;
}

/**
* Print our vars as JS
*/
function post_admin_header() {

if ( !isset( $_GET['page'] ) || $_GET['page'] != $this->plugin_slug )
return;

$conditions = apply_filters(
'acm_conditions',
array(
Expand All @@ -320,12 +329,13 @@ function post_admin_header() {
<?php
}

function display_menu() {
add_menu_page( $this->title, $this->title, apply_filters( 'acm_manage_ads_cap', 'manage_options' ), $this->plugin_slug, array( &$this, 'admin_view_controller' ) );
/**
* Hook in our submenu page to the navigation
*/
function action_admin_menu() {
add_submenu_page( 'tools.php', $this->title, $this->title, apply_filters( 'acm_manage_ads_cap', 'manage_options' ), $this->plugin_slug, array( &$this, 'admin_view_controller' ) );
}



/**
* @todo remove html to views
*/
Expand All @@ -346,13 +356,16 @@ function admin_view_controller() {
*/
function register_scripts_and_styles() {
global $pagenow;
if ( 'admin.php' == $pagenow && isset( $_GET['page'] ) && $_GET['page'] == $this->plugin_slug ) {
wp_enqueue_style( 'acm-jquery-ui-theme', AD_CODE_MANAGER_URL . '/common/css/jquery-ui-1.8.17.custom.css' );
wp_enqueue_style( 'acm-jqgrid', AD_CODE_MANAGER_URL . '/common/css/ui.jqgrid.css' );
wp_enqueue_script( 'acm-jqgrid-locale-en', AD_CODE_MANAGER_URL . '/common/js/grid.locale-en.js', array( 'jquery', 'jquery-ui-core' ) );
wp_enqueue_script( 'acm-jqgrid', AD_CODE_MANAGER_URL . '/common/js/jquery.jqGrid.min.js', array( 'jquery', 'jquery-ui-core' ) );
wp_enqueue_script( 'acm', AD_CODE_MANAGER_URL . '/common/js/acm.js', array( 'jquery', 'jquery-ui-core' ) );
}

// Only load this on the proper page
if ( 'tools.php' != $pagenow || !isset( $_GET['page'] ) || $_GET['page'] != $this->plugin_slug )
return;

wp_enqueue_style( 'acm-jquery-ui-theme', AD_CODE_MANAGER_URL . '/common/css/jquery-ui-1.8.17.custom.css' );
wp_enqueue_style( 'acm-jqgrid', AD_CODE_MANAGER_URL . '/common/css/ui.jqgrid.css' );
wp_enqueue_script( 'acm-jqgrid-locale-en', AD_CODE_MANAGER_URL . '/common/js/grid.locale-en.js', array( 'jquery', 'jquery-ui-core' ) );
wp_enqueue_script( 'acm-jqgrid', AD_CODE_MANAGER_URL . '/common/js/jquery.jqGrid.min.js', array( 'jquery', 'jquery-ui-core' ) );
wp_enqueue_script( 'acm', AD_CODE_MANAGER_URL . '/common/js/acm.js', array( 'jquery', 'jquery-ui-core' ) );
}

/**
Expand Down

0 comments on commit 3020fef

Please sign in to comment.