Admin Page Framework Documentation
  • Package
  • Class
  • Tree

Packages

  • AdminPageFramework
    • FieldType
    • MetaBox
    • Page
    • PostType
    • TaxonomyField

Classes

  • AdminPageFramework
  • AdminPageFramework_Menu
  • AdminPageFramework_Page
  • AdminPageFramework_Setting
  1 <?php
  2 /**
  3  * Admin Page Framework
  4  * 
  5  * http://en.michaeluno.jp/admin-page-framework/
  6  * Copyright (c) 2013-2014 Michael Uno; Licensed MIT
  7  * 
  8  */
  9 if ( ! class_exists( 'AdminPageFramework' ) ) :
 10 /**
 11  * The main class of the framework to create admin pages and forms.
 12  * 
 13  * This class should be extended and the setUp() method should be overridden to define how pages are composed.
 14  * Most of the internal methods are prefixed with the underscore like <code>_getSomething()</code> and callback methods are prefixed with <code>_reply</code>.
 15  * The methods for the users are public and do not have those prefixes.
 16  * 
 17  * <h2>Hooks</h2>
 18  * <p>The class automatically creates WordPress action and filter hooks associated with the class methods.
 19  * The class methods corresponding to the name of the below actions and filters can be extended to modify the page output. Those methods are the callbacks of the filters and the actions.</p>
 20  * <h3>Methods and Action Hooks</h3>
 21  * <ul>
 22  *  <li><strong>start_{instantiated class name}</strong> – triggered at the end of the class constructor. This will be triggered in any admin page.</li>
 23  *  <li><strong>load_{instantiated class name}</strong>[2.1.0+] – triggered when the framework's page is loaded before the header gets sent. This will not be triggered in the admin pages that are not registered by the framework.</li>
 24  *  <li><strong>load_{page slug}</strong>[2.1.0+] – triggered when the framework's page is loaded before the header gets sent. This will not be triggered in the admin pages that are not registered by the framework.</li>
 25  *  <li><strong>load_{page slug}_{tab slug}</strong>[2.1.0+] – triggered when the framework's page is loaded before the header gets sent. This will not be triggered in the admin pages that are not registered by the framework.</li>
 26  *  <li><strong>do_before_{instantiated class name}</strong> – triggered before rendering the page. It applies to all the pages created by the instantiated class object.</li>
 27  *  <li><strong>do_before_{page slug}</strong> – triggered before rendering the page.</li>
 28  *  <li><strong>do_before_{page slug}_{tab slug}</strong> – triggered before rendering the page.</li>
 29  *  <li><strong>do_{instantiated class name}</strong> – triggered in the middle of rendering the page. It applies to all the pages created by the instantiated class object.</li>
 30  *  <li><strong>do_{page slug}</strong> – triggered in the middle of rendering the page.</li>
 31  *  <li><strong>do_{page slug}_{tab slug}</strong> – triggered in the middle of rendering the page.</li>
 32  *  <li><strong>do_after_{instantiated class name}</strong> – triggered after rendering the page. It applies to all the pages created by the instantiated class object.</li>
 33  *  <li><strong>do_after_{page slug}</strong> – triggered after rendering the page.</li>
 34  *  <li><strong>do_after_{page slug}_{tab slug}</strong> – triggered after rendering the page.</li>
 35  *  <li><strong>submit_{instantiated class name}_{submit input id}</strong> – [3.0.0+] triggered after the form is submitted with the submit button of the specified input id.</li>
 36  *  <li><strong>submit_{instantiated class name}_{submit field id}</strong> – [3.0.0+] triggered after the form is submitted with the submit button of the specified field that does not hava section is submitted.</li>
 37  *  <li><strong>submit_{instantiated class name}_{submit section id}_{submit field id}</strong> – [3.0.0+] triggered after the form is submitted with the submit button of the specified section and field is submitted.</li>
 38  *  <li><strong>submit_{instantiated class name}_{submit section id}</strong> – [3.0.0+] triggered after the form is submitted with the submit button of the specified section.</li>
 39  *  <li><strong>submit_{instantiated class name}</strong> – [3.0.0+] triggered after the form is submitted.</li>
 40  * </ul>
 41  * <h3>Methods and Filter Hooks</h3>
 42  * <ul>
 43  *  <li><strong>content_foot_{page slug}_{tab slug}</strong> – receives the output of the top part of the page. [3.0.0+] Changed the name from head_{...}.</li>
 44  *  <li><strong>content_foot_{page slug}</strong> – receives the output of the top part of the page. [3.0.0+] Changed the name from head_{...}.</li>
 45  *  <li><strong>content_foot_{instantiated class name}</strong> – receives the output of the top part of the page, applied to all pages created by the instantiated class object. [3.0.0+] Changed the name from head_{...}.</li>
 46  *  <li><strong>content_{page slug}_{tab slug}</strong> – receives the output of the middle part of the page including form input fields.</li>
 47  *  <li><strong>content_{page slug}</strong> – receives the output of the middle part of the page including form input fields.</li>
 48  *  <li><strong>content_{instantiated class name}</strong> – receives the output of the middle part of the page, applied to all pages created by the instantiated class object.</li>
 49  *  <li><strong>content_bottom_{page slug}_{tab slug}</strong> – receives the output of the bottom part of the page. [3.0.0+] Changed the name from foot_{...}.</li>
 50  *  <li><strong>content_bottom_{page slug}</strong> – receives the output of the bottom part of the page. [3.0.0+] Changed the name from foot_{...}.</li>
 51  *  <li><strong>content_bottom_{instantiated class name}</strong> – receives the output of the bottom part of the page, applied to all pages created by the instantiated class object. [3.0.0+] Changed the name from foot_{...}.</li>
 52  *  <li><strong>section_head_{instantiated class name}_{section ID}</strong> – receives the title and the description output of the given form section ID. The first parameter: the output string.</li> 
 53  *  <li><strong>field_{instantiated class name}_{field ID}</strong> – receives the form input field output of the given input field ID that does not have a section. The first parameter: output string. The second parameter: the array of option.</li>
 54  *  <li><strong>field_{instantiated class name}_{section id}_{field ID}</strong> – [3.0.0+] receives the form input field output of the given input field ID that has a section. The first parameter: output string. The second parameter: the array of option.</li>
 55  *  <li><strong>sections_{instantiated class name}</strong> – receives the registered section arrays. The first parameter: sections container array.</li> 
 56  *  <li><strong>fields_{instantiated class name}</strong> – receives the registered field arrays. The first parameter: fields container array.</li> 
 57  *  <li><strong>fields_{instantiated class name}_{section id}</strong> – [3.0.0+] receives the registered field arrays which belong to the specified section. The first parameter: fields container array.</li> 
 58  *  <li><strong>field_definition_{instantiated class name}_{field ID}</strong> – [3.0.2+] receives the form field definition array of the given input field ID that does not have a section. The first parameter: the field definition array.</li>
 59  *  <li><strong>field_definition_{instantiated class name}_{section id}_{field ID}</strong> – [3.0.2+] receives the form field definition array of the given input field ID that has a section. The first parameter: the field definition array. The second parameter: the integer representing sub-section index if the field belongs to a sub-section.</li>
 60  *  <li><strong>pages_{instantiated class name}</strong> – receives the registered page arrays. The first parameter: pages container array.</li> 
 61  *  <li><strong>tabs_{instantiated class name}_{page slug}</strong> – receives the registered in-page tab arrays. The first parameter: tabs container array.</li> 
 62  *  <li><strong>validation_{instantiated class name}_{field id}</strong> – [3.0.0+] receives the form submission value of the field that does not have a section. The first parameter: ( string|array ) submitted input value. The second parameter: ( string|array ) the old value stored in the database.</li>
 63  *  <li><strong>validation_{instantiated class name}_{section_id}_{field id}</strong> – [3.0.0+] receives the form submission value of the field that has a section. The first parameter: ( string|array ) submitted input value. The second parameter: ( string|array ) the old value stored in the database.</li>
 64  *  <li><strong>validation_{instantiated class name}_{section id}</strong> – [3.0.0+] receives the form submission values that belongs to the section.. The first parameter: ( array ) the array of submitted input values that belong to the section. The second parameter: ( array ) the array of the old values stored in the database.</li>
 65  *  <li><strong>validation_{page slug}_{tab slug}</strong> – receives the form submission values as array. The first parameter: submitted input array. The second parameter: the original array stored in the database.</li>
 66  *  <li><strong>validation_{page slug}</strong> – receives the form submission values as array. The first parameter: submitted input array. The second parameter: the original array stored in the database.</li>
 67  *  <li><strong>validation_{instantiated class name}</strong> – receives the form submission values as array. The first parameter: submitted input array. The second parameter: the original array stored in the database.</li>
 68  *  <li><strong>style_{page slug}_{tab slug}</strong> – receives the output of the CSS rules applied to the tab page of the slug.</li>
 69  *  <li><strong>style_{page slug}</strong> – receives the output of the CSS rules applied to the page of the slug.</li>
 70  *  <li><strong>style_{instantiated class name}</strong> – receives the output of the CSS rules applied to the pages added by the instantiated class object.</li>
 71  *  <li><strong>script_{page slug}_{tab slug}</strong> – receives the output of the JavaScript script applied to the tab page of the slug.</li>
 72  *  <li><strong>script_{page slug}</strong> – receives the output of the JavaScript script applied to the page of the slug.</li>
 73  *  <li><strong>script_{instantiated class name}</strong> – receives the output of the JavaScript script applied to the pages added by the instantiated class object.</li>
 74  *  <li><strong>export_{instantiated class name}_{input id}</strong> – [2.1.5+] receives the exporting array submitted from the specific export button.</li>
 75  *  <li><strong>export_{instantiated class name}_{field id}</strong> – [2.1.5+] receives the exporting array submitted from the specific field that does not have a section.</li>
 76  *  <li><strong>export_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the exporting array submitted from the specific field that has a section.</li>
 77  *  <li><strong>export_{page slug}_{tab slug}</strong> – receives the exporting array sent from the tab page.</li>
 78  *  <li><strong>export_{page slug}</strong> – receives the exporting array submitted from the page.</li>
 79  *  <li><strong>export_{instantiated class name}</strong> – receives the exporting array submitted from the plugin.</li>
 80  *  <li><strong>export_name_{instantiated class name}_{input id}</strong> – receives the exporting file name submitted the specified input id.</li>
 81  *  <li><strong>export_name_{instantiated class name}_{field id}</strong> – receives the exporting file name submitted from the specific field that does not have a section.</li>
 82  *  <li><strong>export_name_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the exporting file name submitted from the specific field that has a section.</li>
 83  *  <li><strong>export_name_{page slug}_{tab slug}</strong> – receives the exporting file name submitted from the tab page.</li>
 84  *  <li><strong>export_name_{page slug}</strong> – receives the exporting file name submitted from the page.</li>
 85  *  <li><strong>export_name_{instantiated class name}</strong> – receives the exporting file name submitted from the script.</li>
 86  *  <li><strong>export_format_{instantiated class name}_{input id}</strong> – receives the exporting file format submitted from the specific export button.</li>
 87  *  <li><strong>export_format_{instantiated class name}_{field id}</strong> – receives the exporting file format submitted from the specific field that does not have a section.</li>
 88  *  <li><strong>export_format_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the exporting file format submitted from the specific field that has a section.</li>
 89  *  <li><strong>export_format_{page slug}_{tab slug}</strong> – receives the exporting file format sent from the tab page.</li>
 90  *  <li><strong>export_format_{page slug}</strong> – receives the exporting file format submitted from the page.</li>
 91  *  <li><strong>export_format_{instantiated class name}</strong> – receives the exporting file format submitted from the plugin.</li> 
 92  *  <li><strong>import_{instantiated class name}_{input id}</strong> – [2.1.5+] receives the importing array submitted from the specific import button.</li>
 93  *  <li><strong>import_{instantiated class name}_{field id}</strong> – [2.1.5+] receives the importing array submitted from the specific import field that does not have a section.</li>
 94  *  <li><strong>import_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the importing array submitted from the specific import field that has a section.</li>
 95  *  <li><strong>import_{page slug}_{tab slug}</strong> – receives the importing array submitted from the tab page.</li>
 96  *  <li><strong>import_{page slug}</strong> – receives the importing array submitted from the page.</li>
 97  *  <li><strong>import_{instantiated class name}</strong> – receives the importing array submitted from the plugin.</li>
 98  *  <li><strong>import_mime_types_{instantiated class name}_{input id}</strong> – [2.1.5+] receives the mime types of the import data submitted from the specific import button.</li>
 99  *  <li><strong>import_mime_types_{instantiated class name}_{field id}</strong> – [2.1.5+] receives the mime types of the import data submitted from the specific import field that does not have a section.</li>
100  *  <li><strong>import_mime_types_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the mime types of the import data submitted from the specific import field that has a section.</li>
101  *  <li><strong>import_mime_types_{page slug}_{tab slug}</strong> – receives the mime types of the import data submitted from the tab page.</li>
102  *  <li><strong>import_mime_types_{page slug}</strong> – receives the mime types of the import data submitted from the page.</li>
103  *  <li><strong>import_mime_types_{instantiated class name}</strong> – receives the mime types of the import data submitted from the plugin.</li>
104  *  <li><strong>import_format_{instantiated class name}_{input id}</strong> – [2.1.5+] receives the import data format submitted from the specific import button.</li>
105  *  <li><strong>import_format_{instantiated class name}_{field id}</strong> – [2.1.5+] receives the import data format submitted from the specific import field that does not have a section.</li>
106  *  <li><strong>import_format_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the import data format submitted from the specific import field that has a section.</li>
107  *  <li><strong>import_format_{page slug}_{tab slug}</strong> – receives the import data format submitted from the tab page.</li>
108  *  <li><strong>import_format_{page slug}</strong> – receives the import data format submitted from the page.</li>
109  *  <li><strong>import_format_{instantiated class name}</strong> – receives the import data format submitted from the plugin.</li>
110  *  <li><strong>import_option_key_{instantiated class name}_{input id}</strong> – [2.1.5+] receives the option array key of the importing array submitted from the specific import button.</li>
111  *  <li><strong>import_option_key_{instantiated class name}_{field id}</strong> – [2.1.5+] receives the option array key of the importing array submitted from the specific import field that does not have a section.</li>
112  *  <li><strong>import_option_key_{instantiated class name}_{section id}_{field id}</strong> – [3.0.0+] receives the option array key of the importing array submitted from the specific import field that has a section.</li>
113  *  <li><strong>import_option_key_{page slug}_{tab slug}</strong> – receives the option array key of the importing array submitted from the tab page.</li>
114  *  <li><strong>import_option_key_{page slug}</strong> – receives the option array key of the importing array submitted from the page.</li>
115  *  <li><strong>import_option_key_{instantiated class name}</strong> – receives the option array key of the importing array submitted from the plugin.</li> 
116  * </ul>
117  * <h3>Remarks</h3>
118  * <p>The slugs must not contain a dot(.) or a hyphen(-) since it is used in the callback method name.</p>
119  * <h3>Examples</h3>
120  * <p>If the instantiated class name is Sample_Admin_Pages, defining the following class method will embed a banner image in all pages created by the class.</p>
121  * <code>class Sample_Admin_Pages extends AdminPageFramework {
122  * ...
123  *     function content_foot_Sample_Admin_Pages( $sContent ) {
124  *         return '<div style="float:right;"><img src="' . plugins_url( 'img/banner468x60.gif', __FILE__ ) . '" /></div>' 
125  *             . $sContent;
126  *     }
127  * ...
128  * }</code>
129  * <p>If the created page slug is my_first_setting_page, defining the following class method will filter the middle part of the page output.</p>
130  * <code>class Sample_Admin_Pages extends AdminPageFramework {
131  * ...
132  *     function content_my_first_setting_page( $sContent ) {
133  *         return $sContent . '<p>Hello world!</p>';
134  *     }
135  * ...
136  * }</code>
137  * <h3>Timing of Hooks</h3>
138  * <code>------ When the class is instantiated ------
139  *  
140  *  start_{instantiated class name}
141  *  load_{instantiated class name}
142  *  load_{page slug}
143  *  load_{page slug}_{tab slug}
144  * 
145  *  sections_{instantiated class name}
146  *  fields_{instantiated class name}
147  *  pages_{instantiated class name}
148  *  tabs_{instantiated class name}_{page slug}
149  * 
150  *  ------ Start Rendering HTML ------
151  *  
152  *  <head>
153  *      <style type="text/css" name="admin-page-framework">
154  *          style_{page slug}_{tab slug}
155  *          style_{page slug}
156  *          style_{instantiated class name}
157  *          script_{page slug}_{tab slug}
158  *          script_{page slug}
159  *          script_{instantiated class name}
160  *      </style>
161  *  
162  *  <head/>
163  *  
164  *  do_before_{instantiated class name}
165  *  do_before_{page slug}
166  *  do_before_{page slug}_{tab slug}
167  *  
168  *  <div class="wrap">
169  *  
170  *      content_foot_{page slug}_{tab slug}
171  *      content_foot_{page slug}
172  *      content_foot_{instantiated class name}
173  *  
174  *      <div class="acmin-page-framework-container">
175  *          <form action="options.php" method="post">
176  *  
177  *              do_form_{page slug}_{tab slug}
178  *              do_form_{page slug}
179  *              do_form_{instantiated class name}
180  *  
181  *              section_head_{instantiated class name}_{section ID}
182  *              field_{instantiated class name}_{field ID}
183  *  
184  *              content_{page slug}_{tab slug}
185  *              content_{page slug}
186  *              content_{instantiated class name}
187  *  
188  *              do_{instantiated class name}
189  *              do_{page slug}
190  *              do_{page slug}_{tab slug}
191  *  
192  *          </form>
193  *      </div>
194  *  
195  *          content_bottom_{page slug}_{tab slug}
196  *          content_bottom_{page slug}
197  *          content_bottom_{instantiated class name}
198  *  
199  *  </div>
200  *  
201  *  do_after_{instantiated class name}
202  *  do_after_{page slug}
203  *  do_after_{page slug}_{tab slug}
204  *  
205  *  ----- After Submitting the Form ------
206  *  
207  *  validation_{instantiated class name}_{submit button input id}
208  *  validation_{instantiated class name}_{submit button field id}
209  *  validation_{page slug}_{tab slug }
210  *  validation_{page slug }
211  *  validation_{instantiated class name }
212  *  export_{page slug}_{tab slug}
213  *  export_{page slug}
214  *  export_{instantiated class name}
215  *  import_{page slug}_{tab slug}
216  *  import_{page slug}
217  *  import_{instantiated class name}
218  * </code>
219  * @abstract
220  * @since           2.0.0
221  * @use             AdminPageFramework_Property_Page
222  * @use             AdminPageFramework_Debug
223  * @use             AdminPageFramework_Property_Page
224  * @use             AdminPageFramework_Message
225  * @use             AdminPageFramework_Link_Page
226  * @use             AdminPageFramework_Utility
227  * @remark          This class stems from several abstract classes.
228  * @extends         AdminPageFramework_Setting
229  * @package         AdminPageFramework
230  * @subpackage      Page
231  */
232 abstract class AdminPageFramework extends AdminPageFramework_Setting_Validation {
233         
234     /**
235      * Registers necessary callbacks ans sets up internal components including properties.
236      * 
237      * <h4>Example</h4>
238      * <code>if ( is_admin() )
239      *  new MyAdminPageClass( 'my_custom_option_key', __FILE__ );</code>
240      * 
241      * @access          public
242      * @since           2.0.0
243      * @see             http://codex.wordpress.org/Roles_and_Capabilities
244      * @see             http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains
245      * @param           string          ( optional ) specifies the option key name to store in the options table. If this is not set, the instantiated class name will be used.
246      * @param           string          ( optional ) used to retrieve the plugin/theme details to auto-insert the information into the page footer.
247      * @param           string          ( optional ) sets the overall access level to the admin pages created by the framework. The used capabilities are listed <a href="http://codex.wordpress.org/Roles_and_Capabilities">here</a>. If not set, <strong>manage_options</strong> will be assigned by default. The capability can be set per page, tab, setting section, setting field.
248      * @param           string          ( optional ) the <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains" target="_blank">text domain</a> used for the framework's system messages. Default: admin-page-framework.
249      * @return          void            returns nothing.
250      */
251     public function __construct( $sOptionKey=null, $sCallerPath=null, $sCapability=null, $sTextDomain='admin-page-framework' ){
252             
253         parent::__construct( 
254             $sOptionKey, 
255             $sCallerPath ? $sCallerPath : AdminPageFramework_Utility::getCallerScriptPath( __FILE__ ),  // this is important to attempt to find the caller script path here when separating the library into multiple files.
256             $sCapability, 
257             $sTextDomain 
258         );
259                     
260         $this->oUtil->addAndDoAction( $this, 'start_' . $this->oProp->sClassName ); // fire the start_{instantiated class name} action.
261 
262     }   
263 
264     /**
265      * The method for all the necessary set-ups. 
266      * 
267      * The users should override this method to set-up necessary settings. To perform certain tasks prior to this method, use the <strong>start_{instantiated class name}</strong> hook that is triggered at the end of the class constructor.
268      * 
269      * <h4>Example</h4>
270      * <code>public function setUp() {
271      *  $this->setRootMenuPage( 'APF Form' ); 
272      *  $this->addSubMenuItems(
273      *      array(
274      *          'title' => 'Form Fields',
275      *          'page_slug' => 'apf_form_fields',
276      *      )
277      *  );      
278      *  $this->addSettingSections(
279      *      array(
280      *          'section_id'        => 'text_fields',
281      *          'page_slug'     => 'apf_form_fields',
282      *          'title'         => 'Text Fields',
283      *          'description'   => 'These are text type fields.',
284      *      )
285      *  );
286      *  $this->addSettingFields(
287      *      array(  
288      *          'field_id' => 'text',
289      *          'section_id' => 'text_fields',
290      *          'title' => 'Text',
291      *          'type' => 'text',
292      *      )   
293      *  );          
294      * }</code>
295      * @abstract
296      * @since           2.0.0
297      * @remark          This is a callback for the <em>wp_loaded</em> hook.
298      * @remark          In v1, this is triggered with the <em>admin_menu</em> hook; however, in v2, this is triggered with the <em>wp_loaded</em> hook.
299      * @access          public
300      * @return          void
301      */ 
302     public function setUp() {}
303         
304     /*
305      * Help Pane Methods
306      */
307     
308     /**
309      * Adds the given contextual help tab contents into the property.
310      * 
311      * <h4>Example</h4>
312      * <code>   $this->addHelpTab( 
313      *      array(
314      *          'page_slug'                 => 'first_page',    // ( mandatory )
315      *          // 'page_tab_slug'          => null,    // ( optional )
316      *          'help_tab_title'            => 'Admin Page Framework',
317      *          'help_tab_id'               => 'admin_page_framework',  // ( mandatory )
318      *          'help_tab_content'          => __( 'This contextual help text can be set with the <em>addHelpTab()</em> method.', 'admin-page-framework' ),
319      *          'help_tab_sidebar_content'  => __( 'This is placed in the sidebar of the help pane.', 'admin-page-framework' ),
320      *      )
321      *  );</code>
322      * 
323      * @since           2.1.0
324      * @remark          Called when registering setting sections and fields.
325      * @param           array           The help tab array.
326      * <h4>Contextual Help Tab Array Structure</h4>
327      * <ul>
328      *  <li><strong>page_slug</strong> - ( required ) the page slug of the page that the contextual help tab and its contents are displayed.</li>
329      *  <li><strong>page_tab_slug</strong> - ( optional ) the tab slug of the page that the contextual help tab and its contents are displayed.</li>
330      *  <li><strong>help_tab_title</strong> - ( required ) the title of the contextual help tab.</li>
331      *  <li><strong>help_tab_id</strong> - ( required ) the id of the contextual help tab.</li>
332      *  <li><strong>help_tab_content</strong> - ( optional ) the HTML string content of the the contextual help tab.</li>
333      *  <li><strong>help_tab_sidebar_content</strong> - ( optional ) the HTML string content of the sidebar of the contextual help tab.</li>
334      * </ul>
335      * @return          void
336      */ 
337     public function addHelpTab( $aHelpTab ) {
338         $this->oHelpPane->_addHelpTab( $aHelpTab );
339     }
340 
341     /*
342      * Head Tag Methods
343      */
344     /**
345      * Enqueues styles by page slug and tab slug.
346      * 
347      * Use this method to pass multiple files to the same page.
348      * 
349      * <h4>Example</h4>
350      * <code>$this->enqueueStyle(  
351      *      array( 
352      *          dirname( APFDEMO_FILE ) . '/asset/css/code.css',
353      *          dirname( APFDEMO_FILE ) . '/asset/css/code2.css',
354      *      ),
355      *      'apf_manage_options' 
356      * );</code>
357      * 
358      * @since           3.0.0
359      * @param           array           The sources of the stylesheet to enqueue: the url, the absolute file path, or the relative path to the root directory of WordPress. Example: <em>array( '/css/mystyle.css', '/css/mystyle2.css' )</em>
360      * @param           string          (optional) The page slug that the stylesheet should be added to. If not set, it applies to all the pages created by the framework.
361      * @param           string          (optional) The tab slug that the stylesheet should be added to. If not set, it applies to all the in-page tabs in the page.
362      * @param           array           (optional) The argument array for more advanced parameters.
363      * @return          array           The array holing the queued items.
364      */
365     public function enqueueStyles( $aSRCs, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) {
366         return $this->oHeadTag->_enqueueStyles( $aSRCs, $sPageSlug, $sTabSlug, $aCustomArgs );
367     }
368     /**
369      * Enqueues a style by page slug and tab slug.
370      * 
371      * <h4>Example</h4>
372      * <code>$this->enqueueStyle(  dirname( APFDEMO_FILE ) . '/asset/css/code.css', 'apf_manage_options' );
373      * $this->enqueueStyle(  plugins_url( 'asset/css/readme.css' , APFDEMO_FILE ) , 'apf_read_me' );</code>
374      * 
375      * @since           2.1.2
376      * @see             http://codex.wordpress.org/Function_Reference/wp_enqueue_style
377      * @param           string          The source of the stylesheet to enqueue: the url, the absolute file path, or the relative path to the root directory of WordPress. Example: '/css/mystyle.css'.
378      * @param           string          (optional) The page slug that the stylesheet should be added to. If not set, it applies to all the pages created by the framework.
379      * @param           string          (optional) The tab slug that the stylesheet should be added to. If not set, it applies to all the in-page tabs in the page.
380      * @param           array           (optional) The argument array for more advanced parameters.
381      * <h4>Argument Array</h4>
382      * <ul>
383      *  <li><strong>handle_id</strong> - ( optional, string ) The handle ID of the stylesheet.</li>
384      *  <li><strong>dependencies</strong> - ( optional, array ) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_style">codex</a>.</li>
385      *  <li><strong>version</strong> - ( optional, string ) The stylesheet version number.</li>
386      *  <li><strong>media</strong> - ( optional, string ) the description of the field which is inserted into the after the input field tag.</li>
387      * </ul>
388      * @return          string          The style handle ID. If the passed url is not a valid url string, an empty string will be returned.
389      */ 
390     public function enqueueStyle( $sSRC, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) {
391         return $this->oHeadTag->_enqueueStyle( $sSRC, $sPageSlug, $sTabSlug, $aCustomArgs );        
392     }
393     /**
394      * Enqueues scripts by page slug and tab slug.
395      * 
396      * <h4>Example</h4>
397      * <code>
398      * $this->enqueueScripts(  
399      *  array( 
400      *          plugins_url( 'asset/js/test.js' , __FILE__ ),   // source url or path
401      *          plugins_url( 'asset/js/test2.js' , __FILE__ ),  
402      *  )
403      *  'apf_read_me',  // page slug
404      * );
405      * </code>
406      *
407      * @since           2.1.5
408      * @param           array           The sources of the stylesheets to enqueue: the URL, the absolute file path, or the relative path to the root directory of WordPress. Example: '/js/myscript.js'.
409      * @param           string          (optional) The page slug that the script should be added to. If not set, it applies to all the pages created by the framework.
410      * @param           string          (optional) The tab slug that the script should be added to. If not set, it applies to all the in-page tabs in the page.
411      * @param           array           (optional) The argument array for more advanced parameters.
412      * @return          array           The array holding the queued items.
413      */
414     public function enqueueScripts( $aSRCs, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) {
415         return $this->oHeadTag->_enqueueScripts( $sSRC, $sPageSlug, $sTabSlug, $aCustomArgs );
416     }   
417     /**
418      * Enqueues a script by page slug and tab slug.
419      *  
420      * <h4>Example</h4>
421      * <code>$this->enqueueScript(  
422      *      plugins_url( 'asset/js/test.js' , __FILE__ ),   // source url or path
423      *      'apf_read_me',  // page slug
424      *      '',     // tab slug
425      *      array(
426      *          'handle_id' => 'my_script', // this handle ID also is used as the object name for the translation array below.
427      *          'translation' => array( 
428      *              'a' => 'hello world!',
429      *              'style_handle_id' => $sStyleHandle, // check the enqueued style handle ID here.
430      *          ),
431      *      )
432      *  );</code>
433      * 
434      * @since           2.1.2
435      * @since           3.0.0           Changed the scope to public
436      * @see             http://codex.wordpress.org/Function_Reference/wp_enqueue_script
437      * @param           string          The URL of the stylesheet to enqueue, the absolute file path, or the relative path to the root directory of WordPress. Example: '/js/myscript.js'.
438      * @param           string          (optional) The page slug that the script should be added to. If not set, it applies to all the pages created by the framework.
439      * @param           string          (optional) The tab slug that the script should be added to. If not set, it applies to all the in-page tabs in the page.
440      * @param           array           (optional) The argument array for more advanced parameters.
441      * <h4>Argument Array</h4>
442      * <ul>
443      *  <li><strong>handle_id</strong> - ( optional, string ) The handle ID of the script.</li>
444      *  <li><strong>dependencies</strong> - ( optional, array ) The dependency array. For more information, see <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">codex</a>.</li>
445      *  <li><strong>version</strong> - ( optional, string ) The stylesheet version number.</li>
446      *  <li><strong>translation</strong> - ( optional, array ) The translation array. The handle ID will be used for the object name.</li>
447      *  <li><strong>in_footer</strong> - ( optional, boolean ) Whether to enqueue the script before <code></head></code> or before<code></body></code> Default: <em>false</em>.</li>
448      * </ul>
449      * @return          string          The script handle ID. If the passed url is not a valid url string, an empty string will be returned.
450      */
451     public function enqueueScript( $sSRC, $sPageSlug='', $sTabSlug='', $aCustomArgs=array() ) { 
452         return $this->oHeadTag->_enqueueScript( $sSRC, $sPageSlug, $sTabSlug, $aCustomArgs );
453     }
454     
455     /**
456     * Adds the given link(s) into the description cell of the plugin listing table.
457     * 
458     * <h4>Example</h4>
459     * <code>$this->addLinkToPluginDescription( 
460     *       "<a href='http://www.google.com'>Google</a>",
461     *       "<a href='http://www.yahoo.com'>Yahoo!</a>"
462     *   );</code>
463     * 
464     * @since            2.0.0
465     * @since            3.0.0           Changed the scope to public from protected.
466     * @remark           Accepts variadic parameters; the number of accepted parameters are not limited to three.
467     * @param            string          the tagged HTML link text.
468     * @param            string          ( optional ) another tagged HTML link text.
469     * @param            string          ( optional ) add more as many as want by adding items to the next parameters.
470     * @access           public
471     * @return           void
472     */      
473     public function addLinkToPluginDescription( $sTaggedLinkHTML1, $sTaggedLinkHTML2=null, $_and_more=null ) {
474         $this->oLink->_addLinkToPluginDescription( func_get_args() );       
475     }
476 
477     /**
478     * Adds the given link(s) into the title cell of the plugin listing table.
479     * 
480     * <h4>Example</h4>
481     * <code>$this->addLinkToPluginTitle( 
482     *       "<a href='http://www.wordpress.org'>WordPress</a>"
483     *   );</code>
484     * 
485     * @since            2.0.0
486     * @since            3.0.0           Changed the scope to public from protected.
487     * @remark           Accepts variadic parameters; the number of accepted parameters are not limited to three.
488     * @param            string          the tagged HTML link text.
489     * @param            string          ( optional ) another tagged HTML link text.
490     * @param            string          ( optional ) add more as many as want by adding items to the next parameters.
491     * @access           public
492     * @return           void
493     */  
494     public function addLinkToPluginTitle( $sTaggedLinkHTML1, $sTaggedLinkHTML2=null, $_and_more=null ) {    
495         $this->oLink->_addLinkToPluginTitle( func_get_args() );     
496     }
497      
498     /**
499      * Sets the overall capability.
500      * 
501      * <h4>Example</h4>
502      * <code>$this->setCpability( 'read' );     // let subscribers access the pages.
503      * </code>
504      * 
505      * @since           2.0.0
506      * @since           3.0.0           Changed the scope to public from protected.
507      * @see             http://codex.wordpress.org/Roles_and_Capabilities
508      * @param           string          The <a href="http://codex.wordpress.org/Roles_and_Capabilities">access level</a> for the created pages.
509      * @return          void
510      * @access          public
511      */ 
512     public function setCapability( $sCapability ) {
513         $this->oProp->sCapability = $sCapability;
514         $this->oForm->sCapability = $sCapability;
515     }
516 
517     /**
518      * Sets the given HTML text into the footer on the left hand side.
519      * 
520      * <h4>Example</h4>
521      * <code>$this->setFooterInfoLeft( '<br />Custom Text on the left hand side.' );
522      * </code>
523      * 
524      * @since           2.0.0
525      * @since           3.0.0           Changed the scope to public from protected.
526      * @param           string          The HTML code to insert.
527      * @param           boolean         If true, the text will be appended; otherwise, it will replace the default text.
528      * @access          public
529      * @return          void
530      */ 
531     public function setFooterInfoLeft( $sHTML, $bAppend=true ) {
532         $this->oProp->aFooterInfo['sLeft'] = $bAppend 
533             ? $this->oProp->aFooterInfo['sLeft'] . PHP_EOL . $sHTML
534             : $sHTML;
535     }
536     
537     /**
538      * Sets the given HTML text into the footer on the right hand side.
539      * 
540      * <h4>Example</h4>
541      * <code>$this->setFooterInfoRight( '<br />Custom Text on the right hand side.' );
542      * </code>
543      * 
544      * @access          public
545      * @since           2.0.0
546      * @since           3.0.0           Changed the scope to public from protected.
547      * @param           string          The HTML code to insert.
548      * @param           boolean         If true, the text will be appended; otherwise, it will replace the default text.
549      * @return          void
550      */ 
551     public function setFooterInfoRight( $sHTML, $bAppend=true ) {
552         $this->oProp->aFooterInfo['sRight'] = $bAppend 
553             ? $this->oProp->aFooterInfo['sRight'] . PHP_EOL . $sHTML
554             : $sHTML;
555     }
556             
557     /**
558      * Sets an admin notice.
559      * 
560      * <h4>Example</h4>
561      * <code>$this->setAdminNotice( sprintf( 'Please click <a href="%1$s">here</a> to upgrade the options.', admin_url( 'admin.php?page="my_page"' ) ), 'updated' );
562      * </code>
563      * 
564      * @access          public
565      * @remark          It should be used before the 'admin_notices' hook is triggered.
566      * @since           2.1.2
567      * @since           3.0.0           Changed the scope to public from protected.
568      * @param           string          The message to display
569      * @param           string          ( optional ) The class selector used in the message HTML element. 'error' and 'updated' are prepared by WordPress but it's not limited to them and can pass a custom name. Default: 'error'
570      * @param           string          ( optional ) The ID of the message. If not set, the hash of the message will be used.
571      */
572     public function setAdminNotice( $sMessage, $sClassSelector='error', $sID='' ) {
573             
574         $sID = $sID ? $sID : md5( $sMessage );
575         $this->oProp->aAdminNotices[ md5( $sMessage ) ] = array(  
576             'sMessage' => $sMessage,
577             'sClassSelector' => $sClassSelector,
578             'sID' => $sID,
579         );
580         add_action( 'admin_notices', array( $this, '_replyToPrintAdminNotices' ) );
581         
582     }
583         /**
584          * A helper function for the above setAdminNotice() method.
585          * @since           2.1.2
586          * @internal
587          */
588         public function _replyToPrintAdminNotices() {
589             
590             foreach( $this->oProp->aAdminNotices as $aAdminNotice ) 
591                 echo "<div class='{$aAdminNotice['sClassSelector']}' id='{$aAdminNotice['sID']}' ><p>"
592                     . $aAdminNotice['sMessage']
593                     . "</p></div>";
594             
595         }   
596     
597     /**
598      * Sets the disallowed query keys in the links that the framework generates.
599      * 
600      * <h4>Example</h4>
601      * <code>$this->setDisallowedQueryKeys( 'my-custom-admin-notice' );
602      * </code>
603      * 
604      * @since           2.1.2
605      * @since           3.0.0           It also accepts a string. Changed the scope to public.
606      * @access          public
607      * @param           array|string    The query key(s) to disallow.
608      * @param           boolean         If true, the passed key(s) will be appended to the property; otherwise, it will override the property.
609      * @return          void
610      */
611     public function setDisallowedQueryKeys( $asQueryKeys, $bAppend=true ) {
612         
613         if ( ! $bAppend ) {
614             $this->oProp->aDisallowedQueryKeys = ( array ) $asQueryKeys;
615             return;
616         }
617         
618         $aNewQueryKeys = array_merge( ( array ) $asQueryKeys, $this->oProp->aDisallowedQueryKeys );
619         $aNewQueryKeys = array_filter( $aNewQueryKeys );    // drop non-values
620         $aNewQueryKeys = array_unique( $aNewQueryKeys );    // drop duplicates
621         $this->oProp->aDisallowedQueryKeys = $aNewQueryKeys;
622         
623     }
624     
625     /**
626      * Retrieves the saved option value from the given option key and the dimensional array key representation.
627      * 
628      * <h4>Example</h4>
629      * <code>
630      * $aData = AdminPageFramework::getOption( 'APF' );
631      * $aSection = AdminPageFramework::getOption( 'APF', 'my_section' );
632      * $sText = AdminPageFramework::getOption( 'APF', array( 'my_section', 'my_text_field' ), 'foo' );
633      * $sColor = AdminPageFramework::getOption( 'APF', 'my_color_field', '#FFF' );
634      * </code>
635      * 
636      * @since           3.0.1
637      * @param           string          $sOptionKey         the option key of the options table.
638      * @param           string          $asKey              the representation of dimensional array keys. If the returning option structure is like the following,
639      * <code>
640      * array(
641      *  'a' =>  array(
642      *      'b' =>  array(
643      *          'c' => 'ccc',
644      *      ),
645      *  ),
646      * )
647      * </code>
648      * then the value 'ccc' can be retrieved with the key representation array of 
649      * <code>
650      * array( 'a', 'b', 'c' )
651      * </code>
652      * @param           mixed           $vDefault           the default value that will be returned if nothing is stored.
653      * @return          mixed           If the field ID is not specified
654      */
655     static public function getOption( $sOptionKey, $asKey=null , $vDefault=null ) {
656         return AdminPageFramework_WPUtility::getOption( $sOptionKey,$asKey, $vDefault );
657     }
658     
659 }
660 endif;
Admin Page Framework Documentation API documentation generated by ApiGen 2.8.0