<?php
/**
 * Constellation Client Portal Wizards
 *
 * Core settings related functionality.
 *
 * @package    ARS_Constellation_Client_Portal
 * @subpackage ARS_Constellation_Client_Portal/admin
 * @author     Adrian Rodriguez
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Constellation Client Portal Wizards Class
 */
class ARS_Constellation_Client_Portal_Wizards {

	/**
	 * Plugin utility functions.
	 *
	 * @access   private
	 * @var      object   $utilities    Plugin utility functions class.
	 */
	private $utilities;

	/**
	 * Plugin admin functions.
	 *
	 * @access   private
	 * @var      object   $accp_admin    Plugin admin functions class.
	 */
	private $accp_admin;

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

	/**
	 * Plugin name.
	 *
	 * @access   private
	 * @var      string   $plugin_name    The plugin name.
	 */
	private $plugin_name;

	/**
	 * Plugin settings class.
	 *
	 * @access   private
	 * @var      object   $accp_admin    Plugin admin functions class.
	 */
	private $core_settings;

	/**
	 * The class construct.
	 */
	public function __construct() {

		$this->utilities     = new ACCP_Utility_Functions();
		$this->accp_admin    = new ARS_Constellation_Client_Portal_Admin( ACCP_PLUGIN_NAME, ACCP_PLUGIN_VERSION );
		$this->plugin_name   = ACCP_PLUGIN_NAME;
		$this->version       = ACCP_PLUGIN_VERSION;
		$this->core_settings = new ARS_Constellation_Client_Portal_Settings();

		/**
		 * Add plugin install wizard admin menu pages.
		 */
		add_action( 'admin_menu', array( $this, 'add_plugin_install_wizard_pages_to_wp_admin' ) );

		/**
		 * Add company onboard wizard admin menu pages.
		 */
		add_action( 'admin_menu', array( $this, 'add_company_onboard_wizard_pages_to_wp_admin' ) );

		/**
		 * Update defined wizard pages for the company onboard wizard.
		 */
		add_action( 'admin_init', array( $this, 'update_defined_pages_for_company_onboard_wizard' ) );

		/**
		 * Add body class to plugin activation wizard pages.
		 */
		add_action( 'admin_init', array( $this, 'add_body_class_to_activation_wizard_admin_pages' ) );

		/**
		 * Add a class to the html element on activation wizard pages.
		 */
		add_action( 'admin_head', array( $this, 'add_html_class_to_activation_wizard_admin_pages' ) );

		/**
		 * Enqueue scripts on wizard pages.
		 */
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_on_activation_wizard_admin_pages' ) );

		/**
		 * Wizard - Add new company via AJAX.
		 */
		add_action( 'wp_ajax_wizard_add_company_via_ajax', array( $this, 'wizard_add_company_via_ajax' ) );

		/**
		 * Wizard - Add new company via AJAX.
		 */
		add_action( 'wp_ajax_wizard_add_company_home_page_via_ajax', array( $this, 'wizard_add_company_home_page_via_ajax' ) );

		/**
		 * Wizard - Generate sample content ajax function.
		 */
		add_action( 'wp_ajax_accp_generate_sample_content_ajax', array( $this, 'accp_generate_sample_content_ajax' ) );
	}


