GetPPWR. */ class GetPPWR_Admin { const PAGE = 'getppwr'; /** * Hooks. */ public static function init() { add_action( 'admin_menu', array( __CLASS__, 'menu' ), 60 ); add_action( 'admin_init', array( __CLASS__, 'return_from_getppwr' ) ); add_action( 'admin_post_getppwr_connect', array( __CLASS__, 'connect' ) ); add_action( 'admin_post_getppwr_unlink', array( __CLASS__, 'unlink' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'assets' ) ); add_filter( 'script_loader_tag', array( __CLASS__, 'module_tag' ), 10, 2 ); add_filter( 'plugin_action_links_' . plugin_basename( GETPPWR_FILE ), array( __CLASS__, 'action_links' ) ); add_filter( 'install_plugin_complete_actions', array( __CLASS__, 'installed_links' ), 10, 3 ); add_action( 'admin_notices', array( __CLASS__, 'welcome_notice' ) ); } /** * Under WooCommerce, as Woo's extension guidelines ask, not a menu of its own. */ public static function menu() { add_submenu_page( 'woocommerce', __( 'GetPPWR', 'getppwr' ), __( 'GetPPWR', 'getppwr' ), 'manage_woocommerce', self::PAGE, array( __CLASS__, 'render' ) ); } /** * A link to the page on the Plugins screen. * * @param array $links The plugin's links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'getppwr' ) . '' ); return $links; } /** * After uploading the plugin: a link straight to its page, so a merchant * who just installed it does not have to look for it (Krister, 29.10.2026). * * @param array $actions The links under "Plugin installed successfully". * @param object $api Unused. * @param string $plugin_file The plugin that was installed. * @return array */ public static function installed_links( $actions, $api, $plugin_file ) { if ( plugin_basename( GETPPWR_FILE ) !== $plugin_file || ! is_plugin_active( $plugin_file ) ) { return $actions; } return array_merge( array( 'getppwr' => '' . esc_html__( 'Open WooCommerce > GetPPWR', 'getppwr' ) . '' ), $actions ); } /** * Once activated, a notice on the Plugins screen pointing to WooCommerce > * GetPPWR. Shown once and dismissible: the directory's guidelines ask * plugins not to keep notices on the dashboard. */ public static function welcome_notice() { if ( ! get_option( 'getppwr_welcome' ) || ! current_user_can( 'manage_woocommerce' ) ) { return; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || 'plugins' !== $screen->id ) { return; } delete_option( 'getppwr_welcome' ); ?>
self::PAGE ), $args ), admin_url( 'admin.php' ) ); } /** * Only on this page. * * @param string $hook The admin page's hook. */ public static function assets( $hook ) { if ( 'woocommerce_page_' . self::PAGE !== $hook ) { return; } // Versioned by the file's own time, so an updated file is never served from the browser's cache. wp_enqueue_style( 'getppwr-admin', GETPPWR_URL . 'assets/admin.css', array(), self::asset_version( 'assets/admin.css' ) ); // The turning globe in the corner: a module, as cobe ships one. wp_enqueue_script( 'getppwr-globe', GETPPWR_URL . 'assets/globe.js', array(), self::asset_version( 'assets/globe.js' ), true ); // The numbers roll into place on the connected page. if ( GetPPWR_API::is_linked() ) { wp_enqueue_script( 'getppwr-numbers', GETPPWR_URL . 'assets/numbers.js', array(), self::asset_version( 'assets/numbers.js' ), true ); } } /** * The plugin's version and the file's modification time. * * @param string $file The file, relative to the plugin's folder. * @return string */ private static function asset_version( $file ) { $path = GETPPWR_DIR . $file; return GETPPWR_VERSION . ( file_exists( $path ) ? '.' . filemtime( $path ) : '' ); } /** * The globe's script is an ES module. * * @param string $tag The script tag. * @param string $handle The script's handle. * @return string */ public static function module_tag( $tag, $handle ) { if ( 'getppwr-globe' !== $handle ) { return $tag; } return str_replace( '