Changeset 2490058
- Timestamp:
- 03/08/2021 11:53:52 PM (5 years ago)
- File:
-
- 1 edited
-
block-pattern-maker/trunk/block-pattern-maker.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
block-pattern-maker/trunk/block-pattern-maker.php
r2420055 r2490058 4 4 Plugin URI: https://github.com/rebelwageslave/block-pattern-maker/ 5 5 Description: Create your own block patterns and use them. 6 Version: 1.06 Version: 2.0 7 7 Author: rebelwageslave 8 8 Author URI: http://github.com/rebelwageslave/ … … 13 13 function dk_block_pattern_maker_init() { 14 14 15 register_post_type('dk_block_patterns', array( 16 'label' => __('Block patterns', 'block-pattern-maker'), 17 'public' => true, 18 'show_in_rest' => true, 19 'exclude_from_search' => true, 20 'menu_icon' => 'dashicons-grid-view' 21 )); 15 register_post_type( 'dk_block_patterns', array( 16 'label' => __( 'Block patterns', 'block-pattern-maker' ), 17 'public' => true, 18 'show_in_rest' => true, 19 'exclude_from_search' => true, 20 'menu_icon' => 'dashicons-grid-view', 21 'taxonomies' => array( 'category' ) 22 ) ); 22 23 23 if ( ! function_exists('register_block_type') ) {24 return;25 }24 if ( ! function_exists( 'register_block_type' ) ) { 25 return; 26 } 26 27 27 $posts = get_posts(28 array(29 'post_type'=> 'dk_block_patterns',30 'numberposts' => -1,31 'post_status' => 'publish'32 )33 );28 $posts = get_posts( 29 array( 30 'post_type' => 'dk_block_patterns', 31 'numberposts' => - 1, 32 'post_status' => 'publish' 33 ) 34 ); 34 35 35 foreach ( $posts as $post ) { 36 if (! $post->post_content ) { 37 continue; 38 } 39 register_block_pattern('dk-'.md5($post->post_title), 40 array( 41 'title' => $post->post_title, 42 'description' => $post->post_title, 43 'content' => $post->post_content, 44 )); 45 } 36 foreach ( $posts as $post ) { 37 if ( ! $post->post_content ) { 38 continue; 39 } 40 $categories = get_the_category( $post->ID ); 41 42 43 $category_names = array(); 44 foreach ( $categories as $category ) { 45 $category_names[] = 'dk_' . $category->slug; 46 /** 47 * @var $category WP_Term 48 */ 49 register_block_pattern_category( 'dk_' . $category->slug, array( 'label' => __( $category->name, 'dk_block_patterns' ) ) ); 50 } 51 52 register_block_pattern( 'dk-' . md5( $post->post_title ), 53 array( 54 'title' => $post->post_title, 55 'description' => $post->post_title, 56 'content' => $post->post_content, 57 'categories' => $category_names 58 ) ); 59 } 46 60 47 61 } 48 62 49 63 50 51 52 53 add_action('init', 'dk_block_pattern_maker_init'); 64 add_action( 'init', 'dk_block_pattern_maker_init' );
Note: See TracChangeset
for help on using the changeset viewer.