	/**
	 * Add a body class to wizard pages.
	 */
	public function add_body_class_to_activation_wizard_admin_pages() {

		if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) || ! is_admin() ) {
			return;
		}

		$defined_pages = $this->get_plugin_activation_defined_wizard_pages();

		if ( ! $defined_pages || empty( $defined_pages ) || ! is_array( $defined_pages ) ) {
			return;
		}

		$url_title_raw = filter_input( INPUT_GET, 'page' );

		if ( ! isset( $url_title_raw ) ) {
			return;
		}

		foreach ( $defined_pages as $slug => $wizard_page ) {

			if ( $url_title_raw === $slug ) {

				add_filter( 'admin_body_class', array( $this, 'get_admin_fullscreen_class' ) );

				break;

			}
		}
	}


	/**
	 * Enqueue wizard scripts.
	 */
	public function enqueue_scripts_on_activation_wizard_admin_pages() {

		if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) || ! is_admin() ) {
			return;
		}

		$defined_pages = $this->get_plugin_activation_defined_wizard_pages();

		if ( ! $defined_pages || empty( $defined_pages ) || ! is_array( $defined_pages ) ) {
			return;
		}

		/**
		 * Allow scripts to be enqueued on additional
		 * non-wizard pages.
		 */
		$additional_page_slugs = array(
			'accp-help-settings',
		);

		$url_title_raw = filter_input( INPUT_GET, 'page' );

		if ( ! isset( $url_title_raw ) ) {
			return;
		}

		foreach ( $defined_pages as $slug => $wizard_page ) {

			if ( $url_title_raw === $slug || in_array( $url_title_raw, $additional_page_slugs, true ) ) {

				wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ars-constellation-client-portal-admin-wizard.js', array( 'jquery' ), $this->version, false );

				break;

			}
		}
	}


	/**
	 * Add a class to the html element on wizard pages.
	 */
	public function add_html_class_to_activation_wizard_admin_pages() {

		if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) || ! is_admin() ) {
			return;
		}

		$defined_pages = $this->get_plugin_activation_defined_wizard_pages();

		if ( ! $defined_pages || empty( $defined_pages ) || ! is_array( $defined_pages ) ) {
			return;
		}

		$url_title_raw = filter_input( INPUT_GET, 'page' );

		if ( ! isset( $url_title_raw ) ) {
			return;
		}

		foreach ( $defined_pages as $slug => $wizard_page ) {

			if ( $url_title_raw === $slug ) {

				?>
				<script type="text/javascript">

					$html_elem = document.querySelector('html.wp-toolbar');

					$html_elem.classList.add('accp-wizard-html-container');

				</script>
				<?php

				break;

			}
		}
	}


	/**
	 * Get the plugin wizard admin fullscreen class.
	 *
	 * @param string $classes - A space separated string of body class names.
	 */
	public function get_admin_fullscreen_class( $classes ) {

		$classes .= ' accp-wizard-admin-full-screen';

		return $classes;
	}


	/**
	 * Define the wizard pages.
	 *
	 * @return array $wizard_pages - Array of settings pages.
	 */
	public function get_plugin_activation_defined_wizard_pages() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$page_list = array(
			'accp-plugin-activation-wizard' => __( 'Initial Set Up', 'constellation-client-portal' ),
		);

		$page_list['accp-wizard-add-company']              = __( 'Add Company', 'constellation-client-portal' );
		$page_list['accp-wizard-add-company-home-page']    = __( 'Add Company Home Page', 'constellation-client-portal' );
		$page_list['accp-wizard-add-company-primary-user'] = __( 'Add Primary User', 'constellation-client-portal' );
		$page_list['accp-wizard-complete-page']            = __( 'Finish', 'constellation-client-portal' );

		/**
		 * Add the remaning Core menu items.
		 */
		$page_list = apply_filters( 'accp_update_defined_plugin_install_wizard_pages', $page_list );

		/**
		 * Generate an array containing the page URL
		 * using the simple page_list array.
		 */
		$wizard_pages = array();

		foreach ( $page_list as $slug => $label ) {

			if ( $slug && $label && ! empty( $slug ) && ! empty( $slug ) ) {

				$wizard_pages[ $slug ] = $this->core_settings->genarate_settings_page_item_array( $slug, $label );

			}
		}

		return $wizard_pages;
	}


	/**
	 * Add the wizard pages to WP Admin.
	 */
	public function add_plugin_install_wizard_pages_to_wp_admin() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$defined_wizard_pages = $this->get_plugin_activation_defined_wizard_pages();

		if ( ! $defined_wizard_pages || empty( $defined_wizard_pages ) ) {
			return;
		}

		$this->add_accp_wizard_pages_to_wp_admin( $defined_wizard_pages );
	}


	/**
	 * Add the company onboard wizard pages to WP Admin.
	 */
	public function add_company_onboard_wizard_pages_to_wp_admin() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$page_list = array(
			'accp-company-onboard-wizard' => __( 'Onboard a Company', 'constellation-client-portal' ),
		);

		/**
		 * Generate an array containing the page URL
		 * using the simple page_list array.
		 */
		$defined_wizard_pages = array();

		foreach ( $page_list as $slug => $label ) {

			if ( $slug && $label && ! empty( $slug ) && ! empty( $slug ) ) {

				$defined_wizard_pages[ $slug ] = $this->core_settings->genarate_settings_page_item_array( $slug, $label );

			}
		}

		if ( ! $defined_wizard_pages || empty( $defined_wizard_pages ) ) {
			return;
		}

		$this->add_accp_wizard_pages_to_wp_admin( $defined_wizard_pages );
	}


	/**
	 * Add the wizard pages to WP Admin.
	 *
	 * @param array $defined_wizard_pages - The array of defined wizard pages.
	 */
	public function add_accp_wizard_pages_to_wp_admin( $defined_wizard_pages ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		if ( ! $defined_wizard_pages || empty( $defined_wizard_pages ) || ! is_array( $defined_wizard_pages ) ) {
			return;
		}

		foreach ( $defined_wizard_pages as $slug => $wizard_page ) {

			$label = $wizard_page[ $slug ]['label'];

			add_submenu_page(
				' ', // Set to empty (not NULL) to hide in the WP Admin menu.
				$label,
				$label,
				'manage_options',
				$slug,
				array( $this, $wizard_page[ $slug ]['callback'] ),
			);

		}
	}


	/**
	 * Generate the settings page html for all settings pages.
	 *
	 * @param string $page_content - The html of all sections to be included in the settings page.
	 * @param bool   $form_wrap - Whether to wrap the settings in a form tag.  Defaults to true.
	 * @param bool   $submit_button - Whether to include the form submit button on the settings page. Defaults to true.
	 * @param string $form_action - "options.php" or empty.  Defaults to empty.
	 * @param string $instantiate_wp_settings - Include the settings name to run settings_fields() and do_settings_sections().  Defaults to empty.
	 */
	public function generate_wizard_page_html( $page_content, $form_wrap = true, $submit_button = true, $form_action = '', $instantiate_wp_settings = '' ) {

		/**
		 * Calculate the current step and total steps
		 * for the status bar.
		 */
		$defined_pages = $this->get_plugin_activation_defined_wizard_pages();
		$current_step  = 0;
		$total_steps   = 0;

		if ( $defined_pages && is_array( $defined_pages ) && ! empty( $defined_pages ) ) {

			$total_steps   = count( $defined_pages );
			$url_title_raw = filter_input( INPUT_GET, 'page' );
			$i             = 1;

			if ( isset( $url_title_raw ) ) {

				foreach ( $defined_pages as $slug => $wizard_page ) {

					if ( $url_title_raw === $slug ) {

						$current_step = $i;

						break;

					}

					$i++; // phpcs:ignore.
				}
			}
		}

		$html = '';

		/**
		 * Wizard status header element.
		 */
		$html .= $this->get_wizard_status_header_content( $current_step, $total_steps );

		/**
		 * Display notices, if any.
		 */
		$html .= $this->core_settings->display_notices();

		$html .= '<div class="accp-wizard-container wrap">';

		/**
		 * Main settings content container.
		 */
		$html .= '<div id="accp-admin-wizard-main-content">';

		/**
		 * Conditionally output the opening form tag.
		 */
		if ( true === $form_wrap ) {

			$action_destination = $form_action && ! empty( $form_action ) ? $form_action : '';

			$html .= '<form action="' . esc_attr( $action_destination ) . '" method="post" enctype="multipart/form-data">';

			/**
			 * Output the settings form nonce field.
			 */
			$html .= $this->get_wizard_form_nonce_field_html();

			if ( $instantiate_wp_settings && ! empty( $instantiate_wp_settings ) ) {

				$html .= $this->instantiate_settings_group( $instantiate_wp_settings );

			}
		}

		/**
		 * Output the settings sections.
		 */
		$html .= $page_content;

		/**
		 * Conditionally output the submit button element.
		 */
		if ( true === $submit_button ) {

			$html .= $this->core_settings->get_settings_submit_button_html();

		}

		/**
		 * Conditionally output the closing form tag.
		 */
		if ( true === $form_wrap ) {

			$html .= '</form>';

		}

		$html .= '</div>';

		$html .= '</div>';

		return $html;
	}


	/**
	 * Get the settings nonce name.
	 */
	public function get_wizard_form_nonce_name() {

		return 'accp_wizard_form_nonce';
	}


	/**
	 * Get the settings nonce field name.
	 */
	public function get_wizard_form_nonce_field_name() {

		return 'accp_wizard_form_nonce';
	}


	/**
	 * Get the settings nonce field html.
	 */
	public function get_wizard_form_nonce_field_html() {

		$nonce_name       = $this->get_wizard_form_nonce_name();
		$nonce_field_name = $this->get_wizard_form_nonce_field_name();
		$nonce            = wp_create_nonce( $nonce_name );

		$html = '';

		$html .= '<input type="hidden" name="' . esc_attr( $nonce_field_name ) . '" value="' . esc_attr( $nonce ) . '">';

		return $html;
	}


	/**
	 * Get the wizard initial page html.
	 *
	 * @param string $next_step_url - The url of the next page in the wizard. Default = null.
	 */
	public function get_plugin_activation_wizard_page_content( $next_step_url = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html       = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$title              = 'Constellation Client Portal';
		$admin_url          = get_admin_url();
		$main_settings_page = $admin_url . 'admin.php?page=accp-settings';
		$logo_url           = ACCP_PLUGIN_DIR_URL . 'assets/img/accp-full-logo.png';
		$wizard_type        = '&wizard_type=plugin-install';

		if ( ! $next_step_url || empty( $next_step_url ) ) {

			$next_step_url = $admin_url . 'admin.php?page=accp-wizard-add-company' . $wizard_type;

		} else {

			$next_step_url = sanitize_url( $next_step_url . $wizard_type );

		}

		if ( true === $this->utilities->is_pro_plugin( $this->plugin_name ) ) {
			$title .= ' Pro';
		}

		$html = '';

		$html .= '<div class="accp-wizard-content-container">';

		$html .= '<h1>' . __( 'Initial Set Up', 'constellation-client-portal' ) . '</h1>';

		$html .= '<div class="accp-wizard-logo-container">';

		$html .= '<img src="' . esc_url( $logo_url ) . '">';

		$html .= '</div>';

		$html .= '<h2>';

		/* translators: %s is the plugin name. */
		$html .= sprintf( __( 'Welcome to %s!', 'constellation-client-portal' ), esc_html( $title ) );

		$html .= '</h2>';

		$html .= '<p>' . __( 'To help you get started, we\'ll walk you through setting up your first company, adding a company home page, and adding a primary user to the company.', 'constellation-client-portal' ) . '</p>';

		/**
		 * Generate default content section.
		 */
		$html .= $this->get_default_content_button_section_html();

		$html .= '<div class="accp-wizard-button-container accp-wizard-next-setup-button-container">';

		$html .= '<h2 class="accp-wizard-title-with-bottom-margin-35">' . __( '2. Continue Setup', 'constellation-client-portal' ) . '</h2>';

		$html .= '<span class="accp-wizard-continue-button"><a href="' . esc_url( $next_step_url ) . '">' . __( 'Continue Set Up', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '<div class="accp-wizard-button-container accp-wizard-skip-setup-button-container">';

		$html .= '<span class="accp-wizard-close-wizard-button"><a href="' . esc_url_raw( $main_settings_page ) . '">' . __( 'Skip Set Up', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '</div>';

		echo wp_kses( $this->generate_wizard_page_html( $html, true, false ), $allowed_html );
	}


	/**
	 * Get default content section html.
	 *
	 * @return string $html - The section html.
	 */
	public function get_default_content_button_section_html() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$html = '';

		$html .= '<div class="accp-wizard-generate-default-content-container">';

		$html .= '<h2>' . __( '1. Generate Sample Content (optional)', 'constellation-client-portal' ) . '</h2>';

		$html .= '<p>';

		$html .= __( 'In addition to proceeding through the wizard, you can optionally click the Generate Sample Content button below to automatically create a sample company, sample home page, and assign yourself to the company in order to quickly get a better idea of how the client portal is structured.', 'constellation-client-portal' );

		$html .= '</p>';

		$html .= $this->get_generate_sample_content_button_html();

		$html .= '</div>';

		return $html;
	}


	/**
	 * Get the Generate Sample Content
	 * button html.
	 *
	 * @param string $classes - Class names separated by a space.
	 *
	 * @return string $html - The element html.
	 */
	public function get_generate_sample_content_button_html( $classes = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$nonce = wp_create_nonce( 'accp_generate_default_content' );

		$html = '';

		$html .= '<span id="accp-wizard-generate-default-content-button-container">';

		$html .= '<a href="#" id="accp-wizard-generate-default-content-button" class="' . esc_attr( $classes ) . '" data-nonce="' . esc_attr( $nonce ) . '">' . __( 'Generate Sample Content', 'constellation-client-portal' ) . '</a>';

		$html .= '</span>';

		return $html;
	}


	/**
	 * Generate sample content AJAX function.
	 */
	public function accp_generate_sample_content_ajax() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		if ( ! isset( $_POST['nonce'] ) ) {
			die();
		}

		$nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) );

		if ( ! wp_verify_nonce( $nonce, 'accp_generate_default_content' ) ) {
			die();
		}

		$current_user_id = get_current_user_id();
		$messages        = array();
		$errors          = array();

		/**
		 * Create Company
		 */
		$post_args = array(
			'post_type'   => 'accp_clientcompany',
			'post_status' => 'publish',
			'post_title'  => 'Sample Company',
		);

		/**
		 * Add the post.
		 */
		$company_id = wp_insert_post( $post_args );

		if ( is_wp_error( $company_id ) ) {

			$errors[] = __( 'The company could not be added.  Please verify your WordPress settings and try again.', 'constellation-client-portal' );
			$errors[] = $company_id->get_error_message();

			$company_id = '';

			$data = array(
				'messages'   => $messages,
				'errors'     => $errors,
				'company_id' => $company_id,
			);

			echo wp_json_encode( $data );

			wp_die();

		} else {

			$messages[] = __( 'The company was successfully added.', 'constellation-client-portal' );

			/**
			 * Do action after successfully adding a company.
			 */
			do_action( 'accp_after_add_sample_company', $company_id );

		}

		/**
		 * Set current user as the primary user for the company.
		 */
		update_post_meta( $company_id, 'accp_company_primary_user', $current_user_id );

		/**
		 * Assign sample company to the current users.
		 */
		$saved_primary_company = get_user_meta( $current_user_id, 'client_company', true );

		if ( ! $saved_primary_company || empty( $saved_primary_company ) ) {

			/**
			 * Set the company as the user's primary company.
			 */
			update_user_meta( $current_user_id, 'client_company', $company_id );

		} else {

			$saved_companies = get_user_meta( $current_user_id, 'client_additional_company', true );

			if ( is_array( $saved_companies ) && ! in_array( $current_user_id, $saved_companies, true ) ) {

				$saved_companies[] = $company_id;

			} else {

				$saved_companies = array( $company_id );
			}

			/**
			 * Add the company ID to the user's additionally assigned companies.
			 */
			update_user_meta( $current_user_id, 'client_additional_company', $saved_companies );
		}

		$messages[] = __( 'The current user has been assigned to the company.', 'constellation-client-portal' );

		/**
		 * Create Client Home Page
		 */
		$page_content = $this->get_sample_page_content_html();

		$page_args = array(
			'post_type'    => 'accp_client_pages',
			'post_status'  => 'publish',
			'post_title'   => 'Sample Client Page',
			'post_content' => wp_kses_post( $page_content ),
		);

		/**
		 * Add the post.
		 */
		$page_id = wp_insert_post( $page_args );

		if ( is_wp_error( $page_id ) ) {

			$errors[] = $page_id->get_error_message();

			$page_id = '';

		} else {

			/**
			 * Assign the home page within the
			 * company post.
			 */
			update_post_meta( $company_id, 'accp_home_page', $page_id );

			/**
			 * Assign the company ID within the client page.
			 */
			update_post_meta( $page_id, 'accp_user', $company_id );

			/**
			 * Create sample unpaid invoice post.
			 */
			$this->add_sample_unpaid_invoice_post( $company_id );

			/**
			 * Create sample paid invoice post.
			 */
			$this->add_sample_paid_invoice_post( $company_id );

			/**
			 * Create sample file post.
			 */
			$this->add_sample_file_post( $company_id );

			$messages[] = __( 'The company home page was successfully added.', 'constellation-client-portal' );

		}

		$data = array(
			'messages'   => $messages,
			'errors'     => $errors,
			'company_id' => $company_id,
		);

		echo wp_json_encode( $data );

		wp_die();
	}


	/**
	 * Get sample client page content.
	 *
	 * @return string $html - The post content.
	 */
	public function get_sample_page_content_html() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$default_unpaid_inv_shortcode = '[accp_clientinvoices invoice_status="unpaid" display_pay_btn="true" display_number="20" order_by="title" order="ASC" show_excerpt="true" excerpt_length="50" show_thumbnail="true" thumbnail_size="portfolio" align_thumbnail="center" show_post_date="true"]';

		$unpaid_inv_shortcode_txt_str = '&#91;accp_clientinvoices invoice_status="unpaid"&#93;';

		$default_unpaid_inv_description = '<p>' .
		sprintf(
			/* translators: %s is the shortcode text string example. */
			__( 'Below is a list of unpaid invoices that was generated by embedding the %s shortcode on the page with the "invoice_status" parameter set to "unpaid".', 'constellation-client-portal' ),
			esc_html( $unpaid_inv_shortcode_txt_str ),
		) . '</p>';

		$default_paid_inv_shortcode = '[accp_clientinvoices invoice_status="paid" display_number="20" order_by="title" order="ASC" show_excerpt="true" excerpt_length="50" show_thumbnail="true" thumbnail_size="portfolio" align_thumbnail="center" show_post_date="true"]';

		$paid_inv_shortcode_txt_str = '&#91;accp_clientinvoices invoice_status="paid"&#93;';

		$default_paid_inv_description = '<p>' .
		sprintf(
			/* translators: %s is the shortcode text string example. */
			__( 'Below is a list of paid invoices that was generated by embedding the %s shortcode on the page with the "invoice_status" parameter set to "paid".', 'constellation-client-portal' ),
			esc_html( $paid_inv_shortcode_txt_str ),
		) . '</p>';

		$default_file_shortcode = '[accp_clientfiles display_number="20" order_by="title" order="ASC" show_excerpt="true" excerpt_length="50" show_thumbnail="true" thumbnail_size="portfolio" align_thumbnail="center" show_post_date="true"]';

		$file_shortcode_txt_str = '&#91;accp_clientfiles&#93;';

		$default_file_description = '<p>' .
		sprintf(
			/* translators: %s is the shortcode text string example. */
			__( 'Below is a list of files that was generated by embedding the %s shortcode on the page.', 'constellation-client-portal' ),
			esc_html( $file_shortcode_txt_str ),
		) . '</p>';

		$unpaid_invoice_shortcode = apply_filters( 'accp_update_sample_content_unpaid_invoice_shortcode', $default_unpaid_inv_shortcode );
		$paid_invoice_shortcode   = apply_filters( 'accp_update_sample_content_paid_invoice_shortcode', $default_paid_inv_shortcode );
		$file_shortcode           = apply_filters( 'accp_update_sample_content_file_shortcode', $default_file_shortcode );

		$unpaid_inv_description = apply_filters( 'accp_update_sample_content_unpaid_invoice_description', $default_unpaid_inv_description );
		$paid_inv_description   = apply_filters( 'accp_update_sample_content_paid_invoice_description', $default_paid_inv_description );
		$file_description       = apply_filters( 'accp_update_sample_content_file_description', $default_file_description );

		$html = '';

		$html .= '<h1>' . __( 'Sample Client Home Page', 'constellation-client-portal' ) . '</h1>';

		$html .= '<p>' . __( 'This is a sample client home page to use as a reference.  Three shortcodes have been added below to display, unpaid invoices, paid invoices, and a list of file posts.', 'constellation-client-portal' ) . '</p>';

		/**
		 * Unpaid invoice section.
		 */
		$html .= '<h2>' . __( 'Unpaid Invoices', 'constellation-client-portal' ) . '</h2>';

		$html .= $unpaid_inv_description;

		$html .= $unpaid_invoice_shortcode;

		/**
		 * Paid invoice section.
		 */
		$html .= '<h2>' . __( 'Paid Invoices', 'constellation-client-portal' ) . '</h2>';

		$html .= $paid_inv_description;

		$html .= $paid_invoice_shortcode;

		/**
		 * File section.
		 */
		$html .= '<h2>' . __( 'Files', 'constellation-client-portal' ) . '</h2>';

		$html .= $file_description;

		$html .= $file_shortcode;

		return $html;
	}


	/**
	 * Add sample unpaid invoice post.
	 *
	 * @param int $company_id - The post ID of the company associated with the sample post.
	 */
	public function add_sample_unpaid_invoice_post( $company_id ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$company_id = (int) $company_id;

		if ( ! $company_id || empty( $company_id ) ) {
			return;
		}

		$default_description = '<p>' .
		sprintf(
			/* translators: %1$s is the Pro version opening link tag. %2$s is the Pro version closing link tag. */
			__( 'This is an unpaid invoice.  You can attach a file to this post to allow users to view and download it on the frontend (optional).  The %1$sPro version%2$s also allows WooCommerce products to be assigned to the invoice, which allows users to make payments within your client portal.', 'constellation-client-portal' ),
			'<a href="https://constellationclientportal.com/" target="_blank">',
			'</a>',
		)
		. '</p>';

		$description = apply_filters( 'accp_update_sample_unpaid_inv_post_description', $default_description );

		$post_content = '<h1>' . __( 'Sample Unpaid Invoice', 'constellation-client-portal' ) . '</h1>';

		$post_content .= $description;

		$args = array(
			'post_type'    => 'accp_clientinvoice',
			'post_content' => wp_kses_post( $post_content ),
			'post_status'  => 'publish',
			'post_title'   => __( 'Sample Unpaid Invoice', 'constellation-client-portal' ),

		);

		$post_id = wp_insert_post( $args );

		if ( ! is_wp_error( $post_id ) ) {

			/**
			 * Assign the post to the specified company.
			 */
			update_post_meta( $post_id, 'accp_user', $company_id );

			/**
			 * Set the invoice status.
			 */
			update_post_meta( $post_id, 'invoice_status', 'unpaid' );

		}
	}


	/**
	 * Add sample paid invoice post.
	 *
	 * @param int $company_id - The post ID of the company associated with the sample post.
	 */
	public function add_sample_paid_invoice_post( $company_id ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$company_id = (int) $company_id;

		if ( ! $company_id || empty( $company_id ) ) {
			return;
		}

		$default_description = '<p>' . __( 'This is a paid invoice.  You can attach a file to this post to allow users to view and download it on the frontend (optional).', 'constellation-client-portal' ) . '</p>';

		$description = apply_filters( 'accp_update_sample_paid_inv_post_description', $default_description );

		$post_content = '<h1>' . __( 'Sample Paid Invoice', 'constellation-client-portal' ) . '</h1>';

		$post_content .= $description;

		$args = array(
			'post_type'    => 'accp_clientinvoice',
			'post_content' => wp_kses_post( $post_content ),
			'post_status'  => 'publish',
			'post_title'   => __( 'Sample Paid Invoice', 'constellation-client-portal' ),

		);

		$post_id = wp_insert_post( $args );

		if ( ! is_wp_error( $post_id ) ) {

			/**
			 * Assign the post to the specified company.
			 */
			update_post_meta( $post_id, 'accp_user', $company_id );

			/**
			 * Set the invoice status.
			 */
			update_post_meta( $post_id, 'invoice_status', 'paid' );

		}
	}


	/**
	 * Add sample file post.
	 *
	 * @param int $company_id - The post ID of the company associated with the sample post.
	 */
	public function add_sample_file_post( $company_id ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$company_id = (int) $company_id;

		if ( ! $company_id || empty( $company_id ) ) {
			return;
		}

		$default_description = '<p>' .
		sprintf(
			/* translators: %1$s is the Pro version opening link tag. %2$s is the Pro version closing link tag. */
			__( 'This is a file post.  You can attach a file to this post to allow users to view and download it on the frontend (optional). The %1$sPro version%2$s also allows due dates to be added to file and invoice posts.', 'constellation-client-portal' ),
			'<a href="https://constellationclientportal.com/" target="_blank">',
			'</a>',
		)
		. '</p>';

		$description = apply_filters( 'accp_update_sample_paid_inv_post_description', $default_description );

		$post_content = '<h1>' . __( 'Sample File Post', 'constellation-client-portal' ) . '</h1>';

		$post_content .= $description;

		$args = array(
			'post_type'    => 'accp_clientfile',
			'post_content' => wp_kses_post( $post_content ),
			'post_status'  => 'publish',
			'post_title'   => __( 'Sample File Post', 'constellation-client-portal' ),

		);

		$post_id = wp_insert_post( $args );

		if ( ! is_wp_error( $post_id ) ) {

			/**
			 * Assign the post to the specified company.
			 */
			update_post_meta( $post_id, 'accp_user', $company_id );

		}
	}


	/**
	 * Get the wizard initial page html.
	 *
	 * @param string $next_step_url - The url of the next page in the wizard. Default = null.
	 */
	public function get_company_onboard_wizard_page_content( $next_step_url = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html       = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$title              = 'Constellation Client Portal';
		$admin_url          = get_admin_url();
		$main_settings_page = $admin_url . 'admin.php?page=accp-settings';
		$logo_url           = ACCP_PLUGIN_DIR_URL . 'assets/img/accp-full-logo.png';
		$wizard_type        = '&wizard_type=company-onboard';

		if ( ! $next_step_url || empty( $next_step_url ) ) {

			$next_step_url = $admin_url . 'admin.php?page=accp-wizard-add-company' . $wizard_type;

		} else {

			$next_step_url = sanitize_url( $next_step_url . $wizard_type );

		}

		if ( true === $this->utilities->is_pro_plugin( $this->plugin_name ) ) {
			$title .= ' Pro';
		}

		$html = '';

		$html .= '<div class="accp-wizard-content-container">';

		$html .= '<h1>' . __( 'Onboard a Company', 'constellation-client-portal' ) . '</h1>';

		$html .= '<div class="accp-wizard-logo-container">';

		$html .= '<img src="' . esc_url( $logo_url ) . '">';

		$html .= '</div>';

		$html .= '<h2>' . __( 'Company onboard wizard.', 'constellation-client-portal' ) . '</h2>';

		$html .= '<p>' . __( 'This wizard will walk you through setting up a company, adding a company home page, and adding a primary user to the company.', 'constellation-client-portal' ) . '</p>';

		$html .= '<div class="accp-wizard-button-container accp-wizard-next-setup-button-container">';

		$html .= '<span class="accp-wizard-continue-button"><a href="' . esc_url( $next_step_url ) . '">Continue Set Up</a></span>';

		$html .= '</div>';

		$html .= '<div class="accp-wizard-button-container accp-wizard-skip-setup-button-container">';

		$html .= '<span class="accp-wizard-close-wizard-button"><a href="' . esc_url_raw( $main_settings_page ) . '">Skip Set Up</a></span>';

		$html .= '</div>';

		$html .= '</div>';

		echo wp_kses( $this->generate_wizard_page_html( $html, true, false ), $allowed_html );
	}


	/**
	 * Get the wizard type url param.
	 *
	 * @return string  $url_string - The url string or empty;
	 */
	public function get_wizard_type_url_string() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$wizard_type = filter_input( INPUT_GET, 'wizard_type' );

		if ( ! isset( $wizard_type ) || empty( $wizard_type ) ) {
			return '';
		}

		$url_string = '&wizard_type=' . $wizard_type;

		return sanitize_text_field( $url_string );
	}


	/**
	 * Update the defined plugin activation wizard pages
	 * for the company onboarding wizard.
	 */
	public function update_defined_pages_for_company_onboard_wizard() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$page_slug = filter_input( INPUT_GET, 'page' );

		if ( ! isset( $page_slug ) ) {
			return;
		}

		if ( ! $page_slug || empty( $page_slug ) || 'accp-company-onboard-wizard' !== $page_slug ) {
			return;
		}

		add_filter(
			'accp_update_defined_plugin_install_wizard_pages',
			function ( $page_list ) {

				/**
				 * Remove the plugin activation wizard first page.
				 */
				unset( $page_list['accp-plugin-activation-wizard'] );

				/**
				 * Add the company onboard wizard first page as
				 * the new first item in the defined page array.
				 */
				$first_item = array( 'accp-company-onboard-wizard' => __( 'Onboard a Company', 'constellation-client-portal' ) );
				$page_list  = $first_item + $page_list;

				return $page_list;
			}
		);
	}


	/**
	 * Get the wizard add company page html.
	 *
	 * @param string $next_step_url - The url of the next page in the wizard. Default = null.
	 */
	public function get_wizard_add_company_page_content( $next_step_url = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html       = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$title              = 'Constellation Client Portal';
		$admin_url          = get_admin_url();
		$main_settings_page = $admin_url . 'admin.php?page=accp-settings';
		$wizard_type        = $this->get_wizard_type_url_string();

		if ( ! $next_step_url || empty( $next_step_url ) ) {

			$next_step_url = $admin_url . 'admin.php?page=accp-wizard-add-company-home-page' . $wizard_type;

		} else {

			$next_step_url = sanitize_url( $next_step_url . $wizard_type );

		}

		$html = '';

		$html .= '<div class="accp-wizard-content-container">';

		$html .= '<h1>' . __( 'Start by adding a company.', 'constellation-client-portal' ) . '</h1>';

		$html .= '<p>' . __( 'The company is the entity, to which, WordPress users and company pages are assigned.  You can create as many companies as you like later, and we\'ll start by creating your first one here.', 'constellation-client-portal' ) . '</p>';

		/**
		 * Company name field.
		 */
		$html .= $this->get_wizard_company_name_field_html();

		/**
		 * Allow actions to fire after the default
		 * wizard fields.
		 *
		 * Buffer the outpuf of the action to ensure
		 * that it appears on the page in the expected place.
		 */
		ob_start();

		do_action( 'accp_wizard_after_company_title_field' );

		$html .= ob_get_contents();

		ob_end_clean();

		$html .= '<div class="accp-wizard-button-container accp-wizard-next-setup-button-container">';

		$html .= '<span class="accp-wizard-continue-button accp-wizard-add-company-step-button"><a href="' . esc_url( $next_step_url ) . '">' . __( 'Continue', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '<div class="accp-wizard-button-container accp-wizard-skip-setup-button-container">';

		$html .= '<span class="accp-wizard-close-wizard-button"><a href="' . esc_url_raw( $main_settings_page ) . '">' . __( 'Skip Set Up', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '</div>';

		echo wp_kses( $this->generate_wizard_page_html( $html, true, false ), $allowed_html );
	}


	/**
	 * Get the wizard add company home page html.
	 *
	 * @param string $next_step_url - The url of the next page in the wizard. Default = null.
	 */
	public function get_wizard_add_company_home_page_page_content( $next_step_url = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html       = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$title              = 'Constellation Client Portal';
		$admin_url          = get_admin_url();
		$main_settings_page = $admin_url . 'admin.php?page=accp-settings';
		$company_id         = filter_input( INPUT_GET, 'company_id', FILTER_SANITIZE_NUMBER_INT );
		$wizard_type        = $this->get_wizard_type_url_string();

		if ( ! $next_step_url || empty( $next_step_url ) ) {

			$next_step_url = $admin_url . 'admin.php?page=accp-wizard-add-company-primary-user' . $wizard_type;

		} else {

			$next_step_url = sanitize_url( $next_step_url . $wizard_type );

		}

		if ( true === $this->utilities->is_pro_plugin( $this->plugin_name ) ) {
			$title .= ' Pro';
		}

		/**
		 * Check for existing client pages.
		 */
		$existing_client_pages = false;

		$args = array(
			'numberposts' => -1,
			'post_type'   => 'accp_client_pages',
			'fields'      => 'ids',
		);

		$client_pages = get_posts( $args );

		if ( $client_pages && ! empty( $client_pages ) && is_array( $client_pages ) ) {
			$existing_client_pages = true;
		}

		$html = '';

		$html .= '<div class="accp-wizard-content-container">';

		$html .= '<h1>' . __( 'Add a home page for your company.', 'constellation-client-portal' ) . '</h1>';

		if ( $company_id && ! empty( $company_id ) ) {

			$html .= '<p>' . __( 'The company home page is the initial page that users see when accessing their company portal.  You can add more (non-home) pages to the company later as needed.', 'constellation-client-portal' ) . '</p>';

			$html .= '<h2>' . __( 'Create a new client page.', 'constellation-client-portal' ) . '</h2>';

			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'Page Title', 'constellation-client-portal' ) . '</label>';

			$html .= '<input type="text" id="accp-client-page-title" class="accp-wizard-input-field accp-wizard-input-field-required" name="accp_client_page_title" required>';

			$html .= '</div>';

			/**
			 * Allow actions to fire after the default
			 * add client page fields.
			 *
			 * Buffer the outpuf of the action to ensure
			 * that it appears on the page in the expected place.
			 */
			ob_start();

			do_action( 'accp_wizard_after_add_new_client_page_title_field' );

			$html .= ob_get_contents();

			ob_end_clean();

			if ( true === $existing_client_pages ) {

				$html .= '<h3 class="accp-center-h3">' . __( 'OR', 'constellation-client-portal' ) . '</h3>';

				$html .= '<h2>' . __( 'Use an existing client page.', 'constellation-client-portal' ) . '</h2>';

				$html .= '<div class="accp-wizard-field-container">';

				$html .= '<label>' . __( 'Use an existing page.', 'constellation-client-portal' ) . '</label>';

				$html .= '<input type="checkbox" id="accp-enable-use-existing-client-page" name="accp_enable_use_existing_client_page" value="use-existing">';

				$html .= '</div>'; // END .accp-wizard-field-container.

				$html .= '<div id="accp-wizard-home-page-select-container" class="accp-wizard-field-container">';

				$html .= '<label>' . __( 'Select a client page.', 'constellation-client-portal' ) . '</label>';

				$html .= '<select name="accp_home_page" id="accp_home_page" class="accp-wizard-input-field">';

				$html .= '<option value="">' . __( 'Select a page...', 'constellation-client-portal' ) . '</option>';

				foreach ( $client_pages as $client_page_id ) {

					$post              = get_post( $client_page_id );
					$post_name         = $post->post_title;
					$is_global         = get_post_meta( $client_page_id, 'accp_make_page_global', true ) ? get_post_meta( $client_page_id, 'accp_make_page_global', true ) : '';
					$assigned_to_label = __( ' (Assigned To: UNASSIGNED)', 'constellation-client-portal' );
					$data_assignment   = 'unassigned';

					if ( $is_global && 'global' === $is_global ) {

						$assigned_to_label = __( ' (Assigned To: Global Page)', 'constellation-client-portal' );
						$data_assignment   = 'global';

					} else {

						$assigned_company_id = get_post_meta( $client_page_id, 'accp_user', true ) ? get_post_meta( $client_page_id, 'accp_user', true ) : '';
						$data_assignment     = 'assigned';

						if ( $assigned_company_id ) {

							$company_name = get_the_title( $assigned_company_id ) ? get_the_title( $assigned_company_id ) : 'No Title Entered';

							if ( $company_name ) {

								$assigned_to_label = ' (Assigned To: ' . esc_html( $company_name ) . ')';

							}
						}
					}

					$html .= '<option class="level-0" value="' . (int) $client_page_id . '" data-assignment="' . esc_attr( $data_assignment ) . '">' . esc_html( $post_name ) . wp_kses_post( $assigned_to_label ) . '</option>';

				}

				$html .= '</select>';
			}

			$html .= '</div>'; // END .accp-wizard-field-container.

			$html .= '<div class="accp-wizard-button-container accp-wizard-next-setup-button-container">';

			$html .= '<span class="accp-wizard-continue-button accp-wizard-add-company-home-page-step-button"><a href="' . esc_url( $next_step_url ) . '" data-company-id="' . esc_attr( $company_id ) . '">' . __( 'Continue', 'constellation-client-portal' ) . '</a></span>';

			$html .= '</div>';

		} else {

			$html .= '<p>' . __( 'No company ID was found.  Please use your browser\'s back button to add a company, or skip this step to proceed without adding a company.', 'constellation-client-portal' ) . '</p>';

		}

		$html .= '<div class="accp-wizard-button-container accp-wizard-skip-setup-button-container">';

		$html .= '<span class="accp-wizard-close-wizard-button"><a href="' . esc_url( $next_step_url ) . '">' . __( 'Skip', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '</div>';

		echo wp_kses( $this->generate_wizard_page_html( $html, true, false ), $allowed_html );
	}


	/**
	 * Get the wizard add company user page html.
	 *
	 * @param string $next_step_url - The url of the next page in the wizard. Default = null.
	 */
	public function get_wizard_add_company_primary_user_page_content( $next_step_url = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html       = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$title              = 'Constellation Client Portal';
		$admin_url          = get_admin_url();
		$main_settings_page = $admin_url . 'admin.php?page=accp-settings';
		$company_id         = filter_input( INPUT_GET, 'company_id', FILTER_SANITIZE_NUMBER_INT );
		$page_id            = filter_input( INPUT_GET, 'page_id', FILTER_SANITIZE_NUMBER_INT ) ? filter_input( INPUT_GET, 'page_id', FILTER_SANITIZE_NUMBER_INT ) : '';
		$page_id_attribute  = $page_id && ! empty( $page_id ) ? 'data-page-id=' . $page_id : '';
		$wizard_type        = $this->get_wizard_type_url_string();

		if ( ! $next_step_url || empty( $next_step_url ) ) {

			$next_step_url = $admin_url . 'admin.php?page=accp-wizard-complete-page' . $wizard_type;

		} else {

			$next_step_url = sanitize_url( $next_step_url . $wizard_type );

		}

		$users = get_users();

		$html = '';

		$html .= '<div class="accp-wizard-content-container">';

		$html .= '<h1>' . __( 'Assign a primary user to your company.', 'constellation-client-portal' ) . '</h1>';

		if ( $company_id && ! empty( $company_id ) ) {

			if ( true === $this->utilities->is_pro_plugin( $this->plugin_name ) ) {

				$html .= '<p>' . __( 'The primary user of a company is the main user designated to receive email notifications for a given company (if email notifications are enabled).  You can add as many users as you need to a company later, and we\'ll just add the primary user for now.', 'constellation-client-portal' ) . '</p>';

			} else {

				$html .= '<p>' . __( 'The primary user of a company is the main user designated to receive email notifications for a given company (pro feature).  You can add as many users as you need to a company later, and we\'ll just add the primary user for now.', 'constellation-client-portal' ) . '</p>';

			}

			$html .= '<p>' . __( 'Tip: It\'s also acceptible to just assign yourself to a company temporarily while you get everything set up.', 'constellation-client-portal' ) . '</p>';

			/**
			 * Assign an existing user.
			 */
			if ( $users && ! empty( $users ) && is_array( $users ) ) {

				$html .= '<div class="accp-wizard-field-container">';

				$html .= '<label>' . __( 'Assign an existing user.', 'constellation-client-portal' ) . '</label>';

				$html .= '<select id="accp-wizard-company-primary-user-field" class="accp-wizard-input-field-required accp-wizard-full-length-field" name="accp_company_primary_user">';

				$html .= '<option value="">' . __( 'Select user', 'constellation-client-portal' ) . '</option>';

				foreach ( $users as $user ) {

					$user_id         = $user->ID;
					$user_name       = $user->user_login;
					$user_first_name = $user->first_name;
					$user_last_name  = $user->last_name;
					$display_text    = $user_name . ( $user_first_name ? ' - ' . $user_first_name : '' ) . ( $user_last_name ? ' ' . $user_last_name : '' );

					$html .= '<option value="' . esc_attr( $user_id ) . '">' . esc_html( $display_text ) . '</option>';

				}

				$html .= '</select>';

				$html .= '</div>'; // END .accp-wizard-field-container.

			}

			/**
			 * Create and assign a new user.
			 */
			$html .= '<h3 class="accp-center-h3">' . __( 'OR', 'constellation-client-portal' ) . '</h3>';

			$html .= '<h2>' . __( 'Create a new user.', 'constellation-client-portal' ) . '</h2>';

			/**
			 * Create new user checkbox.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'Create a new WordPress user.', 'constellation-client-portal' ) . '</label>';

			$html .= '<input type="checkbox" id="accp-wizard-create-new-user" name="accp_wizard_create_new_user" value="create-new">';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * Create new user form container.
			 */
			$html .= '<div id="accp-wizard-create-new-user-container">';

			/**
			 * Username field.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'Username', 'constellation-client-portal' ) . '<abbr>*</abbr></label>';

			$html .= '<input id="accp-new-user-username" class="accp-create-user-text-field accp-wizard-create-new-user-section-required accp-wizard-full-length-field" name="accp_new_user_username" type="text" value="">';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * User role field.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'Role', 'constellation-client-portal' ) . '<abbr>*</abbr></label>';

			$html .= '<select id="accp-new-user-role" class="accp-wizard-create-new-user-section-required accp-wizard-full-length-field" name="accp_new_user_role">';

			/**
			 * Buffer the output to ensure that it
			 * is displayed in the proper place.
			 */
			ob_start();

			wp_dropdown_roles( 'subscriber' );

			$html .= ob_get_contents();

			ob_end_clean();

			$html .= '</select>';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * Email address field.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'Email Address', 'constellation-client-portal' ) . '<abbr>*</abbr></label>';

			$html .= '<input id="accp-new-user-email" class="accp-create-user-text-field accp-wizard-create-new-user-section-required accp-wizard-full-length-field" name="accp_new_user_email" type="email" value="">';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * Password field.
			 */
			$html .= '<div class="accp-wizard-field-container accp-wizard-password-field-with-button-container">';

			$html .= '<label>' . __( 'Password', 'constellation-client-portal' ) . '<abbr>*</abbr></label>';

			$html .= '<input id="accp-new-user-password" class="accp-create-user-text-field accp-wizard-create-new-user-section-required accp-wizard-half-length-field" name="accp_new_user_password" type="text" value=""><span id="accp-wizard-autogenerate-password" class="button">' . __( 'Generate Password', 'constellation-client-portal' ) . '</span>';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * First name field.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'First Name', 'constellation-client-portal' ) . '</label>';

			$html .= '<input id="accp-new-user-firstname" class="accp-create-user-text-field accp-wizard-full-length-field" name="accp_new_user_firstname" type="text" value="">';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * Last name field.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label>' . __( 'Last Name', 'constellation-client-portal' ) . '</label>';

			$html .= '<input id="accp-new-user-lastname" class="accp-create-user-text-field accp-wizard-full-length-field" name="accp_new_user_lastname" type="text" value="">';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * Send email to user field.
			 */
			$html .= '<div class="accp-wizard-field-container">';

			$html .= '<label><input type="checkbox" id="accp-send-user-notification" value="send"> ' . __( 'Send email to new user with a password reset link.', 'constellation-client-portal' ) . '</label>';

			$html .= '</div>'; // END .accp-wizard-field-container.

			/**
			 * Allow actions to fire after the default
			 * add primary user fields.
			 *
			 * Buffer the outpuf of the action to ensure
			 * that it appears on the page in the expected place.
			 */
			ob_start();

			do_action( 'accp_wizard_after_add_primary_user_fields' );

			$html .= ob_get_contents();

			ob_end_clean();

			$html .= '</div>'; // END #accp-wizard-create-new-user-container.

			$html .= '<div class="accp-wizard-button-container accp-wizard-next-setup-button-container">';

			$html .= '<span class="accp-wizard-continue-button accp-wizard-add-company-primary-user-step-button"><a href="' . esc_url( $next_step_url ) . '" data-company-id="' . esc_attr( $company_id ) . '" ' . esc_html( $page_id_attribute ) . '>' . __( 'Continue', 'constellation-client-portal' ) . '</a></span>';

			$html .= '</div>';

		} else {

			$html .= '<p>' . __( 'No company ID was found.  Please use your browser\'s back button to add a company, or skip this step to proceed without adding a company.', 'constellation-client-portal' ) . '</p>';

		}

		$html .= '<div class="accp-wizard-button-container accp-wizard-skip-setup-button-container">';

		$html .= '<span class="accp-wizard-close-wizard-button"><a href="' . esc_url( $next_step_url ) . '">' . __( 'Skip', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '</div>';

		echo wp_kses( $this->generate_wizard_page_html( $html, true, false ), $allowed_html );
	}


	/**
	 * Get the wizard add company user page html.
	 *
	 * @param string $next_step_url - The url of the next page in the wizard. Default = null.
	 */
	public function get_wizard_complete_page_page_content( $next_step_url = '' ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html       = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$title              = 'Constellation Client Portal';
		$admin_url          = get_admin_url();
		$main_settings_page = $admin_url . 'admin.php?page=accp-settings';
		$company_id         = filter_input( INPUT_GET, 'company_id', FILTER_SANITIZE_NUMBER_INT ) ? filter_input( INPUT_GET, 'company_id', FILTER_SANITIZE_NUMBER_INT ) : '';
		$page_id            = filter_input( INPUT_GET, 'page_id', FILTER_SANITIZE_NUMBER_INT ) ? filter_input( INPUT_GET, 'page_id', FILTER_SANITIZE_NUMBER_INT ) : '';
		$wizard_type        = filter_input( INPUT_GET, 'wizard_type' );

		if ( 'company-onboard' === $wizard_type ) {

			$intro = '<p>' . __( 'Congratulations! Your new company has been created.', 'constellation-client-portal' ) . '</p>';

		} else {

			$intro = '<p>' . __( 'Congratulations! You\'ve created your first company to help you get started.  You can add more companies later (as many as you need), and the "next steps" below will help you complete the initial set up of your portal.', 'constellation-client-portal' ) . '</p>';

		}

		$next_step_args = array(
			'company_id'  => $company_id,
			'page_id'     => $page_id,
			'item_tag'    => 'div',
			'wizard_type' => $wizard_type,
		);

		$next_steps = $this->get_wizard_complete_next_steps_list( $next_step_args );

		if ( ! $next_step_url || empty( $next_step_url ) ) {

			$next_step_url = $main_settings_page;

		} else {

			$next_step_url = sanitize_url( $next_step_url );

		}

		if ( true === $this->utilities->is_pro_plugin( $this->plugin_name ) ) {
			$title .= ' Pro';
		}

		$html = '';

		$html .= '<div class="accp-wizard-content-container">';

		$html .= '<h1>' . __( 'Complete', 'constellation-client-portal' ) . '</h1>';

		$html .= $intro;

		$html .= '<h2>' . __( 'Next Steps', 'constellation-client-portal' ) . '</h2>';

		$html .= '<div class="accp-wizard-next-steps-list-container">';

		if ( $next_steps && ! empty( $next_steps ) && is_array( $next_steps ) ) {

			foreach ( $next_steps as $step ) {

				$html .= $step;

			}
		}

		$html .= '</div>';

		$html .= '<div class="accp-wizard-button-container accp-wizard-next-setup-button-container">';

		$html .= '<span class="accp-wizard-continue-button"><a href="' . esc_url( $next_step_url ) . '">' . __( 'Finish', 'constellation-client-portal' ) . '</a></span>';

		$html .= '</div>';

		$html .= '</div>';

		echo wp_kses( $this->generate_wizard_page_html( $html, true, false ), $allowed_html );
	}


	/**
	 * Get the wizard status header.
	 *
	 * @param int $current_step - The current step in the wizard.
	 * @param int $total_steps - The total number of steps in the wizard.
	 */
	public function get_wizard_status_header_content( $current_step, $total_steps ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		if ( ! $current_step || ! $total_steps ) {
			return;
		}

		$allowed_html   = $this->core_settings->get_customized_allowed_html_for_wp_kses();
		$raw_item_width = ( (int) $current_step / (int) $total_steps ) * 100;
		$item_width     = number_format( (float) $raw_item_width, 2, '.', '' );

		$html = '';

		$html .= '<div class="accp-wizard-status-container">';

		$html .= '<span class="accp-wizard-status-step-item" style="width:' . esc_html( $item_width ) . '%; "></span>';

		$html .= '</div>';

		echo wp_kses( $html, $allowed_html );
	}


	/**
	 * Get the company name field html.
	 */
	public function get_wizard_company_name_field_html() {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$allowed_html = $this->core_settings->get_customized_allowed_html_for_wp_kses();

		$html = '';

		$html .= '<div class="accp-wizard-field-container">';

		$html .= '<label>' . __( 'Company Name (required)', 'constellation-client-portal' ) . '</label>';

		$html .= '<input id="accp-wizard-company-name-input" class="accp-wizard-input-field accp-wizard-input-field-required" type="text" name="accp-wizard_company_name_input" required>';

		$html .= '<p class="accp-wizard-field-description">' . __( 'Enter a name for the company.', 'constellation-client-portal' ) . '</p>';

		$html .= '</div>';

		return wp_kses( $html, $allowed_html );
	}


	/**
	 * Add new company AJAX function.
	 */
	public function wizard_add_company_via_ajax() {

		if ( ! isset( $_POST['nonce'] ) ) {
			die();
		}

		$nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) );

		if ( ! wp_verify_nonce( $nonce, 'accp_wizard_form_nonce' ) ) {
			die();
		}

		$errors   = array();
		$messages = array();

		if ( ! isset( $_POST['button_class'] ) ) {

			$errors[] = __( 'Unable to proceed to next step due to missing company ID.  Please refresh the page and try again.', 'constellation-client-portal' );

			$button_selector = '';

		} else {

			$button_selector = sanitize_text_field( wp_unslash( $_POST['button_class'] ) );

		}

		$company_name = __( 'Company Name Not Entered', 'constellation-client-portal' );

		if ( isset( $_POST['company_name'] ) ) {

			$company_name = sanitize_text_field( wp_unslash( $_POST['company_name'] ) );

		}

		$post_args = array(
			'post_type'   => 'accp_clientcompany',
			'post_status' => 'publish',
			'post_title'  => esc_html( $company_name ),
		);

		/**
		 * Allow the post args to be filtered.
		 */
		$post_args = apply_filters( 'accp_update_wizard_add_company_args', $post_args, $company_name );

		/**
		 * Add the post.
		 */
		$post_id = wp_insert_post( $post_args );

		if ( is_wp_error( $post_id ) ) {

			$post_id = '';

			$errors[] = $post_id->get_error_message();

		} else {

			$messages[] = __( 'The company was successfully added', 'constellation-client-portal' );

			/**
			 * Maybe add the company status.
			 */
			if ( isset( $_POST['company_status'] ) ) {

				$company_status = sanitize_text_field( wp_unslash( $_POST['company_status'] ) );

				if ( ! empty( $_POST['company_status'] ) ) {

					update_post_meta( $post_id, 'accp_company_status', $company_status );

				}
			}

			/**
			 * Allow actions to fire after the company
			 * is successfully added.
			 */
			do_action( 'accp_wizard_after_company_successfully_added', $post_id );

		}

		$data = array(
			'button_selector' => $button_selector,
			'messages'        => $messages,
			'errors'          => $errors,
			'post_id'         => $post_id,
		);

		echo wp_json_encode( $data );

		wp_die();
	}


	/**
	 * Add new company AJAX function.
	 */
	public function wizard_add_company_home_page_via_ajax() {

		if ( ! isset( $_POST['nonce'] ) ) {
			die();
		}

		$nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) );

		if ( ! wp_verify_nonce( $nonce, 'accp_wizard_form_nonce' ) ) {
			die();
		}

		$data     = array();
		$errors   = array();
		$messages = array();

		if ( ! isset( $_POST['button_class'] ) ) {

			$errors[] = __( 'Unable to proceed to next step due to missing data.  Please refresh the page and try again.', 'constellation-client-portal' );

			$button_selector = '';

		} else {

			$button_selector = sanitize_text_field( wp_unslash( $_POST['button_class'] ) );

		}

		if ( isset( $_POST['company_id'] ) ) {

			$company_id = sanitize_text_field( wp_unslash( $_POST['company_id'] ) );

		} else {

			$errors[] = __( 'Unable to proceed to next step due to missing company ID.  Please refresh the page and try again.', 'constellation-client-portal' );

			$data = array(
				'button_selector' => $button_selector,
				'messages'        => $messages,
				'errors'          => $errors,
			);

			echo wp_json_encode( $data );

			wp_die();
		}

		$use_existing = false;

		if ( isset( $_POST['use_existing'] ) && ( 'true' === $_POST['use_existing'] || true === $_POST['use_existing'] ) ) {

			$use_existing = true;

		}

		/**
		 * Use an existing client page.
		 */
		if ( true === $use_existing ) {

			if ( ! isset( $_POST['existing_page_id'] ) ) {

				$errors[] = __( 'Unable to proceed to next step due to missing page ID.  Please select an existing company page and try again.', 'constellation-client-portal' );

				$data = array(
					'button_selector' => $button_selector,
					'messages'        => $messages,
					'errors'          => $errors,
				);

				echo wp_json_encode( $data );

				wp_die();

			} else {

				$existing_page_id = isset( $_POST['existing_page_id'] ) ? (int) $_POST['existing_page_id'] : '';

				if ( get_post( $company_id ) && $existing_page_id && ! empty( $existing_page_id ) ) {

					/**
					 * Add the existing company page ID post meta to
					 * the company post.
					 */
					update_post_meta( $company_id, 'accp_home_page', $existing_page_id );

					$messages[] = 'Home page added successfully.';

					$data = array(
						'button_selector' => $button_selector,
						'messages'        => $messages,
						'errors'          => $errors,
						'company_id'      => $company_id,
						'page_id'         => $existing_page_id,
					);

					echo wp_json_encode( $data );

					wp_die();

				} else {

					$errors[] = __( 'There was an error assigning the home page to the company.  Please check the company and try again.', 'constellation-client-portal' );

					$data = array(
						'button_selector' => $button_selector,
						'messages'        => $messages,
						'errors'          => $errors,
						'company_id'      => $company_id,
						'page_id'         => '',
					);

					echo wp_json_encode( $data );

					wp_die();
				}
			}
		} else {

			if ( ! isset( $_POST['page_title'] ) ) {

				$errors[] = __( 'Unable to create the company page.  Please enter a page title and try again.', 'constellation-client-portal' );

				$data = array(
					'button_selector' => $button_selector,
					'messages'        => $messages,
					'errors'          => $errors,
				);

				echo wp_json_encode( $data );

				wp_die();

			}

			/**
			 * Create a new client page post.
			 */

			$page_title = sanitize_text_field( wp_unslash( $_POST['page_title'] ) );

			$post_args = array(
				'post_type'   => 'accp_client_pages',
				'post_status' => 'publish',
				'post_title'  => esc_html( $page_title ),
			);

			/**
			 * Allow the post args to be filtered.
			 */
			$post_args = apply_filters( 'accp_update_wizard_add_company_home_page_args', $post_args, $page_title );

			/**
			 * Add the post.
			 */
			$post_id = wp_insert_post( $post_args );

			if ( is_wp_error( $post_id ) ) {

				$post_id = '';

				$errors[] = $post_id->get_error_message();

			} else {

				/**
				 * Assign the home page within the
				 * company post.
				 */
				update_post_meta( $company_id, 'accp_home_page', $post_id );

				/**
				 * Maybe make the page global.
				 */
				if ( isset( $_POST['make_global'] ) ) {

					$make_global = sanitize_text_field( wp_unslash( $_POST['make_global'] ) );

					if ( $make_global && 'global' === $make_global ) {

						update_post_meta( $post_id, 'accp_make_page_global', 'global' );

					}
				}

				/**
				 * Assign the company ID within the
				 * client page if this is not a global page.
				 */
				$should_assign_company = true;
				$should_assign_company = apply_filters( 'accp_update_wizard_add_client_page_should_assign_company', $should_assign_company );
				$is_global             = false;
				$is_global             = apply_filters( 'accp_update_wizard_add_client_page_is_global', $is_global );

				if ( true === $should_assign_company && false === $is_global ) {

					update_post_meta( $post_id, 'accp_user', $company_id );

				}

				$messages[] = __( 'The company was successfully added', 'constellation-client-portal' );

			}

			$data = array(
				'button_selector' => $button_selector,
				'messages'        => $messages,
				'errors'          => $errors,
				'company_id'      => $company_id,
				'page_id'         => $post_id,
			);

			echo wp_json_encode( $data );

			wp_die();

		}
	}


	/**
	 * Get list of final steps for the wizard complete page.
	 *
	 * @param array $args - Array of args.
	 *
	 * $args = array(
	 * 'company_id'  = $company_id,
	 * 'page_id'     = $page_id,
	 * 'item_tag'    = '', // Ex. li, p, div.
	 * 'wizard_type' = $wizard_type, // plugin-install or company-onboard.
	 * ).
	 *
	 * @return array $next_steps - A list (array) of next steps html.
	 */
	public function get_wizard_complete_next_steps_list( $args = array() ) {

		if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
			return;
		}

		$company_id        = array_key_exists( 'company_id', $args ) && ! empty( $args['company_id'] ) ? (int) $args['company_id'] : '';
		$page_id           = array_key_exists( 'page_id', $args ) && ! empty( $args['page_id'] ) ? (int) $args['page_id'] : '';
		$item_tag          = array_key_exists( 'item_tag', $args ) && ! empty( $args['item_tag'] ) ? sanitize_text_field( $args['item_tag'] ) : '';
		$wizard_type       = array_key_exists( 'wizard_type', $args ) && ! empty( $args['wizard_type'] ) ? sanitize_text_field( $args['wizard_type'] ) : '';
		$tag_open          = '';
		$tag_close         = '';
		$admin_url         = get_admin_url();
		$company_admin     = $admin_url . 'edit.php?post_type=accp_clientcompany';
		$file_admin        = $admin_url . 'edit.php?post_type=accp_clientfile';
		$invoice_admin     = $admin_url . 'edit.php?post_type=accp_clientinvoice';
		$client_page_admin = $admin_url . 'edit.php?post_type=accp_client_pages';
		$home_page         = get_post_meta( $company_id, 'accp_home_page', true ) ? get_post_meta( $company_id, 'accp_home_page', true ) : '';
		$company_edit_link = $company_id && ! empty( $company_id ) ? get_edit_post_link( $company_id ) : '#';
		$primary_user      = get_post_meta( $company_id, 'accp_company_primary_user', true ) ? get_post_meta( $company_id, 'accp_company_primary_user', true ) : '';
		$is_pro            = $this->utilities->is_pro_plugin( $this->plugin_name );

		$shortcode_item_description  = '<p class="accp-wizard-shortcode-item-description">';
		$shortcode_item_description .= '<strong>' . __( 'Example:', 'constellation-client-portal' ) . '</strong>';
		$shortcode_item_description .= '<span class="accp-wizard-shortcode-item-inner-description">';
		$shortcode_item_description .= __( 'Copy and paste one or more of the following shortcodes into your client page.', 'constellation-client-portal' );
		$shortcode_item_description .= '</span>';
		$shortcode_item_description .= '<ul>';
		$shortcode_item_description .= '<li>&#91;accp_clientfiles&#93;</li>';
		$shortcode_item_description .= '<li>&#91;accp_clientinvoices invoice_status="unpaid"&#93;</li>';
		$shortcode_item_description .= '<li>&#91;accp_clientinvoices invoice_status="paid"&#93;</li>';
		$shortcode_item_description .= '</ul>';
		$shortcode_item_description .= '</p>';

		$shortcode_item_description = apply_filters( 'accp_wizard_update_add_shortcode_description_content', $shortcode_item_description );

		$my_home_menu_description  = '<p class="accp-wizard-shortcode-item-description">';
		$my_home_menu_description .= '<strong>' . __( 'Example:', 'constellation-client-portal' ) . '</strong>';
		$my_home_menu_description .= '<span class="accp-wizard-shortcode-item-inner-description">';
		$my_home_menu_description .= __( 'Copy and paste the shortcode below into pages and/or posts where you would like the menu item to appear.', 'constellation-client-portal' );
		$my_home_menu_description .= '</span>';
		$my_home_menu_description .= '<ul>';
		$my_home_menu_description .= '<li>&#91;accp_my_company_page link_text="My Home" hide_logged_out="false"&#93;</li>';
		$my_home_menu_description .= '</ul>';
		$my_home_menu_description .= '</p>';

		if ( $item_tag && ! empty( $item_tag ) ) {

			$tag_open  = '<' . $item_tag . ' class="accp-wizard-next-steps-item">';
			$tag_close = '</' . $item_tag . '>';

		}

		$args['tag_open']  = $tag_open;
		$args['tag_close'] = $tag_close;

		$next_steps = array();

		/**
		 * Add a company.
		 */
		if ( ! $company_id || empty( $company_id ) ) {

			$next_steps['add_company'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Create a Company', 'constellation-client-portal' ) . '</h3>' .

			sprintf(
				/* translators: %1$s = opening a tag, %2$s = closing a tag. */
				__(
					'It looks like no company ID was found.  Start by creating your first %1$scompany%2$s.  This is the entity to which WordPress users are assigned.',
					'constellation-client-portal'
				),
				'<a href="' . esc_url( $company_admin ) . '">',
				'</a>'
			) . $tag_close;

		}

		/**
		 * Add a client page.
		 */
		if ( ( ! $page_id || empty( $page_id ) ) && ( ! $home_page || empty( $home_page ) ) ) {

			$next_steps['add_client_page'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Add a Client Page', 'constellation-client-portal' ) . '</h3>' .

			sprintf(
				/* translators: %1$s = opening a tag, %2$s = closing a tag. */
				__(
					'Add a %1$sclient page%2$s for your company if you have not done so already.  This is what clients will see on the front-end.',
					'constellation-client-portal'
				),
				'<a href="' . esc_url( $client_page_admin ) . '" target="_blank">',
				'</a>'
			) . $tag_close;

		}

		/**
		 * Assign a home page to company.
		 */
		if ( ! $home_page || empty( $home_page ) ) {

			$next_steps['assign_home_page'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Assign Company Home Page', 'constellation-client-portal' ) . '</h3>' .

			sprintf(
				/* translators: %1$s = opening a tag, %2$s = closing a tag. */
				__(
					'Assign a home page within your %1$scompany%2$s. You can assign unlimited pages to a company, but all companies should have one page assigned as the home page.',
					'constellation-client-portal'
				),
				'<a href="' . esc_url( $company_edit_link ) . '" target="_blank">',
				'</a>'
			) . $tag_close;

		}

		/**
		 * Add shortcodes to client page.
		 */
		$next_steps['add_page_content'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Add Shortcodes to Client Pages', 'constellation-client-portal' ) . '</h3>' . __( 'Add list shortcodes to your client pages to display file and invoice lists, if you have not done so already.', 'constellation-client-portal' ) . wp_kses_post( $shortcode_item_description ) . $tag_close;

		/**
		 * Assign primary user.
		 */
		if ( ! $primary_user || empty( $primary_user ) ) {

			if ( true !== $this->utilities->is_pro_plugin( $this->plugin_name ) ) {

				$next_steps['assign_primary_user'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Assign Primary User', 'constellation-client-portal' ) . '</h3>' .

				sprintf(
					/* translators: %1$s = opening a tag, %2$s = closing a tag. */
					__(
						'Assign a primary user within your %1$scompany%2$s. In the Pro version, users set as the primary user for a company receive automatic email notifications if these have been enabled.',
						'constellation-client-portal'
					),
					'<a href="' . esc_url( $company_edit_link ) . '" target="_blank">',
					'</a>'
				) . $tag_close;

			} else {

				$next_steps['assign_primary_user'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Assign Primary User', 'constellation-client-portal' ) . '</h3>' .

				sprintf(
					/* translators: %1$s = opening a tag, %2$s = closing a tag. */
					__(
						'Assign a primary user within your %1$scompany%2$s. Users set as the primary user for a company receive email notifications if these have been enabled.',
						'constellation-client-portal'
					),
					'<a href="' . esc_url( $company_edit_link ) . '" target="_blank">',
					'</a>'
				) . $tag_close;

			}
		}

		/**
		 * Create file or invoice post.
		 */
		$next_steps['add_file_or_inv_post'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Create File and Invoice Posts', 'constellation-client-portal' ) . '</h3>' .

		sprintf(
			/* translators: %1$s = opening file admin a tag, %2$s = closing a tag, %3$s = opening invoice admin a tag, %4$s = closing a tag. */
			__(
				'Create a %1$sfile post%2$s and/or an %3$sinvoice post%4$s, and assign it to your company.  These posts are displayed on the front-end using list shortcodes.',
				'constellation-client-portal'
			),
			'<a href="' . esc_url( $file_admin ) . '" target="_blank">',
			'</a>',
			'<a href="' . esc_url( $invoice_admin ) . '" target="_blank">',
			'</a>'
		) . $tag_close;

		/**
		 * Add a menu to client page.
		 */
		if ( 'company-onboard' !== $wizard_type ) {

			$next_steps['add_my_home_link'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Add My Home Link', 'constellation-client-portal' ) . '</h3>' . __( 'Add a My Home shortcode link throughout your site that will link to user\'s client page.', 'constellation-client-portal' ) . $my_home_menu_description . $tag_close;

		}

		/**
		 * Upgrade section (core only).
		 */
		if ( true !== $is_pro ) {

			if ( 'company-onboard' !== $wizard_type ) {

				$next_steps['upgrade'] = $tag_open . '<h3 class="accp-wizard-next-step-heading">' . __( 'Upgrade to Pro', 'constellation-client-portal' ) . '</h3>' .

				sprintf(
					/* translators: %1$s = opening a tag, %2$s = closing a tag. */
					__(
						'Upgrade to the %1$sPro version%2$s and automatically redirect users to their client page at login, enable automated client email notifications, customize the URL (page slug) for client pages, file and invoice posts - as well as many other powerful features.',
						'constellation-client-portal'
					),
					'<a href="https://constellationclientportal.com/" target="_blank">',
					'</a>'
				) . $tag_close;

			}
		}

		/**
		 * Allow the $next_steps array to be filtered.
		 */
		$next_steps = array_map( 'wp_kses_post', apply_filters( 'accp_update_wizard_complete_next_steps', $next_steps, $args ) );

		return $next_steps;
	}
} // END ARS_Constellation_Client_Portal_Wizards.
