ADD class comments
This commit is contained in:
@ -14,8 +14,10 @@ use Timber\Timber;
|
|||||||
|
|
||||||
require_once __DIR__ . '/src/SMTP.php'; //config email
|
require_once __DIR__ . '/src/SMTP.php'; //config email
|
||||||
require_once __DIR__ . '/vendor/autoload.php'; // Load Composer dependencies.
|
require_once __DIR__ . '/vendor/autoload.php'; // Load Composer dependencies.
|
||||||
|
require_once __DIR__ . '/src/Comments.php'; // ocultar posibilidad de comentarios
|
||||||
|
|
||||||
Timber::init();
|
Timber::init();
|
||||||
|
Comments::init();
|
||||||
|
|
||||||
$site = new StarterSite();
|
$site = new StarterSite();
|
||||||
|
|
||||||
@ -66,48 +68,3 @@ foreach(['/es/documentos/page/:paged','/eu/dokumentuak/page/:paged'] as $route)
|
|||||||
Routes::load('archive-documentos.php', $params, $query, 200);
|
Routes::load('archive-documentos.php', $params, $query, 200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// *************************DEBUGUEANDO...................
|
|
||||||
|
|
||||||
// add_shortcode('test_smtp_db', function() {
|
|
||||||
// global $wpdb;
|
|
||||||
|
|
||||||
// $output = '<h3>Verificación directa en BD:</h3>';
|
|
||||||
|
|
||||||
// // Buscar en la tabla wp_options todas las entradas que contengan 'smtp'
|
|
||||||
// $results = $wpdb->get_results("
|
|
||||||
// SELECT option_name, option_value
|
|
||||||
// FROM {$wpdb->options}
|
|
||||||
// WHERE option_name LIKE '%smtp%'
|
|
||||||
// ORDER BY option_name
|
|
||||||
// ");
|
|
||||||
|
|
||||||
// if ($results) {
|
|
||||||
// $output .= '<ul>';
|
|
||||||
// foreach ($results as $row) {
|
|
||||||
// $value = strlen($row->option_value) > 100 ? substr($row->option_value, 0, 100) . '...' : $row->option_value;
|
|
||||||
// $output .= '<li><strong>' . $row->option_name . ':</strong> ' . esc_html($value) . '</li>';
|
|
||||||
// }
|
|
||||||
// $output .= '</ul>';
|
|
||||||
// } else {
|
|
||||||
// $output .= '<p>❌ No se encontró ninguna opción con "smtp" en la base de datos</p>';
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Probar diferentes variaciones
|
|
||||||
// $output .= '<h4>Pruebas de get_option:</h4><ul>';
|
|
||||||
// $variations = [
|
|
||||||
// 'smtp_host',
|
|
||||||
// 'options_smtp_host',
|
|
||||||
// '_smtp_host',
|
|
||||||
// 'configuracion-smtp-correo_smtp_host'
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// foreach ($variations as $key) {
|
|
||||||
// $value = get_option($key);
|
|
||||||
// $output .= '<li><strong>' . $key . ':</strong> ' . ($value ? esc_html($value) : '❌ VACÍO') . '</li>';
|
|
||||||
// }
|
|
||||||
// $output .= '</ul>';
|
|
||||||
|
|
||||||
// return $output;
|
|
||||||
// });
|
|
||||||
94
src/Comments.php
Normal file
94
src/Comments.php
Normal 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');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ class StarterSite extends Site {
|
|||||||
add_filter('timber/twig', [$this, 'add_videos_embed_to_twig']); //videos embed
|
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
|
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.
|
// función que reconoce los campos ACF en los diferentes idiomas.
|
||||||
add_action('init', function() {
|
add_action('init', function() {
|
||||||
if (function_exists('pll_current_language')) {
|
if (function_exists('pll_current_language')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user