%s', esc_html( $error ) );
}
if ( self::$notice_shown || empty( $_GET['postfee_notice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only chooses which notice is shown.
return;
}
self::$notice_shown = true;
$messages = array(
'paid' => array( 'success', __( 'Payment received. Thank you!', 'postfee' ) ),
'processing' => array( 'info', __( 'Your payment is being processed. This page will update once it is confirmed.', 'postfee' ) ),
'credit_used' => array( 'success', __( 'Your post was submitted using one of your posts.', 'postfee' ) ),
'saved' => array( 'success', __( 'Your changes were saved.', 'postfee' ) ),
'deleted' => array( 'success', __( 'Your post was deleted.', 'postfee' ) ),
'sub_cancelled' => array( 'success', __( 'Your subscription will not renew. You keep access until the end of the current period.', 'postfee' ) ),
'already_subscribed' => array( 'info', __( 'You are already subscribed to this plan.', 'postfee' ) ),
'gateway_error' => array( 'error', __( 'We could not start the payment. Please try again or contact us.', 'postfee' ) ),
'error' => array( 'error', __( 'Something went wrong. Please try again.', 'postfee' ) ),
);
$key = sanitize_key( $_GET['postfee_notice'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only chooses which notice is shown.
if ( isset( $messages[ $key ] ) ) {
printf( '
%s
', esc_attr( $messages[ $key ][0] ), esc_html( $messages[ $key ][1] ) );
}
}
public static function login_prompt() {
printf(
'%s %s
',
esc_html__( 'Please log in to continue.', 'postfee' ),
esc_url( wp_login_url( postfee_page_url( 'submit' ) ) ),
esc_html__( 'Log in', 'postfee' )
);
}
/**
* One plan with its buy button(s). $post_id is the post being paid for
* or upgraded, or 0 when buying credits ahead of time.
*/
private static function plan_card( $plan, $post_id = 0 ) {
?>
' . esc_html__( 'Not available right now.', 'postfee' ) . '';
return;
}
?>
' . esc_html__( 'There are no plans available yet.', 'postfee' ) . '';
return;
}
echo '';
foreach ( $plans as $plan ) {
self::plan_card( $plan, $post_id );
}
echo '
';
}
public static function pay_step( $post ) {
if ( ! $post ) {
echo '' . esc_html__( 'This post does not need a payment.', 'postfee' ) . '
';
return;
}
/* translators: %s: post title */
echo '' . esc_html( sprintf( __( 'Publish “%s”', 'postfee' ), $post->post_title ) ) . '
';
$entitlement = Entitlements::find_usable( get_current_user_id(), $post->post_type );
if ( $entitlement ) {
$remaining = Entitlements::remaining( $entitlement );
?>
' . esc_html__( 'Choose a plan to publish your post.', 'postfee' ) . '';
self::plan_grid( Plans::all( array( 'single', 'package', 'subscription' ), $post->post_type ), $post->ID );
}
public static function upgrade_step( $post ) {
if ( ! $post ) {
echo '' . esc_html__( 'This post cannot be upgraded.', 'postfee' ) . '
';
return;
}
/* translators: %s: post title */
echo '' . esc_html( sprintf( __( 'Upgrade “%s”', 'postfee' ), $post->post_title ) ) . '
';
$plans = Plans::all( array( 'upgrade' ), $post->post_type );
// An expired post can only be brought back by something that adds listing time.
if ( Posts::EXPIRED === $post->post_status ) {
$plans = array_filter(
$plans,
function ( $plan ) {
return $plan['listing_days'] > 0;
}
);
}
self::plan_grid( $plans, $post->ID );
printf( '%s
', esc_url( postfee_page_url( 'dashboard' ) ), esc_html__( '← Back to my posts', 'postfee' ) );
}
/**
* The current user's packages and subscriptions. Prints nothing when they
* have none.
*/
public static function entitlements_table( $heading ) {
$entitlements = Entitlements::current_for_user( get_current_user_id() );
if ( ! $entitlements ) {
return;
}
?>
|
|
|
|
gateway_sub_id;
?>
| plan_id ) ? get_the_title( $entitlement->plan_id ) : '#' . $entitlement->plan_id ); ?> |
credits_total ) );
?>
|
expires_at ) {
esc_html_e( 'No expiry', 'postfee' );
} elseif ( $is_subscription && 'active' === $entitlement->status ) {
/* translators: %s: date */
echo esc_html( sprintf( __( 'Renews around %s', 'postfee' ), postfee_format_date( $entitlement->expires_at ) ) );
} else {
echo esc_html( postfee_format_date( $entitlement->expires_at ) );
}
?>
|
status && in_array( $entitlement->gateway, array( 'stripe', 'paypal' ), true ) ) : ?>
status ) : ?>
gateway && function_exists( 'wc_get_page_permalink' ) ) : ?>
|
post_status ? 0 : (int) get_post_meta( $post->ID, '_postfee_plan_id', true );
}
public static function posts_table( $heading, $per_page = 10 ) {
$post_types = postfee_post_types();
$args = array(
'post_type' => $post_types,
'post_status' => array( 'publish', 'pending', Posts::UNPAID, Posts::EXPIRED ),
'author' => get_current_user_id(),
'posts_per_page' => $per_page,
'paged' => isset( $_GET['postfee_page'] ) ? max( 1, absint( $_GET['postfee_page'] ) ) : 1, // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only pages the user's own posts.
'orderby' => 'modified',
'ignore_sticky_posts' => true,
);
// The plans the user's posts were paid with, for the plan column and the filter.
$plans = array();
$paid_ids = ! $post_types ? array() : get_posts(
array(
'post_status' => array( 'publish', 'pending', Posts::EXPIRED ),
'posts_per_page' => 500,
'paged' => 1,
'fields' => 'ids',
) + $args
);
update_meta_cache( 'post', $paid_ids );
foreach ( $paid_ids as $paid_id ) {
$plan_id = (int) get_post_meta( $paid_id, '_postfee_plan_id', true );
if ( $plan_id && ! isset( $plans[ $plan_id ] ) ) {
$plans[ $plan_id ] = get_the_title( $plan_id ) ? get_the_title( $plan_id ) : '#' . $plan_id;
}
}
$filter = isset( $_GET['postfee_plan'] ) ? absint( $_GET['postfee_plan'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only filters the user's own posts.
if ( isset( $plans[ $filter ] ) ) {
$args['post_status'] = array( 'publish', 'pending', Posts::EXPIRED );
$args['meta_key'] = '_postfee_plan_id'; // phpcs:ignore WordPress.DB.SlowDBQuery -- Limited to one author's posts.
$args['meta_value'] = $filter; // phpcs:ignore WordPress.DB.SlowDBQuery -- Limited to one author's posts.
} else {
$filter = 0;
}
$query = new \WP_Query();
$posts = $post_types ? $query->query( $args ) : array();
if ( ! $posts && $args['paged'] > 1 ) {
// Past the last page, which a link from before a post was deleted can be.
$args['paged'] = 1;
$posts = $query->query( $args );
}
$pages = (int) $query->max_num_pages;
$paged = $args['paged'];
$page_url = function ( $number ) use ( $filter ) {
return postfee_page_url( 'dashboard', array_filter( array( 'postfee_plan' => $filter, 'postfee_page' => $number > 1 ? $number : 0 ) ) );
};
$has_upgrades = (bool) Plans::all( array( 'upgrade' ) );
wp_enqueue_script( 'postfee-my-posts' );
?>
1 ) : ?>
|
|
|
|
|
ID, '_postfee_expires', true );
$payable = in_array( $post->post_status, array( Posts::UNPAID, Posts::EXPIRED ), true );
?>
|
post_status ) : ?>
ID ) ) : ?>
|
|
ID, '_postfee_suspended', true ) ? __( 'Subscription ended', 'postfee' ) : Posts::status_label( $post->post_status ) ); ?> |
post_status && $expires ? wp_date( get_option( 'date_format' ), $expires ) : '—' ); ?> |
post_status ? __( 'Relist', 'postfee' ) : __( 'Pay now', 'postfee' ) ); ?>
post_status ) : ?>
|
1 ) : ?>