label.
*/
private static function tabs() {
return array(
self::TAB_FILES => _x( 'Digital products', 'my page tab', 'paygrab' ),
self::TAB_DOWNLOADS => __( 'Downloads', 'paygrab' ),
);
}
/**
* Tab buttons (before the "Account" tab).
*
* @param WP_User $user Member.
* @param array $opts The theme's paid-article options.
* @param string $default_tab Selected tab.
* @return void
*/
public static function render_tabs( $user, $opts, $default_tab ) {
foreach ( self::tabs() as $key => $label ) {
printf(
'',
$key === $default_tab ? 'is-active' : '',
esc_attr( $key ),
esc_html( $label )
);
}
}
/**
* Tab contents.
*
* @param WP_User $user Member.
* @param array $opts The theme's paid-article options.
* @param string $default_tab Selected tab.
* @return void
*/
public static function render_panels( $user, $opts, $default_tab ) {
$views = array(
self::TAB_FILES => 'orders',
self::TAB_DOWNLOADS => 'downloads',
);
$tabs = self::tabs();
foreach ( $views as $key => $view ) {
printf(
'',
$key === $default_tab ? 'is-active' : '',
esc_attr( $key ),
esc_attr( $tabs[ $key ] )
);
echo Paygrab_Mypage::render( $view, true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in the templates.
echo '';
}
}
/**
* Open PAYGRAB's tab when the URL asks for it (links in emails, the buy box, after paying).
*
* @param string $default_tab Tab the theme would open.
* @param string $requested_tab Tab in the URL.
* @return string
*/
public static function default_tab( $default_tab, $requested_tab ) {
$requested_tab = sanitize_key( (string) $requested_tab );
if ( in_array( $requested_tab, array( self::TAB_FILES, self::TAB_DOWNLOADS ), true ) ) {
return $requested_tab;
}
if ( '' !== paygrab_requested_order() ) {
return self::TAB_FILES;
}
return $default_tab;
}
/**
* Add "purchased files will be lost too" to the theme's withdrawal text.
*
* @param string $description The theme's text (may contain br and a).
* @param WP_User $user Member.
* @return string
*/
public static function withdraw_description( $description, $user ) {
if ( ! $user instanceof WP_User || ! Paygrab_Orders::for_user( $user->ID ) ) {
return $description;
}
return $description . '
' . esc_html__( 'Files you bought can no longer be downloaded either.', 'paygrab' );
}
/**
* Send visitors of PAYGRAB's own buyer page to the theme's My page (the matching tab).
*
* @return void
*/
public static function redirect_own_pages() {
if ( 'GET' !== paygrab_request_method() || self::on_theme_mypage() || ! paygrab_is_page( 'mypage' ) ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen selection only.
$view = isset( $_GET['tab'] ) && 'downloads' === $_GET['tab'] ? 'downloads' : 'orders';
$url = paygrab_mypage_url( paygrab_requested_order(), $view );
foreach ( array( 'paygrab_notice', 'paygrab_error' ) as $key ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET[ $key ] ) ) {
$url = add_query_arg( $key, sanitize_key( wp_unslash( $_GET[ $key ] ) ), $url ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
}
wp_safe_redirect( $url );
exit;
}
}