PHP 7.4.33
Preview: settings-robots-txt-field.php Size: 2.05 KB
/home/zcziejy/ryadselyen/parts/settings-robots-txt-field.php
<?php
	// Exits if accessed directly.
	if ( ! defined( 'ABSPATH' ) ) exit;

	// Default values.
	$robots_txt_content     = '';
	$robots_txt_placeholder = '';

	// Sets robots.txt path.
	$robots_txt_path = home_url( 'robots.txt' );

	if ( YMFSEO_Checker::is_subdir_multisite() ) {
		$robots_txt_path = get_home_url( get_main_site_id(), 'robots.txt' );
	}

	// Gets robots.txt content.
	$response = wp_remote_get( $robots_txt_path );

	if ( is_wp_error ( $response ) || $response[ 'response' ][ 'code' ] != 200 ) {
		$robots_txt_placeholder = sprintf(
			/* translators: %s: robots.txt */
			__( 'Error loading the %s file', 'ym-fast-seo' ),
			'robots.txt',
		);
	} else {
		$robots_txt_content = wp_remote_retrieve_body( $response );
	}

	printf( '<textarea name="%1$s" id="%1$s" class="code" rows="8" cols="50" placeholder="%2$s" %3$s>%4$s</textarea>',
		esc_attr( $args[ 'label_for' ] ),
		esc_attr( $robots_txt_placeholder ),
		( YMFSEO_Checker::is_subdir_multisite() && ! is_main_site() ) ? 'readonly' : '',
		esc_textarea( $robots_txt_content ),
	);

	if ( is_main_site() ) {	
		printf(
			'<p class="description">%s</p>',
			esc_html__( 'To restore the default value, clear this field and save.', 'ym-fast-seo' ),
		);
	}

	if ( YMFSEO_Checker::is_subdir_multisite() ) {
		printf(
			'<p class="description">%s</p>',
			wp_kses_post(
				sprintf(
					/* translators: %s: robots.txt */
					__( 'A network of sites using the subdirectory structure shares a single %s file.', 'ym-fast-seo' ),
					'<code>robots.txt</code>',
				)
			),
		);
		
		if ( ! is_main_site() ) {
			printf(
				'<p class="description">%s</p>',
				wp_kses_post(
					sprintf(
						/* translators: %s: robots.txt */
						__( 'You can edit the %s file only on the main site.', 'ym-fast-seo' ),
						'<code>robots.txt</code>',
					)
				),
			);
		}
	}
?>

<?php if ( is_main_site() ) : ?>
	<script>
		jQuery( function( $ ) {
			wp.codeEditor.initialize( '<?php echo esc_html( $args[ 'label_for' ] ); ?>', {} );
		});
	</script>
<?php endif; ?>

Directory Contents

Dirs: 0 × Files: 16
Name Size Perms Modified Actions
420 B lrw-r--r-- 2026-01-09 04:01:53
Edit Download
836 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
5.27 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
3.95 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
602 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
3.82 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
1.17 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
2.88 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
2.05 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
188 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
1009 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
704 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
680 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
722 B lrw-r--r-- 2025-12-25 08:41:39
Edit Download
3.00 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
1.97 KB lrw-r--r-- 2025-12-25 08:41:39
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).