PluginProbe
Flex Posts – Responsive Posts Block / 1.12.0
Flex Posts – Responsive Posts Block v1.12.0
2.1.0 trunk 1.12.0 2.0.0
flex-posts / blocks / list / block.php

block.php in Flex Posts – Responsive Posts Block 1.12.0, at blocks/list/block.php

85 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Flex Posts List Block
4 *
5 * @package Flex Posts
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Register block
14 */
15 function flex_posts_register_block() {
16 $option = get_option( 'flex_posts' );
17
18 wp_register_script(
19 'flex-posts',
20 plugins_url( 'block.js', __FILE__ ),
21 array( 'wp-blocks', 'wp-element', 'wp-i18n' ),
22 FLEX_POSTS_VERSION,
23 true
24 );
25
26 $categories[] = array(
27 'label' => __( 'All Categories', 'flex-posts' ),
28 'value' => '',
29 );
30
31 $cats = get_categories();
32
33 foreach ( $cats as $cat ) {
34 $categories[] = array(
35 'label' => $cat->name,
36 'value' => $cat->term_id,
37 );
38 }
39
40 $attributes = apply_filters( 'flex_posts_attributes', flex_posts_get_attributes() );
41
42 $attributes2 = $attributes;
43 unset( $attributes2['align'] );
44 unset( $attributes2['className'] );
45
46 wp_localize_script(
47 'flex-posts',
48 'flex_posts',
49 array(
50 'categories' => $categories,
51 'post_types' => flex_posts_get_post_types(),
52 'layouts' => flex_posts_get_layouts(),
53 'order_by' => flex_posts_get_order_by(),
54 'image_sizes' => flex_posts_get_image_sizes(),
55 'taxonomies' => flex_posts_get_taxonomies(),
56 'title_el' => flex_posts_get_title_elements_options(),
57 'attributes' => $attributes2,
58 )
59 );
60
61 $args = array(
62 'editor_script' => 'flex-posts',
63 'render_callback' => 'flex_posts_render_block',
64 'attributes' => $attributes,
65 );
66
67 if ( empty( $option['disable_css'] ) ) {
68 $args['style'] = 'flex-posts';
69 $args['editor_style'] = 'flex-posts';
70 }
71
72 register_block_type( 'flex-posts/list', $args );
73 }
74 add_action( 'init', 'flex_posts_register_block' );
75
76 /**
77 * Render block
78 *
79 * @param array $attributes Attributes.
80 * @return string
81 */
82 function flex_posts_render_block( $attributes ) {
83 return flex_posts_render( $attributes );
84 }
85