post_type ) { return 'hintwise'; } return $file; } /** * Highlight the right sub-menu while editing guides. * * @param string|null $file Submenu file. * @return string|null */ public static function submenu_file( $file ) { $screen = get_current_screen(); if ( $screen && Hintwise_Docs::TYPE === $screen->post_type ) { return 'add' === $screen->action ? 'post-new.php?post_type=' . Hintwise_Docs::TYPE : 'edit.php?post_type=' . Hintwise_Docs::TYPE; } return $file; } /** * Styles and scripts for Hintwise's own screens only: the Site Guide, the Starter library, * Settings, the Pro screens and the guide list / editor. The help button and the Dashboard * widget load their own small, scoped styles (see Hintwise_Panel and Hintwise_Dashboard). * * @param string $hook Hook suffix. */ public static function assets( $hook ) { wp_register_style( 'hintwise-admin', HINTWISE_URL . 'assets/css/admin.css', array(), HINTWISE_VERSION ); if ( ! self::is_own_screen( $hook ) ) { return; } wp_enqueue_style( 'hintwise-admin' ); $screen = get_current_screen(); if ( $screen && Hintwise_Docs::TYPE === $screen->post_type && 'post' === $screen->base ) { wp_enqueue_script( 'hintwise-editor', HINTWISE_URL . 'assets/js/editor.js', array(), HINTWISE_VERSION, true ); } } /** * Whether the current admin screen is one of Hintwise's own. * * @param string $hook Hook suffix. * @return bool */ public static function is_own_screen( $hook ) { $screen = get_current_screen(); if ( $screen && Hintwise_Docs::TYPE === $screen->post_type ) { return true; } // toplevel_page_hintwise and {menu}_page_hintwise-* (library, settings, Pro screens). return 1 === preg_match( '/(^|_)page_hintwise(-[a-z0-9-]+)?$/', (string) $hook ); } /* --------------------------------------------------------------------- * Guide editor * ------------------------------------------------------------------- */ /** * Meta boxes on the guide editor. */ public static function meta_boxes() { add_meta_box( 'hintwise-where', __( 'Where and for whom', 'cedar-hintwise' ), array( __CLASS__, 'render_where_box' ), Hintwise_Docs::TYPE, 'normal', 'high' ); } /** * "Where and for whom" box. * * @param WP_Post $post Guide. */ public static function render_where_box( $post ) { $roles = Hintwise_Docs::roles( $post->ID ); $screens = Hintwise_Docs::screens( $post->ID ); $required = (bool) get_post_meta( $post->ID, Hintwise_Docs::META_REQUIRED, true ); $known = array(); wp_nonce_field( 'hintwise_doc', 'hintwise_doc_nonce' ); ?>

$items ) : ?>
$label ) : ?>


get_names() as $role => $name ) : ?>

{{site}} site name, {{contact}}, {{email}}, {{phone}} your contact details, and {{admin:edit.php}} as a link address for any wp-admin screen.', 'cedar-hintwise' ), array( 'code' => array() ) ); ?>

