Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. <?php
  2. add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
  3. function theme_enqueue_styles() {
  4. wp_enqueue_style( 'parent-main-style', get_template_directory_uri() . '/style.css' );
  5. }
  6.  
  7.  
  8. add_action( 'init', 'codex_book_init' );
  9. /**
  10. * Register a book post type.
  11. *
  12. * @link http://codex.wordpress.org/Function_Reference/register_post_type
  13. */
  14. function codex_book_init() {
  15. $labels = array(
  16. 'name' => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
  17. 'singular_name' => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
  18. 'menu_name' => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
  19. 'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
  20. 'add_new' => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
  21. 'add_new_item' => __( 'Add New Book', 'your-plugin-textdomain' ),
  22. 'new_item' => __( 'New Book', 'your-plugin-textdomain' ),
  23. 'edit_item' => __( 'Edit Book', 'your-plugin-textdomain' ),
  24. 'view_item' => __( 'View Book', 'your-plugin-textdomain' ),
  25. 'all_items' => __( 'All Books', 'your-plugin-textdomain' ),
  26. 'search_items' => __( 'Search Books', 'your-plugin-textdomain' ),
  27. 'parent_item_colon' => __( 'Parent Books:', 'your-plugin-textdomain' ),
  28. 'not_found' => __( 'No books found.', 'your-plugin-textdomain' ),
  29. 'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )
  30. );
  31.  
  32. $args = array(
  33. 'labels' => $labels,
  34. 'description' => __( 'Description.', 'your-plugin-textdomain' ),
  35. 'public' => true,
  36. 'publicly_queryable' => true,
  37. 'show_ui' => true,
  38. 'show_in_menu' => true,
  39. 'query_var' => true,
  40. 'rewrite' => array( 'slug' => 'book' ),
  41. 'capability_type' => 'post',
  42. 'has_archive' => true,
  43. 'hierarchical' => false,
  44. 'menu_position' => null,
  45. 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  46. );
  47.  
  48. register_post_type( 'book', $args );
  49. }
  50.  
  51.  
  52. /*=============================================
  53. = flo_subpages_options =
  54. =============================================*/
  55.  
  56. add_filter('flo_subpages_options', 'flo_custom_cannes_subpages_options');
  57.  
  58. function flo_custom_cannes_subpages_options($subpages_options) {
  59.  
  60. $subpages_options[] = array(
  61. 'page_title' => __('12. Books Settings','flotheme'),
  62. 'menu_title' => __('12. Books','flotheme'),
  63. 'menu_slug' => 'acf-options-12-books'
  64. );
  65.  
  66. return $subpages_options;
  67. }
  68.  
  69. /*===== End of flo_subpages_options ======*/
  70.  
  71.  
  72.  
  73. /**
  74. *
  75. * Template used for inheriting the global custom post layout within custom post editors
  76. *
  77. */
  78. add_filter( 'flo_custom_post_type_layout', 'flo_book_custom_post_type_layout' );
  79. function flo_book_custom_post_type_layout() {
  80. $custom_post_type_layouts = array('book' => 'flo-cn-b');
  81. // where 'flo-cn-b' should be exact name from the options for the current custom post:
  82. // https://i.imgur.com/8eByoxJ.jpg
  83. // https://i.imgur.com/tXYveRB.jpg
  84.  
  85.  
  86. return $custom_post_type_layouts;
  87. }
  88.  
  89.  
  90.  
  91. /*========================================================
  92. = Update flo_cached_layout_options =
  93. ========================================================*/
  94.  
  95. remove_filter('flo_cached_layout_options', 'flo_evora_cached_layout_options');
  96.  
  97. add_filter('flo_cached_layout_options', 'flo_cannes_custom_cached_layout_options');
  98. function flo_cannes_custom_cached_layout_options() {
  99. // the layout options names
  100. $cached_layout = array('flo-cn-g_layout','flo-cn-p_layout', 'flo-cn-v_layout', 'flo-cn-b_layout');
  101.  
  102. // NOTE: the difference from the original theme in the line above is that we added 'flo-cn-b_layout'
  103.  
  104. return $cached_layout;
  105. }
  106.  
  107. /*===== End of Update flo_cached_layout_options ======*/
  108.  
  109.  
  110.  
  111.  
  112. /**
  113. * Filter for any custom post type Otions page
  114. * // array example:
  115. // array( 'page=acf-options-11-videos' => 'videos' )
  116. // the 'flo_theme_videos_options_page' will be build using 'flo_theme_%array_key%_options_page'
  117. // where %array_key% is taken from the array defined above (in this example 'videos')
  118. *
  119. */
  120. add_filter('flo_any_custom_post_option', 'flo_cannes_any_custom_post_option');
  121. function flo_cannes_any_custom_post_option() {
  122. // return array sample:
  123. // array('videos' => 'page=acf-options-11-videos' => 'flo_theme_videos_options_page')
  124. return array(
  125. '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
  126. );
  127. }
  128.  
  129.  
  130. /**
  131. *
  132. * Any Custom Post options filter
  133. * the filter format name is: 'flo_'.$any_custom_post_option[$url_args['query']].'_fields_key'
  134. * in our case the $any_custom_post_option[$url_args['query']] = books
  135. *
  136. */
  137. add_filter('flo_books_fields_key', 'flo_cannes_books_fields_key');
  138. function flo_cannes_books_fields_key() {
  139. return 'field_5b50a9e4e602b';
  140. }
  141.  
  142.  
  143.  
  144. // support for any other custom post types that may be necessary for a customisation or a new theme
  145. // use the filter below in a child theme if necessary
  146. // the returned array should have a key / value pair , where the key is the $screen->base, and the
  147. // value is the option name
  148. // i.e. array('flotheme_page_acf-options-7-videos' => flo_videos_layout_options)
  149. // the value is usually formmed from 'flo_%post_type_plural%_layout_options'
  150. add_filter( 'flo_other_custom_post_types_options', 'flo_cannes_other_custom_post_types_options' );
  151. function flo_cannes_other_custom_post_types_options() {
  152.  
  153. // in this case 'flotheme_page_acf-options-12-books' is taken from 'flotheme_page_' + page url argument value
  154. // for example when we are on the new post type options page, we have an URL like this:
  155. // http://localhost/flo/cannes23/wp-admin/admin.php?page=acf-options-12-books
  156. // https://i.imgur.com/ttVb1Nd.jpg
  157. // and in this case the page URL parameter is 'acf-options-12-books'
  158. return array('flotheme_page_acf-options-12-books' => 'flo_books_layout_options');
  159. }
  160.  
  161. /**
  162. *
  163. * Filter necessary to add support for a new custom post type
  164. *
  165. */
  166. add_filter('flo_custom_posts_scree_post_types', 'flo_cannes_custom_posts_scree_post_types');
  167. function flo_cannes_custom_posts_scree_post_types() {
  168. return array('book');
  169. }
  170.  
  171.  
  172. /**
  173. *
  174. * Filter that defines the correct layout field ID for a new custom post type.
  175. * The format for the filter name is: flo_single_%screen_post_type%_fields_key,
  176. * NOTE: replace %screen_post_type% with the post type name.
  177. * In the example we are having here, %screen_post_type% = book
  178. */
  179. add_filter('flo_single_book_fields_key', 'flo_single_book_fields_key');
  180. function flo_single_book_fields_key() {
  181. // can be found in the json file with "title": "5. Post", Look at the key for "label": "Layout",
  182. // instead of 5. Post it will be your number and Post type name
  183. return 'field_5b50a87b60606';
  184. }
  185.  
  186. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement