Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2021
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @since      0.1
  4.  *
  5.  * @package    pdf-viewer-block
  6.  * @subpackage pdf-viewer-block/admin
  7.  */
  8.  
  9. /**
  10.  * The admin-specific functionality of the plugin.
  11.  *
  12.  * @package    pdf-viewer-block
  13.  * @subpackage pdf-viewer-block/admin
  14.  * @author     audrasjb <[email protected]>
  15.  */
  16.  
  17. /**
  18.  *
  19.  * Enqueue styles and scripts
  20.  *
  21.  */
  22.     if ( ! function_exists( 'register_block_type' ) ) {
  23.         // Gutenberg is not active.
  24.         return;
  25.     }
  26.  
  27.     add_action( 'admin_enqueue_scripts', 'gpvb_enqueue_styles_admin' );
  28.     function gpvb_enqueue_styles_admin() {
  29.         if ( ! gpvb_is_block_editor() ) {
  30.             return;
  31.         }
  32.  
  33.         wp_enqueue_style(
  34.             'gpvb-admin-styles',
  35.             plugin_dir_url( __FILE__ ) . 'css/admin.css',
  36.             array(),
  37.             '',
  38.             'all'
  39.         );
  40.         wp_register_script(
  41.             'gpvb-admin-scripts',
  42.             plugins_url( 'js/block.js', __FILE__ ),
  43.             array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ),
  44.             filemtime( plugin_dir_path( __FILE__ ) . 'js/block.js' ),
  45.             true
  46.         );
  47.         wp_enqueue_script( 'gpvb-admin-scripts' );
  48.     }
  49.     register_block_type( 'pdf-viewer-block/standard',
  50.         array(
  51.             'editor_script' => 'gpvb-admin-scripts',
  52.             'editor_style'  => 'gpvb-admin-styles',
  53.         )
  54.     );
  55.  
  56. function gpvb_is_block_editor() {
  57.     // Check WordPress version.
  58.     if ( version_compare( get_bloginfo( 'version' ), '5.0.0', '<' ) ) {
  59.         return false;
  60.     }
  61.  
  62.     $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
  63.  
  64.     if ( ! $screen instanceof WP_Screen ) {
  65.         return false;
  66.     }
  67.  
  68.     if ( method_exists( $screen, 'is_block_editor' ) ) {
  69.         return $screen->is_block_editor();
  70.     }
  71.  
  72.     if ( 'post' === $screen->base ) {
  73.         return gpvb_use_block_editor_for_post_type( $screen->post_type );
  74.     }
  75.  
  76.     return false;
  77. }
  78.  
  79. function gpvb_use_block_editor_for_post_type() {
  80.     if ( ! post_type_exists( $post_type ) ) {
  81.         return false;
  82.     }
  83.  
  84.     if ( ! post_type_supports( $post_type, 'editor' ) ) {
  85.         return false;
  86.     }
  87.  
  88.     $post_type_object = get_post_type_object( $post_type );
  89.     if ( $post_type_object && ! $post_type_object->show_in_rest ) {
  90.         return false;
  91.     }
  92.  
  93.     /**
  94.      * Filter whether a post is able to be edited in the block editor.
  95.      *
  96.      * @since 5.0.0
  97.      *
  98.      * @param bool   $use_block_editor  Whether the post type can be edited or not. Default true.
  99.      * @param string $post_type         The post type being checked.
  100.      */
  101.     return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement