Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Apr 23, 2024
1 parent cb83bf4 commit e0cfbaa
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 56 deletions.
43 changes: 43 additions & 0 deletions src/Admin/AdminAboutPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function __construct( Plugin $plugin, $file ) {
// Actions.
add_action( 'admin_menu', [ $this, 'admin_menu' ] );
add_action( 'admin_head', [ $this, 'admin_head' ] );

add_action( 'pronamic_pay_install', [ $this, 'install' ] );
}

/**
Expand Down Expand Up @@ -161,4 +163,45 @@ public function get_version() {
public function render_page() {
include $this->get_file();
}

/**
* Install.
*
* @return void
*/
public function install() {
$current_version = \get_option( 'pronamic_pay_version', null );

try {
$about_page_version = $this->get_version();
} catch ( \Exception $e ) {
$about_page_version = '';
}

$about_page_version_viewed = \get_option( 'pronamic_pay_about_page_version', null );

$tab = null;

if ( null === $current_version ) {
// No version? This is a new install :).
$tab = 'getting-started';
} elseif ( \version_compare( $about_page_version_viewed, $about_page_version, '<' ) ) {
// Show about page only if viewed version is lower then current version.
$tab = 'new';
}

if ( null !== $tab ) {
$url = \add_query_arg(
[
'page' => 'pronamic-pay-about',
'tab' => $tab,
],
\admin_url( 'index.php' )
);

\set_transient( 'pronamic_pay_admin_redirect', $url, 3600 );
}

\update_option( 'pronamic_pay_about_page_version', $about_page_version );
}
}
66 changes: 11 additions & 55 deletions src/Admin/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,14 @@ class Install {
*/
private $plugin;

/**
* Admin.
*
* @var AdminModule
*/
private $admin;

/**
* Constructs and initializes an install object.
*
* @link https://github.com/woothemes/woocommerce/blob/2.4.3/includes/class-wc-install.php
*
* @param Plugin $plugin Plugin.
* @param AdminModule $admin Admin.
* @param Plugin $plugin Plugin.
*/
public function __construct( Plugin $plugin, AdminModule $admin ) {
public function __construct( Plugin $plugin ) {
$this->plugin = $plugin;
$this->admin = $admin;

// Actions.
add_action( 'init', [ $this, 'init' ], 5 );
Expand Down Expand Up @@ -80,13 +70,13 @@ public function init() {
foreach ( $upgrades as $upgrade ) {
$version = $upgrade->get_version();

if ( ! version_compare( $version_option, $version, '<' ) ) {
if ( ! \version_compare( $version_option, $version, '<' ) ) {
continue;
}

$upgrade->execute();

update_option( $version_option_name, $version );
\update_option( $version_option_name, $version );
}
}
}
Expand All @@ -101,50 +91,16 @@ private function install() {
$this->create_roles();

// Rewrite Rules.
flush_rewrite_rules();
\flush_rewrite_rules();

// Version.
$version = $this->plugin->get_version();

$current_version = get_option( 'pronamic_pay_version', null );

// Redirect.
if ( null !== $this->admin->about_page ) {
try {
$about_page_version = $this->admin->about_page->get_version();
} catch ( \Exception $e ) {
$about_page_version = '';
}

$about_page_version_viewed = get_option( 'pronamic_pay_about_page_version', null );

$tab = null;

if ( null === $current_version ) {
// No version? This is a new install :).
$tab = 'getting-started';
} elseif ( version_compare( $about_page_version_viewed, $about_page_version, '<' ) ) {
// Show about page only if viewed version is lower then current version.
$tab = 'new';
}

if ( null !== $tab ) {
$url = add_query_arg(
[
'page' => 'pronamic-pay-about',
'tab' => $tab,
],
admin_url( 'index.php' )
);

set_transient( 'pronamic_pay_admin_redirect', $url, 3600 );
}

update_option( 'pronamic_pay_about_page_version', $about_page_version );
}
// Action.
\do_action( 'pronamic_pay_install' );

// Update version.
update_option( 'pronamic_pay_version', $version );
\update_option( 'pronamic_pay_version', $version );
}

/**
Expand All @@ -157,7 +113,7 @@ private function install() {
*/
private function create_roles() {
// Payer role.
add_role(
\add_role(
'payer',
__( 'Payer', 'pronamic_ideal' ),
[
Expand All @@ -166,7 +122,7 @@ private function create_roles() {
);

// @link https://developer.wordpress.org/reference/functions/wp_roles/.
$roles = wp_roles();
$roles = \wp_roles();

// Payments.
$payment_capabilities = PaymentPostType::get_capabilities();
Expand All @@ -187,7 +143,7 @@ private function create_roles() {
private function get_upgradeable_integrations() {
$integrations = $this->plugin->integrations;

$integrations = array_filter(
$integrations = \array_filter(
$integrations,
/**
* Filter integration with version option name.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ public function plugins_loaded() {
$this->admin = new Admin\AdminModule( $this );
}

new Admin\Install( $this, $this->admin );
new Admin\Install( $this );

$controllers = [
new PagesController(),
Expand Down

0 comments on commit e0cfbaa

Please sign in to comment.