Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
- function theme_enqueue_styles() {
- wp_enqueue_style( 'parent-main-style', get_template_directory_uri() . '/style.css' );
- }
- add_action( 'init', 'codex_book_init' );
- /**
- * Register a book post type.
- *
- * @link http://codex.wordpress.org/Function_Reference/register_post_type
- */
- function codex_book_init() {
- $labels = array(
- 'name' => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
- 'singular_name' => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
- 'menu_name' => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
- 'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
- 'add_new' => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
- 'add_new_item' => __( 'Add New Book', 'your-plugin-textdomain' ),
- 'new_item' => __( 'New Book', 'your-plugin-textdomain' ),
- 'edit_item' => __( 'Edit Book', 'your-plugin-textdomain' ),
- 'view_item' => __( 'View Book', 'your-plugin-textdomain' ),
- 'all_items' => __( 'All Books', 'your-plugin-textdomain' ),
- 'search_items' => __( 'Search Books', 'your-plugin-textdomain' ),
- 'parent_item_colon' => __( 'Parent Books:', 'your-plugin-textdomain' ),
- 'not_found' => __( 'No books found.', 'your-plugin-textdomain' ),
- 'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )
- );
- $args = array(
- 'labels' => $labels,
- 'description' => __( 'Description.', 'your-plugin-textdomain' ),
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'book' ),
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => false,
- 'menu_position' => null,
- 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
- );
- register_post_type( 'book', $args );
- }
- /*=============================================
- = flo_subpages_options =
- =============================================*/
- add_filter('flo_subpages_options', 'flo_custom_cannes_subpages_options');
- function flo_custom_cannes_subpages_options($subpages_options) {
- $subpages_options[] = array(
- 'page_title' => __('12. Books Settings','flotheme'),
- 'menu_title' => __('12. Books','flotheme'),
- 'menu_slug' => 'acf-options-12-books'
- );
- return $subpages_options;
- }
- /*===== End of flo_subpages_options ======*/
- /**
- *
- * Template used for inheriting the global custom post layout within custom post editors
- *
- */
- add_filter( 'flo_custom_post_type_layout', 'flo_book_custom_post_type_layout' );
- function flo_book_custom_post_type_layout() {
- $custom_post_type_layouts = array('book' => 'flo-cn-b');
- // where 'flo-cn-b' should be exact name from the options for the current custom post:
- // https://i.imgur.com/8eByoxJ.jpg
- // https://i.imgur.com/tXYveRB.jpg
- return $custom_post_type_layouts;
- }
- /*========================================================
- = Update flo_cached_layout_options =
- ========================================================*/
- remove_filter('flo_cached_layout_options', 'flo_evora_cached_layout_options');
- add_filter('flo_cached_layout_options', 'flo_cannes_custom_cached_layout_options');
- function flo_cannes_custom_cached_layout_options() {
- // the layout options names
- $cached_layout = array('flo-cn-g_layout','flo-cn-p_layout', 'flo-cn-v_layout', 'flo-cn-b_layout');
- // NOTE: the difference from the original theme in the line above is that we added 'flo-cn-b_layout'
- return $cached_layout;
- }
- /*===== End of Update flo_cached_layout_options ======*/
- /**
- * Filter for any custom post type Otions page
- * // array example:
- // array( 'page=acf-options-11-videos' => 'videos' )
- // the 'flo_theme_videos_options_page' will be build using 'flo_theme_%array_key%_options_page'
- // where %array_key% is taken from the array defined above (in this example 'videos')
- *
- */
- add_filter('flo_any_custom_post_option', 'flo_cannes_any_custom_post_option');
- function flo_cannes_any_custom_post_option() {
- // return array sample:
- // array('videos' => 'page=acf-options-11-videos' => 'flo_theme_videos_options_page')
- return array(
- 'page=acf-options-12-books' => 'books' // in this case 'page=acf-options-12-books' is the URL param from the Books options page: https://i.imgur.com/DyboEnx.jpg
- );
- }
- /**
- *
- * Any Custom Post options filter
- * the filter format name is: 'flo_'.$any_custom_post_option[$url_args['query']].'_fields_key'
- * in our case the $any_custom_post_option[$url_args['query']] = books
- *
- */
- add_filter('flo_books_fields_key', 'flo_cannes_books_fields_key');
- function flo_cannes_books_fields_key() {
- return 'field_5b50a9e4e602b';
- }
- // support for any other custom post types that may be necessary for a customisation or a new theme
- // use the filter below in a child theme if necessary
- // the returned array should have a key / value pair , where the key is the $screen->base, and the
- // value is the option name
- // i.e. array('flotheme_page_acf-options-7-videos' => flo_videos_layout_options)
- // the value is usually formmed from 'flo_%post_type_plural%_layout_options'
- add_filter( 'flo_other_custom_post_types_options', 'flo_cannes_other_custom_post_types_options' );
- function flo_cannes_other_custom_post_types_options() {
- // in this case 'flotheme_page_acf-options-12-books' is taken from 'flotheme_page_' + page url argument value
- // for example when we are on the new post type options page, we have an URL like this:
- // http://localhost/flo/cannes23/wp-admin/admin.php?page=acf-options-12-books
- // https://i.imgur.com/ttVb1Nd.jpg
- // and in this case the page URL parameter is 'acf-options-12-books'
- return array('flotheme_page_acf-options-12-books' => 'flo_books_layout_options');
- }
- /**
- *
- * Filter necessary to add support for a new custom post type
- *
- */
- add_filter('flo_custom_posts_scree_post_types', 'flo_cannes_custom_posts_scree_post_types');
- function flo_cannes_custom_posts_scree_post_types() {
- return array('book');
- }
- /**
- *
- * Filter that defines the correct layout field ID for a new custom post type.
- * The format for the filter name is: flo_single_%screen_post_type%_fields_key,
- * NOTE: replace %screen_post_type% with the post type name.
- * In the example we are having here, %screen_post_type% = book
- */
- add_filter('flo_single_book_fields_key', 'flo_single_book_fields_key');
- function flo_single_book_fields_key() {
- // can be found in the json file with "title": "5. Post", Look at the key for "label": "Layout",
- // instead of 5. Post it will be your number and Post type name
- return 'field_5b50a87b60606';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement