__( 'Not saved: you do not manage the shop.', 'ai-eshop-optimizer' ) ) ); } $posted = isset( $_POST['hours'] ) && is_array( $_POST['hours'] ) ? wp_unslash( $_POST['hours'] ) : array(); $listed = AIEO_Staff_Digest::save( $posted ); wp_send_json_success( array( 'message' => $listed ? sprintf( _n( 'Saved: %d address gets a list, the others each submission.', 'Saved: %d addresses get a list, the others each submission.', count( $listed ), 'ai-eshop-optimizer' ), count( $listed ) ) : __( 'Saved: every address gets each submission as it arrives.', 'ai-eshop-optimizer' ), ) ); } public function render_subtab() { $form = 'aieo-card-staff-notifications-form'; $map = AIEO_Staff_Digest::addresses(); list( $open, $close ) = AIEO_DMM_UI::card( array( 'anchor' => 'staff-notifications-addresses', 'icon' => 'bell', 'title' => __( 'How each address hears of new submissions', 'ai-eshop-optimizer' ), 'description' => __( 'The site forms, the product requests and the contact form mail these addresses. Each one gets a mail for every submission, or one list every few hours with each submission\'s time, who sent it and its link in the admin; no list is sent when nothing came. Who is mailed is set on each form, under Product Requests and under Contact Form.', 'ai-eshop-optimizer' ), 'footer' => $map ? \Rooster\Admin\States::save_button( $form ) : '', ) ); echo $open; if ( ! $map ) { echo \Rooster\Admin\States::state( 'first-use', array( 'compact' => true, 'title' => __( 'No staff address is mailed yet.', 'ai-eshop-optimizer' ), 'text' => __( 'A form that mails its entries, Product Requests or the contact form adds its addresses here.', 'ai-eshop-optimizer' ) ) ); echo $close; return; } $prefs = AIEO_Staff_Digest::prefs(); $waiting = AIEO_Staff_Digest::waiting(); $choices = AIEO_Staff_Digest::choices(); $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); $rows = ''; foreach ( $map as $email => $what ) { $id = 'aieo-sn-' . substr( md5( $email ), 0, 10 ); $hours = (int) ( $prefs[ $email ] ?? 0 ); $user = get_user_by( 'email', $email ); $help = $what ? sprintf( __( 'Gets: %s.', 'ai-eshop-optimizer' ), implode( ', ', $what ) ) : __( 'No form, request or message is mailed to it now.', 'ai-eshop-optimizer' ); if ( isset( $waiting[ $email ] ) ) { $due = (int) strtotime( $waiting[ $email ]['oldest'] . ' UTC' ) + max( 1, $hours ) * HOUR_IN_SECONDS; $help .= ' ' . sprintf( _n( '%1$d waits for its next list (around %2$s).', '%1$d wait for its next list (around %2$s).', $waiting[ $email ]['count'], 'ai-eshop-optimizer' ), $waiting[ $email ]['count'], wp_date( $format, $hours > 0 ? $due : time() + AIEO_Staff_Digest::EVERY ) ); } $rows .= \Rooster\Admin\Ui::field_row( array( 'id' => $id, 'label' => $user ? $user->display_name . ' <' . $email . '>' : $email, 'control' => \Rooster\Admin\Ui::select( 'hours[' . $email . ']', $choices, (string) $hours, array( 'id' => $id ) ), 'help' => $help, ) ); } echo AIEO_DMM_UI::card_form( 'aieo_dmm_staff_notifications_save', 'staff_notifications', $form, '