Last active
March 27, 2016 06:45
-
-
Save michaeluno/45c900ee56d3063776b4 to your computer and use it in GitHub Desktop.
Testing name space hooks with Admin Pag Framework.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Admin Page Framework Test - Namespace Hooks | |
* Description: | |
* Author: Michael Uno | |
* Author URI: http://michaeluno.jp | |
* Version: 1.0.0 | |
*/ | |
function loadAdminPageFrameworkTestNamespaceHooks() { | |
// If using PHP v5.3 or below, return. | |
if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { | |
return; | |
} | |
include( dirname( __FILE__ ) . '/APF_Test_NamespaceHooks.php' ); | |
} | |
// admin_page_framework_loader_ + _action_after_loading_plugin | |
add_action( 'admin_page_framework_loader_action_after_loading_plugin', 'loadAdminPageFrameworkTestNamespaceHooks', 100 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Foo\Bar; | |
class APF_Test_NamespaceHooks extends \AdminPageFramework { | |
/** | |
* Sest up pages. | |
*/ | |
public function setUp() { | |
$this->setRootMenuPage( 'Settings' ); // where to belong | |
$this->addSubMenuItem( | |
array( | |
'title' => __( 'APF Namespace Test', 'admin-page-framework-examples' ), // page and menu title | |
'page_slug' => 'apf_test_namespace' // page slug | |
) | |
); | |
$this->addSettingSections( | |
array( | |
'section_id' => 'custom_repeatable_values', | |
'page_slug' => 'apf_test_namespace', | |
) | |
); | |
$this->addSettingFields( | |
'custom_repeatable_values', // the target section ID | |
array( | |
'field_id' => 'my_text_field', | |
'title' => __( 'Text', 'admin-page-framework-examples' ), | |
'type' => 'text', | |
), | |
array( | |
'field_id' => '__submit', | |
'type' => 'submit', | |
'save' => false, // do not save the value | |
) | |
); | |
} | |
} | |
new APF_Test_NamespaceHooks( | |
'apf_test_namespace_hooks' // the option key name stored in the options table. | |
); | |
function insertCustomText() { | |
echo "<h3>Current Action/Filter Hook</h3>"; | |
echo "<p>" | |
. sprintf( | |
'This is inserted with the <code>%1$s</code> hook.', | |
current_filter() | |
) | |
. "</p>"; | |
} | |
add_action( 'do_Foo\Bar\APF_Test_NamespaceHooks', 'Foo\Bar\insertCustomText' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment