/*
Theme Name: SoftwareSaathi_Info Theme
Theme URI: https://info.softwaresaathi.com/
Template: astra
Author: Software Saathi
Author URI: https://softwaresaathi.com/
Version: 4.8.10.1738585849
Updated: 2025-02-03 18:00:49

*/

// Remove WordPress generator tag
remove_action('wp_head', 'wp_generator');
add_filter('the_generator', '__return_empty_string');

// Remove Elementor generator tag
add_action('wp_head', function() {
  remove_action('wp_head', [ \Elementor\Plugin::instance()
    ->frontend, 'print_google_fonts' ]);
}, 0);

// Also suppress via output buffer (catches all generator tags)
add_action('template_redirect', function() {
  ob_start(function($html) {
    return preg_replace('/]+>/i', '', $html);
  });
});


// ============================================
// BLOCK REST API - USERS ENDPOINT
// ============================================
add_filter('rest_endpoints', function($endpoints) {
  if (!is_user_logged_in()) {
    unset($endpoints['/wp/v2/users']);
    unset($endpoints['/wp/v2/users/(?P<id>[\d]+)']);
    unset($endpoints['/wp/v2/plugins']);
    unset($endpoints['/wp/v2/themes']);
  }
  return $endpoints;
});

// ============================================
// BLOCK UNAUTHENTICATED REST ACCESS
// ============================================
add_filter('rest_authentication_errors', function($result) {
  if (true === $result || is_wp_error($result)) {
    return $result;
  }
  if (!is_user_logged_in()) {
    $auth = isset($_SERVER['HTTP_AUTHORIZATION']) 
            ? $_SERVER['HTTP_AUTHORIZATION'] : '';
    if (empty($auth)) {
      return new WP_Error(
        'rest_not_logged_in',
        'REST API restricted.',
        array('status' => 401)
      );
    }
  }
  return $result;
});
