HEX
Server: LiteSpeed
System: Linux baciro.idweb.host 4.18.0-553.5.1.lve.1.el8.x86_64 #1 SMP Fri Jun 14 15:38:45 UTC 2024 x86_64
User: yastidua (1245)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/yastidua/httpdocs/wp-content/plugins/jetformbuilder/includes/form-actions/get-form-data.php
<?php


namespace Jet_Form_Builder\Form_Actions;

trait Get_Form_Data {

	/**
	 * Get post ID from the current request and validate user acess to this post
	 *
	 * @return [type] [description]
	 */
	public function get_post_id_from_request() {

		$post_id = ! empty( $_GET['post'] ) ? absint( $_GET['post'] ) : false;

		if ( ! $post_id ) {
			wp_die( 'Form ID not found in the request', 'Error!' );
		}

		if ( ! $this->check_user_access( $post_id ) ) {
			wp_die( 'You haven`t access to this form', 'Error!' );
		}

		return $post_id;

	}

	/**
	 * Returns from data by ID
	 *
	 * @param  [type] $form_id [description]
	 *
	 * @return [type]          [description]
	 */
	public function get_from_data( $form_id ) {
		$post       = get_post( $form_id );
		$meta_value = $this->parse_meta_value(
			get_post_meta( $form_id ),
			array( '_edit_lock' )
		);

		$for_encoding = $this->parse_form_data(
			array(
				'post_title'   => $post->post_title,
				'post_content' => $post->post_content,
				'meta_input'   => $meta_value,
			)
		);

		return array( $post, $for_encoding );
	}

	public function parse_form_data( $data ) {
		return $data;
	}

	private function parse_meta_value( $meta, $exclude = array() ) {
		$response = array();

		foreach ( $meta as $key => $value ) {
			if ( in_array( $key, $exclude ) ) {
				continue;
			}
			$response[ $key ] = $value[0];
		}

		return $response;
	}
}