Provides methods for registering custom post types.
Hooks
The class automatically creates WordPress action and filter hooks associated
with the class methods. 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 actions.
Methods and Action Hooks
- start_ + extended class name – triggered at the end of
the class constructor.
Methods and Filter Hooks
- cell_{post type slug}_{column key} – receives the output
string for the listing table of the custom post type's post. The first
parameter: output string. The second parameter: the post ID.
- columns_{post type slug} – receives the array containing
the header columns for the listing table of the custom post type's post. The
first parameter: the header columns container array.
- sortable_columns_{post type slug} – receives the array
containing the sortable header column array for the listing table of the custom
post type's post. The first parameter: the sortable header columns container
array.
Remarks
The slugs must not contain a dot(.) or a hyphen(-) since it is used in the
callback method name.
public
|
#
__construct( string $sPostType, array $aArgs = array(), string $sCallerPath = null, string $sTextDomain = 'admin-page-framework' )
The constructor of the class object.
The constructor of the class object.
Registers necessary hooks and sets up internal properties.
Example
new APF_PostType(
'apf_posts',
array(
'labels' => array(
'name' => 'Admin Page Framework',
'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' ),
'taxonomies' => array( '' ),
'menu_icon' => null,
'has_archive' => true,
'show_admin_column' => true,
)
);
Parameters
- $sPostType
string The post type slug.
- $aArgs
array The argument
array passed to register_post_type().
- $sCallerPath
string The path of the caller script. This is used to retrieve the script information
to insert it into the footer. If not set, the framework tries to detect it.
- $sTextDomain
string The text domain of the caller script.
Since
2.0.0
2.1.6 Added the $sTextDomain parameter.
See
|
public
|
#
setUp( )
The method for all necessary set-ups.
The method for all necessary set-ups.
Example
public function setUp() {
$this->setAutoSave( false );
$this->setAuthorTableFilter( true );
$this->addTaxonomy(
'sample_taxonomy',
array(
'labels' => array(
'name' => '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,
'show_in_sidebar_menus' => false,
)
);
}
Since
2.0.0
Remark
The user should override this method in their class definition.
A callback for the wp_loaded hook.
|
public
array
|
#
enqueueStyles( mixed $aSRCs, mixed $aCustomArgs = array() )
Enqueues styles by page slug and tab slug.
Enqueues styles by page slug and tab slug.
Returns
array An array holding the handle IDs of queued items.
Since
3.0.0
|
public
string
|
#
enqueueStyle( string $sSRC, array $aCustomArgs = array() )
Enqueues a style by page slug and tab slug.
Enqueues a style by page slug and tab slug.
Parameters
- $sSRC
string The URL of the stylesheet to enqueue, the absolute file path, or the relative
path to the root directory of WordPress. Example: '/css/mystyle.css'.
- $aCustomArgs
array (optional) The argument array for more advanced parameters.
Custom Argument Array
- handle_id - ( optional, string ) The handle ID of the
stylesheet.
- dependencies - ( optional, array ) The dependency array.
For more information, see codex.
- version - ( optional, string ) The stylesheet version
number.
- media - ( optional, string ) the description of the field
which is inserted into after the input field tag.
Returns
string The script handle ID. If the passed url is not a valid url string, an empty
string will be returned.
Since
3.0.0
See
|
public
array
|
#
enqueueScripts( mixed $aSRCs, mixed $aCustomArgs = array() )
Enqueues scripts by page slug and tab slug.
Enqueues scripts by page slug and tab slug.
Returns
array An array holding the handle IDs of queued items.
Since
3.0.0
|
public
string
|
#
enqueueScript( string $sSRC, array $aCustomArgs = array() )
Enqueues a script by page slug and tab slug.
Enqueues a script by page slug and tab slug.
Example
$this->enqueueScript(
plugins_url( 'asset/js/test.js' , __FILE__ ),
array(
'handle_id' => 'my_script',
'translation' => array(
'a' => 'hello world!',
'style_handle_id' => $sStyleHandle,
),
)
);
Parameters
- $sSRC
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'.
- $aCustomArgs
array (optional) The argument array for more advanced parameters.
Custom Argument Array
- handle_id - ( optional, string ) The handle ID of the
script.
- dependencies - ( optional, array ) The dependency array.
For more information, see codex.
- version - ( optional, string ) The stylesheet version
number.
- translation - ( optional, array ) The translation array.
The handle ID will be used for the object name.
- in_footer - ( optional, boolean ) Whether to enqueue the
script before
</head > or before </body>
Default: false.
Returns
string The script handle ID. If the passed url is not a valid url string, an empty
string will be returned.
Since
3.0.0
See
|
protected
|
#
setAutoSave( boolean $bEnableAutoSave = True )
Enables or disables the auto-save feature in the custom post type's post
submission page.
Enables or disables the auto-save feature in the custom post type's post
submission page.
Example
$this->setAutoSave( false );
Parameters
- $bEnableAutoSave
boolean If true, it enables the auto-save; otherwise, it disables it. return void
Since
2.0.0
|
protected
|
#
addTaxonomy( string $sTaxonomySlug, array $aArgs )
Adds a custom taxonomy to the class post type.
Example
$this->addTaxonomy(
'sample_taxonomy',
array(
'labels' => array(
'name' => '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,
'show_in_sidebar_menus' => false,
)
);
Adds a custom taxonomy to the class post type.
Example
$this->addTaxonomy(
'sample_taxonomy',
array(
'labels' => array(
'name' => '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,
'show_in_sidebar_menus' => false,
)
);
Parameters
- $sTaxonomySlug
string The taxonomy slug.
- $aArgs
array The taxonomy argument array passed to the second parameter of the register_taxonomy()
function.
Since
2.0.0
See
|
protected
|
#
setAuthorTableFilter( boolean $bEnableAuthorTableFileter = false )
Sets whether the author drop-down filter is enabled/disabled in the post type
post list table.
Sets whether the author drop-down filter is enabled/disabled in the post type
post list table.
Example
$this->setAuthorTableFilter( true );
Parameters
- $bEnableAuthorTableFileter
boolean If true, it enables the author filter; otherwise, it disables it.
Since
2.0.0
|
protected
|
#
setPostTypeArgs( array $aArgs )
Sets the post type arguments.
Sets the post type arguments.
This is only necessary if it is not set in the constructor.
Parameters
- $aArgs
array The array
of arguments to be passed to the second parameter of the
register_post_type() function.
Since
2.0.0
See
|