403Webshell
Server IP : 43.130.17.34  /  Your IP : 216.73.217.6
Web Server : nginx/1.28.0
System : Linux VM-4-12-opencloudos 6.6.92-34.1.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 21:32:13 CST 2025 x86_64
User : www ( 1000)
PHP Version : 8.0.26
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /www/wwwroot/yespkg.com/wp-content/plugins/mail-manager-wpforms/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/wwwroot/yespkg.com/wp-content/plugins/mail-manager-wpforms/admin/class-admin.php
<?php
/**
 * The admin-specific functionality of the plugin.
 *
 * @link       https://mmw.diviaccessories.com/
 * @since      1.0.0
 *
 * @package    mail-manager-wpforms
 * @subpackage mail-manager-wpforms/admin
 */

namespace MMWPF\Admin;

use MMWPF\Core\Notice;
use MMWPF\Admin\Form_List_Table;
use MMWPF\Admin\Form_Entries_Table;

/**
 * The admin-specific functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the admin-specific stylesheet and JavaScript.
 *
 * @package    mail-manager-wpforms
 * @subpackage mail-manager-wpforms/admin
 * @author     nishanmazumder<arosh019@gmail.com>
 */
class Admin {

	use \MMWPF\TRT\Trait_Manager;

	/**
	 * The ID of this plugin.
	 * Used on slug of plugin menu.
	 * Used on Root Div ID for React too.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $plugin_name    The ID of this plugin.
	 */
	private $plugin_name;

	/**
	 * The version of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $version    The current version of this plugin.
	 */
	private $version;

	/**
	 * Form ID
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      int $form_id Form ID.
	 */
	private $form_id;

	/**
	 * Entry ID
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      int $entry_id Entry ID.
	 */
	private $entry_id;

	/**
	 * Action
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      int $action Current Action.
	 */
	private $action;

	/**
	 * Notice
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      object $notice WP_Error object.
	 */
	private static $notice;

	/**
	 * Initialize the class and set its properties.
	 *
	 * @since    1.0.0
	 *
	 * @param array $action Current action.
	 * @param array $form_id Current form ID.
	 * @param array $entry_id Current entry ID.
	 */
	public function __construct( $action, $form_id, $entry_id ) {

		self::$notice = Notice::get_instance();
		self::mmwpf_database_int();

		$this->action   = $action;
		$this->form_id  = $form_id;
		$this->entry_id = $entry_id;

		// update entry status (unread to read).
		if ( isset( $this->entry_id ) && null !== $this->action && 'view' === $this->action ) {
			$entry_viewed = self::$db_instance->unreaded_single;

			if ( $entry_viewed( $this->entry_id ) ) {
				self::$notice->set_notice(
					'entry_viewed',
					__( 'Entry viewed!', 'mail-manager-wpforms' ),
					'success'
				);
			}
		}
	}

	/**
	 * Add Admin Page Menu page.
	 *
	 * @since    1.0.0
	 */
	public function add_mmwpf_admin_menu() {
		add_menu_page(
			esc_html__( 'Mail Manager', 'mail-manager-wpforms' ),
			esc_html__( 'Mail Manager', 'mail-manager-wpforms' ),
			'manage_options',
			'mail-manager-wpf',
			function () {
				// Show form list.
				$this->show_form_list();
				$this->show_form_entries();
				$this->show_form_entry();
			},
			'dashicons-media-spreadsheet'
		);

		add_submenu_page(
			'mail-manager-wpf',
			__( 'Settings', 'mail-manager-wpforms' ),
			__( 'Settings', 'mail-manager-wpforms' ),
			'manage_options',
			'mail-manager-wpf-settings',
			array( $this, 'add_submenu_settings_callback' )
		);
	}

	/**
	 * MAIL_MANAGER_WPF sub/settings page.
	 *
	 * @since    1.0.0
	 */
	public function add_submenu_settings_callback() {
		?>
		<div><h1>Settings</h1></div>
		<div id="mmwpf-admin-settings"></div>
		<?php
	}

