Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @since 0.1
- *
- * @package pdf-viewer-block
- * @subpackage pdf-viewer-block/admin
- */
- /**
- * The admin-specific functionality of the plugin.
- *
- * @package pdf-viewer-block
- * @subpackage pdf-viewer-block/admin
- * @author audrasjb <[email protected]>
- */
- /**
- *
- * Enqueue styles and scripts
- *
- */
- if ( ! function_exists( 'register_block_type' ) ) {
- // Gutenberg is not active.
- return;
- }
- add_action( 'admin_enqueue_scripts', 'gpvb_enqueue_styles_admin' );
- function gpvb_enqueue_styles_admin() {
- if ( ! gpvb_is_block_editor() ) {
- return;
- }
- wp_enqueue_style(
- 'gpvb-admin-styles',
- plugin_dir_url( __FILE__ ) . 'css/admin.css',
- array(),
- '',
- 'all'
- );
- wp_register_script(
- 'gpvb-admin-scripts',
- plugins_url( 'js/block.js', __FILE__ ),
- array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ),
- filemtime( plugin_dir_path( __FILE__ ) . 'js/block.js' ),
- true
- );
- wp_enqueue_script( 'gpvb-admin-scripts' );
- }
- register_block_type( 'pdf-viewer-block/standard',
- array(
- 'editor_script' => 'gpvb-admin-scripts',
- 'editor_style' => 'gpvb-admin-styles',
- )
- );
- function gpvb_is_block_editor() {
- // Check WordPress version.
- if ( version_compare( get_bloginfo( 'version' ), '5.0.0', '<' ) ) {
- return false;
- }
- $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
- if ( ! $screen instanceof WP_Screen ) {
- return false;
- }
- if ( method_exists( $screen, 'is_block_editor' ) ) {
- return $screen->is_block_editor();
- }
- if ( 'post' === $screen->base ) {
- return gpvb_use_block_editor_for_post_type( $screen->post_type );
- }
- return false;
- }
- function gpvb_use_block_editor_for_post_type() {
- if ( ! post_type_exists( $post_type ) ) {
- return false;
- }
- if ( ! post_type_supports( $post_type, 'editor' ) ) {
- return false;
- }
- $post_type_object = get_post_type_object( $post_type );
- if ( $post_type_object && ! $post_type_object->show_in_rest ) {
- return false;
- }
- /**
- * Filter whether a post is able to be edited in the block editor.
- *
- * @since 5.0.0
- *
- * @param bool $use_block_editor Whether the post type can be edited or not. Default true.
- * @param string $post_type The post type being checked.
- */
- return apply_filters( 'use_block_editor_for_post_type', true, $post_type );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement