';
}
/**
* Shows a "connect first" box when there's no API key, and says whether it did.
*
* @return bool True when connected.
*/
private static function require_connection() {
if ( WalletPB_API::is_connected() ) {
return true;
}
echo '
';
return false;
}
/**
* The connect form, shown on the Pass Template tab until an account is connected.
*/
private static function render_connect() {
echo '
';
echo '
' . esc_html__( 'Connect your account', 'walletpassbuilder' ) . '
';
echo '
' . wp_kses(
sprintf(
/* translators: 1: sign-up link, 2: API key page link. */
__( 'You need a WalletPassBuilder account (create one free). Then copy your API key from API in the dashboard and paste it here.', 'walletpassbuilder' ),
esc_url( 'https://walletpassbuilder.com/signup' ),
esc_url( 'https://walletpassbuilder.com/api-keys' )
),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
) . '
';
echo '';
echo '
';
}
/**
* The connected account, with Disconnect - on the Settings tab.
*/
private static function render_account() {
echo '
' . esc_html__( 'Passes are created in your account\'s default workspace. Change it in WalletPassBuilder under Settings > Workspace.', 'walletpassbuilder' ) . '
';
}
echo '';
}
/**
* One label and value row.
*
* @param string $label Label.
* @param string $value Value.
*/
private static function info_row( $label, $value ) {
echo '
' . esc_html( $label ) . '
' . esc_html( $value ) . '
';
}
/**
* A page in the WalletPassBuilder web app, through sign-in if needed.
*
* @param string $path App path, such as "/home".
* @param string $campaign Campaign tag for where the link was clicked.
* @return string
*/
private static function app_url( $path, $campaign ) {
// The campaign tags ride on the page it lands on: a signed-in visitor skips straight past /login.
$next = $path . '?utm_source=wordpress&utm_medium=plugin&utm_campaign=' . rawurlencode( $campaign );
return 'https://walletpassbuilder.com/login?next=' . rawurlencode( $next );
}
/**
* The saved key with only its start and end shown.
*
* @return string
*/
private static function masked_key() {
$key = WalletPB_API::api_key();
return strlen( $key ) > 14 ? substr( $key, 0, 9 ) . str_repeat( '•', 8 ) . substr( $key, -4 ) : str_repeat( '•', 8 );
}
/**
* Pass Template tab: the connect form until an account is connected, then the template.
*/
private static function tab_pass() {
if ( ! WalletPB_API::is_connected() ) {
self::render_connect();
return;
}
// The templates share this editor and the brand: the Generic Pass (the shortcode's pass) and,
// for each booking plugin installed, its booking passes (a card per booking).
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- only picks which template to show.
$class = self::integration_for( isset( $_GET['template'] ) ? sanitize_key( wp_unslash( $_GET['template'] ) ) : '' );
$booking = '' !== $class;
$v = $booking ? array_merge( WalletPB_Template::values(), $class::booking_template() ) : WalletPB_Template::values();
$pass = $booking ? array() : WalletPB_Template::pass();
$logo = $v['logo_id'] ? wp_get_attachment_image_url( $v['logo_id'], 'thumbnail' ) : '';
$logo = $logo ? $logo : WalletPB_Template::default_logo_url();
$name = function ( $field ) {
return 'walletpb[' . $field . ']';
};
$templates = array_filter(
WalletPB_Integration::all(),
function ( $integration ) {
return $integration::available();
}
);
if ( $templates ) {
echo '';
}
$mode = $booking ? $class::SOURCE : 'event';
$host_info = $booking ? self::integration_info( WalletPB_Integration::host_of( $class::SOURCE ) ) : null;
echo '';
}
/**
* Integrations tab: a compact card per installed booking plugin, the others as one line.
*/
private static function tab_integrations() {
if ( ! self::require_connection() ) {
return;
}
$installed = array();
$missing = array();
foreach ( WalletPB_Integration::hosts() as $host => $entry ) {
$first = $entry[1][0];
if ( $first::available() ) {
$installed[ $host ] = $entry;
} else {
$missing[ $host ] = $entry;
}
}
// Those that are on first.
uksort(
$installed,
function ( $x, $y ) use ( $installed ) {
$on_x = $installed[ $x ][1][0]::enabled();
$on_y = $installed[ $y ][1][0]::enabled();
return $on_x === $on_y ? 0 : ( $on_x ? -1 : 1 );
}
);
// None of the supported plugins is active: say what this tab does and offer them.
if ( ! $installed ) {
echo '
' . esc_html__( 'Give every booking or ticket its own wallet pass', 'walletpassbuilder' ) . '
';
echo '
' . esc_html__( 'Install one of these plugins and turn it on here. Each customer then gets their own pass, kept up to date when their booking changes.', 'walletpassbuilder' ) . '
' . esc_html( ! empty( $info['idle'] ) ? $info['idle'] : __( 'Turns on in one click. No credits are used until a booking comes in.', 'walletpassbuilder' ) ) . '
';
$answers = array(
__( 'A booking didn\'t get a pass', 'walletpassbuilder' ) => __( 'Check that its integration is on under Integrations, then look in Activity: a failed entry says why, and Retry sends it again once that\'s fixed.', 'walletpassbuilder' ),
__( 'Passes on phones haven\'t changed', 'walletpassbuilder' ) => __( 'Saving a template updates the passes already on phones. It can take a few minutes for them to change.', 'walletpassbuilder' ),
__( 'When do reminders appear?', 'walletpassbuilder' ) => __( 'iPhone shows the pass on the lock screen at the start time; Google Wallet sends a reminder the day before.', 'walletpassbuilder' ),
__( 'What uses pass credits?', 'walletpassbuilder' ) => __( 'Creating a pass uses one credit, and so does each booking\'s own pass. Your plan and balance are on the Settings tab.', 'walletpassbuilder' ),
);
foreach ( $answers as $question => $answer ) {
echo '' . esc_html( $question ) . '
' . esc_html( $answer ) . '
';
}
/* translators: 1: the WordPress.org forum link, 2: the support email address. */
echo '
' . wp_kses_post( sprintf( __( 'You can also ask on the %1$s or email %2$s.', 'walletpassbuilder' ), $forum, $mail ) ) . '
';
if ( ! WalletPB_API::is_connected() ) {
/* translators: %s: the support email address. */
echo '
' . wp_kses_post( sprintf( __( 'Connect your account on the Pass Template tab to message us from here, or email %s.', 'walletpassbuilder' ), $mail ) ) . '
';
return;
}
echo '
' . esc_html__( 'It goes straight to the WalletPassBuilder team, with your account, and we reply by email.', 'walletpassbuilder' ) . '