@@ -550,18 +550,22 @@ function ifset( &$var, $return = false ) { // phpcs:ignore Universal.NamingConve
550
550
* @return boolean if webmentions are open
551
551
*/
552
552
function webmentions_open ( $ post = null ) {
553
- $ _post = get_post ( $ post );
554
- $ post_id = $ _post ? $ _post ->ID : 0 ;
555
-
556
- // If the post type does not support Webmentions do not even check further
557
- if ( ! post_type_supports ( get_post_type ( $ post_id ), 'webmentions ' ) ) {
558
- return false ;
553
+ $ post = get_post ( $ post );
554
+ $ post_id = $ post ? $ post ->ID : 0 ;
555
+ $ open = false ;
556
+ if ( $ post ) {
557
+ // Always consider the home mention link page to be open.
558
+ if ( get_option ( 'webmention_home_mentions ' ) === $ post ->ID ) {
559
+ $ open = true ;
560
+ } elseif ( ! post_type_supports ( get_post_type ( $ post ), 'webmentions ' ) ) {
561
+ // If the post type does not support Webmentions do not even check further.
562
+ $ open = false ;
563
+ } else {
564
+ // If the webmentions_disabled meta key exists then consider webmentions closed. Otherwise consider them open.
565
+ $ open = ! ( metadata_exists ( 'post ' , $ post_id , 'webmentions_disabled ' ) ); // Invert the result, as exists is closed and not exists is open.
566
+ }
559
567
}
560
568
561
- if ( get_option ( 'webmention_home_mentions ' ) === $ post_id ) {
562
- return true ;
563
- }
564
- $ open = ( $ _post && ( pings_open ( $ post ) ) );
565
569
/**
566
570
* Filters whether the current post is open for webmentions.
567
571
*
@@ -572,23 +576,6 @@ function webmentions_open( $post = null ) {
572
576
return apply_filters ( 'webmentions_open ' , $ open , $ post_id );
573
577
}
574
578
575
- /**
576
- * Return enabled status of Homepage Webmentions.
577
- *
578
- * @since 3.8.9
579
- *
580
- * @param bool $open Whether the current post is open for pings.
581
- * @param int $post_id The post ID.
582
- * @return boolean if pings are open
583
- */
584
- function webmention_pings_open ( $ open , $ post_id ) {
585
- if ( get_option ( 'webmention_home_mentions ' ) === $ post_id ) {
586
- return true ;
587
- }
588
-
589
- return $ open ;
590
- }
591
-
592
579
/**
593
580
* Retrieve the default comment status for a given post type.
594
581
*
@@ -602,16 +589,7 @@ function webmention_pings_open( $open, $post_id ) {
602
589
* @return string
603
590
*/
604
591
function webmention_get_default_comment_status ( $ status , $ post_type , $ comment_type ) {
605
- if ( 'webmention ' === $ comment_type ) {
606
- return post_type_supports ( $ post_type , 'webmentions ' ) ? 'open ' : 'closed ' ;
607
- }
608
-
609
- // Since support for the pingback comment type is used to keep pings open...
610
- if ( ( 'pingback ' === $ comment_type ) ) {
611
- return ( post_type_supports ( $ post_type , 'webmentions ' ) ? 'open ' : $ status );
612
- }
613
-
614
- return $ status ;
592
+ return is_registered_webmention_comment_type ( $ comment_type ) ? 'open ' : $ status ;
615
593
}
616
594
617
595
/**
@@ -707,3 +685,31 @@ function is_html( $string ) { // phpcs:ignore Universal.NamingConventions.NoRese
707
685
return ( wp_strip_all_tags ( $ string ) !== $ string );
708
686
}
709
687
}
688
+
689
+ /**
690
+ * Check if a site supports the block editor.
691
+ *
692
+ * @return boolean True if the site supports the block editor, false otherwise.
693
+ */
694
+ function site_supports_blocks () {
695
+ $ return = true ;
696
+
697
+ if ( \version_compare ( \get_bloginfo ( 'version ' ), '5.9 ' , '< ' ) ) {
698
+ $ return = false ;
699
+ } elseif ( \function_exists ( 'classicpress_version ' ) ) {
700
+ $ return = false ;
701
+ } elseif (
702
+ ! \function_exists ( 'register_block_type_from_metadata ' ) ||
703
+ ! \function_exists ( 'do_blocks ' )
704
+ ) {
705
+ $ return = false ;
706
+ }
707
+
708
+ /**
709
+ * Allow plugins to disable block editor support,
710
+ * thus disabling blocks registered by the Webmentions plugin.
711
+ *
712
+ * @param boolean $supports_blocks True if the site supports the block editor, false otherwise.
713
+ */
714
+ return apply_filters ( 'webmention_site_supports_blocks ' , $ return );
715
+ }
0 commit comments