1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Page Framework Loader |
4
|
|
|
* |
5
|
|
|
* Demonstrates the usage of Admin Page Framework. |
6
|
|
|
* |
7
|
|
|
* http://admin-page-framework.michaeluno.jp/ |
8
|
|
|
* Copyright (c) 2013-2022, Michael Uno; Licensed GPLv2 |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Adds a tab of the set page to the loader plugin. |
14
|
|
|
* |
15
|
|
|
* @since 3.5.0 |
16
|
|
|
*/ |
17
|
|
|
class AdminPageFrameworkLoader_AdminPage_Help_FAQ extends AdminPageFrameworkLoader_AdminPage_Tab_ReadMeBase { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Triggered when the tab is loaded. |
21
|
|
|
*/ |
22
|
|
|
public function replyToLoadTab( $oAdminPage ) { |
23
|
|
|
|
24
|
|
|
$_aSections = $this->getContentsByHeader( $this->getFAQContents(), 4 ); |
25
|
|
|
foreach( $_aSections as $_iIndex => $_aContent ) { |
26
|
|
|
|
27
|
|
|
$_sTitle = $_aContent[ 0 ]; |
28
|
|
|
$_sContent = $this->_getFAQSubSections( $_aContent[ 1 ] ); |
29
|
|
|
if ( in_array( $_sTitle, array( 'Tutorials' ) ) ) { |
30
|
|
|
continue; |
31
|
|
|
} |
32
|
|
|
$oAdminPage->addSettingSections( |
33
|
|
|
$this->sPageSlug, // the target page slug |
34
|
|
|
array( |
35
|
|
|
'section_id' => 'faq_sections_' . $_iIndex, |
36
|
|
|
'tab_slug' => $this->sTabSlug, |
37
|
|
|
'section_tab_slug' => 'apf_faq', |
38
|
|
|
'title' => $_sTitle, |
39
|
|
|
'content' => $_sContent, |
40
|
|
|
) |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
/** |
46
|
|
|
* @return array|string If sections exits, an array holding sections. If no, a string content of the item. |
47
|
|
|
*/ |
48
|
|
|
private function _getFAQSubSections( $asItems ) { |
49
|
|
|
|
50
|
|
|
if ( empty( $asItems ) ) { |
51
|
|
|
return array(); |
52
|
|
|
} |
53
|
|
|
$aItems = $this->getContentsByHeader( $asItems, 5 ); |
54
|
|
|
|
55
|
|
|
$_aNestedSections = array(); |
56
|
|
|
$_iLastIndex = count( $aItems ) - 1; |
57
|
|
|
foreach( $aItems as $_iIndex => $_aContent ) { |
58
|
|
|
|
59
|
|
|
$_oParser = new AdminPageFramework_WPReadmeParser( $_aContent[ 1 ] ); |
60
|
|
|
|
61
|
|
|
// If no sections, return the contents of the first item. |
62
|
|
|
if ( ! $_aContent[ 0 ] ) { |
63
|
|
|
return $_oParser->get(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$_aNestedSections[] = array( |
67
|
|
|
'section_id' => 'faq_item_' . $_iIndex, |
68
|
|
|
'title' => $_aContent[ 0 ], |
69
|
|
|
'collapsible' => array( |
70
|
|
|
'toggle_all_button' => $_iLastIndex === $_iIndex |
71
|
|
|
? array( 'bottom-right' ) |
72
|
|
|
: ( 0 === $_iIndex |
73
|
|
|
? array( 'top-right' ) |
74
|
|
|
: false |
75
|
|
|
), |
76
|
|
|
), |
77
|
|
|
'content' => $_oParser->get(), |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
return $_aNestedSections; |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
private function getFAQContents() { |
84
|
|
|
|
85
|
|
|
$_aReplacements = array( |
86
|
|
|
'%PLUGIN_DIR_URL%' => AdminPageFrameworkLoader_Registry::getPluginURL(), |
87
|
|
|
'%WP_ADMIN_URL%' => admin_url(), |
88
|
|
|
); |
89
|
|
|
$_oWPReadmeParser = new AdminPageFramework_WPReadmeParser( |
90
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/readme.txt', |
91
|
|
|
$_aReplacements |
92
|
|
|
); |
93
|
|
|
return $_oWPReadmeParser->getRawSection( 'Frequently asked questions' ); |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|