menu_title(); } /** * Capability needed to open the screen. * * @return string */ abstract public function capability(); /** * Outputs the screen. * * @return void */ abstract public function render(); /** * Enqueues assets for the screen. Override when needed. * * @return void */ public function enqueue() {} /** * URL of the screen. * * @param array $args Extra query arguments. * @return string */ public static function url( array $args = array() ) { return AdminLinks::url( static::SLUG, $args ); } /** * Remembers the hook suffix and hooks asset loading to this screen only. * * @param string $hook Hook suffix. * @return void */ public function set_hook( $hook ) { $this->hook = (string) $hook; if ( '' !== $this->hook ) { add_action( 'load-' . $this->hook, array( $this, 'on_load' ) ); } } /** * Runs when the screen loads, before output. * * @return void */ public function on_load() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_action( 'admin_notices', array( Notices::class, 'render' ) ); } /** * Registers the shared admin stylesheet. * * @return void */ protected function enqueue_admin_style() { wp_enqueue_style( 'turtlereport-admin', TURTLEREPORT_URL . 'assets/css/admin.css', array( 'turtlereport-shell' ), self::asset_version( 'assets/css/admin.css' ) ); } /** * Version string for a plugin asset. Adds the file's modified time, so an * updated file is fetched again even when browser or page caches kept the * old one under the same plugin version. * * @param string $relative Path relative to the plugin folder. * @return string */ public static function asset_version( $relative ) { $time = @filemtime( TURTLEREPORT_DIR . $relative ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- A missing file just falls back to the plugin version. return $time ? TURTLEREPORT_VERSION . '.' . $time : TURTLEREPORT_VERSION; } }