*/ public static function checks() { $settings = admin_url( 'admin.php?page=' . Paygrab_Settings_Page::SLUG ); $protect = Paygrab_Files::last_check(); $pages = paygrab_page_url( 'checkout' ) && paygrab_page_url( 'mypage' ) && paygrab_page_url( 'register' ) && paygrab_page_url( 'login' ) && paygrab_page_url( 'tokushoho' ); $product = (bool) get_posts( array( 'post_type' => Paygrab_Product::TYPE, 'post_status' => 'publish', 'posts_per_page' => 1, 'fields' => 'ids', ) ); return array( array( 'label' => __( 'Create the pages (done automatically)', 'paygrab' ), 'done' => $pages, 'url' => $settings . '#pages', 'button' => __( 'Check the pages', 'paygrab' ) ), array( 'label' => Paygrab_Gateways::bank_only() ? __( 'Enter the bank account', 'paygrab' ) : __( 'Set up a way to pay', 'paygrab' ), 'done' => Paygrab_Gateways::ready(), 'url' => $settings . '#payment', 'button' => Paygrab_Gateways::bank_only() ? __( 'Enter the bank account', 'paygrab' ) : __( 'Set up payments', 'paygrab' ), ), array( 'label' => __( 'Fill in the legal notice', 'paygrab' ), 'done' => ! Paygrab_Settings::missing_law_items(), 'url' => $settings . '#law', 'button' => __( 'Fill in the legal notice', 'paygrab' ) ), array( 'label' => __( 'Check that files cannot be opened from outside', 'paygrab' ), 'done' => is_array( $protect ) && 'ok' === $protect['status'], 'url' => $settings . '#protect', 'button' => __( 'Check the file protection', 'paygrab' ) ), array( 'label' => __( 'Check that test emails arrive', 'paygrab' ), 'done' => (bool) get_option( 'paygrab_test_mail_sent' ), 'url' => $settings . '#mail', 'button' => __( 'Send a test email', 'paygrab' ) ), array( 'label' => __( 'Create your first product', 'paygrab' ), 'done' => $product, 'url' => Paygrab_Admin_Products::form_url(), 'button' => __( 'Add new product', 'paygrab' ) ), ); } /** * UTC datetime of the first moment of a month (site time). * * @param string $modify e.g. 'first day of this month', 'first day of last month'. * @return string */ private static function month_start( $modify ) { return ( new DateTimeImmutable( $modify . ' 00:00', wp_timezone() ) )->setTimezone( new DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' ); } /** * Days until a deadline (site time), and the text for it. * * @param string $gmt Deadline in UTC. * @return array{text:string,soon:bool} */ private static function due( $gmt ) { $tz = wp_timezone(); $today = new DateTimeImmutable( 'today', $tz ); $day = ( new DateTimeImmutable( $gmt . ' UTC' ) )->setTimezone( $tz )->setTime( 0, 0 ); $days = (int) $today->diff( $day )->format( '%r%a' ); $date = wp_date( 'n/j', strtotime( $gmt . ' UTC' ) ); if ( $days < 0 ) { /* translators: %s: date */ return array( 'text' => sprintf( __( 'Due %s (passed)', 'paygrab' ), $date ), 'soon' => true ); } if ( $days <= 1 ) { /* translators: 1: today / tomorrow, 2: date */ return array( 'text' => sprintf( __( 'Due %1$s (%2$s)', 'paygrab' ), 0 === $days ? __( 'today', 'paygrab' ) : __( 'tomorrow', 'paygrab' ), $date ), 'soon' => true ); } /* translators: 1: date, 2: number of days */ return array( 'text' => sprintf( __( 'Due %1$s (%2$d days left)', 'paygrab' ), $date, $days ), 'soon' => false ); } /** * The screen. * * @return void */ public static function render() { if ( ! current_user_can( 'manage_options' ) ) { return; } $checks = self::checks(); $done = count( array_filter( wp_list_pluck( $checks, 'done' ) ) ); $left = count( $checks ) - $done; $ready = 0 === $left; $first = $ready && ! get_option( self::READY_SEEN ); if ( $first ) { update_option( self::READY_SEEN, time(), false ); } $protect = Paygrab_Files::last_check(); $this_month = self::month_start( 'first day of this month' ); $next_month = self::month_start( 'first day of next month' ); $last_month = self::month_start( 'first day of last month' ); $now = Paygrab_Orders::stats_between( $this_month, $next_month ); $before = Paygrab_Orders::stats_between( $last_month, $this_month ); $diff = $now['total'] - $before['total']; $counts = Paygrab_Orders::count_by_status(); $selling = count( Paygrab_Admin_Products::selling_ids() ); $bank = Paygrab_Gateways::get( 'bank_manual' ); $by_hand = $bank && $bank->is_available(); $pending = $by_hand ? Paygrab_Orders::query( array( 'status' => 'pending', 'per_page' => 20 ) )['items'] : array(); // Only orders the seller confirms by hand; payments that the gateway confirms (Stripe) are left out. $by_gateway = static function ( $id ) { $gateway = Paygrab_Gateways::get( (string) $id ); return $gateway && $gateway->confirms_payments(); }; $pending = array_slice( array_values( array_filter( $pending, static fn( $o ) => ! $by_gateway( $o->gateway ) ) ), 0, 5 ); $automatic = 0; foreach ( Paygrab_Orders::count_pending_by_gateway() as $paygrab_gateway => $paygrab_count ) { $automatic += $by_gateway( $paygrab_gateway ) ? $paygrab_count : 0; } $recent = Paygrab_Orders::latest( 5 ); $settings = admin_url( 'admin.php?page=' . Paygrab_Settings_Page::SLUG ); ?>
' . esc_html__( 'Nothing was sold in the last 30 days.', 'paygrab' ) . '
'; return; } echo '