" . __( 'This is a hidden page.', 'admin-page-framework-demo' ) . "
";
echo "
" . __( 'It is useful when you have a setting page that requires a proceeding page.', 'admin-page-framework-demo' ) . "
";
$strLinkToGoBack = $this->oUtil->getQueryAdminURL( array( 'page' => 'apf_sample_page' ) );
echo "" . __( 'Go Back', 'admin-page-framework-demo' ). "";
}
/*
* Import and Export Callbacks
* */
public function export_format_APF_Demo_export_single( $strFormatType, $strFieldID ) { // export_format_ + {extended class name} + _ + {field id}
return isset( $_POST[ $this->oProps->strOptionKey ]['apf_manage_options']['exports']['export_format_type'] )
? $_POST[ $this->oProps->strOptionKey ]['apf_manage_options']['exports']['export_format_type']
: $strFormatType;
}
public function import_format_apf_manage_options_export_import( $strFormatType, $strFieldID ) { // import_format_ + page slug + _ + tab slug
return isset( $_POST[ $this->oProps->strOptionKey ]['apf_manage_options']['imports']['import_format_type'] )
? $_POST[ $this->oProps->strOptionKey ]['apf_manage_options']['imports']['import_format_type']
: $strFormatType;
}
public function import_APF_Demo_import_single( $vData, $arrOldOptions, $strFieldID, $strInputID, $strImportFormat, $strOptionKey ) { // import_ + {extended class name} + _ + {field id}
if ( $strImportFormat == 'text' ) {
$this->setSettingNotice( __( 'The text import type is not supported.', 'admin-page-framework-demo' ) );
return $arrOldOptions;
}
$this->setSettingNotice( __( 'Importing options are validated.', 'admin-page-framework-demo' ), 'updated' );
return $vData;
}
/*
* Validation Callbacks
* */
public function validation_APF_Demo_verify_text_field_submit( $arrNewInput, $arrOldOptions ) { // validation_ + {extended class name} + _ + {field ID}
// Set a flag.
$fVerified = true;
// We store values that have an error in an array and pass it to the setFieldErrors() method.
// It internally stores the error array in a temporary area of the database called transient.
// The used name of the transient is a md5 hash of 'instantiated class name' + '_' + 'page slug'.
// The library class will search for this transient when it renders the form fields
// and if it is found, it will display the error message set in the field array.
$arrErrors = array();
// Check if the submitted value meets your criteria. As an example, here a numeric value is expected.
if ( ! is_numeric( $arrNewInput['apf_builtin_field_types']['verification']['verify_text_field'] ) ) {
// Start with the section key in $arrErrors, not the key of page slug.
$arrErrors['verification']['verify_text_field'] = 'The value must be numeric: ' . $arrNewInput['apf_builtin_field_types']['verification']['verify_text_field'];
$fVerified = false;
}
// An invalid value is found.
if ( ! $fVerified ) {
// Set the error array for the input fields.
$this->setFieldErrors( $arrErrors );
$this->setSettingNotice( 'There was an error in your input.' );
return $arrOldOptions;
}
return $arrNewInput;
}
public function validation_apf_builtin_field_types_files( $arrInput, $arrOldPageOptions ) { // validation_ + page slug + _ + tab slug
// Display the uploaded file information.
$arrFileErrors = array();
$arrFileErrors[] = $_FILES[ $this->oProps->strOptionKey ]['error']['apf_builtin_field_types']['file_uploads']['file_single'];
$arrFileErrors[] = $_FILES[ $this->oProps->strOptionKey ]['error']['apf_builtin_field_types']['file_uploads']['file_multiple'][0];
$arrFileErrors[] = $_FILES[ $this->oProps->strOptionKey ]['error']['apf_builtin_field_types']['file_uploads']['file_multiple'][1];
$arrFileErrors[] = $_FILES[ $this->oProps->strOptionKey ]['error']['apf_builtin_field_types']['file_uploads']['file_multiple'][2];
foreach( $_FILES[ $this->oProps->strOptionKey ]['error']['apf_builtin_field_types']['file_uploads']['file_repeatable'] as $arrFile )
$arrFileErrors[] = $arrFile;
if ( in_array( 0, $arrFileErrors ) )
$this->setSettingNotice( '
File(s) Uploaded
' . $this->oDebug->getArray( $_FILES ), 'updated' );
return $arrInput;
}
public function validation_APF_Demo( $arrInput, $arrOldOptions ) {
// If the delete options button is pressed, return an empty array that will delete the entire options stored in the database.
if ( isset( $_POST[ $this->oProps->strOptionKey ]['apf_manage_options']['submit_buttons_confirm']['submit_delete_options_confirmation'] ) )
return array();
return $arrInput;
}
/*
* Read Me
* */
public function do_before_apf_read_me() { // do_before_ + page slug
include_once( dirname( __FILE__ ) . '/third-party/wordpress-plugin-readme-parser/parse-readme.php' );
$this->oWPReadMe = new WordPress_Readme_Parser;
$this->arrWPReadMe = $this->oWPReadMe->parse_readme( dirname( __FILE__ ) . '/readme.txt' );
}
public function do_apf_read_me_description() { // do_ + page slug + _ + tab slug
echo $this->arrWPReadMe['sections']['description'];
// var_dump( $this->arrWPReadMe );
}
public function do_apf_read_me_installation() { // do_ + page slug + _ + tab slug
// echo htmlspecialchars( $this->arrWPReadMe['sections']['installation'], ENT_QUOTES, bloginfo( 'charset' ) );
echo $this->arrWPReadMe['sections']['installation'];
}
public function do_apf_read_me_frequently_asked_questions() { // do_ + page slug + _ + tab slug
echo $this->arrWPReadMe['sections']['frequently_asked_questions'];
}
public function do_apf_read_me_other_notes() {
echo $this->arrWPReadMe['remaining_content'];
}
public function do_apf_read_me_screenshots() { // do_ + page slug + _ + tab slug
echo $this->arrWPReadMe['sections']['screenshots'];
}
public function do_apf_read_me_changelog() { // do_ + page slug + _ + tab slug
echo $this->arrWPReadMe['sections']['changelog'];
}
/*
* Custom field types - This is another way to register a custom field type.
* This method gets fired when the framework tries to define field types.
*/
public function field_types_APF_Demo( $arrFieldTypeDefinitions ) { // field_types_ + {extended class name}
// 1. Include the file that defines the custom field type.
// This class should extend the predefined abstract class that the library prepares already with necessary methods.
$strFilePath = dirname( __FILE__ ) . '/third-party/geometry-custom-field-type/GeometryCustomFieldType.php';
if ( file_exists( $strFilePath ) ) include_once( $strFilePath );
// 2. Instantiate the class - use the getDefinitionArray() method to get the field type definition array.
// Then assign it to the filtering array with the key of the field type slug.
$oFieldType = new GeometryCustomFieldType( 'APF_Demo', 'geometry', $this->oMsg );
$arrFieldTypeDefinitions['geometry'] = $oFieldType->getDefinitionArray();
// 3. Return the modified array.
return $arrFieldTypeDefinitions;
}
}
// Instantiate the main framework class so that the pages and form fields will be created.
if ( is_admin() )
new APF_Demo;
class APF_PostType extends AdminPageFramework_PostType {
public function start_APF_PostType() { // start_ + extended class name
// the setUp() method is too late to add taxonomies. So we use start_{class name} action hook.
$this->setAutoSave( false );
$this->setAuthorTableFilter( true );
$this->addTaxonomy(
'apf_sample_taxonomy', // taxonomy slug
array( // argument - for the argument array keys, refer to : http://codex.wordpress.org/Function_Reference/register_taxonomy#Arguments
'labels' => array(
'name' => 'Sample Genre',
'add_new_item' => 'Add New Genre',
'new_item_name' => "New Genre"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_table_filter' => true, // framework specific key
'show_in_sidebar_menus' => true, // framework specific key
)
);
$this->addTaxonomy(
'apf_second_taxonomy',
array(
'labels' => array(
'name' => 'Non Hierarchical',
'add_new_item' => 'Add New Taxonomy',
'new_item_name' => "New Sample Taxonomy"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => false,
'show_admin_column' => true,
'show_in_nav_menus' => false,
'show_table_filter' => true, // framework specific key
'show_in_sidebar_menus' => false, // framework specific key
)
);
$this->setFooterInfoLeft( ' Custom Text on the left hand side.' );
$this->setFooterInfoRight( ' Custom text on the right hand side' );
}
/*
* Extensible methods
*/
public function setColumnHeader( $arrColumnHeader ) {
$arrColumnHeaders = array(
'cb' => '', // Checkbox for bulk actions.
'title' => __( 'Title', 'admin-page-framework' ), // Post title. Includes "edit", "quick edit", "trash" and "view" links. If $mode (set from $_REQUEST['mode']) is 'excerpt', a post excerpt is included between the title and links.
'author' => __( 'Author', 'admin-page-framework' ), // Post author.
// 'categories' => __( 'Categories', 'admin-page-framework' ), // Categories the post belongs to.
// 'tags' => __( 'Tags', 'admin-page-framework' ), // Tags for the post.
'comments' => '', // Number of pending comments.
'date' => __( 'Date', 'admin-page-framework' ), // The date and publish status of the post.
'samplecolumn' => __( 'Sample Column' ),
);
return array_merge( $arrColumnHeader, $arrColumnHeaders );
}
// public function setSortableColumns( $arrColumns ) {
// return array_merge( $arrColumns, $this->oProp->arrColumnSortable );
// }
/*
* Callback methods
*/
public function cell_apf_posts_samplecolumn( $strCell, $intPostID ) { // cell_ + post type + column key
return "the post id is : {$intPostID}";
}
}
new APF_PostType(
'apf_posts', // post type slug
array( // argument - for the array structure, refer to http://codex.wordpress.org/Function_Reference/register_post_type#Arguments
'labels' => array(
'name' => 'Admin Page Framework',
'all_items' => __( 'Sample Posts', 'admin-page-framework-demo' ),
'singular_name' => 'Admin Page Framework',
'add_new' => 'Add New',
'add_new_item' => 'Add New APF Post',
'edit' => 'Edit',
'edit_item' => 'Edit APF Post',
'new_item' => 'New APF Post',
'view' => 'View',
'view_item' => 'View APF Post',
'search_items' => 'Search APF Post',
'not_found' => 'No APF Post found',
'not_found_in_trash' => 'No APF Post found in Trash',
'parent' => 'Parent APF Post'
),
'public' => true,
'menu_position' => 110,
// 'supports' => array( 'title', 'editor', 'comments', 'thumbnail' ), // 'custom-fields'
'supports' => array( 'title' ),
'taxonomies' => array( '' ),
'has_archive' => true,
'show_admin_column' => true, // ( framework specific key ) this is for custom taxonomies to automatically add the column in the listing table.
'menu_icon' => plugins_url( 'asset/image/wp-logo_16x16.png', __FILE__ ),
// ( framework specific key ) this sets the screen icon for the post type.
'screen_icon' => dirname( __FILE__ ) . '/asset/image/wp-logo_32x32.png', // a file path can be passed instead of a url, plugins_url( 'asset/image/wp-logo_32x32.png', __FILE__ )
)
); // should not use "if ( is_admin() )" for the this class because posts of custom post type can be accessed from the front-end pages.
class APF_MetaBox extends AdminPageFramework_MetaBox {
public function start_APF_MetaBox() {
add_filter( 'the_content', array( $this, 'printMetaFieldValues' ) );
}
public function setUp() {
$this->addHelpText(
__( 'This text will appear in the contextual help pane.', 'admin-page-framework-demo' ),
__( 'This description goes to the sidebar of the help pane.', 'admin-page-framework-demo' )
);
$this->addSettingFields(
array(
'strFieldID' => 'sample_metabox_text_field',
'strTitle' => 'Text Input',
'strDescription' => 'The description for the field.',
'strType' => 'text',
'strHelp' => 'This is help text.',
'strHelpAside' => 'This is additional help text which goes to the side bar of the help pane.',
),
array(
'strFieldID' => 'sample_metabox_textarea_field',
'strTitle' => 'Textarea',
'strDescription' => 'The description for the field.',
'strHelp' => __( 'This a text area input field, which is larger than the text input field.', 'admin-page-framework-demo' ),
'strType' => 'textarea',
'vCols' => 60,
'vDefault' => 'This is a default text.',
),
array( // Rich Text Editor
'strFieldID' => 'sample_rich_textarea',
'strTitle' => 'Rich Text Editor',
'strType' => 'textarea',
'vRich' => true, // array( 'media_buttons' => false ) <-- a setting array can be passed. For the specification of the array, see http://codex.wordpress.org/Function_Reference/wp_editor
),
array(
'strFieldID' => 'checkbox_field',
'strTitle' => 'Checkbox Input',
'strDescription' => 'The description for the field.',
'strType' => 'checkbox',
'vLabel' => 'This is a check box.',
),
array(
'strFieldID' => 'select_filed',
'strTitle' => 'Select Box',
'strDescription' => 'The description for the field.',
'strType' => 'select',
'vLabel' => array(
'one' => __( 'One', 'demo' ),
'two' => __( 'Two', 'demo' ),
'three' => __( 'Three', 'demo' ),
),
'vDefault' => 'one', // 0 means the first item
),
array (
'strFieldID' => 'radio_field',
'strTitle' => 'Radio Group',
'strDescription' => 'The description for the field.',
'strType' => 'radio',
'vLabel' => array(
'one' => __( 'Option One', 'demo' ),
'two' => __( 'Option Two', 'demo' ),
'three' => __( 'Option Three', 'demo' ),
),
'vDefault' => 'one',
),
array (
'strFieldID' => 'checkbox_group_field',
'strTitle' => 'Checkbox Group',
'strDescription' => 'The description for the field.',
'strType' => 'checkbox',
'vLabel' => array(
'one' => __( 'Option One', 'admin-page-framework-demo' ),
'two' => __( 'Option Two', 'admin-page-framework-demo' ),
'three' => __( 'Option Three', 'admin-page-framework-demo' ),
),
'vDefault' => array(
'one' => true,
'two' => false,
'three' => false,
),
),
array (
'strFieldID' => 'image_field',
'strTitle' => 'Image',
'strDescription' => 'The description for the field.',
'strType' => 'image',
),
array (
'strFieldID' => 'color_field',
'strTitle' => __( 'Color', 'admin-page-framework-demo' ),
'strType' => 'color',
),
array (
'strFieldID' => 'size_field',
'strTitle' => __( 'Size', 'admin-page-framework-demo' ),
'strType' => 'size',
'vDefault' => array( 'size' => 5, 'unit' => '%' ),
),
array (
'strFieldID' => 'sizes_field',
'strTitle' => __( 'Multiple Sizes', 'admin-page-framework-demo' ),
'strType' => 'size',
'vLabel' => array(
'weight' => __( 'Weight', 'admin-page-framework-demo' ),
'length' => __( 'Length', 'admin-page-framework-demo' ),
'capacity' => __( 'File Size', 'admin-page-framework-demo' ),
),
'vSizeUnits' => array( // notice that the array key structure corresponds to the vLabel array's.
'weight' => array( 'mg'=>'mg', 'g'=>'g', 'kg'=>'kg' ),
'length' => array( 'cm'=>'cm', 'mm'=>'mm', 'm'=>'m' ),
'capacity' => array( 'b'=>'b', 'kb'=>'kb', 'mb'=>'mb', 'gb' => 'gb', 'tb' => 'tb' ),
),
'vDefault' => array(
'weight' => array( 'size' => 15, 'unit' => 'g' ),
'length' => array( 'size' => 100, 'unit' => 'mm' ),
'capacity' => array( 'size' => 30, 'unit' => 'mb' ),
),
'vDelimiter' => ' ',
),
array (
'strFieldID' => 'taxonomy_checklist',
'strTitle' => __( 'Taxonomy Checklist', 'admin-page-framework-demo' ),
'strType' => 'taxonomy',
'vTaxonomySlug' => get_taxonomies( '', 'names' ),
),
array()
);
}
public function printMetaFieldValues( $strContent ) {
if ( ! isset( $GLOBALS['post']->ID ) || get_post_type() != 'apf_posts' ) return $strContent;
// 1. To retrieve the meta box data - get_post_meta( $post->ID ) will return an array of all the meta field values.
// or if you know the field id of the value you want, you can do $value = get_post_meta( $post->ID, $field_id, true );
$intPostID = $GLOBALS['post']->ID;
$arrPostData = array();
foreach( ( array ) get_post_custom_keys( $intPostID ) as $strKey ) // This way, array will be unserialized; easier to view.
$arrPostData[ $strKey ] = get_post_meta( $intPostID, $strKey, true );
// 2. To retrieve the saved options in the setting pages created by the framework - use the get_option() function.
// The key name is the class name by default. This can be changed by passing an arbitrary string
// to the first parameter of the constructor of the AdminPageFramework class.
$arrSavedOptions = get_option( 'APF_Demo' );
return "
" . __( 'Saved Meta Field Values', 'admin-page-framework-demo' ) . "
"
. $this->oDebug->getArray( $arrSavedOptions );
}
public function validation_APF_MetaBox( $arrInput, $arrOldInput ) {
// You can check the passed values and correct the data by modifying them.
// $this->oDebug->logArray( $arrInput );
return $arrInput;
}
}
new APF_MetaBox(
'sample_custom_meta_box',
'My Custom Meta Box',
array( 'apf_posts' ), // post, page, etc.
'normal',
'default'
);
/*
* If you find this framework useful, include it in your project!
* And please leave a nice comment in the review page, http://wordpress.org/support/view/plugin-reviews/admin-page-framework
*
* If you have a suggestion, the GitHub repository is open to anybody so post an issue there.
* https://github.com/michaeluno/admin-page-framework/issues
*
* Happy coding!
*/