-
Notifications
You must be signed in to change notification settings - Fork 6
/
class-wpzoom-instagram-block.php
109 lines (96 loc) · 2.53 KB
/
class-wpzoom-instagram-block.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Exit if accessed directly.
*/
defined( 'ABSPATH' ) or die;
/**
* WPZOOM Instagram Block class
*
* @package Wpzoom_Instagram_Block
*/
class Wpzoom_Instagram_Block {
/**
* @var WPZOOM_Instagram_Widget_Settings The reference to *Singleton* instance of this class
*
* @since 1.8.4
*/
private static $instance;
/**
* @var Wpzoom_Instagram_Widget_Display
*/
protected $display;
/**
* Returns the *Singleton* instance of this class.
*
* @return WPZOOM_Instagram_Widget_Settings The *Singleton* instance.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*/
public function __construct() {
$this->display = Wpzoom_Instagram_Widget_Display::getInstance();
add_action( 'init', array( $this, 'init' ) );
add_filter( 'block_categories_all', array( $this, 'block_categories' ), 10, 2 );
}
/**
* Initialize the block.
*/
public function init() {
register_block_type(
'wpzoom/instagram-block',
array(
'api_version' => 2,
'category' => 'wpzoom-blocks',
'editor_script' => 'wpz-insta_block-backend-script',
'script' => 'wpz-insta_block-frontend-script',
'style' => 'wpz-insta_block-frontend-style',
'render_callback' => array( $this, 'render' ),
'attributes' => array(
'feed' => array(
'type' => 'integer',
'default' => -1,
),
'align' => array(
'type' => 'string',
'default' => 'none',
),
),
)
);
}
/**
* Add the WPZOOM block category if needed.
*/
public function block_categories( $categories ) {
if ( empty( $categories ) || ( ! empty( $categories ) && is_array( $categories ) && ! in_array( 'wpzoom-blocks', wp_list_pluck( $categories, 'slug' ) ) ) ) {
$categories = array_merge(
$categories,
array(
array(
'slug' => 'wpzoom-blocks',
'title' => esc_html__( 'WPZOOM - Blocks', 'instagram-widget-by-wpzoom' ),
),
)
);
}
return $categories;
}
/**
* Render the block content.
*/
public function render( $block_attributes, $content ) {
$feed_id = isset( $block_attributes['feed'] ) ? intval( $block_attributes['feed'] ) : -1;
if ( $feed_id > -1 ) {
return $this->display->output_feed( $feed_id, false, $block_attributes );
} else {
return wp_kses_post( __( '<p class="error"><strong>Please select a feed to display...</strong></p>', 'instagram-widget-by-wpzoom' ) );
}
}
}
Wpzoom_Instagram_Block::get_instance();