Skip to content

awps/AdminPage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZeroWP - AdminPage

Advanced WordPress Admin pages, the easy way...

###License: GPL The license allows the usage in any projects(personal or commercial). An attribution link is not required, but very appreciated.

##Requirements:

  • PHP 5.3+

##How to use: ###Include the files

require_once dirname(__FILE__) . "/src/AdminPage/mod.php";

###Create a page

class ExamplePage extends ZeroWP\Admin\Page{

	public function settings(){
		return array(
			'parent_slug' => false, // This is a parent page, not a subpage
			'menu_title'  => __('Example page', 'text-domain'),
		);
	}

	public function page(){
	  echo 'Page content here!';
	}
}
$example_page = new ExamplePage('page-slug');
$example_page->init(); //Initialize this page.

The page is available at: [site_url]/wp-admin/admin.php?page=page-slug

###Create a tab

class ExampleTab extends ZeroWP\Admin\Tab{

	public function settings(){
		return array(
			'label' => __('Tab title', 'text-domain')
		);
	}

	public function page(){
	  echo 'Tab content here!';
	}
}
new ExampleTab('tabid', 'page-slug');

The tab is available at: [site_url]/wp-admin/admin.php?page=page-slug&tab=tabid

###All available settings for pages: ZeroWP\Admin\Page

All settings are optional. Use only that you need.

public function settings(){
	return array(
		'menu_title'    => '',
		'page_title'    => '',
		'parent_slug'   => null,
		'capability'    => 'manage_options',
		'menu_icon'     => '',
		'menu_position' => null,
		'default_tab_label' => '',
	);
}

###All available settings for tabs: ZeroWP\Admin\Tab

All settings are optional. Use only that you need.

public function settings(){
	return array(
		'label'    => '',
	);
}
  • 'label'
    Default: ''. The tab title. If empty the ID will be used(tab slug).

###Add scripts and styles

enqueue(). This method allows to enqueue scripts and styles only on the page that you've created. The scripts and styles will be available in all other tabs that you'll create. This method is also available in ZeroWP\Admin\Tab and the rules are the same(the scripts/styles will be available in all other tabs and parent page).

Here is a basic example:

public function enqueue(){
	wp_register_style( 'example-css', 'example.css' );
	wp_enqueue_style( 'example-css' );

	wp_register_script( 'example-js', 'example.js' );
	wp_enqueue_script( 'example-js' );
}

###Using in plugins:

This piece of code can be included in plugins as it is and will work without problems, but it is recomended to replace the namespace ZeroWP with your own. Doing so you'll avoid conflicts with other plugins that are using this code as well.
Just do a global search&replace in your favorite text editor and you're done!
Happy coding.

Releases

No releases published

Packages

No packages published

Languages