Permalink
Browse files

Changed the behaviour of not loading form components in `admin-ajax.p…

…hp` so that custom field types can access `admin-ajax.php` using Ajax.
  • Loading branch information...
michaeluno committed Jan 12, 2017
1 parent 41069bc commit ec46e484853b645a31eb1ecd63a5f38ed6255a7a
Showing with 257 additions and 90 deletions.
  1. +1 −1 development/admin-page-framework-include-class-list.php
  2. +11 −2 development/factory/_common/_abstract/AdminPageFramework_Factory_Controller.php
  3. +3 −1 development/factory/_common/_abstract/AdminPageFramework_Factory_Router.php
  4. +32 −3 development/factory/_common/_abstract/_model/AdminPageFramework_Property_Base.php
  5. +1 −1 development/factory/_common/form/AdminPageFramework_Form_Model.php
  6. +8 −4 development/factory/admin_page/AdminPageFramework_Model_Form.php
  7. +5 −4 development/factory/admin_page/AdminPageFramework_Model_Menu.php
  8. +52 −27 development/factory/admin_page/AdminPageFramework_Router.php
  9. +10 −10 development/factory/admin_page/_model/AdminPageFramework_Property_admin_page.php
  10. +61 −8 development/factory/admin_page/_model/delegate/AdminPageFramework_Model_Menu__RegisterMenu.php
  11. +4 −4 development/factory/meta_box/AdminPageFramework_MetaBox_Model.php
  12. +33 −8 development/factory/meta_box/AdminPageFramework_MetaBox_Router.php
  13. +5 −4 development/factory/network_admin_page/AdminPageFramework_NetworkAdmin.php
  14. +11 −5 development/factory/page_meta_box/AdminPageFramework_PageMetaBox_Router.php
  15. +3 −2 development/factory/page_meta_box/_model/AdminPageFramework_Property_page_meta_box.php
  16. +1 −1 development/factory/post_type/AdminPageFramework_PostType_Router.php
  17. +2 −2 development/factory/taxonomy_field/AdminPageFramework_TaxonomyField_Router.php
  18. +6 −1 development/factory/user_meta/AdminPageFramework_UserMeta_Router.php
  19. +3 −2 development/factory/widget/AdminPageFramework_Widget_Controller.php
  20. +5 −0 readme.txt
