Skip to content

Commit

Permalink
fix(Utilities): count() used on non-Countable value.
Browse files Browse the repository at this point in the history
Method: `utilities::get_action()`

Reported by: @NikeLaos - https://wordpress.org/support/topic/get-some-warnings/
  • Loading branch information
Archetyped committed May 29, 2020
1 parent 4f902b7 commit 8dcdabb
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions includes/class.utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,34 +847,36 @@ function get_plugin_textdomain() {
* @param mixed $default (optional) Default action if no action exists
* @return string Current action
*/
function get_action($default = null) {
function get_action( $default = null ) {
$action = '';
//Check if action is set in URL
if ( isset($_GET['action']) )

// Check if action is set in URL
if ( isset( $_GET['action'] ) ) {
$action = $_GET['action'];
//Otherwise, Determine action based on plugin plugin admin page suffix
elseif ( isset($_GET['page']) && ($pos = strrpos($_GET['page'], '-')) && $pos !== false && ( $pos != count($_GET['page']) - 1 ) )
$action = trim(substr($_GET['page'], $pos + 1), '-_');
} elseif ( isset( $_GET['page'] ) && ( $pos = strrpos( $_GET['page'], '-' ) ) && $pos !== false && ( $pos != strlen( $_GET['page'] ) - 1 ) ) {
// Otherwise, Determine action based on plugin admin page suffix
$action = trim( substr( $_GET['page'], $pos + 1 ), '-_' );
}

//Determine action for core admin pages
if ( ! isset($_GET['page']) || empty($action) ) {
// Determine action for core admin pages
if ( ( ! isset( $_GET['page'] ) || empty( $action ) ) && isset( $_SERVER['SCRIPT_NAME'] ) ) {
$actions = array(
'add' => array('page-new', 'post-new'),
'edit-item' => array('page', 'post'),
'edit' => array('edit', 'edit-pages')
'add' => array( 'page-new', 'post-new' ),
'edit-item' => array( 'page', 'post' ),
'edit' => array( 'edit', 'edit-pages' ),
);
$page = basename($_SERVER['SCRIPT_NAME'], '.php');
$page = basename( $_SERVER['SCRIPT_NAME'], '.php' );

foreach ( $actions as $act => $pages ) {
if ( in_array($page, $pages) ) {
if ( in_array( $page, $pages ) ) {
$action = $act;
break;
}
}
}
if ( empty($action) )
if ( empty( $action ) ) {
$action = $default;
}
return $action;
}

Expand Down

0 comments on commit 8dcdabb

Please sign in to comment.