ADD class comments

This commit is contained in:
2025-11-03 07:57:01 +00:00
parent 05ac1a5655
commit 10fa996656
3 changed files with 98 additions and 46 deletions

94
src/Comments.php Normal file
View File

@@ -0,0 +1,94 @@
<?php
/**
* Class Comments.
* Code refactored from:
* https://gist.github.com/mattclements/eab5ef656b2f946c4bfb
*
* @package Foo
*/
namespace App;
/**
* Class Comments - actions and filters related to WordPress comments.
*
* @package Foo
*/
class Comments {
/**
* Static function must be called after require within functions.php
* This will setup all action and filter hooks related to comments.
*/
public static function init() {
$self = new self();
// Admin actions.
add_action( 'admin_init', array( $self, 'disable_comments_post_types_support' ) );
add_action( 'admin_init', array( $self, 'disable_comments_dashboard' ) );
add_action( 'admin_init', array( $self, 'disable_comments_admin_menu_redirect' ) );
add_action( 'admin_menu', array( $self, 'disable_comments_admin_menu' ) );
add_action( 'wp_before_admin_bar_render', array( $self, 'admin_bar_render' ) );
// Frontend.
add_action( 'init', array( $self, 'disable_comments_admin_bar' ) );
// Close comments on the front-end.
add_filter( 'comments_open', '__return_false', 20, 2 );
add_filter( 'pings_open', '__return_false', 20, 2 );
// Hide existing comments.
add_filter( 'comments_array', '__return_empty_array', 10, 2 );
}
/** Disable support for comments and trackbacks in post types. */
public function disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
if ( post_type_supports( $post_type, 'comments' ) ) {
remove_post_type_support( $post_type, 'comments' );
remove_post_type_support( $post_type, 'trackbacks' );
}
}
}
/** Remove comments page in menu. */
public function disable_comments_admin_menu() {
remove_menu_page( 'edit-comments.php' );
}
/** Redirect any user trying to access comments page. */
public function disable_comments_admin_menu_redirect() {
global $pagenow;
if ( 'edit-comments.php' === $pagenow ) {
wp_safe_redirect( admin_url() );
exit;
}
}
/** Remove comments metabox from dashboard. */
public function disable_comments_dashboard() {
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
}
/** Remove comments links from admin bar. */
public function disable_comments_admin_bar() {
if ( is_admin_bar_showing() ) {
remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
}
}
/** Remove comments links from admin bar. */
public function admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu( 'comments' );
error_log('✅ admin_bar_render');
}
}

View File

@@ -35,7 +35,8 @@ class StarterSite extends Site {
add_filter('timber/context', [$this, 'add_global_context']); // variables globales
add_filter('timber/twig', [$this, 'add_videos_embed_to_twig']); //videos embed
add_action('pre_get_posts', array($this, 'exclude_pages_from_search')); //exclude pages with ACF
// función que reconoce los campos ACF en los diferentes idiomas.
add_action('init', function() {
if (function_exists('pll_current_language')) {