| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\ServerInformation; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
|
| 7 |
// no direct access allowed |
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* WPAdminify |
| 14 |
* |
| 15 |
* @package Server Information: Robots.txt file |
| 16 |
* |
| 17 |
* @author WP Adminify <support@wpadminify.com> |
| 18 |
*/ |
| 19 |
|
| 20 |
class ServerInfo_Robots_Details { |
| 21 |
|
| 22 |
|
| 23 |
public function __construct() { |
| 24 |
$this->init(); |
| 25 |
} |
| 26 |
|
| 27 |
public function init() { |
| 28 |
?> |
| 29 |
|
| 30 |
<div class="wrap"> |
| 31 |
|
| 32 |
<h1> |
| 33 |
<?php echo Utils::admin_page_title( esc_html__( 'Robots.txt File', 'adminify' ) ); ?> |
| 34 |
</h1> |
| 35 |
|
| 36 |
<p style="color: #ce2754; font-weight: bold"> |
| 37 |
<?php |
| 38 |
$name = 'robots.txt'; |
| 39 |
printf( wp_kses_post( __( 'For security reasons you can only read the %1$s file! Please connect to your server and modify the file in a file editor.', 'adminify' ) ), esc_html( $name ) ); |
| 40 |
?> |
| 41 |
</p> |
| 42 |
|
| 43 |
<p> |
| 44 |
<strong><?php esc_html_e( 'To affect your custom configuration in the robots.txt file, you have to save the file in the "root" folder of your WordPress installation.', 'adminify' ); ?></strong> |
| 45 |
</p> |
| 46 |
|
| 47 |
<p> |
| 48 |
<?php esc_html_e( 'Search Engines read a file at yourdomain.com/robots.txt to get information on what they should and shouldn’t check. Adding entries to robots.txt to help SEO is popular misconception. Google says you are welcome to use robots.txt to block parts of your site but these days prefers you don’t.', 'adminify' ); ?> |
| 49 |
<br> |
| 50 |
<a href="https://wordpress.org/support/article/search-engine-optimization/#robots-txt-optimization" target="_blank" rel="noopener"><?php esc_html_e( 'Learn more about the robots.txt file in WordPress.', 'adminify' ); ?></a> |
| 51 |
</p> |
| 52 |
</div> |
| 53 |
|
| 54 |
<?php |
| 55 |
|
| 56 |
// Get the wp "robots.txt" file |
| 57 |
$file = $this->jltwp_adminify_robots_txt_file(); |
| 58 |
|
| 59 |
// Get the wp "robots.txt" file content |
| 60 |
$file_content = $this->jltwp_adminify_robots_txt_file_content( $file ); |
| 61 |
|
| 62 |
if ( $file ) { |
| 63 |
?> |
| 64 |
<p> |
| 65 |
<?php echo esc_html__( 'robots.txt file was found at:', 'adminify' ) . ' <strong>' . esc_html( $file ) . '</strong>'; ?> |
| 66 |
<br> |
| 67 |
</p> |
| 68 |
<?php } ?> |
| 69 |
|
| 70 |
<textarea id="robots_log_area" class="adminify-info-text-area" readonly><?php echo esc_html( $file_content ); ?></textarea> |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
<?php |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
function jltwp_adminify_robots_txt_file() { |
| 79 |
|
| 80 |
// Call wp file system |
| 81 |
global $wp_filesystem; |
| 82 |
WP_Filesystem(); |
| 83 |
|
| 84 |
// Get the path of wp "robots.txt" file |
| 85 |
$file = get_home_path() . 'robots.txt'; |
| 86 |
|
| 87 |
// Check if "robots.txt" file exist |
| 88 |
if ( |
| 89 |
$wp_filesystem->exists( $file ) |
| 90 |
) { |
| 91 |
return $file; |
| 92 |
} |
| 93 |
|
| 94 |
// File not exist |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
function jltwp_adminify_robots_txt_file_content( $file ) { |
| 101 |
|
| 102 |
// Call wp file system |
| 103 |
global $wp_filesystem; |
| 104 |
WP_Filesystem(); |
| 105 |
|
| 106 |
// Show this notice, if no file exist |
| 107 |
$content = esc_html__( 'robots.txt file not found!', 'adminify' ); |
| 108 |
|
| 109 |
// Check if "robots.txt" file exist |
| 110 |
if ( $wp_filesystem->exists( $file ) ) { |
| 111 |
$content = $wp_filesystem->get_contents( $file ); |
| 112 |
|
| 113 |
// Check if the file content is empty |
| 114 |
if ( $wp_filesystem->get_contents( $file ) == '' ) { |
| 115 |
$content = esc_html__( 'File content is empty.', 'adminify' ); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
return $content; |
| 120 |
} |
| 121 |
} |
| 122 |
|