id, array( 'dashboard', 'plugins', 'edit-' . SWCC_Topic::POST_TYPE ), true ) ) { return; } echo self::activation_notice_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- built from escaped parts below. } /** * The notice markup, or '' when there is nothing to say. Separated so a fixture can call it. * * Gone once the site is enrolled, and gone for good for a user who hides it (1.1.1): a notice * that cannot be dismissed is the kind the directory's guideline 11 is about. * * @return string */ public static function activation_notice_html() { if ( ! current_user_can( 'manage_options' ) || SWCC_Site_Credentials::is_activated() || SWCC_Site_Credentials::is_staging() || SWCC_Settings_Page::is_clone() ) { return ''; } if ( '1' === (string) get_user_meta( get_current_user_id(), self::META_NOTICE_DISMISSED, true ) ) { return ''; } $sentence = sprintf( /* translators: 1: link to the plugin's Settings page, 2: link to the plans page on saidweekly.com. */ __( 'saidweekly is installed but not started yet. Start the free plan under Settings → saidweekly (no account, card or license key), or choose a paid plan at saidweekly.com and paste the license key from your email there.', 'saidweekly' ), esc_url( admin_url( 'options-general.php?page=' . SWCC_Settings_Page::PAGE_SLUG ) ), esc_url( self::PRICING_URL ) ); $dismiss = sprintf( '%2$s', esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=' . self::DISMISS_ACTION ), self::DISMISS_ACTION ) ), esc_html__( 'Hide this notice', 'saidweekly' ) ); return '

' . wp_kses( $sentence, array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ) ) . ' ' . $dismiss . '

'; } /** * Add a Settings shortcut to this plugin's row on the Plugins screen. * * @param string[] $links Existing plugin action links. * @return string[] */ public static function plugin_settings_link( $links ) { if ( ! current_user_can( 'manage_options' ) ) { return $links; } $settings_link = sprintf( '%2$s', esc_url( admin_url( 'options-general.php?page=' . SWCC_Settings_Page::PAGE_SLUG ) ), esc_html__( 'Settings', 'saidweekly' ) ); // Where to begin, on the one screen every administrator sees (1.0.8, 1.1.0): "Start free" // to Settings until the site is enrolled, "Plans" to saidweekly.com after, for an upgrade. $plans_link = SWCC_Site_Credentials::is_activated() ? sprintf( '%2$s', esc_url( self::PRICING_URL ), esc_html__( 'Plans', 'saidweekly' ) ) : sprintf( '%2$s', esc_url( admin_url( 'options-general.php?page=' . SWCC_Settings_Page::PAGE_SLUG ) ), esc_html__( 'Start free', 'saidweekly' ) ); array_unshift( $links, $settings_link, $plans_link ); return $links; } /** * The one script behind every "are you sure?" link (1.1.1), so no markup carries an onclick. * * @return void */ private static function enqueue_confirm() { wp_enqueue_script( 'swcc-confirm', SWCC_PLUGIN_URL . 'assets/js/confirm.js', array(), SWCC_VERSION, true ); } /** * Enqueue admin styles on the topic screens only. * * @param string $hook_suffix Current admin page identifier. * @return void */ public static function enqueue_assets( $hook_suffix ) { // The importer is a submenu page, so its hook suffix is generated rather than one of // the core screens below; it needs the mapping-step script and nothing else. if ( false !== strpos( $hook_suffix, SWCC_Topic_Importer::PAGE_SLUG ) ) { wp_enqueue_script( 'swcc-import-mapping', SWCC_PLUGIN_URL . 'assets/js/import-mapping.js', array(), SWCC_VERSION, true ); return; } // The Generate Calendar screen has one link that asks before replacing the calendar (1.1.1). if ( false !== strpos( $hook_suffix, SWCC_Calendar_Page::PAGE_SLUG ) ) { self::enqueue_confirm(); return; } if ( ! in_array( $hook_suffix, array( 'post.php', 'post-new.php', 'edit.php' ), true ) ) { return; } $screen = get_current_screen(); if ( ! $screen instanceof WP_Screen || SWCC_Topic::POST_TYPE !== $screen->post_type ) { return; } // The regenerate, clear-hold and release links ask first; the question is a data attribute. self::enqueue_confirm(); wp_enqueue_style( 'swcc-admin', SWCC_PLUGIN_URL . 'assets/css/admin.css', array(), SWCC_VERSION ); if ( 'edit.php' === $hook_suffix ) { // Depends on inline-edit-post because it wraps inlineEditPost.edit(), which does not // exist until core's script has run. wp_enqueue_script( 'swcc-quick-edit', SWCC_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'inline-edit-post' ), SWCC_VERSION, true ); } if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ) ) { wp_enqueue_script( 'swcc-admin', SWCC_PLUGIN_URL . 'assets/js/admin.js', array(), SWCC_VERSION, true ); // A fixed topic (queued; 1.0.4) keeps its title too. The title box is core's, outside // the meta box, so it is held here; keep_fixed_title() refuses a change on the server. $editing = get_post(); if ( 'post.php' === $hook_suffix && $editing instanceof WP_Post && SWCC_Topic::is_fixed( $editing->ID ) ) { wp_add_inline_script( 'swcc-admin', "( function () { var t = document.getElementById( 'title' ); if ( t ) { t.readOnly = true; t.setAttribute( 'aria-describedby', 'swcc-fixed-notice' ); } }() );" ); } } } }