	/**
	 * CSV Export
	 *
	 * @since  1.0.0
	 */
	public function export_csv() {
		global $wp_filesystem;

		if ( ! $wp_filesystem ) {
			require_once ABSPATH . 'wp-admin/includes/file.php';
			WP_Filesystem();
		}

		if ( ! WP_Filesystem( request_filesystem_credentials( site_url() ) ) ) {
			return self::$notice->set_notice(
				'wrong_file',
				__( 'Unable to connect filesystem!', 'mail-manager-wpforms' ),
				'error'
			);
		}

		$upload_dir = wp_upload_dir();
		$file_path  = $upload_dir['basedir'] . '/mmwpf_temp_data_' . uniqid() . '.csv';

		$data = self::$db_instance->csv_data;

		if ( empty( $data( $this->form_id ) ) ) {
			return self::$notice->set_notice(
				'no_data',
				__( 'No data available!', 'mail-manager-wpforms' ),
				'error'
			);
		}

		// Get and put CSV data.
		$csv_data   = $this->array_to_csv_conversion( $data( $this->form_id ) );
		$is_written = $wp_filesystem->put_contents( $file_path, $csv_data, FS_CHMOD_FILE );

		if ( $is_written ) {
			ob_clean();
			$filename = 'mmwpf_data_' . gmdate( 'Y-m-d_H-i-s' ) . '.csv';

			header( 'Content-Type: text/csv' );
			header( "Content-Disposition: attachment;filename={$filename}" );

			echo esc_html( $wp_filesystem->get_contents( $file_path ) );
			$wp_filesystem->delete( $file_path );
			exit;

		} else {
			return self::$notice->set_notice(
				'wrong_file',
				__( 'Could not write to the file.', 'mail-manager-wpforms' ),
				'error'
			);
		}
	}

	/**
	 * Array to CSV conversion
	 *
	 * @since  1.0.0
	 *
	 * @param array $data Array data.
	 *
	 * @return string
	 */
	public function array_to_csv_conversion( $data ) {
		$csv_data = '';
		$headers  = array();
		$rows     = array();

		foreach ( $data as $row ) {

			$sanitize_json_string = '';
			if ( is_string( $row['form_value'] ) ) {
				$sanitize_json_string = str_replace( array( '\r', '\n' ), ' - ', $row['form_value'] );
			}

			$form_values = json_decode( $sanitize_json_string, true );
			$per_entries = array();

			foreach ( $form_values as $value ) {

				if ( ! in_array( $value['name'], $headers, true ) ) {
					$headers[] = $value['name'];
				}

				$per_entries[ $value['name'] ] = $value['value'] ?? __( 'No data available!', 'mail-manager-wpforms' );
			}

			$rows[] = $per_entries;
		}

		// Add all header to CSV.
		$csv_data .= implode( ',', $headers ) . "\n";

		// Add all row data to CSV.
		foreach ( $rows as $row ) {
			$csv_rows = array();

			foreach ( $headers as $header ) {
				$csv_rows[] = $row[ $header ];
			}

			$csv_data .= implode( ',', $csv_rows ) . "\n";
		}

		return $csv_data;
	}

	/**
	 * Display form list
	 *
	 * @since  1.0.0
	 */
	public function show_form_list() {

		if ( ! class_exists( '\MMWPF\Admin\Form_List_Table' ) ) {
			return self::$notice->set_notice(
				'wrong_file',
				__( 'Class not found!', 'mail-manager-wpforms' ),
				'warning'
			);
		}

		if ( null !== $this->action ) {
			return;
		}

		$list_table = Form_List_Table::get_instance();
		$list_table->prepare_items();

		?>
		<div class="wrap mail-manager-wpforms-form-table">
			<h2><?php esc_html_e( 'Form List', 'mail-manager-wpforms' ); ?></h2>
		<?php $list_table->display(); ?>
		</div>
		<?php
	}

