options_panel_dir = LAYERS_TEMPLATE_DIR . '/core/options-panel/';
$this->set_valid_page_slugs();
add_action( 'wp_dashboard_setup', array( &$this, 'layers_add_dashboard_widgets' ) );
if( !defined( 'LAYERS_DISABLE_MARKETPLACE' ) ){
add_filter( 'media_upload_tabs', array( &$this, 'upload_upsell_media_tab' ) );
add_action( 'media_upload_upsell_media', array( &$this, 'upload_upsell_media_form' ) );
add_action( 'print_media_templates', array( &$this, 'upload_upsell_media_template' ) );
}
}
public function init() {
// Load template
$this->body( $this->get_current_page() );
}
/**
* Set a list of valid pages we can access via this method
*/
public function set_valid_page_slugs(){
global $submenu;
if( !isset( $submenu[ 'layers-dashboard' ] ) ) return;
$page_list = $submenu[ 'layers-dashboard' ];
$this->valid_page_slugs = array();
foreach( $page_list as $sub_menu_page ){
// Make sure that the slug is valid
if( !isset( $sub_menu_page[2] ) ) continue;
// Load up the valid pages
$this->valid_page_slugs[] = $sub_menu_page[2];
}
// Layers Marketplace is on it's own top level menu, so we have to shimmy it in
$this->valid_page_slugs[] = 'layers-marketplace';
$this->valid_page_slugs[] = 'layers-envato-marketplace';
}
/**
* Parse $_GET['page'] and get the current page template to load
*/
public function get_current_page(){
// Make sure we have a 'page' query to look at
if( ! isset( $_GET['page'] ) ) wp_die( __( 'No page argument has been set.' , 'layerswp' ) );
// Set the current page if the 'page' query exists
$current_page = $_GET['page'];
// Check the current page against valid pages
if( ! in_array( $current_page , $this->valid_page_slugs ) ) wp_die( __( 'Invalid page slug' , 'layerswp' ) );
// Set the page slug if everything is kosher
$page_slug = str_replace( 'layers-', '' , $current_page );
// Sanitize the slug
$page_slug = esc_attr( $page_slug );
// Return the page slug
return $page_slug;
}
/**
* Complex Header with Menu
*/
public function marketplace_header( $title = NULL, $excerpt = NULL, $marketplace = 'layerswp' ){
$api = new Layers_API();
if( isset( $_GET[ 'type' ] ) ) $type = $_GET[ 'type' ]; else $type = 'themes' ?>
Layers', 'http://layerswp.com' ), 'layerswp' ); ?>
Layers', 'http://layerswp.com' ), 'layerswp' ); ?>
load_partial( $partial );
}
private function load_partial( $partial = NULL ) {
// Include Partials, we're using require so that inside the partial we can use $this to access the header and footer
require $this->options_panel_dir . 'partials/' . $partial . '.php';
}
public function upload_upsell_media_template(){
$this->body( 'discover-more-photos' );
}
function upload_upsell_media_tab($tabs) {
$tabs['upsell_media'] = __( 'Discover More' , 'layerswp' );
return $tabs;
}
// call the new tab with wp_iframe
function upload_upsell_media_form() {
wp_iframe( array( &$this, 'upload_upsell_media_template' ) );
}
/**
* Footer
*/
public function footer( $args = array() ){ ?>