CFF_Modern_Feed_Block.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CustomFacebookFeed\Admin\Blocks; |
| 4 | |
| 5 | use FacebookFeed\Vendor\Smashballoon\Framework\Packages\Blocks\SB_Feed_Block; |
| 6 | use CustomFacebookFeed\Builder\CFF_Db; |
| 7 | |
| 8 | class CFF_Modern_Feed_Block extends SB_Feed_Block { |
| 9 | |
| 10 | protected function get_block_name() { |
| 11 | return 'smashballoon/facebook-feed'; |
| 12 | } |
| 13 | |
| 14 | protected function get_shortcode_tag() { |
| 15 | return 'custom-facebook-feed'; |
| 16 | } |
| 17 | |
| 18 | protected function get_script_handle() { |
| 19 | return 'sb-feed-blocks'; |
| 20 | } |
| 21 | |
| 22 | protected function get_text_domain() { |
| 23 | return 'custom-facebook-feed'; |
| 24 | } |
| 25 | |
| 26 | protected function get_plugin_dir() { |
| 27 | return trailingslashit( CFF_PLUGIN_DIR ); |
| 28 | } |
| 29 | |
| 30 | protected function get_enqueue_scripts_action() { |
| 31 | return 'cff_enqueue_scripts'; |
| 32 | } |
| 33 | |
| 34 | protected function get_localize_var_name() { |
| 35 | return 'cffFacebookFeedBlock'; |
| 36 | } |
| 37 | |
| 38 | protected function get_feed_block_id() { |
| 39 | return 'facebook'; |
| 40 | } |
| 41 | |
| 42 | protected function get_init_function() { |
| 43 | return 'cff_init'; |
| 44 | } |
| 45 | |
| 46 | protected function get_block_dir() { |
| 47 | return $this->get_plugin_dir() . 'vendor/smashballoon/framework/Packages/Blocks/dist/feed-blocks/facebook'; |
| 48 | } |
| 49 | |
| 50 | protected function get_editor_localize_data() { |
| 51 | $feeds = CFF_Db::feeds_query(); |
| 52 | |
| 53 | return array( |
| 54 | 'feeds' => ! empty( $feeds ) ? $feeds : array(), |
| 55 | 'feed_url' => admin_url( 'admin.php?page=cff-feed-builder' ), |
| 56 | 'nonce' => wp_create_nonce( 'cff-blocks' ), |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | public function register_hooks() { |
| 61 | add_action( |
| 62 | 'cff_enqueue_scripts', |
| 63 | function ( $force = false ) { |
| 64 | \cff_main()->enqueue_styles_assets(); |
| 65 | \cff_main()->enqueue_scripts_assets(); |
| 66 | // When the parent block fires this action with $force = true (iframe |
| 67 | // editor preview or a page that contains the block) the feed must |
| 68 | // load regardless of the "load assets only with shortcode" option, |
| 69 | // which otherwise prevents enqueue_*_assets() from enqueueing. |
| 70 | if ( $force ) { |
| 71 | wp_enqueue_style( 'cff' ); |
| 72 | wp_enqueue_script( 'cffscripts' ); |
| 73 | } |
| 74 | } |
| 75 | ); |
| 76 | |
| 77 | parent::register_hooks(); |
| 78 | |
| 79 | if ( doing_action( 'init' ) || did_action( 'init' ) ) { |
| 80 | $this->register_block(); |
| 81 | } |
| 82 | |
| 83 | remove_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) ); |
| 84 | add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ), 25 ); |
| 85 | } |
| 86 | } |
| 87 |