'dashboard' ) ) ) . '">' . esc_html__( 'Dashboard', 'hyperdrop' ) . '' ); return $links; } /** * Styles and scripts for HyperDrop's own admin screens only. */ public static function assets() { if ( ! in_array( self::current_page(), self::slugs(), true ) ) { return; } wp_enqueue_style( 'hyperdrop-admin', HYPERDROP_URL . 'assets/admin.css', array(), hyperdrop_asset_ver( 'assets/admin.css' ) ); wp_enqueue_script( 'hyperdrop-admin', HYPERDROP_URL . 'assets/admin.js', array(), hyperdrop_asset_ver( 'assets/admin.js' ), true ); if ( 'wizard' === self::current_tab() ) { $deps = array(); if ( current_user_can( 'upload_files' ) ) { // Media Library for the category image picker. wp_enqueue_media(); $deps[] = 'media-editor'; } wp_enqueue_script( 'hyperdrop-wizard', HYPERDROP_URL . 'assets/wizard.js', $deps, hyperdrop_asset_ver( 'assets/wizard.js' ), true ); wp_add_inline_script( 'hyperdrop-wizard', 'window.hyperdropWizard = ' . wp_json_encode( HyperDrop_Wizard::script_data() ) . ';', 'before' ); } } /** * "Go live" / "Back to test mode" button for a drop. */ public static function testing_button( $scope, $to_testing ) { ?>
'dashboard' ) ); } self::done( '', array( 'tab' => 'dashboard' ) ); } /** * Admin bar: switch between admin view (see everything) and shopper view (locks apply). */ public static function do_shopper_view() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'Not allowed.', 'hyperdrop' ) ); } check_admin_referer( 'hyperdrop_shopper_view' ); $on = isset( $_GET['on'] ) && '1' === sanitize_key( wp_unslash( $_GET['on'] ) ); update_user_meta( get_current_user_id(), 'hyperdrop_shopper_view', $on ? 'yes' : 'no' ); $back = wp_get_referer(); wp_safe_redirect( $back ? $back : home_url( '/' ) ); exit; } /** * @param WP_Admin_Bar $bar */ public static function admin_bar( $bar ) { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $shopper = HyperDrop_Drop::shopper_view(); $testing = count( HyperDrop_Drop::testing_terms() ) + count( HyperDrop_Drop::testing_products() ); $bar->add_node( array( 'id' => 'hyperdrop', 'title' => $shopper ? esc_html__( 'π HyperDrop: Shopper view', 'hyperdrop' ) : ( $testing ? esc_html__( 'π§ͺ HyperDrop', 'hyperdrop' ) : esc_html__( 'π HyperDrop', 'hyperdrop' ) ), 'href' => self::url( array( 'tab' => 'dashboard' ) ), ) ); $bar->add_node( array( 'parent' => 'hyperdrop', 'id' => 'hyperdrop-view', 'title' => $shopper ? esc_html__( 'Back to admin view (see everything)', 'hyperdrop' ) : esc_html__( 'View the store as a shopper (locks apply to me)', 'hyperdrop' ), 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=hyperdrop_shopper_view&on=' . ( $shopper ? '0' : '1' ) ), 'hyperdrop_shopper_view' ), ) ); if ( $testing ) { $bar->add_node( array( 'parent' => 'hyperdrop', 'id' => 'hyperdrop-testing', /* translators: %d: number of drops */ 'title' => esc_html( sprintf( _n( '%d drop in test mode (hidden from the public)', '%d drops in test mode (hidden from the public)', $testing, 'hyperdrop' ), $testing ) ), 'href' => self::url( array( 'tab' => 'dashboard' ) ), ) ); } } /** Admin page slug for each screen. */ public static function slugs() { $slugs = array( 'dashboard' => 'hyperdrop', 'wizard' => 'hyperdrop-new', 'codes' => 'hyperdrop-codes', 'generate' => 'hyperdrop-create', 'limits' => 'hyperdrop-limits', 'design' => 'hyperdrop-design', 'settings' => 'hyperdrop-settings', ); if ( ! defined( 'HYPERDROP_PRO_VERSION' ) ) { $slugs['pro'] = 'hyperdrop-pro'; } /** Add-ons can add screens: key => page slug (render with the hyperdrop_admin_tab_{key} action). */ return (array) apply_filters( 'hyperdrop_admin_slugs', $slugs ); } /** Tab labels. */ public static function tab_labels() { $labels = array( 'dashboard' => __( 'Dashboard', 'hyperdrop' ), 'wizard' => __( '+ New exclusive drop', 'hyperdrop' ), 'codes' => __( 'Codes', 'hyperdrop' ), 'generate' => __( 'Create codes', 'hyperdrop' ), 'limits' => __( 'Limits', 'hyperdrop' ), 'design' => __( 'Design', 'hyperdrop' ), 'settings' => __( 'Settings', 'hyperdrop' ), 'pro' => __( 'Pro', 'hyperdrop' ), ); return (array) apply_filters( 'hyperdrop_admin_tab_labels', $labels ); } public static function menu() { $labels = self::tab_labels(); /** Add-ons can show a count next to the menu (e.g. sign-ups waiting for review). */ $count = (int) apply_filters( 'hyperdrop_menu_count', 0 ); $badge = $count ? ' ' . $count . '' : ''; add_menu_page( __( 'HyperDrop', 'hyperdrop' ), __( 'HyperDrop', 'hyperdrop' ) . $badge, self::CAP, 'hyperdrop', array( __CLASS__, 'page' ), 'dashicons-lock', 56 // Right below WooCommerce / Products. ); foreach ( self::slugs() as $tab => $slug ) { $label = isset( $labels[ $tab ] ) ? $labels[ $tab ] : $tab; add_submenu_page( 'hyperdrop', $label . ' β ' . __( 'HyperDrop', 'hyperdrop' ), $label, self::CAP, $slug, array( __CLASS__, 'page' ) ); } } protected static function drop_products() { return get_posts( array( 'post_type' => 'product', 'post_status' => array( 'publish', 'draft', 'private', 'future' ), 'posts_per_page' => 200, 'meta_key' => '_hyperdrop_enabled', // phpcs:ignore 'meta_value' => 'yes', // phpcs:ignore 'orderby' => 'title', 'order' => 'ASC', ) ); } protected static function protected_terms() { $terms = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => false, 'meta_query' => array( array( 'key' => '_hyperdrop_protected', 'value' => 'yes' ) ), // phpcs:ignore ) ); return is_wp_error( $terms ) ? array() : $terms; } /** * Scope strings: '' = everything / any, 'p:ID' = product drop, 't:ID' = protected category. * * @return int[] [ product_id, term_id ] */ public static function parse_scope( $scope ) { if ( preg_match( '/^([pt]):(\d+)$/', (string) $scope, $m ) ) { return 'p' === $m[1] ? array( (int) $m[2], 0 ) : array( 0, (int) $m[2] ); } return array( 0, 0 ); } public static function current_scope() { $scope = ''; if ( self::$verified_action ) { // Inside an admin action that guard() checked: confirm the same nonce here, then read the form. $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; if ( false !== wp_verify_nonce( $nonce, self::$verified_action ) ) { if ( isset( $_REQUEST['scope'] ) ) { $scope = sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ); } elseif ( ! empty( $_REQUEST['product_id'] ) ) { $scope = 'p:' . absint( $_REQUEST['product_id'] ); } } } else { $scope = self::nav( 'scope' ); if ( '' === $scope && absint( self::nav( 'product_id' ) ) ) { $scope = 'p:' . absint( self::nav( 'product_id' ) ); } } // Only "p:' . esc_html( $msg ) . '
| email ); ?> | status ) ); ?> | created_at ), strtotime( current_time( 'mysql' ) ) ) ) ); ?> |
| code ); ?> source ? esc_html__( 'Requested by email', 'hyperdrop' ) : esc_html__( 'Created by admin', 'hyperdrop' ); ?> |
email ? $r->email : 'β' ); ?> | status && $r->expires_at && strtotime( $r->expires_at ) < strtotime( current_time( 'mysql' ) ); ?>status ) ); ?> | uses . ' / ' . ( (int) $r->max_uses ? $r->max_uses : 'β' ) ); ?> | expires_at ? mysql2date( 'M j, Y g:ia', $r->expires_at ) : 'β' ); ?> | sent_at ? mysql2date( 'M j g:ia', $r->sent_at ) : 'β' ); ?> | status && $r->email ) { self::action_button( $r, 'send', $r->sent_at ? __( 'Resend', 'hyperdrop' ) : __( 'Email code', 'hyperdrop' ) ); } if ( 'disabled' === $r->status ) { self::action_button( $r, 'enable', __( 'Enable', 'hyperdrop' ) ); } else { self::action_button( $r, 'disable', __( 'Disable', 'hyperdrop' ) ); } self::action_button( $r, 'delete', __( 'Delete', 'hyperdrop' ) ); ?> | |
' . wp_kses_post( sprintf( /* translators: 1: current site time, 2: settings link */ __( 'Your site clock is set to UTC (it thinks it is %1$s now). Code expiry dates and drop schedules use this clock, so times you enter may be hours off. Set your timezone (pick your city, e.g. Chicago).', 'hyperdrop' ), esc_html( wp_date( 'g:ia' ) ), esc_url( admin_url( 'options-general.php#timezone_string' ) ) ) ) . '
' . esc_html( $empty ) . '
'; return; } echo '| ' . esc_html__( 'Name', 'hyperdrop' ) . ' | '; foreach ( $fields as $f ) { echo '' . esc_html( $f[0] ) . '' . esc_html( $f[2] ) . ' | '; } echo '
|---|---|
| ' . esc_html( $r['name'] ) . ' '; echo $r['locked'] ? '' . esc_html( HyperDrop_Schedule::phase_label( HyperDrop_Schedule::phase( $scope ) ) ) . ' β ' . esc_html__( 'limits active', 'hyperdrop' ) . '' : '' . esc_html__( 'Open to everyone β limits paused', 'hyperdrop' ) . ''; echo ' | ';
foreach ( $fields as $k => $f ) {
echo wp_kses( self::limit_cell( $scope, $k, isset( $l[ $k ] ) ? $l[ $k ] : 0, $f[1] ), hyperdrop_allowed_html() );
}
echo '