HEX
Server: Apache/2
System: Linux bq-e705.pointdnshere.com 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User: wellmix (1103)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/wellmix/public_html/wp-content/plugins/pymntpl-paypal-woocommerce/src/Admin/Install.php
<?php


namespace PaymentPlugins\WooCommerce\PPCP\Admin;

use PaymentPlugins\WooCommerce\PPCP\Constants;

/**
 * Class Install
 *
 * @package PaymentPlugins\WooCommerce\PPCP\Admin
 */
class Install {

	private $version;

	/**
	 * Install constructor.
	 *
	 * @param string $plugin_name
	 */
	public function __construct( $plugin_name, $version ) {
		$this->version = $version;
		register_activation_hook( $plugin_name, [ $this, 'install' ] );
		add_filter( 'plugin_action_links_' . $plugin_name, [ $this, 'add_links' ] );
		add_action( 'admin_init', [ $this, 'initialize' ] );
	}

	public function initialize() {
		if ( get_option( Constants::INSTALL_PROCESS, 'no' ) === 'yes' ) {
			// redirect to the API Settings page if this is the first time the merchant is installing the plugin.
			delete_option( Constants::INSTALL_PROCESS );
			wp_safe_redirect( admin_url( 'admin.php?page=wc-ppcp-main&wc_ppcp_init' ) );
		}
	}

	public function install() {
		if ( ! get_option( Constants::VERSION_KEY, null ) ) {
			// only add this option if this is the first time the merchant is activating the plugin
			update_option( Constants::INSTALL_PROCESS, 'yes' );
		}
		update_option( Constants::VERSION_KEY, $this->version );
	}

	public function add_links( $links ) {
		return $links + [
				'settings' => sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp_api' ), esc_html__( 'Settings', 'pymntpl-paypal-woocommerce' ) )
			];
	}

}