\AdminPageFramework_WPUtilities

Provides utility methods which use WordPress functions.

Summary

Methods
Properties
Constants
doActions()
addAndDoActions()
addAndDoAction()
addAndApplyFilters()
addAndApplyFilter()
getFilterArrayByPrefix()
goRedirect()
getCurrentAdminURL()
getQueryAdminURL()
getQueryURL()
getSRCFromPath()
resolveSRC()
No public properties found
No constants found
getScriptData()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

doActions()

doActions(array $arrActionHooks, mixed $vArgs1, mixed $vArgs2, mixed $_and_more) : void

Triggers the do_action() function with the given action names and the arguments.

This is useful to perform do_action() on multiple action hooks with the same set of arguments. For example, if there are the following action hooks, action_name, action_name1, and action_name2, and to perform these, normally it takes the following lines. do_action( 'action_name1', $var1, $var2 ); do_action( 'action_name2', $var1, $var2 ); do_action( 'action_name3', $var1, $var2 );

This method saves these line this way: $this->doActions( array( 'action_name1', 'action_name2', 'action_name3' ), $var1, $var2 );

Example

$this->doActions( array( 'action_name1' ), $var1, $var2, $var3 );

Parameters

array $arrActionHooks

a numerically indexed array consisting of action hook names to execute.

mixed $vArgs1

an argument to pass to the action callbacks.

mixed $vArgs2

another argument to pass to the action callbacks.

mixed $_and_more

add as many arguments as necessary to the next parameters.

addAndDoActions()

addAndDoActions(object $oCallerObject, array $arrActionHooks, mixed $vArgs1, mixed $vArgs2, mixed $_and_more) : void

Adds the method of the given action hook name(s) to the given action hook(s) with arguments.

In other words, this enables to register methods to the custom hooks with the same name and triggers the callbacks (not limited to the registered ones) assigned to the hooks. Of course, the registered methods will be triggered right away. Thus, the magic overloading __call() should catch them and redirect the call to the appropriate methods. This enables, at the same time, publicly the added custom action hooks; therefore, third-party scripts can use the action hooks.

This is the reason the object instance must be passed to the first parameter. Regular functions as the callback are not supported for this method.

Example

$this->oUtil->addAndDoActions( $this, array( 'my_action1', 'my_action2', 'my_action3' ), 'argument_a', 'argument_b' );

Parameters

object $oCallerObject

the object that holds the callback method that matches the action hook name.

array $arrActionHooks

a numerically index array consisting of action hook names that serve as the callback method names.

mixed $vArgs1

the argument to pass to the hook callback functions.

mixed $vArgs2

another argument to pass to the hook callback functions.

mixed $_and_more

add as many arguments as necessary to the next parameters.

addAndDoAction()

addAndDoAction( $oCallerObject,  $strActionHook,  $vArgs1,  $vArgs2,  $_and_more) : void

Adds the methods of the given action hook name to the given action hook with arguments.

Parameters

$oCallerObject
$strActionHook
$vArgs1
$vArgs2
$_and_more

addAndApplyFilters()

addAndApplyFilters()

addAndApplyFilter()

addAndApplyFilter()

getFilterArrayByPrefix()

getFilterArrayByPrefix( $strPrefix,  $strClassName,  $strPageSlug,  $strTabSlug,  $fReverse) : array

Provides an array consisting of filters for the addAndApplyFileters() method.

The order is, page + tab -> page -> class, by default but it can be reversed with the $fReverse parameter value.

Parameters

$strPrefix
$strClassName
$strPageSlug
$strTabSlug
$fReverse

Returns

array —

Returns an array consisting of the filters.

goRedirect()

goRedirect( $strURL)

Redirects to the given URL and exits. Saves one extra line, exit;.

Parameters

$strURL

getCurrentAdminURL()

getCurrentAdminURL()

Retrieves the current URL in the admin page.

getQueryAdminURL()

getQueryAdminURL(array $arrAddingQueries, array $arrRemovingQueryKeys, string $strSubjectURL) : string

Returns a url with modified query stings.

Identical to the getQueryURL() method except that if the third parameter is omitted, it will use the currently browsed admin url.

Parameters

array $arrAddingQueries

The appending query key value pairs e.g. array( 'page' => 'my_page_slug', 'tab' => 'my_tab_slug' )

array $arrRemovingQueryKeys

( optional ) The removing query keys. e.g. array( 'settings-updated', 'my-custom-admin-notice' )

string $strSubjectURL

( optional ) The subject url to modify

Returns

string —

The modified url.

getQueryURL()

getQueryURL(array $arrAddingQueries, array $arrRemovingQueryKeys, string $strSubjectURL) : string

Returns a url with modified query stings.

Parameters

array $arrAddingQueries

The appending query key value pairs

array $arrRemovingQueryKeys

The removing query key value pairs

string $strSubjectURL

The subject url to modify

Returns

string —

The modified url.

getSRCFromPath()

getSRCFromPath( $strFilePath) : string

Calculates the URL from the given path.

Parameters

$strFilePath

Returns

string —

The source url

resolveSRC()

resolveSRC( $strSRC,  $fReturnNullIfNotExist)

Resolves the given src.

Checks if the given string is a url, a relative path, or an absolute path and returns the url if it's not a relative path.

Parameters

$strSRC
$fReturnNullIfNotExist

getScriptData()

getScriptData( $strPath,  $strType)

Returns an array of plugin data from the given path.

An alternative to get_plugin_data() as some users change the location of the wp-admin directory.

Parameters

$strPath
$strType