@@ -1,6 +1,6 @@
<?php
/**
- Admin Page Framework - Inclusion Class Files v3.8.13b04 by Michael Uno
+ Admin Page Framework - Inclusion Class Files v3.8.14b01 by Michael Uno
Generated by PHP Class Files Inclusion List Creator
<http://en.michaeluno.jp/admin-page-framework>
Copyright (c) 2013-2017, Michael Uno; Licensed under MIT <http://opensource.org/licenses/MIT> */
@@ -17,13 +17,22 @@
abstract class AdminPageFramework_Factory_Controller extends AdminPageFramework_Factory_View {
/**
- * Should be extended
+ * Should be extended.
*
* @internal
*/
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.
*
@@ -157,7 +157,9 @@ public function __construct( $oProp ) {
// Required sub-class objects
$this->oProp = $oProp;
- if ( $this->oProp->bIsAdmin && ! $this->oProp->bIsAdminAjax ) {
+// @deprecated 3.8.14
+// if ( $this->oProp->bIsAdmin && ! $this->oProp->bIsAdminAjax ) {
+ if ( $this->oProp->bIsAdmin ) {
$this->oUtil->registerAction( 'current_screen', array( $this, '_replyToLoadComponents' ) );
}
@@ -261,7 +261,7 @@
public $_bSetupLoaded;
/**
- * Indicates whether the current page is in admin-ajax.php
+ * Indicates whether the current page is in `admin-ajax.php`
*
* @since 3.1.3
* @internal
@@ -377,7 +377,15 @@
* @since 3.8.5
*/
public $bShowDebugInfo = true;
-
+
+ /**
+ * Stores URL query key-value pairs.
+ * For admin-ajax.php, the referrer's will be stored. For other cases, the `$_GET` variable values will be used.
+ * @since 3.8.14
+ * @var array
+ */
+ public $aQuery = array();
+
/**
* Sets up necessary property values.
*
@@ -410,6 +418,8 @@ private function ___setProperties( $oCaller, $sCallerPath, $sClassName, $sCapabi
$this->bIsAdminAjax = 'admin-ajax.php' === $this->sPageNow;
$this->bShowDebugInfo = $this->isDebugMode();
+ $this->aQuery = $this->___getURLQuery();
+
// Overloading property items - these will be set on demand
unset(
$this->aScriptInfo,
@@ -419,6 +429,23 @@ private function ___setProperties( $oCaller, $sCallerPath, $sClassName, $sCapabi
);
}
+ /**
+ *
+ * @since 3.8.14
+ * @return array
+ * @internal
+ */
+ private function ___getURLQuery() {
+
+ if ( ! $this->bIsAdminAjax ) {
+ return $_GET;
+ }
+
+ $_aParts = parse_url( $_SERVER[ 'HTTP_REFERER' ] );
+ parse_str( $_aParts[ 'query' ], $_aQuery );
+ return $_GET + $_aQuery;
+
+ }
/**
* Sets up global variables.
@@ -450,7 +477,9 @@ public function getFormArguments() {
return array(
'caller_id' => $this->sClassName,
'structure_type' => $this->_sPropertyType, // @todo change this to admin_page
- 'action_hook_form_registration' => $this->_sFormRegistrationHook,
+ 'action_hook_form_registration' => $this->bIsAdminAjax
+ ? 'admin_init' // 3.8.14
+ : $this->_sFormRegistrationHook,
) + $this->aFormArguments;
}
/**
@@ -206,7 +206,7 @@ public function _replyToRegisterFormItems() {
if ( ! $this->isInThePage() ) {
return;
}
-
+
// Load field type definitions.
$this->_setFieldTypeDefinitions( 'admin_page_framework' ); // site-wide
$this->_setFieldTypeDefinitions( $this->aArguments[ 'caller_id' ] ); // per class
@@ -61,10 +61,11 @@
public function __construct( $sOptionKey=null, $sCallerPath=null, $sCapability='manage_options', $sTextDomain='admin-page-framework' ) {
parent::__construct( $sOptionKey, $sCallerPath, $sCapability, $sTextDomain );
-
- if ( $this->oProp->bIsAdminAjax ) {
- return;
- }
+
+ // @deprecated 3.8.14
+// if ( $this->oProp->bIsAdminAjax ) {
+// return;
+// }
if ( ! $this->oProp->bIsAdmin ) {
return;
}
@@ -410,6 +411,9 @@ private function _getSectionTabSlug( $aSectionset ) {
* @return boolean Whether or not the form registration should be allowed in the current screen.
*/
public function _replyToDetermineWhetherToProcessFormRegistration( $bAllowed ) {
+ if ( $this->oProp->bIsAdminAjax ) {
+ return true;
+ }
$_sPageSlug = $this->oProp->getCurrentPageSlug();
return $this->oProp->isPageAdded( $_sPageSlug );
}
@@ -27,10 +27,11 @@
public function __construct( $sOptionKey=null, $sCallerPath=null, $sCapability='manage_options', $sTextDomain='admin-page-framework' ) {
parent::__construct( $sOptionKey, $sCallerPath, $sCapability, $sTextDomain );
-
- if ( $this->oProp->bIsAdminAjax ) {
- return;
- }
+
+ // @deprecated 3.8.14
+// if ( $this->oProp->bIsAdminAjax ) {
+// return;
+// }
new AdminPageFramework_Model_Menu__RegisterMenu( $this );
@@ -43,17 +43,36 @@ public function __construct( $sOptionKey=null, $sCallerPath=null, $sCapability='
parent::__construct( $this->oProp );
- if ( $this->oProp->bIsAdminAjax ) {
- return;
- }
+// @deprecated 3.8.14
+// if ( $this->oProp->bIsAdminAjax ) {
+// return;
+// }
if ( ! $this->oProp->bIsAdmin ) {
return;
}
- add_action( 'wp_loaded', array( $this, '_replyToDetermineToLoad' ) );
-
- }
-
+ add_action( 'wp_loaded', array( $this, '_replyToDetermineToLoad' ) );
+ add_action( 'set_up_' . $this->oProp->sClassName, array( $this, '_replyToLoadComponentsForAjax' ), 100 );
+
+ }
+
+ /**
+ * Loads page components for ajax calls.
+ *
+ * @since 3.8.14
+ * @remark It is assumed that the `setUp()` method is already called.
+ * @callback add_action wp_loaded
+ */
+ public function _replyToLoadComponentsForAjax() {
+ if ( ! $this->oProp->bIsAdminAjax ) {
+ return;
+ }
+ new AdminPageFramework_Model_Menu__RegisterMenu( $this, 'pseudo_admin_menu' );
+ do_action( 'pseudo_admin_menu', '' );
+ do_action( 'pseudo_current_screen' );
+
+ }
+
/**
* Instantiates a link object based on the type.
*
@@ -154,11 +173,11 @@ private function _getCallbackName( $sMethodName, $sPageSlug, array $aKnownMethod
* @internal
*/
protected function _doPageLoadCall( $sMethodName, $sPageSlug, $sTabSlug, $oScreen ) {
-
- if ( ! $this->_isPageLoadCall( $sMethodName, $sPageSlug, $oScreen->id ) ) {
+
+ if ( ! $this->_isPageLoadCall( $sMethodName, $sPageSlug, $oScreen ) ) {
return;
}
-
+
// [3.4.6+] Set the page and tab slugs to the default form section so that added form fields without a section will appear in different pages and tabs.
$this->_setPageAndTabSlugsForForm( $sPageSlug, $sTabSlug );
@@ -174,13 +193,13 @@ protected function _doPageLoadCall( $sMethodName, $sPageSlug, $sTabSlug, $oScree
),
$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.
// Re-retrieve the current tab slug as in-page tabs may be added during the above `load_{...}` hooks.
- // Note that the if the tab is the first item, and the user arrives the page by clicking on the sidebar menu, the tab slug will be empty unless an in-page tab is added.
+ // Note that if the tab is the first item and the user arrives the page by clicking on the sidebar menu,
+ // the tab slug will be empty unless an in-page tab is added.
$sTabSlug = $this->oProp->getCurrentTabSlug( $sPageSlug );
-
if ( strlen( $sTabSlug ) ) {
$this->_setShowDebugInfoProperty( $sPageSlug, $sTabSlug ); // 3.8.8+
$this->oUtil->addAndDoActions(
@@ -248,23 +267,23 @@ private function _setPageAndTabSlugsForForm( $sPageSlug, $sTabSlug ) {
* Determines whether the function call is of a page load.
* @since 3.5.3
* @internal
- * @return boolean True if it is a page load call; othwrwise, false.
- * @param string $sMethodName The undefined method name that is passed to the __call() overload method.
- * @param string $sPageSlug The currently loading page slug.
- * @param string $sScreenID The screen ID that the WordPress screen object gives.
+ * @return boolean True if it is a page load call; othwrwise, false.
+ * @param string $sMethodName The undefined method name that is passed to the __call() overload method.
+ * @param string $sPageSlug The currently loading page slug.
+ * @param object|string $osScreenORPageHook The screen ID that the WordPress screen object gives.
*/
- private function _isPageLoadCall( $sMethodName, $sPageSlug, $sScreenID ) {
+ private function _isPageLoadCall( $sMethodName, $sPageSlug, $osScreenORPageHook ) {
if ( substr( $sMethodName, strlen( 'load_pre_' ) ) !== $sPageSlug ) {
return false;
}
if ( ! isset( $this->oProp->aPageHooks[ $sPageSlug ] ) ) {
return false;
}
- if ( $sScreenID !== $this->oProp->aPageHooks[ $sPageSlug ] ) {
- return false;
- }
- return true;
+ $_sPageHook = is_object( $osScreenORPageHook )
+ ? $osScreenORPageHook->id
+ : $sPageSlug; // for ajax calls
+ return $_sPageHook === $this->oProp->aPageHooks[ $sPageSlug ];
}
@@ -278,11 +297,12 @@ private function _isPageLoadCall( $sMethodName, $sPageSlug, $sScreenID ) {
* @internal
*/
protected function _isInstantiatable() {
-
+
+// @deprecated 3.8.14
// Disable in admin-ajax.php
- if ( isset( $GLOBALS[ 'pagenow' ] ) && 'admin-ajax.php' === $GLOBALS[ 'pagenow' ] ) {
- return false;
- }
+// if ( isset( $GLOBALS[ 'pagenow' ] ) && 'admin-ajax.php' === $GLOBALS[ 'pagenow' ] ) {
+// return false;
+// }
// Nothing to do in the network admin area.
return ! is_network_admin();
@@ -299,7 +319,12 @@ protected function _isInstantiatable() {
* @internal
*/
protected function _isInThePage() {
-
+
+ // 3.8.14+
+ if ( $this->oProp->bIsAdminAjax ) {
+ return true;
+ }
+
// If the setUp method is not loaded yet,
if ( ! did_action( 'set_up_' . $this->oProp->sClassName ) ) {
return true;
@@ -493,11 +493,11 @@ public function isPageAdded( $sPageSlug='' ) {
* @remark Do not return `null` when not found as some framework methods check the retuened value with `isset()` and if null is given, `isset()` yields `false` while it does `true` for an emtpy string ('').
*/
public function getCurrentPageSlug() {
- return $this->getElement(
- $_GET, // subject array
- 'page', // key
- '' // default
- );
+ return $this->getElement(
+ $this->aQuery,
+ 'page',
+ ''
+ );
}
/**
@@ -513,9 +513,9 @@ public function getCurrentPageSlug() {
* @remark Do not return `null` when not found as some framework methods check the returned value with `isset()` and if null is given, `isset()` yields `false` while it does `true` for an empty string ('').
*/
public function getCurrentTabSlug( $sCurrentPageSlug='' ) {
-
+
// It is possible that the tab slug is not set if it is the default tab.
- $_sTabSlug = $this->getElement( $_GET, 'tab' );
+ $_sTabSlug = $this->getElement( $this->aQuery, 'tab', '' );
if ( $_sTabSlug ) {
return $_sTabSlug;
}
@@ -544,10 +544,10 @@ public function getCurrentTab( $sCurrentPageSlug='' ) {
* @internal
* @remark Used in the __call() method in the main class.
* @return string The default in-page tab slug if found; otherwise, an empty string.
- */
+ */
public function getDefaultInPageTab( $sPageSlug ) {
-
- if ( ! $sPageSlug ) {
+
+ if ( ! $sPageSlug ) {
return '';
}
return $this->getElement(
Oops, something went wrong.

0 comments on commit ec46e48

Please sign in to comment.