	/**
	 * Display Entries
	 *
	 * @return void
	 * @since  1.0.0
	 */
	public function show_form_entries() {
		$cases = array( '-1', 'entries', 'trashed', 'deleted', 'restored', 'bulk_trashed', 'bulk_unreaded', 'bulk_saved', 'bulk_deleted' );

		if ( ! in_array( $this->action, $cases, true ) ) {
			return;
		}

		if ( ! class_exists( '\MMWPF\Admin\Form_Entries_Table' ) ) {
			return self::$notice->set_notice(
				'wrong_file',
				__( 'Class not found!', 'mail-manager-wpforms' ),
				'warning'
			);
		}

		$table = Form_Entries_Table::get_instance();
		?>
		<div class="wrap mail-manager-wpforms-entries-table">
			<h2>
			<?php
				echo esc_html(
					sprintf(
						// Translators: %s is the name of form.
						__( 'Form Entries: %s', 'mail-manager-wpforms' ),
						get_the_title( $this->form_id )
					)
				);
			?>
			</h2>
			<form method="get">
				<input type="hidden" name="page" value="mail-manager-wpf">
				<input type="hidden" name="formId" value="<?php echo esc_attr( $this->form_id ); ?>">
			<?php
				$table->prepare_items();
				$table->before_extra_table_nav();
				$table->display();
			?>
			</form>
		</div>
		<?php
	}

	/**
	 * Display Entry
	 *
	 * @since  1.0.0
	 * @return void
	 */
	public function show_form_entry() {

		if ( 'view' !== $this->action ) {
			return;
		}

		?>
		<div class="wrap mmwpf-single-table-wrapper mail-manager-wpforms-form-table">
			<div class="mmwpf-single-table-header">
				<h2>
					<?php
					echo esc_html(
						sprintf(
						// Translators: %s is the name of form.
							__( 'Entry: %s', 'mail-manager-wpforms' ),
							get_the_title( $this->form_id )
						)
					);
					?>
				</h2>

				<a class="mmwpf-back-to-entries" href="<?php echo esc_url( admin_url( 'admin.php?page=mail-manager-wpf&action=entries&formId=' . $this->form_id ) ); ?>">
					<?php esc_html_e( ' &#8656; Back to entries', 'mail-manager-wpforms' ); ?>
				</a>
			</div>
		
			<table class="wp-list-table widefat striped mmwpf-single-table">
				<thead>
					<th>
						<?php esc_html_e( 'Form Fields', 'mail-manager-wpforms' ); ?>
					</th>
					<th>
						<?php esc_html_e( 'Form Data', 'mail-manager-wpforms' ); ?>
					</th>
				</thead>
				<tbody>

				<?php
				if ( is_array( self::$db_instance->single_data ) ) {
					foreach ( self::$db_instance->single_data as $value ) {
						?>
					<tr>
						<?php
						if ( is_array( $value ) ) {
							foreach ( $value as $key => $val ) {
								if ( 'name' === $key || 'value' === $key ) {
									?>
								<td> <?php echo esc_html( $val ); ?> </td> 
									<?php
								}
							}
						}
						?>
				</tr>
						<?php
					}
				}
				?>
				</tbody>
				<tfoot>
					<th>
						<?php esc_html_e( 'Form Fields', 'mail-manager-wpforms' ); ?>
					</th>
					<th>
						<?php esc_html_e( 'Form Data', 'mail-manager-wpforms' ); ?>
					</th>
				</tfoot>
			</table>
		</div>
		<?php
	}

	/**
	 * Get entries column name.
	 *
	 * @since    1.0.0
	 * @deprecated 1.1.2 Use get_forms_entries_columns_name() instead.
	 *
	 * @param array $columns Column name.
	 * @return array
	 */
	public function get_entries_column_name( $columns ) {

		if ( ! self::$db_instance->entry_data ) {
			return array( 'no data!' );
		}

		// just need first array for column name.
		$form_values = reset( self::$db_instance->entry_data );

		if ( ! $form_values ) {
			return array();
		}

		$static_columns = array(
			'cb'         => '<input type="checkbox" />',
			'id'         => __( 'ID', 'mail-manager-wpforms' ),
			'form_id'    => __( 'Form ID', 'mail-manager-wpforms' ),
			'form_value' => __( 'Description', 'mail-manager-wpforms' ),
			'status'     => __( 'Status', 'mail-manager-wpforms' ),
			'date'       => __( 'Date', 'mail-manager-wpforms' ),
			'action'     => __( 'Action', 'mail-manager-wpforms' ),
		);

		$new_columns = array();
		$columns     = array_merge_recursive( $static_columns, $columns );
		$form_values = json_decode( $form_values['form_value'] );

		foreach ( $columns as $key => $value ) {
			if ( 'form_value' === $key ) {
				foreach ( $form_values as $field ) {
					$trim_key = str_replace( ' ', '_', strtolower( $field->name ) );

					$new_columns[ $trim_key ] = $field->name;
				}
			} else {
				$new_columns[ $key ] = $value;
			}
		}

		return $new_columns;
	}

