michaeluno / admin-page-framework Goto Github PK
View Code? Open in Web Editor NEWFacilitates WordPress plugin and theme development.
Home Page: http://admin-page-framework.michaeluno.jp/
License: Other
Facilitates WordPress plugin and theme development.
Home Page: http://admin-page-framework.michaeluno.jp/
License: Other
Feature request for v3:
When you choose a radio, checkbox or an option in a select field, reveal another hidden field.
Michael
Great work. Is there a way/tutorial on how to make repeatable fields in both options and metaboxes?
It's due to the change to define built-in field types before any custom field types.
In the demo plugin, add an example of retrieving the options saved with the setting forms which uses the Settings API, not the one with the meta box, in the front-end.
Is anybody interested in developing v3? I'm planning to start developing Admin Page Framework v3 which will have many breaking changes.
The goal of v3 is to have no more breaking changes in the future.
As I had written some custom field types, I've started realizing that, to incorporate with third party scripts including jQuery libraries, array key naming might be better to be all lower-cased to keep consistency with them. For example, the sample dial
field type uses the knob library and the settings are defined with the data-{...}
attribute. Since their setting attributes are all lower case, if the framework uses a different naming style for the settings, the user has to learn two different rules at the same time just to use a single field type.
This kind of situation happened before with writing a wrapper function for the WordPress core wp_enqueue_script()
and wp_enqueue_style()
functions. A similar situation probably will occur in the future as so many open-source libraries use lower case letters for their settings and parameters.
So I'm thinking that to have lower case letters where the user interacts with and keep the Hungarian notation where only the system uses.
To convert the array keys used by this framework into all lower case, it breaks the scripts using the previous versions of the framework. Is it worth breaking them? There are other issues that cannot be solved without breaking changes. So let's have them at once so that hopefully we no longer have breaking changes in the future.
Use lower-cased characters with underscores like my_variable
for array keys where the framework users may use to define settings including pages, tabs, sections and fields. And employ the PHP Alternative Hungarian Notation syntax internally such as aMyArray
where the users don't need to see.
Some methods should be renamed such as showPageHeadingTabs
because it can imply rendering an output. However, what it does is just to set the visibility property. The actual rendering process is done by a different method.
So the name should be setPageHeadingTabVisibility()
or something.
Also for internal methods, the prefix of underscore will be added such as _doInternalTask()
.
For callback methods, the prefix of replyTo
will be added such as replyToAddStyle()
.
Currently the vLabel
key's value determines whether a field holds multiple input elements or not. And the value can be either an array, a string, or a numeric value. This is confusing when defining a field type.
I think that to define the sub-elements, numeric keys can be used.
array(
'section_id' => 'my_text_section',
'field_id' => 'my_text_field',
'title' => 'My Text Fields',
'type' => 'text',
'default' => 'hello',
'label' => 'first field element.',
array(
'label' => 'second field element.',
'default' => 'hi',
),
array(
'label' => 'third field element.',
'default' => 'bye',
),
)
Currently it's hard to write a custom field type that supports repeatable fields. One reason is that there is no means to rebind the JavaScript function attached to the input tag at the moment. Maybe it is doable by writing a repeatable-field script which allows a callback function to be assigned when a repeat event occurs.
Also the vDelimiter
element may need to be dropped to help the repeatable script simple.
If the repeatable field script is well structured to support almost all fields, then sortable fields can be introduced.
Currently the select
field type's value is saved as a string for the single select type, holding the key specified in the vLabel
element as its value. This may need to be changed to always have an array as it seems to be confusing for some users: #9
When retrieving saved option values, sometimes it's cumbersome to specify the section ids in the array. Since the field id needs to be always unique, sections may not be necessary in the saved option array.
From
$value = $array['page_slug']['section_id']['field_id'];
To
$value = $array['page_slug']['field_id'];
Or even drop the page slug key.
$value = $array['field_id'];
So it helps implement this request as well: #12
There are some filter names which should be reviewed: #34
Also there are duplicated filters and added filters #64
To help development be easier, it's better to keep classes in separate files. However, it might be overwhelming for programming beginners to have so many files to use the library. So like the minified version of the jQuery library, let's have two versions of the library; one is for the development of the library itself and the other is for the users to just include.
For the developers who fork the library:
For the users who just use the library:
In order to make this possible, a script to combine and minify those separate files to create the minified version is needed. If somebody can take this task, it would be greatly appreciated.
This is already included in the 3.0.0b branch. What is does is to define tag attributes by array.
For example,
$aAttributes = array( 'name' => 'my_name', 'type' => 'text' );
will generate <input name="my_name" type="text" />
Include the documentation in the demo plugin. #55 (comment)
Let me know what you think and tell me if something else should be changed or introduced.
It's now ready to be tested.
https://github.com/michaeluno/admin-page-framework/tree/3.0.0b
[Edit]
Is it possible to define alle Notices for every field, or to override the standard messages without hacking into the main class?
The setSettingNotice and setAdminNotice is fine, but sometimes (file upload) both, the custom set Notice appears and the standard one (like "File has been uploaded).
Maybe this would be a cool advantage if one could change that or leave them blank.
( As addressed in #40 )
It would be nice if the new WP 3.7 Uploader is used when uploading files and images.
[Edited by michaeluno] the title has been modified from WP 3.7 Uploader New Style to WP 3.5 Uploader New Style.
Post type labels should be displayed in tabs and the taxonomy labels' check-boxes are placed inside the box.
This should be done without JavaScript.
Use the class selectors instead for input elements so that the users have more flexibility to customize the element styles.
First of all, let me just say; great work on the framework. It's simply awesome!
Though I seem to be having an issue (or maybe just a lapse of stupidity). In your documentation for v2 you state that one can change the menu position of the created Menu Page as the third parameter of the setRootMenuPage-function.
setRootMenuPage(string $strRootMenuLabel, string $strURLIcon16x16, string $intMenuPosition) : void
I have located the issue and fixed it. On line 1635 the code is:
isset( $this->arrRootMenu['intPosition'] ) ? $this->arrRootMenu['intPosition'] : null // menu position
Which by what I can figure out should be (and which fixed the issue):
isset( $this->oProps->arrRootMenu['intPosition'] ) ? $this->oProps->arrRootMenu['intPosition'] : null // menu position
Just wanted to let you know!
In my plugin, I have the settings in a separate file:
read-offline.php
|-----settings/read-offline-settings.php
|------class/admin-page-framework.php
The following (set in read-offline-settings.php) doesn't work:
$this->addLinkToPluginDescription(
"<a href='http://www.google.com'>Google</a>",
"<a href='http://www.yahoo.com'>Yahoo!</a>",
"<a href='http://en.michaeluno.jp'>miunosoft</a>",
"<a href='https://github.com/michaeluno/admin-page-framework' title='Contribute to the GitHub repository!' >Repository</a>"
);
$this->addLinkToPluginTitle(
"<a href='http://www.wordpress.org'>WordPress</a>"
);
$this->setFooterInfoLeft( '<br />Custom Text on the left hand side.' );
.. and hence, plugin info and Powered by Admin Page Framework
doesn't appear.
This one work:
$this->setFooterInfoRight( '<br />Custom text on the right hand side' );
Addressed in #40.
Please add reset as a new field type to strType.
I kown I can do it using the example on APF -> Manage Options -> Reset demo, but I believe it should be part of the framework.
Btw, I really really like the framework :)
Hi,
while working on a project I found out, that a simple HTML field could be helpful.
A field rendered in a section by just adding a simple empty div where you can add HTML.
Like this
private function getHtmlField( $arrOutput=array() ) {
$arrFields = $this->arrField['fRepeatable'] ?
( empty( $this->vValue ) ? array( '' ) : ( array ) $this->vValue )
: $this->arrField['vLabel'];
foreach( ( array ) $arrFields as $strKey => $strLabel )
$arrOutput[] = "<div class='{$this->strFieldClassSelector}' id='field-{$this->strTagID}_{$strKey}'>"
. "<div class='" . $this->getCorrespondingArrayValue( $this->arrField['vClassAttribute'], $strKey, '' ) . "'>"
. $this->getCorrespondingArrayValue( $this->arrField['vContent'], $strKey, '' )
. "</div></div>";
return "<div class='admin-page-framework-field-html' id='{$this->strTagID}'>"
. implode( '', $arrOutput )
. "</div>";
}
and usage:
array( // Sample HTML field
'strFieldID' => 'field_sample_html',
'strSectionID' => 'section_html',
'strTitle' => __( 'Sample HTML Box' ),
'strType' => 'html',
'vClassAttribute' => 'textclass',
'vContent' => '<strong>HTML Text</strong><br/>Hi there',
)
And output it like this. So you can use some jQuery for example to set some info for the user. For example a checklist which shows what kind of files are need to be uploaded and which are already in the database.
Hey, i tried to add the wordpress wysiwyg editor but did not have any success. Maybe this is an idea for a next update.
As well as the new WP 3.7. Media uploader for files and images?
Kind regards
Hi there,
I´ve got a submit button like this:
array( // Felder aktuelles Jahr
'strFieldID' => 'data_current_submit',
'strSectionID' => 'data_current',
'strType' => 'submit',
'vLabel' => 'Tabellendaten aktivieren',
'vDisable' => $this->bool
),
Can I somehow trigger a function when hitting this submit button? And how? Should I use the validation method?
In WordPress v3.8, add_menu_page()
accepts dashicons so it's not a big deal to do it.
When the unit select drop-down list is clicked, the focus gets changed to the size(text) field input so it's hard to select the unit.
This is due to the for
attribute set in the label tag. I need to figure out the way to prevent this by not affecting the element structure.
Done.
Custom field types should be able to assign a callback function to an event when the user presses one of the repeatable buttons.
( addressed in #40 )
For multiple fields by one field id, numeric keys will be used instead of an array of vLabel
.
Addressed in #40.
Not an issue, more a question.
When using enqueueScript(), in which order are the enqueued scripts loaded ?
If I want to pass a value to a enqueued script, I usally use wp_localize_script. How can I pass a value to a script loaded using enqueueScript() ?
Btw, I learned a lot about passing values from this article. It might help if you plan to add a method that does the same as wp_localize_script.
The File Upload Field does not work for me. When I upload a file (e.g. pdf, text or even an image) no file is added to the media library or to any other folder. The input field which shows the name of the file is cleared when saving the data.
Besides when using an image upload field text-files, or other files are uploaded to the media library.
Maybe it´s usefull to add an extra definition to the file field to support MIME Types?
As there is a method added in v2.1.5 to resolve a file path into the URL, the methods, setRootMenuPage()
, addSubMenuPage()
, and getStylesForPostTypeScreenIcon()
should accept a file path to set an icon so that the user does not have to use the plugins_url()
function.
Received error when using with WP 3.6:
Strict standards: Declaration of Admin_Page_Framework_Walker_Category_Checklist::start_el() should be compatible with Walker::start_el(&$output, $object, $depth = 0, $args = Array, $current_object_id = 0)...
extended class name + _ + section_ + section ID
– receives the description output of the given form section ID. The first parameter: output string. The second parameter: the array of option.
extended class name + _ + field_ + field ID
– receives the form input field output of the given input field ID. The first parameter: output string. The second parameter: the array of option.
These filters may ought to be changed to section_ + {extended class name} + _ + {section ID}
and field_ + {extended class name} + _ + {section ID}
to be consistent with the names of the other filters.
Can be quickly reproduced by adding 'vValue' array to the selecter demo in "admin-page-framework-demo.php".
$this->addSettingFields(
array(
'strFieldID' => 'test_drpdwn_2',
'strSectionID' => 'test_fields',
'strTitle' => 'Options - 2',
'strDescription' => 'some more options but with vValue set',
'strType' => 'select', // Single Drop-down List
'vDefault'=> 2,
'vValue' => array ( 'first option', 2 , 'etc option' ),
'vLabel' => array ( 'first option' , 'next option' , 'etc option' ),
)
);
Adding the vValue optional array causes the 'selected="selected"' option tag in the output option field to remain fixed on the value=0 option, the vValue field does not seem to have taken effect either. Any calls to this value result in 0 until the vValue field is removed. I have tried using intergers, strings and different orders.
I've been researching on how it can be achieved to allow using the same page slugs. It appears that page slugs added via add_submenu_pages()
method cannot be used for multiple root pages.
On line 149 in wp-admin/admin.php (WordPress v3.6), there is:
do_action($page_hook);
Before that line, it is hard-coded that the $page_hook
variable is defined based on the $REQUEST['page']
value. And the only the callback of the last assigned one is triggered.
This results on rendering the page contents of a different script using the framework on a page that uses the same page slug value. So the user would need to use unique page slugs to avoid collisions with different plugins or themes.
I'm just leaving a note here for myself.
There should be methods for enqueuing scripts and style by page slug and tab slug.
head_ + page slug – receives the output of the top part of the page.
head_ + page slug + _ + tab slug – receives the output of the top part of the page.
head_ + extended class name – receives the output of the top part of the page, applied to all pages created by the instantiated class object.
content_ + page slug – receives the output of the middle part of the page including form input fields.
content_ + page slug + _ + tab slug – receives the output of the middle part of the page including form input fields.
content_ + extended class name – receives the output of the middle part of the page, applied to all pages created by the instantiated class object.
foot_ + page slug – receives the output of the bottom part of the page.
foot_ + page slug + _ + tab slug – receives the output of the bottom part of the page.
foot_ + extended class name – receives the output of the bottom part of the page, applied to all pages created by the instantiated class object.
The words, head
and foot
might not be the best naming choices for these filters because they often remind of the head and foot HTML tags, not the positions.
So instead of head
, content
, and foot
, it might be better to replace them with top
, middle
, and bottom
.
[Edit]
Now I started to think top_{...}
, middle_{...}
, and bottom_{...}
are not enough either because they won't remind of string contents. Maybe top_content_{...}
, middle_content_{...}
, and bottom_content_{...}
could be better. I don't know.
The script should combine all the separated classes into one file and remove PHP comments except the heading comment that inserts the library info and the copy right.
Addressed in #40.
Hi there,
I have a slight Problem. In one or my Tabs on my options page I use the import field to upload a file, when doing so, every other options (even in other tabs) are deleted. In the database the whole options field is empty.
I removed every action on my self defined import function to test if one of my functions causes the problem but it remains.
Does the import button somehow deletes all options?
public function setUp() {
$this->addInPageTabs(
/*
* Options Page
* */
array(
'strPageSlug' => 'options',
'strTabSlug' => 'options',
'numOrder' => 1,
),
/*
* List Page
* */
array(
'strPageSlug' => 'lists',
'strTabSlug' => 'lists',
)
);
$this->addSettingSections(
array(
'strSectionID' => 'start_date',
'strPageSlug' => 'options',
'strTabSlug' => 'options',
'strTitle' => 'Aktivierung des Kalenders',
'numOrder' => 1,
),
array(
'strSectionID' => 'list_upload',
'strPageSlug' => 'lists',
'strTabSlug' => 'lists',
'strTitle' => 'Listen hochladen für Datenübernahme',
)
);
$this->addSettingFields(
array( // Single File Upload Field
'strFieldID' => 'file_sponsors',
'strSectionID' => 'list_upload',
'strType' => 'import',
'vLabel' => 'Sponsoren importieren',
'vAcceptAttribute' => 'text/csv'
),
array( // Single File Upload Field
'strFieldID' => 'file_prices',
'strSectionID' => 'list_upload',
'strType' => 'import',
'vLabel' => 'Preise importieren',
'vAcceptAttribute' => 'text/csv'
)
}
public function import_lists() {
// do something here
}
This is a feature request.
I currently am in need of a field which is sortable. Such as the jQuery ui sortable interaction: http://jqueryui.com/sortable/
If this is unclear, I will try to explain further.
Thank you for this awesome framework.
When retrieving saved option values, sometimes it's cumbersome to specify the section ids in the array. Since the field id needs to be always unique, sections may not be necessary in the saved option array.
From
$value = $array['page_slug']['section_id']['field_id'];
To
$value = $array['page_slug']['field_id'];
( Addressed in: #40 )
Currently the date
field type relies on external CSS files,
wp_enqueue_style( 'jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
The jquery-ui.css
file has links to images on the external server that means the user's browser will connect to the server when the date picker field is rendered, which should be avoided.
Although it's possible to include those files into the framework, it will become multiple files whereas currently it is a single file. I think it is much easier for beginners to include a single file than multiple files as it eliminates the process of confirming required files.
Advanced users who know the structure of the framework will have less problems including multiple files. So it should be fine to leave the date field as a custom field type. This way, I can introduce additional custom time
and date_time
field types, which also will have to include multiple files.
If anybody will have a problem with this change, let me know.
Delimiter elements should be inserted after additional HTML elements.
Currently hidden tabs can be created with the fHide
key. Similarly, there should be an option to hide the page from the sidebar menu, which will allow to create hidden sub-pages while they will be still accessible as well as the relevant hooks and callbacks.
$this->addSubMenuItems(
array(
'strPageTitle' => __( 'Hidden Page', 'admin-page-framework-demo ),
'strPageSlug' => 'my_hidden_page',
'fShowInMenu' => false,
)
);
Hi,
i just wanted to use the import button to process a csv-file. But I did not get it working. The documentation is not that explicit when it comes to the import functionality.
Can you give me a hint?
I'm working on making it possible for the user to define custom field types.
When the user presses the "+" button, it creates another input field and the "-" button removes the associated input field.
This allows the user to have desired number of elements. For example, to enter urls per line in textarea can be avoided with this functionality.
The class properties, $intEnqueuedScriptIndex
, and $intEnqueuedStyletIndex
that hold the handle id's suffix index do not seem to get incremented.
I tried to validate an import field with validation_ but it seems not to work.
I have got an import button AND a submit button on the same page and they both need seperate validations.
I tried also the new method validation_extendedClassName_inputID/fieldID
To simplify and save the space in the footer, the script version number will only be displayed on mouse hover.
AdminPageFramework_Properties::getOptions() only get saved settings , I'd like to get the default settings.
Ad of v2.1.7, they are gone.
The Export Format Type option was meant to set the format type for the below single export button. So it should be fixed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.