Skip to content

Commit

Permalink
Fixed admin urls in the popover menu
Browse files Browse the repository at this point in the history
  • Loading branch information
frozzare committed Dec 21, 2014
1 parent e7e3687 commit 93ebde4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion includes/admin/class-papi-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function admin_menu() {
$only_page_type = _papi_filter_settings_only_page_type( $post_type );

if ( ! empty( $only_page_type ) ) {
$submenu[$edit_url][10][2] = _papi_get_page_new_url( $only_page_type, false, $post_type );
$submenu[$edit_url][10][2] = _papi_get_page_new_url( $only_page_type, false, $post_type, array( 'page_type', 'post_type' ) );
} else {
$page = 'papi-add-new-page,' . $post_type;

Expand Down
25 changes: 19 additions & 6 deletions includes/lib/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
* @return string
*/

function _papi_get_page_new_url( $page_type, $append_admin_url = true, $post_type = null ) {
function _papi_get_page_new_url( $page_type, $append_admin_url = true, $post_type = null, $exclude = array() ) {
$admin_url = $append_admin_url ? get_admin_url() : '';
$query_strings = _papi_get_page_query_strings();

$admin_url = $admin_url . 'post-new.php?page_type=' . $page_type . _papi_get_page_query_strings();
$admin_url = $admin_url . 'post-new.php?page_type=' . $page_type . _papi_get_page_query_strings( '&', $exclude );

if ( ! is_null( $post_type ) && in_array( 'post_type', $exclude ) ) {
$admin_url .= '&post_type=' . $post_type;
}

return _papi_append_post_type_query( $admin_url, $post_type );
}
Expand All @@ -35,13 +40,14 @@ function _papi_get_page_new_url( $page_type, $append_admin_url = true, $post_typ
* Get page query strings.
*
* @param string $first_char
* @param array $exlude
*
* @since 1.0.0
*
* @return string
*/

function _papi_get_page_query_strings( $first_char = '&' ) {
function _papi_get_page_query_strings( $first_char = '&', $exclude = array() ) {
$request_uri = $_SERVER['REQUEST_URI'];
$parsed_url = parse_url( $request_uri );

Expand All @@ -54,16 +60,19 @@ function _papi_get_page_query_strings( $first_char = '&' ) {
$query = str_replace( '?', '', $query );
$query = explode( '&', $query );

$query = array_filter( $query, function ( $q ) {
$q = explode('=', $q);
$query = array_filter( $query, function ( $q ) use ( $exclude ) {
$q = explode( '=', $q );

if ( empty( $q ) ) {
return false;
}

$q = $q[0];

return in_array( $q, array( 'page_type', 'post_new', 'post_parent', 'papi_bypass', 'npparent' ) );
$allowed = array( 'post_type', 'page_type', 'post_new', 'post_parent', 'papi_bypass', 'npparent' );
$allowed = array_diff( $allowed, $exclude );

return in_array( $q, $allowed );
} );

$query = implode( '&', $query );
Expand All @@ -79,6 +88,10 @@ function _papi_get_page_query_strings( $first_char = '&' ) {
$query = substr( $query, 0, - 1 );
}

if ( in_array( 'post_type', $exclude ) ) {
return $query;
}

return _papi_append_post_type_query( $query );
}

Expand Down

0 comments on commit 93ebde4

Please sign in to comment.