Skip to content

Commit 3a59d9b

Browse files
author
Chris Gårdenberg
committed
Added skeleton code to start the plugin with some settings.
1 parent ebea549 commit 3a59d9b

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

class-edu-klarnacheckout.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
defined( 'ABSPATH' ) || die( 'This plugin must be run within the scope of WordPress.' );
3+
4+
if ( ! class_exists( 'EDU_KlarnaCheckout' ) ) {
5+
class EDU_KlarnaCheckout extends EDU_Integration {
6+
public function __construct() {
7+
$this->id = 'eduadmin-klarnacheckout';
8+
$this->displayName = __( 'Klarna Checkout', 'eduadmin-wp-klarna-checkout' );
9+
$this->description = '';
10+
11+
$this->init_form_fields();
12+
$this->init_settings();
13+
14+
add_action( 'eduadmin-checkpaymentplugins', array( $this, 'intercept_booking' ) );
15+
add_action( 'eduadmin-processbooking', array( $this, 'process_booking' ) );
16+
add_action( 'wp_loaded', array( $this, 'process_klarnaresponse' ) );
17+
}
18+
19+
public function intercept_booking() {
20+
if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
21+
return;
22+
}
23+
}
24+
25+
public function process_booking() {
26+
if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
27+
return;
28+
}
29+
}
30+
31+
public function process_klarnaresponse() {
32+
if ( 'no' === $this->get_option( 'enabled', 'no' ) ) {
33+
return;
34+
}
35+
}
36+
37+
public function init_form_fields() {
38+
$this->setting_fields = array(
39+
'enabled' => array(
40+
'title' => __( 'Enabled', 'edauadmin-wp-klarna-checkout' ),
41+
'type' => 'checkbox',
42+
'description' => __( 'Enables/Disabled the integration with Klarna Checkout', 'eduadmin-wp-klarna-checkout' ),
43+
'default' => 'no',
44+
),
45+
'username' => array(
46+
'title' => __( 'Username (UID)', 'eduadmin-wp-klarna-checkout' ),
47+
'type' => 'text',
48+
'description' => __( 'The API credential username from Klarna', 'eduadmin-wp-klarna-checkout' ),
49+
'default' => '',
50+
),
51+
'password' => array(
52+
'title' => __( 'Password', 'eduadmin-wp-klarna-checkout' ),
53+
'type' => 'password',
54+
'description' => __( 'Password for the API credentials from Klarna', 'eduadmin-wp-klarna-checkout' ),
55+
'default' => '',
56+
),
57+
);
58+
}
59+
}
60+
}

eduadmin-wp-klarna-checkout.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,43 @@
2828
You should have received a copy of the GNU General Public License
2929
along with this program. If not, see <http://www.gnu.org/licenses/>.
3030
*/
31+
32+
add_action( 'admin_init', function () {
33+
if ( is_admin() && current_user_can( 'activate_plugins' ) && ( ! is_plugin_active( 'eduadmin-booking/eduadmin.php' ) && ! is_plugin_active( 'eduadmin/eduadmin.php' ) ) ) {
34+
add_action( 'admin_notices', function () {
35+
?>
36+
<div class="error">
37+
<p><?php esc_html_e( 'This plugin requires the EduAdmin-WordPress-plugin to be installed and activated.', 'eduadmin-wp-klarna-checkout' ); ?></p>
38+
</div>
39+
<?php
40+
} );
41+
deactivate_plugins( plugin_basename( __FILE__ ) );
42+
if ( isset( $_GET['activate'] ) ) {
43+
unset( $_GET['activate'] );
44+
}
45+
}
46+
} );
47+
48+
if ( ! class_exists( 'EDU_KlarnaCheckout_Loader' ) ) {
49+
final class EDU_KlarnaCheckout_Loader {
50+
public function __construct() {
51+
add_action( 'plugins_loaded', array( $this, 'init' ) );
52+
}
53+
54+
public function init() {
55+
if ( class_exists( 'EDU_Integration' ) ) {
56+
require_once __DIR__ . '/class-edu-klarnacheckout.php';
57+
58+
add_filter( 'edu_integrations', array( $this, 'add_integration' ) );
59+
}
60+
}
61+
62+
public function add_integration( $integrations ) {
63+
$integrations[] = 'EDU_KlarnaCheckout';
64+
65+
return $integrations;
66+
}
67+
}
68+
69+
$edu_klarnacheckout_loader = new EDU_KlarnaCheckout_Loader();
70+
}

0 commit comments

Comments
 (0)