Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Commit

Permalink
fixed issue with empty slug
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Nov 7, 2015
1 parent b3abefe commit 3f13d27
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 80 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Contributions and Bugs
----------------------

If you have ideas on how to improve the library or if you discover a bug, I would appreciate if you shared them with me, right here on Github. In either case, please open a new issue [here](https://github.com/felixarntz/wpdlib/issues/new)!

You can also contribute to the library by translating it. Among the library files, there is a `.pot` file which you can use as a starting point. When you're done with a translation, you can either create a pull request with the new translation files or you can send them to me manually.
5 changes: 5 additions & 0 deletions assets/fields.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions assets/fields.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions inc/WPDLib/Components/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,16 @@ public function get_parent( $index = 0, $depth = 1 ) {
* @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated
*/
public function validate( $parent = null ) {
if ( $parent !== null ) {
if ( null !== $parent ) {
if ( count( $this->parents ) > 0 && ! $this->supports_multiparents() ) {
return new UtilError( 'no_multiparent_component', sprintf( __( 'The component %1$s of class %2$s already has a parent assigned and is not a multiparent component.', 'wpdlib' ), $this->slug, get_class( $this ) ), '', ComponentManager::get_scope() );
}
$this->parents[ $parent->slug ] = $parent;
}
if ( ! $this->validated ) {
if ( empty( $this->slug ) ) {
return new UtilError( 'empty_slug_component', __( 'A component with an empty slug is not allowed.', 'wpdlib' ), '', ComponentManager::get_scope() );
}
$defaults = $this->get_defaults();
foreach ( $defaults as $key => $default ) {
if ( ! isset( $this->args[ $key ] ) ) {
Expand All @@ -295,9 +298,10 @@ public function validate( $parent = null ) {
* Checks if the slug of the component is valid.
*
* @since 0.5.0
* @param WPDLib\Components\Base $parent the parent component of the component
* @return bool whether the component slug is valid
*/
public function is_valid_slug() {
public function is_valid_slug( $parent = null ) {
if ( $this->valid_slug === null ) {
$globalnames = $this->supports_globalslug();
if ( $globalnames !== true ) {
Expand Down
6 changes: 3 additions & 3 deletions inc/WPDLib/Components/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function is_already_added( $screen_slug ) {
/**
* Creates the admin menu.
*
* If the menu has an empty slug, the children are added as a page, but not added into any menu.
* If the menu has the slug 'none', the children are added as a page, but not added into any menu.
* Otherwise the children will simply be added to the menu. The first child will be added using `add_menu_page()`.
*
* @since 0.5.0
Expand All @@ -101,7 +101,7 @@ public function is_already_added( $screen_slug ) {
public function create() {
foreach ( $this->get_children() as $menu_item ) {
if ( is_callable( array( $menu_item, 'add_to_menu' ) ) ) {
if ( empty( $this->slug ) ) {
if ( 'none' == $this->slug ) {
$this->add_non_menu_page( $menu_item );
} elseif ( ! $this->is_already_added( $menu_item->slug ) ) {
$this->add_menu_page( $menu_item );
Expand Down Expand Up @@ -346,7 +346,7 @@ protected function add_submenu_page( $menu_item ) {
/**
* Adds a new page to the WordPress admin which should not be part of any menu.
*
* This function is only used for the special case when a menu component's slug is empty.
* This function is only used for the special case when a menu component's slug is set to 'none'.
* This allows you to add pages that are not visible in any menu.
*
* @since 0.5.0
Expand Down
Binary file modified languages/wpdlib-de_DE.mo
Binary file not shown.
Loading

0 comments on commit 3f13d27

Please sign in to comment.