	/**
	 * Get entries column name.
	 *
	 * @since    1.1.2
	 *
	 * @param array $columns Column name.
	 * @return array
	 */
	public function get_forms_entries_columns_name( $columns ) {
		$new_columns = array();
		$form_fields = wpforms_get_form_fields( $this->form_id );

		$static_columns = array(
			'cb'         => '<input type="checkbox" />',
			'id'         => __( 'ID', 'mail-manager-wpforms' ),
			'form_id'    => __( 'Form ID', 'mail-manager-wpforms' ),
			'form_value' => __( 'Description', 'mail-manager-wpforms' ),
			'status'     => __( 'Status', 'mail-manager-wpforms' ),
			'date'       => __( 'Date', 'mail-manager-wpforms' ),
			'action'     => __( 'Action', 'mail-manager-wpforms' ),
		);

		$columns = array_merge_recursive( $static_columns, $columns );

		foreach ( $columns as $key => $value ) {
			if ( 'form_value' === $key ) {
				foreach ( $form_fields as $field ) {
					$trim_key                 = str_replace( ' ', '_', strtolower( $field['label'] ) );
					$new_columns[ $trim_key ] = $field['label'];
				}
			} else {
				$new_columns[ $key ] = $value;
			}
		}

		return $new_columns;
	}

	/**
	 * Set entries column name.
	 *
	 * @since    1.0.0
	 *
	 * @param array $columns Column name.
	 * @return array
	 */
	public function entries_column_name( $columns ) {
		return $this->get_forms_entries_columns_name( $columns );
	}

	/**
	 * Add entries action
	 *
	 * @since    1.0.0
	 *
	 * @param array $item Entry data.
	 * @return array
	 */
	public function mmwpf_add_entries_action( $item ) {
		$actions    = array();
		$get_filter = isset( $_GET['mmwpf_filter'] ) ? sanitize_key( wp_unslash( $_GET['mmwpf_filter'] ) ) : 'all';
		$nonce      = wp_create_nonce( 'wpf_entry_nonce_' . $item['id'] );

		$actions_raw = array(
			'view'     => __( 'View', 'mail-manager-wpforms' ),
			'trashed'  => __( 'Trash', 'mail-manager-wpforms' ),
			'deleted'  => __( 'Delete', 'mail-manager-wpforms' ),
			'restored' => __( 'Restore', 'mail-manager-wpforms' ),
		);

		if ( 'trashed' === $get_filter ) {
			array_splice( $actions_raw, 0, 2 );
		} else {
			array_splice( $actions_raw, 2 );
		}

		foreach ( $actions_raw as $key => $value ) {
			$actions[ $key ] = sprintf(
				'<a href="%s">%s</a>',
				add_query_arg(
					array(
						'action'   => $key,
						'eId'      => $item['id'],
						'_wpnonce' => $nonce,
					)
				),
				$value
			);
		}

		return $actions;
	}

