<commit_before><?php

require_once( AMP__DIR__ . '/includes/utils/class-amp-html-utils.php' );

class Analytics_Options_Serializer {

	public static function save() {

		// Request must come from user with right capabilities
		if ( ! current_user_can( 'administrator' ) ) {
			wp_die( 'Sorry, you do not have the necessary permissions to perform this action' );
		}

		// Ensure request is coming from analytics option form
		check_admin_referer( 'analytics-options', 'analytics-options' );

		$option_name = 'amp-analytics';

		// Check conditions and proceed if correct
		if ( ! ( empty( $_POST['vendor-type'] ) || empty( $_POST['config'] ) ) &&
				AMP_HTML_Utils::valid_json( stripslashes($_POST['config'] ) ) ) {

			if ( empty( $_POST['id-value'] ) ) {
				$_POST['id-value'] = md5( $_POST['config'] );
			}

			// Prepare the data for the new analytics setting
			$new_analytics_option = array(
				$_POST['id-value'],
				sanitize_key($_POST['vendor-type']),
				stripslashes( $_POST['config'] )
			);
			// Identifier for analytics option
			$inner_option_name = sanitize_key($_POST['vendor-type'] . '-' . $_POST['id-value'] );

			// Grab the amp_options from the DB
			$amp_options = get_option( 'amp-options' );
			if ( ! $amp_options ) {<commit_msg>Wrap safety checks around if_admin() to enable tests<commit_after><?php

require_once( AMP__DIR__ . '/includes/utils/class-amp-html-utils.php' );

class Analytics_Options_Serializer {

	public static function save() {

		if ( is_admin() ) {
			// Request must come from user with right capabilities
			if ( ! current_user_can( 'administrator' ) ) {
				wp_die( 'Sorry, you do not have the necessary permissions to perform this action' );
			}
			// Ensure request is coming from analytics option form
			check_admin_referer( 'analytics-options', 'analytics-options' );
		}

		$option_name = 'amp-analytics';

		// Check save/delete pre-conditions and proceed if correct
		if ( ! ( empty( $_POST['vendor-type'] ) || empty( $_POST['config'] ) ) &&
				AMP_HTML_Utils::valid_json( stripslashes($_POST['config'] ) ) ) {

			if ( empty( $_POST['id-value'] ) ) {
				$_POST['id-value'] = md5( $_POST['config'] );
			}

			// Prepare the data for the new analytics setting
			$new_analytics_option = array(
				$_POST['id-value'],
				sanitize_key($_POST['vendor-type']),
				stripslashes( $_POST['config'] )
			);
			// Identifier for analytics option
			$inner_option_name = sanitize_key($_POST['vendor-type'] . '-' . $_POST['id-value'] );

			// Grab the amp_options from the DB
			$amp_options = get_option( 'amp-options' );
			if ( ! $amp_options ) {
{'fraction_non_alphanumeric': 0.15019157088122606, 'fraction_numerical': 0.0007662835249042146, 'mean_word_length': 3.7300724637681157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404079', 'n_tokens_mistral': 936, 'n_tokens_neox': 822, 'n_words': 206}