Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two plugin fixes #12

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions omnisend/class-omnisend-core-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
// Omnisend for Woo plugin.
const OMNISEND_CORE_WOOCOMMERCE_PLUGIN_API_KEY_OPTION = 'omnisend_api_key';

spl_autoload_register( array( 'Omnisend_Core_Bootstrap', 'autoloader' ) );
register_uninstall_hook( __FILE__, 'Omnisend_Core_Bootstrap::uninstall' );
add_action( 'plugins_loaded', 'Omnisend_Core_Bootstrap::load' );

class Omnisend_Core_Bootstrap {

public static function load() {
spl_autoload_register( array( 'Omnisend_Core_Bootstrap', 'autoloader' ) );

public static function load(): void {
add_action( 'admin_notices', 'Omnisend_Core_Bootstrap::admin_notices' );
add_action( 'admin_menu', 'Omnisend_Core_Bootstrap::add_admin_menu' );
add_action( 'admin_enqueue_scripts', 'Omnisend_Core_Bootstrap::load_omnisend_admin_styles' );
Expand All @@ -63,7 +63,7 @@ public static function add_admin_menu() {
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $omnisend_icon, $position );
}

public static function load_omnisend_admin_styles() {
public static function load_omnisend_admin_styles(): void {
// phpcs:disable WordPress.Security.NonceVerification
if ( isset( $_GET['page'] ) ) {
if ( in_array( $_GET['page'], array( 'omnisend' ), true ) ) {
Expand All @@ -83,7 +83,7 @@ public static function load_omnisend_admin_styles() {
}
}

public static function admin_notices() {
public static function admin_notices(): void {
if ( Options::is_connected() && self::is_omnisend_woocommerce_plugin_active() && ! get_option( OMNISEND_CORE_WOOCOMMERCE_PLUGIN_API_KEY_OPTION ) ) {
echo '<div class="notice notice-error">If you want to use <strong>Omnisend for Woo</strong> plugin please contact customer support.</p></div>';
}
Expand Down Expand Up @@ -120,4 +120,8 @@ public static function autoloader( $class_name ): void {
require_once $path;
}
}

public static function uninstall(): void {
Options::delete_all();
}
}
2 changes: 0 additions & 2 deletions omnisend/includes/Internal/class-connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Omnisend\Internal;

use Omnisend\Public\Client\V1\Client;
use Omnisend\Public\Client\V1\Contact;
use Omnisend_Core_Bootstrap;

defined( 'ABSPATH' ) || die( 'no direct access' );
Expand Down
14 changes: 9 additions & 5 deletions omnisend/includes/Internal/class-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
defined( 'ABSPATH' ) || die( 'no direct access' );

class Options {

private const OPTION_API_KEY = 'omnisend_core_api_key';
private const OPTION_BRAND_ID = 'omnisend_core_brand_id';
private const OPTION_STORE_CONNECTED = 'omnisend_core_store_connected';
// omni_send instead of omnisend used to distinct and not interfere with Omnisend for Woo plugin.
private const OPTION_API_KEY = 'omni_send_core_api_key';
private const OPTION_BRAND_ID = 'omni_send_core_brand_id';
private const OPTION_STORE_CONNECTED = 'omni_send_core_store_connected';

public static function get_api_key(): string {
$api_key = get_option( self::OPTION_API_KEY );
Expand Down Expand Up @@ -55,9 +55,13 @@ public static function is_connected(): bool {
return self::is_store_connected() && self::get_api_key();
}

public static function disconnect() {
public static function disconnect(): void {
delete_option( self::OPTION_API_KEY );
delete_option( self::OPTION_BRAND_ID );
delete_option( self::OPTION_STORE_CONNECTED );
}

public static function delete_all(): void {
self::disconnect();
}
}
4 changes: 2 additions & 2 deletions omnisend/includes/Internal/class-snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
class Snippet {

public static function add() {
$brand_id = Omnisend_Core_Options::get_brand_id();
$brand_id = Options::get_brand_id();
if ( $brand_id ) {
require_once 'view/snippet.html';
require_once __DIR__ . '/../../view/snippet.html';
}
}
}
Loading