<commit_before><?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Papi Admin Post Handler.
 *
 * @package Papi
 */

class Papi_Admin_Post_Handler extends Papi_Admin_Data_Handler {

	/**
	 * The constructor.
	 */

	public function __construct() {
		$this->setup_actions();
	}

	/**
	 * Setup actions.
	 *
	 * @todo Try to get this working
	 */

	private function setup_actions() {
		add_action( 'save_post', [$this, 'save_meta_boxes'], 1, 2 );
	}

	/**
	 * Pre save page template and page type.
	 *
	 * @param int $post_id
	 */

	private function pre_save( $post_id ) {
		// Can't proceed without a post id.
		if ( empty( $post_id ) ) {
			return;
		}

		$data = $this->get_pre_data();

		foreach ( $data as $key => $value ) {
			if ( empty( $value ) ) {
				continue;
			}

			update_post_meta( $post_id, $key, $value );
		}
	}

	/**
	 * Save meta boxes.
	 *
	 * @param int $post_id
	 * @param object $post
	 */

	public function save_meta_boxes( $post_id, $post ) {
		// Can't proceed without a post id or post.
		if ( empty( $post_id ) || empty( $post ) ) {
			return;
		}

		// Don't save meta boxes for revisions or autosaves
		if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
			return;
		}

		// Check if our nonce is vailed.
		if ( ! wp_verify_nonce( papi_get_sanitized_post( 'papi_meta_nonce' ), 'papi_save_data' ) ) {
			return;
		}

		// Check the post being saved has the same id as the post id. This will prevent other save post events.
		if ( papi_get_sanitized_post( 'post_ID' ) != strval( $post_id ) ) {
			return;
		}

		// Check for any of the capabilities before we save the code.
		if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( 'edit_pages' ) ) {
			return;
		}

		$this->save_property( $post_id );
	}

	/**
	 * Save property and property type.
	 *
	 * @param int $post_id<commit_msg>Check save post events before nonce<commit_after><?php

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Papi Admin Post Handler.
 *
 * @package Papi
 */

class Papi_Admin_Post_Handler extends Papi_Admin_Data_Handler {

	/**
	 * The constructor.
	 */

	public function __construct() {
		$this->setup_actions();
	}

	/**
	 * Setup actions.
	 *
	 * @todo Try to get this working
	 */

	private function setup_actions() {
		add_action( 'save_post', [$this, 'save_meta_boxes'], 1, 2 );
	}

	/**
	 * Pre save page template and page type.
	 *
	 * @param int $post_id
	 */

	private function pre_save( $post_id ) {
		// Can't proceed without a post id.
		if ( empty( $post_id ) ) {
			return;
		}

		$data = $this->get_pre_data();

		foreach ( $data as $key => $value ) {
			if ( empty( $value ) ) {
				continue;
			}

			update_post_meta( $post_id, $key, $value );
		}
	}

	/**
	 * Save meta boxes.
	 *
	 * @param int $post_id
	 * @param object $post
	 */

	public function save_meta_boxes( $post_id, $post ) {
		// Can't proceed without a post id or post.
		if ( empty( $post_id ) || empty( $post ) ) {
			return;
		}

		// Don't save meta boxes for revisions or autosaves
		if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
			return;
		}

		// Check the post being saved has the same id as the post id. This will prevent other save post events.
		if ( papi_get_sanitized_post( 'post_ID' ) != strval( $post_id ) ) {
			return;
		}

		// Check if our nonce is vailed.
		if ( ! wp_verify_nonce( papi_get_sanitized_post( 'papi_meta_nonce' ), 'papi_save_data' ) ) {
			return;
		}

		// Check for any of the capabilities before we save the code.
		if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( 'edit_pages' ) ) {
			return;
		}

		$this->save_property( $post_id );
	}

	/**
	 * Save property and property type.
	 *
	 * @param int $post_id
{'fraction_non_alphanumeric': 0.13862928348909656, 'fraction_numerical': 0.0010384215991692627, 'mean_word_length': 2.9077079107505073, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6124152', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1378, 'n_words': 386}