get_names() ) ) ); update_post_meta( $post_id, Hintwise_Docs::META_ROLES, $roles ); if ( hintwise_is_pro() ) { if ( ! empty( $_POST['hintwise_required'] ) ) { update_post_meta( $post_id, Hintwise_Docs::META_REQUIRED, 1 ); } else { delete_post_meta( $post_id, Hintwise_Docs::META_REQUIRED ); } } } /** * Guide list columns. * * @param array $cols Columns. * @return array */ public static function columns( $cols ) { $out = array(); foreach ( $cols as $k => $v ) { $out[ $k ] = $v; if ( 'title' === $k ) { $out['hintwise_screens'] = __( 'Shown on', 'cedar-hintwise' ); $out['hintwise_roles'] = __( 'Visible to', 'cedar-hintwise' ); } } unset( $out['date'] ); return $out; } /** * Guide list column values. * * @param string $col Column. * @param int $post_id Guide ID. */ public static function column( $col, $post_id ) { if ( 'hintwise_screens' === $col ) { $labels = array_map( array( 'Hintwise_Screens', 'label' ), Hintwise_Docs::screens( $post_id ) ); echo $labels ? esc_html( implode( ', ', $labels ) ) : ''; } elseif ( 'hintwise_roles' === $col ) { $names = wp_roles()->get_names(); $roles = array_map( function ( $r ) use ( $names ) { return isset( $names[ $r ] ) ? translate_user_role( $names[ $r ] ) : $r; }, Hintwise_Docs::roles( $post_id ) ); echo esc_html( $roles ? implode( ', ', $roles ) : __( 'Everyone', 'cedar-hintwise' ) ); } } /** * "Read" link in the guide list. * * @param array $actions Actions. * @param WP_Post $post Post. * @return array */ public static function row_actions( $actions, $post ) { if ( Hintwise_Docs::TYPE === $post->post_type ) { unset( $actions['view'], $actions['inline hide-if-no-js'] ); $actions['hintwise_read'] = '' . esc_html__( 'Read', 'cedar-hintwise' ) . ''; } return $actions; } /* --------------------------------------------------------------------- * Starter library * ------------------------------------------------------------------- */ /** * Library screen. */ public static function render_library() { if ( ! Hintwise_Settings::can_manage() ) { return; } $installed = Hintwise_Library::installed(); ?>

$pack ) : ?> $t ) { $guides[] = array( 'id' => $id . '/preview-' . $i, 'title' => $t, ); } } ?>

array( __( 'Name or company', 'cedar-hintwise' ), 'text', __( 'e.g. Northwind Web Studio', 'cedar-hintwise' ) ), 'contact_email' => array( __( 'Support email', 'cedar-hintwise' ), 'email', 'support@example.com' ), 'contact_phone' => array( __( 'Phone', 'cedar-hintwise' ), 'tel', '' ), 'contact_url' => array( __( 'Support page or booking link', 'cedar-hintwise' ), 'url', 'https://' ), 'contact_hours' => array( __( 'Opening hours', 'cedar-hintwise' ), 'text', __( 'e.g. Mon–Fri, 9:00–17:00', 'cedar-hintwise' ) ), ); foreach ( $fields as $key => $f ) : ?>


id, 'hintwise' ) || ! isset( $_GET['hintwise_msg'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $msg = sanitize_key( wp_unslash( $_GET['hintwise_msg'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $type = 'success'; if ( 'saved' === $msg ) { $text = __( 'Settings saved.', 'cedar-hintwise' ); } elseif ( preg_match( '/^added-(\d+)$/', $msg, $m ) ) { /* translators: %d: number of guides */ $text = sprintf( _n( '%d guide added to your handbook. Open the Site Guide to read it, or edit it under All guides.', '%d guides added to your handbook. Open the Site Guide to read them, or edit them under All guides.', (int) $m[1], 'cedar-hintwise' ), (int) $m[1] ); } elseif ( preg_match( '/^imported-(\d+)$/', $msg, $m ) ) { /* translators: %d: number of guides */ $text = sprintf( _n( '%d guide imported.', '%d guides imported.', (int) $m[1], 'cedar-hintwise' ), (int) $m[1] ); } elseif ( 'import-error' === $msg ) { $text = __( 'That file could not be imported. Choose a .json file exported by Hintwise.', 'cedar-hintwise' ); $type = 'error'; } elseif ( 'none' === $msg ) { $text = __( 'Tick at least one guide to add.', 'cedar-hintwise' ); $type = 'warning'; } else { /** * Filters the text of a Hintwise result notice (Pro messages). * * @param string $text Text. * @param string $msg Message key. */ $text = (string) apply_filters( 'hintwise_notice_text', '', $msg ); if ( '' === $text ) { return; } } printf( '

%2$s

', esc_attr( $type ), esc_html( $text ) ); } /** * Plugin list links. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Get started', 'cedar-hintwise' ) . '' ); if ( ! hintwise_is_pro() ) { $links[] = '' . esc_html__( 'Go Pro', 'cedar-hintwise' ) . ''; } return $links; } }