0 ? sprintf( ' %1$s', esc_html( number_format_i18n( $pending ) ), esc_attr( sprintf( /* translators: %d: number of pending quotes */ _n( '%d pending quote', '%d pending quotes', $pending, 'nuxwp-devis' ), $pending ) ) ) : ''; add_submenu_page( 'woocommerce', __( 'Quotes', 'nuxwp-devis' ), __( 'Quotes', 'nuxwp-devis' ) . $bubble, 'manage_woocommerce', self::PAGE, array( $this, 'render_page' ) ); } /** * Pending badge style (every admin screen; the menu is global). */ public function menu_badge_style() { wp_add_inline_style( 'admin-menu', '#adminmenu .devisqr-menu-badge{display:inline-block;vertical-align:top;box-sizing:border-box;margin:1px 0 -1px 6px;padding:0 6px;min-width:18px;height:18px;border-radius:9px;background:#3858e9;color:#fff;font-size:9px;line-height:18px;font-weight:600;text-align:center}#adminmenu .wp-submenu .devisqr-menu-badge{margin-top:0}' ); } /** * "Settings" link on the Plugins screen. * * @param array $links Links. * @return array */ public function action_links( $links ) { $url = admin_url( 'admin.php?page=' . self::PAGE . '#/settings' ); array_unshift( $links, '' . esc_html__( 'Settings', 'nuxwp-devis' ) . '' ); return $links; } /** * Assets (only on our screen). * * @param string $hook Hook suffix. */ public function enqueue_assets( $hook ) { if ( 'woocommerce_page_' . self::PAGE !== $hook ) { return; } wp_enqueue_media(); wp_enqueue_style( 'devisqr-admin', DEVISQR_PLUGIN_URL . 'assets/css/devisqr-admin.css', array(), DEVISQR_VERSION ); wp_enqueue_script( 'devisqr-admin', DEVISQR_PLUGIN_URL . 'assets/js/devisqr-admin.js', array( 'wp-element', 'wp-i18n' ), DEVISQR_VERSION, true ); wp_set_script_translations( 'devisqr-admin', 'nuxwp-devis', DEVISQR_PLUGIN_DIR . 'languages' ); wp_localize_script( 'devisqr-admin', 'devisqrAdmin', array( 'restUrl' => esc_url_raw( rest_url( DevisQR_API::NAMESPACE . '/admin/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'currency' => DevisQR_Helpers::js_currency(), 'shortcode' => '[devisqr_button]', 'proUrl' => 'https://nuxwp.com/nuxwp-devis-pro', 'uiLanguage' => DevisQR_Texts::user_choice(), 'siteLanguage' => 0 === strpos( determine_locale(), 'fr' ) ? 'fr' : 'en', 'siteLanguageName' => self::site_language_name(), 'edition' => defined( 'DEVISQR_EDITION' ) ? DEVISQR_EDITION : 'free', ) ); } /** * Human name of the site language (what customers see), e.g. "Français". * * @return string */ private static function site_language_name() { $locale = get_locale(); if ( 0 === strpos( $locale, 'en' ) ) { return 'English'; } $cached = get_transient( 'devisqr_site_lang_name' ); if ( is_array( $cached ) && isset( $cached['locale'], $cached['name'] ) && $cached['locale'] === $locale ) { return $cached['name']; } if ( ! function_exists( 'wp_get_available_translations' ) ) { require_once ABSPATH . 'wp-admin/includes/translation-install.php'; } $translations = wp_get_available_translations(); // Core does not cache a failed API call: we cache the outcome ourselves. $name = isset( $translations[ $locale ]['native_name'] ) ? $translations[ $locale ]['native_name'] : $locale; set_transient( 'devisqr_site_lang_name', array( 'locale' => $locale, 'name' => $name ), 12 * HOUR_IN_SECONDS ); return $name; } /** * Mount point. */ public function render_page() { echo '
'; } }