	/**
	 * Process entries action
	 *
	 * @since  1.0.0
	 *
	 * @return mixed
	 */
	public function process_single_action() {
		// single entry delete.
		if ( $this->entry_id && $this->action
		&& property_exists( self::$db_instance, $this->action ) ) {
			$_nonce_key = isset( $_GET['_wpnonce'] ) ? sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ) : '';

			if ( $_nonce_key && ! wp_verify_nonce( $_nonce_key, 'wpf_entry_nonce_' . $this->entry_id ) ) {
				return self::$notice->set_notice(
					'nonce_verify',
					__( 'Nonce verification failed from single action!', 'mail-manager-wpforms' ),
					'error'
				);
			}

			$action_method = $this->action;
			$done_action   = self::$db_instance->$action_method ?? fn( $no_error ) => $no_error;
			if ( $done_action( $this->entry_id ) ) {
				// Translators: %s is the action name of entries.
				$message = sprintf( __( 'Entry %s successfully!', 'mail-manager-wpforms' ), $this->action );

				return self::$notice->set_notice(
					'single_action_message',
					$message,
					'success'
				);
			}
		}
	}

	/**
	 * Process bulk action
	 *
	 * @since  1.0.0
	 *
	 * @return mixed
	 */
	public function process_bulk_action() {

		$cases = array( 'bulk_trashed', 'bulk_unreaded', 'bulk_saved', 'bulk_deleted' );
		if ( $this->action && ! in_array( $this->action, $cases, true ) ) {
			return;
		}

		$_nonce_key = isset( $_GET['_wpnonce'] ) ? sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ) : '';
		if ( $_nonce_key && ! wp_verify_nonce( $_nonce_key, 'bulk-entries' ) ) {
			return self::$notice->set_notice(
				'nonce_verify',
				__( 'Nonce verification failed on bulk process!', 'mail-manager-wpforms' ),
				'error'
			);
		}

		$row_affected = 0;
		$delete_ids   = isset( $_GET['entries'] ) ? array_map( 'absint', $_GET['entries'] ) : array();

		if ( empty( $delete_ids ) ) {
			return;
		}

		$action_method = substr( $this->action, 5 ); // remove bulk_ from action.
		$bulk_action   = self::$db_instance->$action_method ?? fn( $no_error ) => $no_error;

		foreach ( $delete_ids as $id ) {
			if ( $bulk_action( $id ) ) {
				++$row_affected;
			}
		}

		if ( 0 < $row_affected ) {
			$message = sprintf(
			// Translators: %d is the action of entries.
				__( '%1$s Entries %2$s successfully!', 'mail-manager-wpforms' ),
				$row_affected,
				$action_method
			);

			return self::$notice->set_notice(
				'bulk_action_message',
				$message,
				'success'
			);

		}
	}

	/**
	 * Add custom screen options
	 *
	 * @since    1.0.0
	 *
	 * @param string $screen_settings Screen settings.
	 *
	 * @return string
	 */
	public function add_screen_options_for_entries( $screen_settings ) {
		// Display entries.
		add_screen_option(
			'per_page',
			array(
				'label'   => 'Show entries',
				'default' => 10,
				'option'  => 'entries_table_per_page_' . $this->form_id,
			)
		);

		// Display Columns.
		$columns = $this->get_entries_column_name( array() );

		if ( ! $columns ) {
			return $screen_settings;
		}

		unset( $columns['cb'], $columns['id'], $columns['form_id'], $columns['action'] );

		$selected_columns = get_user_meta( get_current_user_id(), 'mmwpf_entries_columns_' . $this->form_id );
		$default_checked  = isset( $selected_columns[0] ) && ! empty( $selected_columns[0] );

		// save default column.
		if ( ! $default_checked ) {
			$default_columns = array_slice( array_keys( $columns ), 0, 2 );
			update_user_meta( get_current_user_id(), 'mmwpf_entries_columns_' . $this->form_id, $default_columns );
		}

		$checkboxes = '<fieldset style="display: flex; flex-wrap: wrap;"><legend>' . __( 'Show Columns', 'mail-manager-wpforms' ) . '</legend>';

		$i = 0;
		foreach ( $columns as $key => $label ) {

			$checked = '';

			if ( ! $default_checked ) {
				if ( 2 > $i ) {
					$checked = 'checked';
					++$i;
				}
			} else {
				$checked = in_array( $key, $selected_columns[0], true ) ? 'checked' : '';
			}

			$checkboxes .= sprintf(
				'<label for="%1$s"> <input type="checkbox" name="mmwpf_column_checkbox[%1$s]" id="mmwpf_%1$s" value="1" %2$s /> %3$s </label><br />',
				esc_attr( $key ),
				esc_attr( $checked ),
				esc_html( $label )
			);
		}

		$checkboxes .= '</fieldset>';

		return $screen_settings . $checkboxes;
	}

	/**
	 * Set Screen options
	 *
	 * @since  1.0.0
	 *
	 * @return void
	 */
	public function save_screen_options_for_entries() {
		if ( filter_has_var( INPUT_POST, 'screen-options-apply' )
				&& check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ) ) {

			$wp_screen_options = array();
			if ( isset( $_POST['wp_screen_options'] ) ) {
				$wp_screen_options = array_map( 'sanitize_text_field', wp_unslash( $_POST['wp_screen_options'] ) );
			}

			// update pagination.
			$entries_per_page = 'entries_table_per_page_' . $this->form_id;
			if ( $wp_screen_options && isset( $wp_screen_options['option'] )
					&& $wp_screen_options['option'] === $entries_per_page ) {
				update_user_meta( get_current_user_id(), 'entries_table_per_page_' . $this->form_id, (int) $wp_screen_options['value'] );
			}

			// update column checkbox.
			if ( isset( $_POST['mmwpf_column_checkbox'] ) ) {
				$selected    = array_map( 'sanitize_key', wp_unslash( $_POST['mmwpf_column_checkbox'] ) );
				$columns     = $this->get_entries_column_name( array() );
				$form_fields = array_intersect( array_keys( $columns ), array_keys( $selected ) );

				update_user_meta( get_current_user_id(), 'mmwpf_entries_columns_' . $this->form_id, $form_fields );
			}
		}
	}

	/**
	 * Save Entry Data.
	 *
	 * @since    1.0.0
	 *
	 * @return mixed
	 */
	public function mmwpf_save_entry() {

		check_ajax_referer( 'mmwpf_nonce', 'nonce' );

		$entry_id = isset( $_POST['entry_id'] ) ? absint( $_POST['entry_id'] ) : null;
		if ( null === $entry_id ) {
			wp_send_json_error( array( 'message' => 'Invalid data ID.' ) );
			return;
		}

		$update = self::$db_instance->saved_by_ajax ?? fn( $no_error ) => $no_error;

		if ( $update( $entry_id ) ) {
			wp_send_json_success(
				array(
					'message' => __( 'Entry saved successfully.', 'mail-manager-wpforms' ),
					'id'      => $entry_id,
				)
			);

			return;
		}

		wp_send_json_error(
			array(
				'message' => __( 'Database update failed.', 'mail-manager-wpforms' ),
			)
		);
	}

	/**
	 * Form data insert
	 *
	 * @param  array $fields Sanitized entry field values/properties.
	 * @param  array $entry Original $_POST global.
	 * @param  int   $form_id Form ID.
	 *
	 * @since  1.0.0
	 */
	public function mail_manager_wpf_insert( $fields, $entry, $form_id ) {
		if ( ! $fields ) {
			return self::$notice->set_notice(
				'wrong_file',
				__( 'Form entries not found!', 'mail-manager-wpforms' ),
				'warning'
			);
		}

		self::$db_instance->db->insert(
			self::$db_instance->table,
			array(
				'form_id'    => $form_id,
				'save'       => 0,
				'form_value' => wp_json_encode( $fields ),
				'status'     => 0,
				'date'       => current_time( 'mysql' ),
			)
		);
	}

	/**
	 * Enables rest api for forms.
	 *
	 * @since  1.0.0
	 *
	 * @return void
	 */
	public function register_route_for_forms_data() {
		register_rest_route(
			'wp/v2',
			'/mmwpf-forms-data/',
			array(
				'methods'             => 'GET',
				'callback'            => array( $this, 'callback_get_wpforms_data' ),
				'permission_callback' => function () {
					return is_user_logged_in() && current_user_can( 'manage_options' );
				},
			)
		);
	}

	/**
	 * Get forms data.
	 *
	 * @since  1.0.0
	 *
	 * @return object
	 */
	public function callback_get_wpforms_data() {
		$data = array();

		$forms = get_posts(
			array(
				'post_type' => 'wpforms',
				'order'     => 'ASC',
			)
		);

		foreach ( $forms as $form ) {
			$data[] = array(
				'id'    => $form->ID,
				'title' => $form->post_title,
				'slug'  => $form->post_name,
			);
		}

		return new \WP_REST_Response( $data, 200 );
	}

	/**
	 * Redirection on current page.
	 *
	 * @since  1.0.0
	 *
	 * @return void
	 */
	public function redirect_current() {
		wp_safe_redirect(
			add_query_arg(
				array(
					'action' => 'entries',
					'formId' => $this->form_id,
				),
				admin_url( 'admin.php?page=mail-manager-wpf' )
			)
		);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit