Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
<?php
/**
* The robots.txt editor module.
*
* @since 0.9.0
* @package RankMath
* @subpackage RankMath
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath;
use RankMath\KB;
use RankMath\Helper;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Arr;
defined( 'ABSPATH' ) || exit;
/**
* Robots_Txt class.
*/
class Robots_Txt {
use Hooker;
/**
* Class constructor.
*/
public function __construct() {
if ( is_super_admin() ) {
$this->filter( 'rank_math/settings/general', 'add_settings' );
}
// Custom robots text.
if ( ! is_admin() && Helper::get_settings( 'general.robots_txt_content' ) ) {
$this->action( 'robots_txt', 'robots_txt', 10, 2 );
}
}
/**
* Replace robots.txt content.
*
* @param string $content Robots.txt file content.
* @param bool $public Whether the site is considered "public".
*
* @return string New robots.txt content.
*/
public function robots_txt( $content, $public ) {
return 0 === absint( $public ) ? $content : Helper::get_settings( 'general.robots_txt_content' );
}
/**
* Add module settings into general optional panel.
*
* @param array $tabs Array of option panel tabs.
*
* @return array
*/
public function add_settings( $tabs ) {
Arr::insert(
$tabs,
[
'robots' => [
'icon' => 'rm-icon rm-icon-robots',
'title' => esc_html__( 'Edit robots.txt', 'rank-math' ),
/* translators: Link to kb article */
'desc' => sprintf( esc_html__( 'Edit your robots.txt file to control what bots see. %s.', 'rank-math' ), '<a href="' . KB::get( 'edit-robotstxt', 'Options Panel Robots Tab' ) . '" target="_blank">' . esc_html__( 'Learn more', 'rank-math' ) . '</a>' ),
'file' => dirname( __FILE__ ) . '/options.php',
'classes' => 'rank-math-advanced-option',
'after_row' => '<div class="rank-math-desc">' . __( 'Leave the field empty to let WordPress handle the contents dynamically. If an actual robots.txt file is present in the root folder of your site, this option won\'t take effect and you have to edit the file directly, or delete it and then edit from here.', 'rank-math' ) . '</div>',
],
],
5
);
return $tabs;
}
/**
* Get robots.txt related data: whether the file exists, the contents
* of the file, and the "Search engine visibility" setting for the site.
*
* @return array
*/
public static function get_robots_data() {
$wp_filesystem = Helper::get_filesystem();
$public = absint( get_option( 'blog_public' ) );
$default = '# This file is automatically added by Rank Math SEO plugin to help a website index better';
$default .= "\n# More info: " . KB::get( 'seo-suite', 'Robots' ) . "\n";
$default .= "User-Agent: *\n";
if ( 0 === $public ) {
$default .= "Disallow: /\n";
} else {
$default .= "Disallow: /wp-admin/\n";
$default .= "Allow: /wp-admin/admin-ajax.php\n";
}
$default = apply_filters( 'robots_txt', $default, $public );
if ( empty( $wp_filesystem ) || ! Helper::is_filesystem_direct() ) {
return [
'exists' => false,
'default' => $default,
'public' => $public,
'writable' => false,
];
}
if ( $wp_filesystem->exists( ABSPATH . 'robots.txt' ) ) {
return [
'exists' => true,
'default' => $wp_filesystem->get_contents( ABSPATH . 'robots.txt' ),
'public' => $public,
];
}
return [
'exists' => false,
'default' => $default,
'public' => $public,
];
}
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden.

View File

@@ -0,0 +1,86 @@
<?php
/**
* The robots.txt settings.
*
* @package RankMath
* @subpackage RankMath\Settings
*/
use RankMath\Robots_Txt;
use RankMath\Helper;
defined( 'ABSPATH' ) || exit;
$data = Robots_Txt::get_robots_data();
$attributes = [ 'data-gramm' => 'false' ];
$desc = '';
if ( $data['exists'] ) {
$attributes['readonly'] = 'readonly';
$attributes['value'] = $data['default'];
$desc = esc_html__( 'Contents are locked because a robots.txt file is present in the root folder.', 'rank-math' );
} else {
$attributes['placeholder'] = $data['default'];
}
if ( isset( $data['writable'] ) && false === $data['writable'] ) {
$attributes['placeholder'] = $data['default'];
$desc = esc_html__( 'Rank Math could not detect if a robots.txt file exists or not because of a filesystem issue. The file contents entered here may not be applied.', 'rank-math' );
unset( $attributes['readonly'], $attributes['value'] );
}
if ( 0 === $data['public'] ) {
$attributes['readonly'] = 'readonly';
}
if ( ! Helper::is_edit_allowed() ) {
$cmb->add_field(
[
'id' => 'edit_disabled',
'type' => 'notice',
'what' => 'error',
'content' => __( 'robots.txt file is not writable.', 'rank-math' ),
]
);
$attributes['disabled'] = 'disabled';
}
$cmb->add_field(
[
'id' => 'robots_txt_content',
'type' => 'textarea',
'attributes' => $attributes,
'classes' => 'nob rank-math-code-box',
'sanitization_cb' => [ '\RankMath\CMB2', 'sanitize_robots_text' ],
]
);
if ( $desc ) {
$cmb->add_field(
[
'id' => 'robots_locked',
'type' => 'notice',
'what' => 'warning',
'classes' => 'nob nopt rank-math-notice',
'content' => wp_kses_post( $desc ),
]
);
return;
} elseif ( 0 === $data['public'] ) {
$cmb->add_field(
[
'id' => 'site_not_public',
'type' => 'notice',
'what' => 'warning',
'classes' => 'nob nopt rank-math-notice',
'content' => wp_kses_post(
sprintf(
// Translators: placeholder is the Settings page URL.
__( '<strong>Warning:</strong> your site\'s search engine visibility is set to Hidden in <a href="%1$s" target="_blank">Settings &gt; Reading</a>. This means that the changes you make here will not take effect. Set the search engine visibility to Public to be able to change the robots.txt content.', 'rank-math' ),
admin_url( 'options-reading.php' )
)
),
]
);
return;
}