-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpmpro-square.php
100 lines (89 loc) · 3.49 KB
/
pmpro-square.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* Plugin Name: Paid Memberships Pro - Square Gateway
* Plugin URI: https://www.paidmembershipspro.com/add-ons/square
* Description: PMPro Gateway integration for Square
* Version: 0.1
* Author: Paid Memberships Pro
* Author URI: https://www.paidmembershipspro.com
* Text Domain: pmpro-square
* License: GPLv3 or later
* Domain Path: /languages
*/
define( "PMPRO_SQUARE_DIR", plugin_dir_path( __FILE__ ) );
define( "PMPRO_SQUARE_URL", plugin_dir_url( __FILE__ ) );
/**
* Loads rest of Square gateway if PMPro is active.
*/
function pmpro_square_load_gateway() {
load_plugin_textdomain( 'pmpro-square' );
if ( class_exists( 'PMProGateway' ) ) {
require_once( PMPRO_SQUARE_DIR . 'includes/libs/autoload.php' );
require_once( PMPRO_SQUARE_DIR . 'classes/class.pmprogateway_square.php' );
}
}
add_action( 'plugins_loaded', 'pmpro_square_load_gateway' );
/**
* Runs only when the plugin is activated.
*
* @since 0.1.0
*/
function pmpro_square_admin_notice_activation_hook() {
// Create transient data.
set_transient( 'pmpro-square-admin-notice', true, 5 );
// Cron to check the webhook status.
if ( ! wp_next_scheduled( 'pmpro_square_check_webhooks_status' ) ) {
wp_schedule_event( time(), 'weekly', 'pmpro_square_check_webhooks_status' );
}
}
register_activation_hook( __FILE__, 'pmpro_square_admin_notice_activation_hook' );
/**
* Admin Notice on Activation.
*
* @since 0.1.0
*/
function pmpro_square_admin_notice() {
// Check transient, if available display notice.
if ( get_transient( 'pmpro-square-admin-notice' ) ) {
?>
<div class="updated notice is-dismissible">
<p><?php printf( esc_html__( 'Thank you for activating the Paid Memberships Pro: Square Add On. <a href="%s">Visit the payment settings page</a> to configure the Square Payment Gateway.', 'pmpro-square' ), esc_url( get_admin_url( null, 'admin.php?page=pmpro-paymentsettings' ) ) ); ?></p>
</div>
<?php
// Delete transient, only display this notice once.
delete_transient( 'pmpro-square-admin-notice' );
}
}
add_action( 'admin_notices', 'pmpro_square_admin_notice' );
/**
* Function to add links to the plugin action links
*
* @param array $links Array of links to be shown in plugin action links.
*/
function pmpro_square_plugin_action_links( $links ) {
if ( current_user_can( 'manage_options' ) ) {
$new_links = array(
'<a href="' . get_admin_url( null, 'admin.php?page=pmpro-paymentsettings' ) . '">' . __( 'Configure Square', 'pmpro-square' ) . '</a>',
);
$links = array_merge( $links, $new_links );
}
return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'pmpro_square_plugin_action_links' );
/**
* Function to add links to the plugin row meta
*
* @param array $links Array of links to be shown in plugin meta.
* @param string $file Filename of the plugin meta is being shown for.
*/
function pmpro_square_plugin_row_meta( $links, $file ) {
if ( strpos( $file, 'pmpro-square.php' ) !== false ) {
$new_links = array(
'<a href="' . esc_url( 'https://www.paidmembershipspro.com/add-ons/square/' ) . '" title="' . esc_attr__( 'View Documentation', 'pmpro-square' ) . '">' . esc_html__( 'Docs', 'pmpro-square' ) . '</a>',
'<a href="' . esc_url( 'https://www.paidmembershipspro.com/support/' ) . '" title="' . esc_attr__( 'Visit Customer Support Forum', 'pmpro-square' ) . '">' . esc_html__( 'Support', 'pmpro-square' ) . '</a>',
);
$links = array_merge( $links, $new_links );
}
return $links;
}
add_filter( 'plugin_row_meta', 'pmpro_square_plugin_row_meta', 10, 2 );