WebberZone / contextual-related-posts

Contextual Related Posts WordPress plugin
https://webberzone.com/plugins/contextual-related-posts/
38 stars 23 forks source link

Don't enqueue wp-editor on widgets.php #152

Closed ajaydsouza closed 2 years ago

ajaydsouza commented 2 years ago

https://github.com/WebberZone/contextual-related-posts/blob/8515c61b836915ecd23c75e5ac7cb694a91be074/includes/admin/blocks/related-posts.php#L66

    global $pagenow;
    // Skip block registration if Gutenberg is not enabled/merged.
    if ( ! function_exists( 'register_block_type' ) ) {
        return;
    }
    $dir         = dirname( __FILE__ );
    $file_prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

    $dependencies = array( 'wp-element', 'wp-blocks', 'wp-components', 'wp-i18n' );

    if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
        array_push( $dependencies, 'wp-editor', 'wp-edit-post', 'wp-block-editor' );
    } elseif ( 'widgets.php' === $pagenow ) {
        array_push( $dependencies, 'wp-edit-widgets' );
    }

    $index_js = "popular-posts/index{$file_prefix}.js";
    wp_register_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
        'popular-posts-block-editor',
        plugins_url( $index_js, __FILE__ ),
        $dependencies,
        filemtime( "$dir/$index_js" )
    );