\n order deny,allow\n deny from all\n\n"; if ( $wp_filesystem->exists( $htaccess_file ) && $wp_filesystem->is_writable( $htaccess_file ) ) { $htaccess_content = $wp_filesystem->get_contents( $htaccess_file ); if ( strpos( $htaccess_content, 'xmlrpc.php' ) === false ) { $wp_filesystem->put_contents( $htaccess_file, $htaccess_code . $htaccess_content, FS_CHMOD_FILE ); } } } else { // If the switch is disabled, remove any xmlrpc.php block from .htaccess. $htaccess_file = ABSPATH . '.htaccess'; $htaccess_code = "\n order deny,allow\n deny from all\n\n"; if ( $wp_filesystem->exists( $htaccess_file ) && $wp_filesystem->is_writable( $htaccess_file ) ) { $htaccess_content = $wp_filesystem->get_contents( $htaccess_file ); $updated_content = str_replace( $htaccess_code, '', $htaccess_content ); $wp_filesystem->put_contents( $htaccess_file, $updated_content, FS_CHMOD_FILE ); } } } add_action( 'init', 'ns_shield_disable_xml_rpc' );