Permalink
Browse files

Supported the `load()` method and `load_{class name}` callback for th…

…e user meta factory.

Also refactored the part calling `setUp()` method and its callbacks.
  • Loading branch information...
michaeluno committed Jan 13, 2017
1 parent 5b93f19 commit 19f510dd26ef105547745b1f0fb56b7f64ad5ba2
@@ -23,16 +23,8 @@
*/
public function start() {}
public function setUp() {}
-
- /**
- * Shouold be extended.
- *
- * @since 3.8.14
- * @return void
- */
public function load() {}
-
/**
* Allows the user to check if the current page belongs to the admin pages of the factory component.
*
@@ -37,19 +37,7 @@ public function __construct( $oProp ) {
}
- /**
- * Calls the setUp() method.
- *
- * @since 3.1.0
- * @todo Deprecate this method. This method was intended to be used in a user defined abstract class
- * but it requires to call the setUp() method in the overridden method so it's not that useful.
- * @internal
- * @deprecated 3.8.14
- */
-// protected function _setUp() {
-// $this->setUp();
-// }
-
+
/**
* Called upon fieldset resource registration.
*
@@ -207,6 +207,30 @@ public function _replyToLoadComponents( /* $oScreen */ ) {
}
+ /**
+ * Calls the load method and callbacks.
+ * @since 3.8.14
+ */
+ protected function _load( $aActions=array() ) {
+ $aActions = empty( $aActions )
+ ? array(
+ 'load_' . $this->oProp->sClassName,
+ )
+ : $aActions;
+ $this->load();
+ $this->oUtil->addAndDoActions( $this, $aActions, $this );
+ }
+
+ /**
+ * Calls the `setUp()` method and callbacks.
+ */
+ protected function _setUp() {
+ $aActions = array(
+ 'set_up_' . $this->oProp->sClassName,
+ );
+ $this->setUp();
+ $this->oUtil->addAndDoActions( $this, $aActions, $this );
+ }
/**
* Determines whether the class object is instantiatable in the current page.
@@ -249,16 +273,8 @@ public function _replyToDetermineToLoad() {
return;
}
- // Calls `setUp()` and the user will set up the meta box.
- $this->setUp();
-
- /**
- * This action hook must be called AFTER the _setUp() method
- * as there are callback methods that hook into this hook
- * and assumes required configurations have been made.
- */
- $this->oUtil->addAndDoAction( $this, "set_up_{$this->oProp->sClassName}", $this );
-
+ $this->_setUp();
+
}
@@ -440,9 +440,10 @@ private function ___getURLQuery() {
if ( ! $this->bIsAdminAjax ) {
return $_GET;
}
-
- $_aParts = parse_url( $_SERVER[ 'HTTP_REFERER' ] );
- parse_str( $_aParts[ 'query' ], $_aQuery );
+ parse_str(
+ parse_url( $_SERVER[ 'HTTP_REFERER' ], PHP_URL_QUERY ), // query string such as `foo=bar&abc=xyz`
+ $_aQuery
+ );
return $_GET + $_aQuery;
}
@@ -184,14 +184,11 @@ protected function _doPageLoadCall( $sMethodName, $sPageSlug, $sTabSlug, $oScree
$this->_setShowDebugInfoProperty( $sPageSlug ); // 3.8.8+
// Do actions in this order, class -> page -> in-page tab. This order is important as some methods rely on it.
- $this->load(); // 3.7.12+
- $this->oUtil->addAndDoActions(
- $this, // the caller object
- array(
+ $this->_load(
+ array(
"load_{$this->oProp->sClassName}",
"load_{$sPageSlug}",
- ),
- $this // the admin page object - this lets third-party scripts use the framework methods.
+ )
);
// * Note that the in-page tabs handling method `_replyToFinalizeInPageTabs()` is called in the above action hook.
@@ -67,11 +67,9 @@ public function __construct( $sMetaBoxID, $sTitle, $asPostTypeOrScreenID=array(
* @internal
*/
public function _replyToCallLoadMethods() {
- $this->load();
- $this->oUtil->addAndDoActions( $this, 'load_' . $this->oProp->sClassName, $this );
+ $this->_load();
}
-
/**
* Determines whether the meta box belongs to the loading page.
*
@@ -46,12 +46,12 @@ public function _replyToDetermineToLoadAdmin( /* $oScreen */ ) {
if ( ! $this->_isInThePage() ) {
return;
}
-
- $this->load();
- $this->oUtil->addAndDoAction(
- $this,
- "load_{$this->oProp->sPostType}",
- $this
+
+ $this->_load(
+ array(
+ "load_{$this->oProp->sPostType}",
+ "load_{$this->oProp->sClassName}", // 3.8.14+
+ )
);
}
@@ -69,16 +69,7 @@ public function _replyToDetermineToLoadAdmin( /* $oScreen */ ) {
* @since 3.7.10
*/
public function _replyToDetermineToLoad() {
-
- $this->setUp();
-
- // This action hook must be called AFTER the _setUp() method as there are callback methods that hook into this hook and assumes required configurations have been made.
- $this->oUtil->addAndDoAction(
- $this,
- "set_up_{$this->oProp->sClassName}",
- $this
- );
-
+ $this->_setUp();
}
/**
@@ -16,8 +16,7 @@
* @internal
*/
abstract class AdminPageFramework_TaxonomyField_Router extends AdminPageFramework_Factory {
-
-
+
/**
* Sets up hooks.
*
@@ -93,7 +92,10 @@ public function _replyToSetUpHooks( $oFactory ) {
add_filter( "manage_edit-{$_sTaxonomySlug}_sortable_columns", array( $this, '_replyToSetSortableColumns' ) );
add_action( "manage_{$_sTaxonomySlug}_custom_column", array( $this, '_replyToPrintColumnCell' ), 10, 3 );
- }
+ }
+
+ // 3.8.14+
+ $this->_load();
}
@@ -31,7 +31,9 @@ public function __construct( $oProp ) {
}
$this->oUtil->registerAction(
- 'current_screen',
+ $this->oProp->bIsAdminAjax
+ ? 'wp_loaded'
+ : 'current_screen',
array( $this, '_replyToDetermineToLoad' )
);
@@ -78,12 +80,14 @@ public function _replyToSetUpHooks( $oFactory ) {
// Hooks to display fields.
add_action( 'show_user_profile', array( $this, '_replyToPrintFields' ) ); // profile.php
add_action( 'edit_user_profile', array( $this, '_replyToPrintFields' ) ); // profile.php
- add_action( 'user_new_form', array( $this, '_replyToPrintFields' ) ); // user-new.php
+ add_action( 'user_new_form', array( $this, '_replyToPrintFields' ) ); // user-new.php
// Hooks to save field values.
- add_action( 'personal_options_update', array( $this, '_replyToSaveFieldValues' ) ); // profile.php
+ add_action( 'personal_options_update', array( $this, '_replyToSaveFieldValues' ) ); // profile.php
add_action( 'edit_user_profile_update', array( $this, '_replyToSaveFieldValues' ) ); // profile.php
- add_action('user_register', array( $this, '_replyToSaveFieldValues' ) ); // user-new.php
+ add_action('user_register', array( $this, '_replyToSaveFieldValues' ) ); // user-new.php
+
+ $this->_load(); // 3.8.14+
}
@@ -194,22 +194,20 @@ private function _loadFrameworkFactory() {
* @since 3.7.9
*/
if ( $this->oCaller->oUtil->hasBeenCalled( '_widget_load_' . $this->oCaller->oProp->sClassName ) ) {
-
- // The saved option callback is done with the below load_... callback so for widget form instances called from the second time
- // need to call the callback manually.
+
+ /**
+ * The saved option callback is done with the below load_... callback so for widget form instances called from the second time
+ * need to call the callback manually.
+ */
$this->oCaller->oForm->aSavedData = $this->_replyToGetSavedFormData();
return;
}
-
- // Trigger the load() method and load_{...} actions. The user sets up the form.
- // Use `call_user_func_array()` rather than `$this->oCaller->load( $this->oCaller );` to avoid missing parameter PHP warnings.
- // This way user can either set a first parameter or omit it.
- // @todo Examine whether passing the caller object is necessary or not as other factory classes' load() method does not receive it and thus it is not consistent.
- call_user_func_array(
- array( $this->oCaller, 'load' ),
- array( $this->oCaller )
- );
+
+ /**
+ * Trigger the load() method and load_{...} actions. The user sets up the form.
+ */
+ call_user_func( array( $this->oCaller, 'load' ) );
$this->oCaller->oUtil->addAndDoActions(
$this->oCaller,
array(
@@ -234,8 +232,7 @@ private function _getFormCallbacks() {
'saved_data' => array( $this, '_replyToGetSavedFormData' ),
)
- + $this->oCaller->oProp->getFormCallbacks()
- ;
+ + $this->oCaller->oProp->getFormCallbacks();
}
/**

0 comments on commit 19f510d

Please sign in to comment.