Plugin Directory

Changeset 3848540


Ignore:
Timestamp:
12/06/2026 09:54:43 PM (less than one hour ago)
Author:
premiumpressthemes
Message:

PremiumPress Directory 1.1.1

Location:
premiumpress-directory
Files:
12 added
68 edited
1 copied

Legend:

Unmodified
Added
Removed
  • premiumpress-directory/tags/1.1.1/assets/css/frontend.css

    r3838627 r3848540  
    331331.ppd-card__facts {
    332332        margin: 0 0 4px;
     333        font-size: 0.95rem; /* the theme's body size is too big next to the card title */
     334        line-height: 1.4;
    333335        font-weight: 700;
    334336}
    … …  
    370372
    371373.ppd-search__field label,
     374.ppd-search__field legend,
    372375.ppd-sort label {
    373376        font-size: 0.8rem;
    … …  
    377380.ppd-search__form input[type="search"],
    378381.ppd-search__form input[type="text"],
     382.ppd-search__form input[type="number"],
    379383.ppd-search__form select,
    380384.ppd-sort select {
    … …  
    12481252}
    12491253
     1254.ppd-single__price {
     1255        margin: 0 0 10px;
     1256        font-size: 1.5rem;
     1257        font-weight: 700;
     1258        line-height: 1.2;
     1259}
     1260
    12501261.ppd-single__meta {
    12511262        display: flex;
    … …  
    14511462        font-size: 1.35rem;
    14521463}
     1464
     1465/* Sold / status badge (classifieds: Sold, jobs: Filled …) */
     1466.ppd-badge--status,
     1467.ppd-chip--status {
     1468        background: #1f2937;
     1469        border-color: #1f2937;
     1470        color: #fff;
     1471}
     1472
     1473.ppd-status--sold {
     1474        color: #1f2937;
     1475}
     1476
     1477/* Min–max range filters (price, salary …) */
     1478.ppd-search__field--range {
     1479        display: flex;
     1480        flex-direction: column;
     1481        gap: 4px;
     1482        border: 0;
     1483        margin: 0;
     1484        padding: 0;
     1485        min-width: 0;
     1486}
     1487
     1488.ppd-search__field--range legend {
     1489        padding: 0;
     1490        margin-bottom: 0;
     1491        float: left;
     1492        width: 100%;
     1493}
     1494
     1495.ppd-search__range {
     1496        display: flex;
     1497        align-items: center;
     1498        gap: 6px;
     1499}
     1500
     1501.ppd-search__range input {
     1502        width: 100%;
     1503        min-width: 0;
     1504}
  • premiumpress-directory/tags/1.1.1/blocks/listings/block.json

    r3837691 r3848540  
    77        "icon": "location-alt",
    88        "description": "A grid of directory listings, optionally filtered by category, location or tag.",
    9         "keywords": [ "directory", "listings", "grid" ],
     9        "keywords": [
     10                "directory",
     11                "listings",
     12                "grid"
     13        ],
    1014        "textdomain": "premiumpress-directory",
    1115        "attributes": {
    12                 "number": { "type": "number", "default": 12 },
    13                 "columns": { "type": "number", "default": 3 },
    14                 "category": { "type": "string", "default": "" },
    15                 "location": { "type": "string", "default": "" },
    16                 "tag": { "type": "string", "default": "" },
    17                 "orderby": { "type": "string", "default": "date", "enum": [ "date", "title", "rand", "rating" ] },
    18                 "excerpt": { "type": "boolean", "default": true },
    19                 "pagination": { "type": "boolean", "default": false }
     16                "number": {
     17                        "type": "number",
     18                        "default": 12
     19                },
     20                "columns": {
     21                        "type": "number",
     22                        "default": 3
     23                },
     24                "category": {
     25                        "type": "string",
     26                        "default": ""
     27                },
     28                "location": {
     29                        "type": "string",
     30                        "default": ""
     31                },
     32                "tag": {
     33                        "type": "string",
     34                        "default": ""
     35                },
     36                "orderby": {
     37                        "type": "string",
     38                        "default": "date",
     39                        "enum": [
     40                                "date",
     41                                "title",
     42                                "rand",
     43                                "rating"
     44                        ]
     45                },
     46                "excerpt": {
     47                        "type": "boolean",
     48                        "default": true
     49                },
     50                "pagination": {
     51                        "type": "boolean",
     52                        "default": false
     53                }
    2054        },
    2155        "supports": {
    2256                "html": false,
    23                 "align": [ "wide", "full" ],
    24                 "spacing": { "margin": true, "padding": true }
     57                "align": [
     58                        "wide",
     59                        "full"
     60                ],
     61                "spacing": {
     62                        "margin": true,
     63                        "padding": true
     64                }
    2565        },
    2666        "editorScript": "file:./index.js",
  • premiumpress-directory/tags/1.1.1/blocks/my-listings/block.json

    r3837691 r3848540  
    77        "icon": "id",
    88        "description": "A member's own listings with edit, renew and delete, plus their saved favourites.",
    9         "keywords": [ "directory", "account", "dashboard", "favourites" ],
     9        "keywords": [
     10                "directory",
     11                "account",
     12                "dashboard",
     13                "favourites"
     14        ],
    1015        "textdomain": "premiumpress-directory",
    11         "supports": { "html": false, "multiple": false },
     16        "supports": {
     17                "html": false,
     18                "multiple": false
     19        },
    1220        "editorScript": "file:./index.js",
    1321        "style": "premiumpress-frontend"
  • premiumpress-directory/tags/1.1.1/blocks/search/block.json

    r3837691 r3848540  
    77        "icon": "search",
    88        "description": "A search form with results: keyword, category, location, distance and a map.",
    9         "keywords": [ "directory", "search", "map", "near me" ],
     9        "keywords": [
     10                "directory",
     11                "search",
     12                "map",
     13                "near me"
     14        ],
    1015        "textdomain": "premiumpress-directory",
    1116        "attributes": {
    12                 "number": { "type": "number", "default": 12 },
    13                 "columns": { "type": "number", "default": 3 },
    14                 "map": { "type": "boolean", "default": true }
     17                "number": {
     18                        "type": "number",
     19                        "default": 12
     20                },
     21                "columns": {
     22                        "type": "number",
     23                        "default": 3
     24                },
     25                "map": {
     26                        "type": "boolean",
     27                        "default": true
     28                }
    1529        },
    1630        "supports": {
    1731                "html": false,
    1832                "multiple": false,
    19                 "align": [ "wide", "full" ],
    20                 "spacing": { "margin": true, "padding": true }
     33                "align": [
     34                        "wide",
     35                        "full"
     36                ],
     37                "spacing": {
     38                        "margin": true,
     39                        "padding": true
     40                }
    2141        },
    2242        "editorScript": "file:./index.js",
  • premiumpress-directory/tags/1.1.1/blocks/submit/block.json

    r3837691 r3848540  
    77        "icon": "plus-alt",
    88        "description": "The form members use to add or edit their own listing.",
    9         "keywords": [ "directory", "submit", "add listing", "form" ],
     9        "keywords": [
     10                "directory",
     11                "submit",
     12                "add listing",
     13                "form"
     14        ],
    1015        "textdomain": "premiumpress-directory",
    11         "supports": { "html": false, "multiple": false },
     16        "supports": {
     17                "html": false,
     18                "multiple": false
     19        },
    1220        "editorScript": "file:./index.js",
    1321        "style": "premiumpress-frontend"
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-editor.php

    r3838627 r3848540  
    4949
    5050        public function menu(): void {
    51                 $hook = add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Edit listing', 'premiumpress-directory' ), '', 'edit_posts', self::PAGE, array( $this, 'render' ) );
     51                $hook = add_submenu_page( PremiumPress_Admin_UI::parent(), sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Edit %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), '', 'edit_posts', self::PAGE, array( $this, 'render' ) );
    5252                // Hidden from the menu only after WordPress has checked access (admin_head).
    5353                add_action(
    … …  
    6262                                static function () {
    6363                                        global $title;
    64                                         $title = __( 'Edit listing', 'premiumpress-directory' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- the admin page title WordPress lost.
     64                                        $title = sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Edit %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- the admin page title WordPress lost.
    6565                                }
    6666                        );
    … …  
    113113                                'max'       => self::MAX_IMAGES,
    114114                                'pick'      => __( 'Choose photos', 'premiumpress-directory' ),
    115                                 'use'       => __( 'Add to listing', 'premiumpress-directory' ),
     115                                'use'       => sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Add to %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ),
    116116                                'main'      => __( 'Main photo', 'premiumpress-directory' ),
    117117                                'remove'    => __( 'Remove photo', 'premiumpress-directory' ),
    … …  
    167167                if ( $skip ) {
    168168                        /* translators: %d: number of photos */
    169                         echo '<div class="ppd-a-note ppd-a-note--warn">' . esc_html( sprintf( _n( '%d photo already belongs to another listing, so it stays there. Upload a copy to use it here too.', '%d photos already belong to another listing, so they stay there. Upload a copy to use them here too.', $skip, 'premiumpress-directory' ), $skip ) ) . '</div>';
     169                        echo '<div class="ppd-a-note ppd-a-note--warn">' . esc_html( sprintf( /* translators: 1: number, 2: singular item name, lowercase */ _n( '%1$d photo already belongs to another %2$s, so it stays there. Upload a copy to use it here too.', '%1$d photos already belong to another %2$s, so they stay there. Upload a copy to use them here too.', $skip, 'premiumpress-directory' ), $skip, PremiumPress_Profiles::one() ) ) . '</div>';
    170170                }
    171171                if ( 'title' === $err ) {
    … …  
    217217
    218218                // 1. Basics.
    219                 self::panel_open( 1, 'comment', __( 'About your listing', 'premiumpress-directory' ), __( 'Give it a clear name and say what makes it stand out.', 'premiumpress-directory' ) );
     219                self::panel_open( 1, 'comment', sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'About your %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), __( 'Give it a clear name and say what makes it stand out.', 'premiumpress-directory' ) );
    220220                echo '<label class="ppd-ed-label" for="ppd-ed-title">' . esc_html__( 'Title', 'premiumpress-directory' ) . ' <span class="ppd-ed-req">*</span></label><input type="text" id="ppd-ed-title" class="ppd-ed-input ppd-ed-input--big" name="ppd_title" value="' . esc_attr( 'auto-draft' === $post->post_status ? '' : $post->post_title ) . '" maxlength="200" required data-ppd-check="title">';
    221221                echo '<label class="ppd-ed-label" for="ppd_content">' . esc_html__( 'Description', 'premiumpress-directory' ) . '</label><div class="ppd-ed-editor" data-ppd-check="content">';
    … …  
    341341                        echo '</div><p class="ppd-ed-tip">';
    342342                        PremiumPress_Admin_UI::e_icon( 'info', 18 );
    343                         echo ' ' . esc_html__( 'Shown as buttons on the listing page. Leave any of them empty to hide its button.', 'premiumpress-directory' ) . '</p>';
     343                        echo ' ' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Shown as buttons on the %s page. Leave any of them empty to hide its button.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p>';
    344344                        self::panel_close( 5, $order );
    345345                }
    … …  
    461461                $id = (int) $post->ID;
    462462                echo '<section class="ppd-a-card ppd-a-pad ppd-ed-side"><div class="ppd-ed-ring"><svg viewBox="0 0 36 36" aria-hidden="true" focusable="false"><circle cx="18" cy="18" r="15.5" class="ppd-ed-ring-bg"/><circle cx="18" cy="18" r="15.5" class="ppd-ed-ring-fg" data-ppd-ring pathLength="100" stroke-dasharray="0 100"/></svg><b data-ppd-pct>0%</b></div>';
    463                 echo '<div class="ppd-ed-ringcopy"><strong>' . esc_html__( 'Your listing', 'premiumpress-directory' ) . '</strong><span>' . esc_html__( 'Complete listings get more views.', 'premiumpress-directory' ) . '</span></div>';
     463                echo '<div class="ppd-ed-ringcopy"><strong>' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Your %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</strong><span>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Complete %s get more views.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</span></div>';
    464464                echo '<ul class="ppd-ed-checks">';
    465465                $checks = array(
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-listings.php

    r3838627 r3848540  
    339339                echo '</select><button type="submit" class="ppd-a-btn">' . esc_html__( 'Apply', 'premiumpress-directory' ) . '</button></div>';
    340340
    341                 echo '<div class="ppd-a-tablewrap"><table class="ppd-a-table ppd-a-table--listings"><thead><tr><th class="ppd-a-check"><input type="checkbox" data-ppd-checkall aria-label="' . esc_attr__( 'Select all', 'premiumpress-directory' ) . '"></th><th>' . esc_html__( 'Name', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Photos', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Reviews', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Status', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Complete', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Featured', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Date', 'premiumpress-directory' ) . '</th><th><span class="screen-reader-text">' . esc_html__( 'Actions', 'premiumpress-directory' ) . '</span></th></tr></thead><tbody>';
     341                echo '<div class="ppd-a-tablewrap"><table class="ppd-a-table ppd-a-table--listings"><thead><tr><th class="ppd-a-check"><input type="checkbox" data-ppd-checkall aria-label="' . esc_attr__( 'Select all', 'premiumpress-directory' ) . '"></th><th>' . esc_html__( 'Name', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Photos', 'premiumpress-directory' ) . '</th>' . ( PremiumPress_Engage::reviews_on() ? '<th>' . esc_html__( 'Reviews', 'premiumpress-directory' ) . '</th>' : '' ) . '<th>' . esc_html__( 'Status', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Complete', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Featured', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Date', 'premiumpress-directory' ) . '</th><th><span class="screen-reader-text">' . esc_html__( 'Actions', 'premiumpress-directory' ) . '</span></th></tr></thead><tbody>';
    342342                $pills = array(
    343343                        'publish' => array( __( 'Published', 'premiumpress-directory' ), 'green' ),
    … …  
    369369                        PremiumPress_Admin_UI::e_icon( 'image', 15 );
    370370                        echo ' ' . esc_html( number_format_i18n( count( PremiumPress_Listing::image_ids( $id ) ) ) ) . '</span></td>';
    371                         echo '<td class="ppd-a-meta">' . ( $stats['count'] ? '<span class="ppd-a-stars-sm">★</span> ' . esc_html( number_format_i18n( $stats['avg'], 1 ) ) . ' <small>(' . esc_html( number_format_i18n( $stats['count'] ) ) . ')</small>' : '<span class="ppd-a-muted">—</span>' ) . '</td>';
     371                        if ( PremiumPress_Engage::reviews_on() ) {
     372                                echo '<td class="ppd-a-meta">' . ( $stats['count'] ? '<span class="ppd-a-stars-sm">★</span> ' . esc_html( number_format_i18n( $stats['avg'], 1 ) ) . ' <small>(' . esc_html( number_format_i18n( $stats['count'] ) ) . ')</small>' : '<span class="ppd-a-muted">—</span>' ) . '</td>';
     373                        }
    372374                        echo '<td>' . wp_kses_post( PremiumPress_Admin_UI::pill( $pill[0], $pill[1] ) ) . '</td>';
    373375                        echo '<td><span class="ppd-a-bar"><span class="ppd-a-bar-in ppd-a-bar--' . ( $pct >= 70 ? 'green' : ( $pct >= 40 ? 'orange' : 'red' ) ) . '" style="width:' . esc_attr( (string) $pct ) . '%"></span></span><b class="ppd-a-pct">' . esc_html( $pct . '%' ) . '</b></td>';
    … …  
    513515                                if ( current_user_can( $obj->cap->delete_terms ) && (int) get_option( 'default_' . $tax ) !== (int) $t->term_id ) {
    514516                                        /* translators: %s: term name */
    515                                         echo '<a class="is-danger" data-ppd-confirm="' . esc_attr( sprintf( __( 'Delete "%s"? Listings in it are kept.', 'premiumpress-directory' ), $t->name ) ) . '" href="' . esc_url( self::term_url( 'delete', $tax, (int) $t->term_id ) ) . '">' . esc_html__( 'Delete', 'premiumpress-directory' ) . '</a>';
     517                                        echo '<a class="is-danger" data-ppd-confirm="' . esc_attr( sprintf( /* translators: 1: category or location name, 2: plural item name, e.g. Listings */ __( 'Delete "%1$s"? %2$s in it are kept.', 'premiumpress-directory' ), $t->name, PremiumPress_Profiles::many( true ) ) ) . '" href="' . esc_url( self::term_url( 'delete', $tax, (int) $t->term_id ) ) . '">' . esc_html__( 'Delete', 'premiumpress-directory' ) . '</a>';
    516518                                }
    517519                                echo '</td></tr>';
    … …  
    571573                wp_nonce_field( self::A_TERM . '_edit_' . $tax . '_' . $id );
    572574                /* translators: %s: number of listings */
    573                 echo '<div class="ppd-a-sect-copy"><h2>' . esc_html( $t->name ) . '</h2><p>' . esc_html( sprintf( _n( 'Used on %s listing.', 'Used on %s listings.', (int) $t->count, 'premiumpress-directory' ), number_format_i18n( (int) $t->count ) ) ) . '</p>';
     575                echo '<div class="ppd-a-sect-copy"><h2>' . esc_html( $t->name ) . '</h2><p>' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'Used on %1$s %2$s.', 'Used on %1$s %2$s.', (int) $t->count, 'premiumpress-directory' ), number_format_i18n( (int) $t->count ), ( 1 === (int) $t->count ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</p>';
    574576                $link = get_term_link( $t );
    575577                if ( ! is_wp_error( $link ) ) {
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-reviews.php

    r3838627 r3848540  
    4242
    4343        public function menu(): void {
    44                 add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Reviews', 'premiumpress-directory' ), __( 'Reviews', 'premiumpress-directory' ), 'moderate_comments', self::PAGE, array( $this, 'render' ), 5 );
     44                if ( PremiumPress_Engage::reviews_on() ) {
     45                        add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Reviews', 'premiumpress-directory' ), __( 'Reviews', 'premiumpress-directory' ), 'moderate_comments', self::PAGE, array( $this, 'render' ), 5 );
     46                }
    4547                add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Members', 'premiumpress-directory' ), '', 'list_users', self::MEMBERS, array( $this, 'render_members' ) );
    4648                add_action(
    … …  
    255257                $total = (int) get_comments( array_merge( $args, array( 'count' => true, 'number' => 0, 'offset' => 0 ) ) );
    256258
    257                 PremiumPress_Admin_UI::open( 'reviews', __( 'Reviews', 'premiumpress-directory' ), __( 'Reviews left across your directory.', 'premiumpress-directory' ) );
     259                PremiumPress_Admin_UI::open( 'reviews', __( 'Reviews', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Reviews left across your %s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    258260                if ( $done >= 0 && isset( self::actions()[ $did ] ) ) {
    259261                        /* translators: 1: number, 2: action, e.g. Approve */
    … …  
    286288                        echo '<div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">';
    287289                        PremiumPress_Admin_UI::e_icon( 'star', 22 );
    288                         echo '</span><strong>' . esc_html__( 'No reviews here', 'premiumpress-directory' ) . '</strong><span>' . esc_html__( 'Reviews appear here as visitors leave them on your listings.', 'premiumpress-directory' ) . '</span></div></section>';
     290                        echo '</span><strong>' . esc_html__( 'No reviews here', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Reviews appear here as visitors leave them on your %s.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</span></div></section>';
    289291                        PremiumPress_Admin_UI::close();
    290292                        return;
    … …  
    328330                                echo '<a href="' . esc_url( self::edit_url( $id ) ) . '">' . esc_html__( 'Edit', 'premiumpress-directory' ) . '</a>';
    329331                                if ( '1' === $state && 'publish' === get_post_status( $pid ) ) {
    330                                         echo '<a href="' . esc_url( (string) get_comment_link( $c ) ) . '" target="_blank" rel="noopener">' . esc_html__( 'View on the listing', 'premiumpress-directory' ) . '</a>';
     332                                        echo '<a href="' . esc_url( (string) get_comment_link( $c ) ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'View on the %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</a>';
    331333                                }
    332334                                echo '<a href="' . esc_url( self::one_url( $id, 'spam' ) ) . '">' . esc_html__( 'Mark as spam', 'premiumpress-directory' ) . '</a><a class="is-danger" href="' . esc_url( self::one_url( $id, 'trash' ) ) . '">' . esc_html__( 'Move to trash', 'premiumpress-directory' ) . '</a>';
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-ui.php

    r3838627 r3848540  
    6464        /** The screens that wear this look, by their `page` value. */
    6565        public static function pages(): array {
    66                 return array( self::OVERVIEW, self::HUB, PremiumPress_Admin_Reviews::PAGE, PremiumPress_Admin_Reviews::MEMBERS, PremiumPress_Settings::SETUP, self::LISTINGS, self::TAXONOMIES, PremiumPress_Fields::PAGE, PremiumPress_Admin_Editor::PAGE, PremiumPress_Engage::REPORTS_PAGE, PremiumPress_Porting::PAGE, PremiumPress_Settings::PAGE, PremiumPress_Design::PAGE );
     66                /** A plugin's own screens (e.g. Applications) wear the same look. */
     67                return (array) apply_filters( 'premiumpress_admin_pages', array( self::OVERVIEW, self::HUB, PremiumPress_Admin_Reviews::PAGE, PremiumPress_Admin_Reviews::MEMBERS, PremiumPress_Settings::SETUP, self::LISTINGS, self::TAXONOMIES, PremiumPress_Fields::PAGE, PremiumPress_Admin_Editor::PAGE, PremiumPress_Engage::REPORTS_PAGE, PremiumPress_Porting::PAGE, PremiumPress_Settings::PAGE, PremiumPress_Design::PAGE ) );
    6768        }
    6869
    … …  
    215216                $out = array(
    216217                        array( 't' => __( 'Overview', 'premiumpress-directory' ), 'd' => __( 'What is new and what needs your attention', 'premiumpress-directory' ), 'u' => self::url( self::OVERVIEW ) ),
    217                         array( 't' => (string) $p['plural'], 'd' => __( 'Manage every listing', 'premiumpress-directory' ), 'u' => self::url( self::LISTINGS ) ),
     218                        array( 't' => (string) $p['plural'], 'd' => sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Manage every %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), 'u' => self::url( self::LISTINGS ) ),
    218219                        /* translators: %s: singular item name, e.g. Listing */
    219220                        array( 't' => sprintf( __( 'Add %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['singular'] ) ), 'd' => __( 'Open the editor for a new one', 'premiumpress-directory' ), 'u' => PremiumPress_Admin_Editor::url( 0, array( 'new' => 1 ) ) ),
    220221                        array( 't' => __( 'Taxonomies', 'premiumpress-directory' ), 'd' => __( 'Categories, locations and tags', 'premiumpress-directory' ), 'u' => self::url( self::TAXONOMIES ) ),
    221                         array( 't' => __( 'Reviews', 'premiumpress-directory' ), 'd' => __( 'Approve, edit or remove reviews', 'premiumpress-directory' ), 'u' => PremiumPress_Admin_Reviews::url() ),
     222                        ...( PremiumPress_Engage::reviews_on() ? array( array( 't' => __( 'Reviews', 'premiumpress-directory' ), 'd' => __( 'Approve, edit or remove reviews', 'premiumpress-directory' ), 'u' => PremiumPress_Admin_Reviews::url() ) ) : array() ),
    222223                        array( 't' => __( 'Members', 'premiumpress-directory' ), 'd' => __( 'Everyone with an account', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Admin_Reviews::MEMBERS ) ),
    223224                        array( 't' => __( 'Reports', 'premiumpress-directory' ), 'd' => __( 'Things visitors have flagged', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Engage::REPORTS_PAGE ) ),
    224                         array( 't' => __( 'Import / Export', 'premiumpress-directory' ), 'd' => __( 'Spreadsheets in and out, and moving from another directory plugin', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Porting::PAGE ) ),
     225                        array( 't' => __( 'Import / Export', 'premiumpress-directory' ), 'd' => ( PremiumPress_Switch::names() ? __( 'Spreadsheets in and out, and moving from another directory plugin', 'premiumpress-directory' ) : __( 'Spreadsheets in and out', 'premiumpress-directory' ) ), 'u' => self::url( PremiumPress_Porting::PAGE ) ),
    225226                        array( 't' => __( 'Design', 'premiumpress-directory' ), 'd' => __( 'WordPress style or the built-in design', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Design::PAGE ) ),
    226                         array( 't' => __( 'Settings', 'premiumpress-directory' ), 'd' => __( 'How your directory works', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Settings::PAGE ) ),
     227                        array( 't' => __( 'Settings', 'premiumpress-directory' ), 'd' => sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'How your %s works', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ), 'u' => self::url( PremiumPress_Settings::PAGE ) ),
    227228                        array( 't' => __( 'Setup wizard', 'premiumpress-directory' ), 'd' => __( 'Answer a few questions to set up the basics', 'premiumpress-directory' ), 'u' => PremiumPress_Wizard::url() ),
    228229                        array( 't' => __( 'Upgrade', 'premiumpress-directory' ), 'd' => __( 'What the PremiumPress theme adds', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Settings::PAGE, array( 'tab' => 'upgrade' ) ) ),
    … …  
    376377                        unset( $rows['reviews'], $rows['reports'] );
    377378                }
    378                 return $rows;
     379                if ( ! PremiumPress_Engage::reviews_on() ) {
     380                        unset( $rows['reviews'] );
     381                }
     382                /** A plugin's own screens add their sidebar rows: key => [label, url, icon, count]. */
     383                return (array) apply_filters( 'premiumpress_admin_nav', $rows );
    379384        }
    380385
    … …  
    397402
    398403                // Sidebar.
    399                 echo '<aside class="ppd-a-side" id="ppd-a-side" aria-label="' . esc_attr__( 'Directory menu', 'premiumpress-directory' ) . '"><div class="ppd-a-side-in">';
     404                echo '<aside class="ppd-a-side" id="ppd-a-side" aria-label="' . esc_attr( sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s menu', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ) ) . '"><div class="ppd-a-side-in">';
    400405                echo '<div class="ppd-a-brand"><span class="ppd-a-logo" aria-hidden="true">PP</span><span class="ppd-a-brandmeta"><span class="ppd-a-brandname">' . esc_html__( 'Dashboard', 'premiumpress-directory' ) . '</span>';
    401406                /* translators: %s: profile menu name, e.g. Directory */
    … …  
    515520                                        /* translators: %s: plural item name, lowercase */
    516521                                        array( 'clock', __( 'Setup & Expiry', 'premiumpress-directory' ), sprintf( __( 'What needs your approval, how long %s stay live, and the terms people agree to.', 'premiumpress-directory' ), $many ), PremiumPress_Settings::section_url( 'listings' ), 0, 'manage_options' ),
    517                                         array( 'star', __( 'Reviews', 'premiumpress-directory' ), __( 'Approve, edit or remove the reviews visitors leave.', 'premiumpress-directory' ), PremiumPress_Admin_Reviews::url(), $waiting, 'moderate_comments' ),
     522                                        ...( PremiumPress_Engage::reviews_on() ? array( array( 'star', __( 'Reviews', 'premiumpress-directory' ), __( 'Approve, edit or remove the reviews visitors leave.', 'premiumpress-directory' ), PremiumPress_Admin_Reviews::url(), $waiting, 'moderate_comments' ) ) : array() ),
    518523                                ),
    519524                        ),
    … …  
    528533                                        array( 'file', __( 'Custom Fields', 'premiumpress-directory' ), sprintf( __( 'The extra details asked for on each %s, and where they show.', 'premiumpress-directory' ), $one ), self::url( PremiumPress_Fields::PAGE ), 0, 'manage_options' ),
    529534                                        /* translators: %s: plural item name, lowercase */
    530                                         array( 'upload', __( 'Import / Export', 'premiumpress-directory' ), sprintf( __( 'Bring %s in from a file or another directory plugin, or download them as a spreadsheet.', 'premiumpress-directory' ), $many ), self::url( PremiumPress_Porting::PAGE ), 0, 'manage_options' ),
     535                                        array( 'upload', __( 'Import / Export', 'premiumpress-directory' ), sprintf( ( PremiumPress_Switch::names() ? __( 'Bring %s in from a file or another directory plugin, or download them as a spreadsheet.', 'premiumpress-directory' ) : __( 'Bring %s in from a file, or download them as a spreadsheet.', 'premiumpress-directory' ) ), $many ), self::url( PremiumPress_Porting::PAGE ), 0, 'manage_options' ),
    531536                                ),
    532537                        ),
    … …  
    737742                        array( 'list', 'blue', (string) $p['plural'], self::daily_listings( 30 ), self::daily_listings( 30, 30 ), self::url( self::LISTINGS ), __( 'View all', 'premiumpress-directory' ), (int) wp_count_posts( PremiumPress_Post_Types::TYPE )->publish ),
    738743                        array( 'users', 'green', __( 'Members', 'premiumpress-directory' ), self::daily_members( 30 ), self::daily_members( 30, 30 ), self::url( PremiumPress_Admin_Reviews::MEMBERS ), __( 'View all', 'premiumpress-directory' ), (int) count_users()['total_users'] ),
    739                         array( 'star', 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( 30 ), self::daily_reviews( 30, 30 ), PremiumPress_Admin_Reviews::url(), __( 'View all', 'premiumpress-directory' ), (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'approve', 'count' => true ) ) ),
     744                        ...( PremiumPress_Engage::reviews_on() ? array( array( 'star', 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( 30 ), self::daily_reviews( 30, 30 ), PremiumPress_Admin_Reviews::url(), __( 'View all', 'premiumpress-directory' ), (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'approve', 'count' => true ) ) ) ) : array() ),
    740745                        array( 'flag', 'purple', __( 'Reports', 'premiumpress-directory' ), self::daily_reports( 30 ), self::daily_reports( 30, 30 ), self::url( PremiumPress_Engage::REPORTS_PAGE ), __( 'View all', 'premiumpress-directory' ), PremiumPress_Engage::open_reports() ),
    741746                );
    … …  
    781786                self::moderation_card();
    782787                self::status_card();
    783                 self::recent_reviews_card();
     788                if ( PremiumPress_Engage::reviews_on() ) {
     789                        self::recent_reviews_card();
     790                }
    784791                echo '</div></div>';
    785792
    … …  
    789796        private static function moderation_card(): void {
    790797                $pending = (int) wp_count_posts( PremiumPress_Post_Types::TYPE )->pending;
    791                 $reviews = (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'hold', 'count' => true ) );
     798                $reviews = PremiumPress_Engage::reviews_on() ? (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'hold', 'count' => true ) ) : 0;
    792799                $reports = PremiumPress_Engage::open_reports();
    793800                $p       = PremiumPress_Profiles::current();
    … …  
    801808                        $rows = array(
    802809                                array( (string) $p['plural'], $pending, self::url( self::LISTINGS, array( 'status' => 'pending' ) ) ),
    803                                 array( __( 'Reviews', 'premiumpress-directory' ), $reviews, PremiumPress_Admin_Reviews::url( array( 'status' => 'hold' ) ) ),
     810                                ...( PremiumPress_Engage::reviews_on() ? array( array( __( 'Reviews', 'premiumpress-directory' ), $reviews, PremiumPress_Admin_Reviews::url( array( 'status' => 'hold' ) ) ) ) : array() ),
    804811                                array( __( 'Reports', 'premiumpress-directory' ), $reports, self::url( PremiumPress_Engage::REPORTS_PAGE ) ),
    805812                        );
    … …  
    846853                        array( 'ring', __( 'Expiring within 30 days', 'premiumpress-directory' ), $expiring, 'publish' ),
    847854                );
    848                 echo '<section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html__( 'Listing status', 'premiumpress-directory' ) . '</h2><ul class="ppd-a-rows">';
     855                echo '<section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html( sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s status', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ) ) . '</h2><ul class="ppd-a-rows">';
    849856                foreach ( $rows as $r ) {
    850857                        echo '<li><a href="' . esc_url( self::url( self::LISTINGS, array( 'status' => $r[3] ) ) ) . '"><span class="ppd-a-dot ppd-a-dot--' . esc_attr( $r[0] ) . '"></span>' . esc_html( $r[1] ) . '<b>' . esc_html( number_format_i18n( $r[2] ) ) . '</b>';
    … …  
    10011008                        'members'  => __( 'Members', 'premiumpress-directory' ),
    10021009                );
     1010                if ( ! PremiumPress_Engage::reviews_on() ) {
     1011                        unset( $labels['reviews'] );
     1012                }
    10031013                foreach ( $labels as $k => $label ) {
    10041014                        echo '<a class="ppd-a-tab' . ( $k === $tab ? ' is-active' : '' ) . '" href="' . esc_url( self::url( self::OVERVIEW, array( 'feed' => $k ) ) . '#ppd-recent' ) . '">' . esc_html( $label ) . ' <span class="ppd-a-tabcount">' . esc_html( number_format_i18n( $counts[ $k ] ) ) . '</span></a>';
    … …  
    10721082                        array( 'blue', (string) $p['plural'], self::daily_listings( $days ) ),
    10731083                        array( 'green', __( 'Members', 'premiumpress-directory' ), self::daily_members( $days ) ),
    1074                         array( 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( $days ) ),
     1084                        ...( PremiumPress_Engage::reviews_on() ? array( array( 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( $days ) ) ) : array() ),
    10751085                );
    10761086                $max = 1;
    … …  
    11241134                $p = PremiumPress_Profiles::current();
    11251135                $n = array();
    1126                 if ( 'directory' === PremiumPress_Profiles::current_key() ) {
     1136                if ( PremiumPress_Wizard::niches() ) {
    11271137                        $n[] = __( 'What it is about', 'premiumpress-directory' );
    11281138                }
    … …  
    11421152                self::e_icon( 'sparkle', 16 );
    11431153                echo esc_html__( 'Setup wizard', 'premiumpress-directory' ) . '</span>';
    1144                 echo '<h2 id="ppd-a-cta-h">' . esc_html( $done ? __( 'Change how your directory is set up', 'premiumpress-directory' ) : __( 'Set up your directory in a few minutes', 'premiumpress-directory' ) ) . '</h2>';
    1145                 echo '<p>' . esc_html( $done ? __( 'Run the setup again any time to change what it is about, the town, the homepage or the design.', 'premiumpress-directory' ) : __( 'Answer a few plain questions and your directory is ready for visitors. Nothing is sent anywhere, and you can change every answer later.', 'premiumpress-directory' ) ) . '</p>';
     1154                echo '<h2 id="ppd-a-cta-h">' . esc_html( $done ? sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Change how your %s is set up', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) : sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Set up your %s in a few minutes', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h2>';
     1155                echo '<p>' . esc_html( $done ? __( 'Run the setup again any time to change what it is about, the town, the homepage or the design.', 'premiumpress-directory' ) : sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Answer a few plain questions and your %s is ready for visitors. Nothing is sent anywhere, and you can change every answer later.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    11461156                echo '<ol class="ppd-a-cta-steps">';
    11471157                foreach ( self::setup_names() as $i => $name ) {
    … …  
    11621172                self::e_icon( 'sparkle', 20 );
    11631173                echo '</span><h2>' . esc_html__( 'Setup wizard', 'premiumpress-directory' ) . '</h2></div>';
    1164                 echo '<p>' . esc_html( $done ? __( 'Change what your directory is about, the town, the homepage or the design.', 'premiumpress-directory' ) : __( 'A few plain questions and your directory is ready for visitors.', 'premiumpress-directory' ) ) . '</p>';
     1174                echo '<p>' . esc_html( $done ? sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Change what your %s is about, the town, the homepage or the design.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) : sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'A few plain questions and your %s is ready for visitors.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    11651175                echo '<a class="ppd-a-btn ppd-a-btn--primary ppd-a-btn--block" href="' . esc_url( PremiumPress_Wizard::url() ) . '">' . esc_html( $done ? __( 'Open the setup wizard', 'premiumpress-directory' ) : __( 'Start the setup wizard', 'premiumpress-directory' ) ) . '</a></section>';
    11661176        }
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-compat.php

    r3837691 r3848540  
    3131                }
    3232                echo '<div class="notice notice-info is-dismissible"><p>';
    33                 echo esc_html__( 'PremiumPress Directory is paused because your PremiumPress theme now manages your listings, reviews and favourites. Nothing has been lost — you can deactivate this plugin.', 'premiumpress-directory' );
     33                $many = mb_strtolower( (string) PremiumPress_Profiles::current()['plural'] );
     34                echo esc_html(
     35                        sprintf(
     36                                /* translators: 1: plugin name, 2: plural item name, lowercase */
     37                                __( '%1$s is paused because your PremiumPress theme now manages your %2$s and favourites. Nothing has been lost — you can deactivate this plugin.', 'premiumpress-directory' ),
     38                                PREMIUMPRESS_NAME,
     39                                $many
     40                        )
     41                );
     42                echo '</p></div>';
     43        }
     44
     45        /**
     46         * The other PremiumPress listings plugins. Each exposes `running()` once it has
     47         * taken charge; the original Directory plugin is treated as running whenever it
     48         * is active.
     49         */
     50        const SIBLINGS = array( 'PremiumPress' . '_Plugin', 'PPClassifieds' . '_Plugin', 'PPJobBoard' . '_Plugin', 'PPRealEstate' . '_Plugin' );
     51
     52        /** Is another PremiumPress listings plugin already in charge on this request? */
     53        public static function sibling_active(): bool {
     54                foreach ( self::SIBLINGS as $class ) {
     55                        if ( str_replace( '_Compat', '_Plugin', __CLASS__ ) === $class || ! class_exists( $class, false ) ) {
     56                                continue;
     57                        }
     58                        if ( ! method_exists( $class, 'running' ) || $class::running() ) {
     59                                return true;
     60                        }
     61                }
     62                return false;
     63        }
     64
     65        public static function register_sibling_notice(): void {
     66                add_action( 'admin_notices', array( __CLASS__, 'sibling_notice' ) );
     67        }
     68
     69        public static function sibling_notice(): void {
     70                $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
     71                if ( ! $screen || 'plugins' !== $screen->id || ! current_user_can( 'activate_plugins' ) ) {
     72                        return;
     73                }
     74                echo '<div class="notice notice-warning"><p>';
     75                /* translators: %s: plugin name */
     76                echo esc_html( sprintf( __( '%s is paused because another PremiumPress listings plugin is active. They share the same listings, so please keep only one of them active.', 'premiumpress-directory' ), PREMIUMPRESS_NAME ) );
    3477                echo '</p></div>';
    3578        }
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-design.php

    r3838627 r3848540  
    208208         */
    209209        public static function theme_designs(): array {
    210                 return array(
    211                         'kiosk'      => array( 'Kiosk', __( 'Classic directory', 'premiumpress-directory' ) ),
    212                         'herald'     => array( 'Herald', __( 'Classic directory', 'premiumpress-directory' ) ),
    213                         'bureau'     => array( 'Bureau', __( 'Classic directory', 'premiumpress-directory' ) ),
    214                         'marylebone' => array( 'Marylebone', __( 'City guide', 'premiumpress-directory' ) ),
    215                         'gridline'   => array( 'Gridline', __( 'City guide', 'premiumpress-directory' ) ),
    216                         'bazaar'     => array( 'Bazaar', __( 'City guide', 'premiumpress-directory' ) ),
    217                         'slice'      => array( 'Slice', __( 'Local food', 'premiumpress-directory' ) ),
    218                         'carryout'   => array( 'Carryout', __( 'Local food', 'premiumpress-directory' ) ),
    219                         'supper'     => array( 'Supper', __( 'Local food', 'premiumpress-directory' ) ),
    220                         'volt'       => array( 'Volt', __( 'Sports coaches', 'premiumpress-directory' ) ),
    221                         'sideline'   => array( 'Sideline', __( 'Sports coaches', 'premiumpress-directory' ) ),
    222                         'podium'     => array( 'Podium', __( 'Sports coaches', 'premiumpress-directory' ) ),
    223                 );
     210                return (array) require PREMIUMPRESS_DIR . 'includes/design-data.php';
    224211        }
    225212
    … …  
    256243                }
    257244                if ( 'pages' === $view ) {
    258                         PremiumPress_Admin_UI::open( 'design', __( 'Directory pages', 'premiumpress-directory' ), __( 'The pages your directory uses, and the sample listings.', 'premiumpress-directory' ) );
     245                        PremiumPress_Admin_UI::open( 'design', sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ), sprintf( /* translators: 1: what the site is, e.g. directory, job board, 2: plural item name, e.g. listings, jobs */ __( 'The pages your %1$s uses, and the sample %2$s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun(), PremiumPress_Profiles::many() ) );
    259246                        echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">';
    260247                        PremiumPress_Admin_UI::e_icon( 'back', 16 );
    … …  
    269256                        return;
    270257                }
    271                 PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), __( 'Your pages, logo and colours, and how your directory looks.', 'premiumpress-directory' ) );
     258                PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your pages, logo and colours, and how your %s looks.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    272259                $groups = array(
    273260                        array(
    274261                                __( 'Ready-made designs', 'premiumpress-directory' ),
    275                                 __( 'Give your directory a new look in one click.', 'premiumpress-directory' ),
     262                                sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Give your %s a new look in one click.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ),
    276263                                array(
    277                                         array( 'sparkle', __( 'Ready-made designs', 'premiumpress-directory' ), __( 'Choose the look of your directory pages: your WordPress theme\'s style, the built-in design, or a Directory theme design.', 'premiumpress-directory' ), self::url( array( 'view' => 'designs' ) ) ),
     264                                        array( 'sparkle', __( 'Ready-made designs', 'premiumpress-directory' ), sprintf( /* translators: 1: what the site is, e.g. directory, 2: theme name, e.g. Directory theme */ __( 'Choose the look of your %1$s pages: your WordPress theme\'s style, the built-in design, or a %2$s design.', 'premiumpress-directory' ), PremiumPress_Profiles::noun(), (string) PremiumPress_Profiles::current()['theme_name'] ), self::url( array( 'view' => 'designs' ) ) ),
    278265                                ),
    279266                        ),
    … …  
    283270                                array(
    284271                                        array( 'file', __( 'All pages', 'premiumpress-directory' ), __( 'Manage the pages your website uses.', 'premiumpress-directory' ), self::wp_tool( 'pages' ) ),
    285                                         array( 'list', __( 'Directory pages', 'premiumpress-directory' ), __( 'The Directory, Add a listing and My listings pages, and the sample listings.', 'premiumpress-directory' ), PremiumPress_Settings::section_url( 'pages' ) ),
     272                                        array( 'list', sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ), sprintf( /* translators: 1: what the site is, capitalised, e.g. Directory, 2: one item with its article, e.g. a listing, an ad, 3: plural item name, e.g. listings, jobs */ __( 'The %1$s, Add %2$s and My %3$s pages, and the sample %3$s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ), PremiumPress_Profiles::a_one(), PremiumPress_Profiles::many() ), PremiumPress_Settings::section_url( 'pages' ) ),
    286273                                        array( 'edit', __( 'Brand & logo', 'premiumpress-directory' ), __( 'Your logo, site title, brand colours and fonts.', 'premiumpress-directory' ), self::url( array( 'view' => 'identity' ) ) ),
    287274                                        array( 'image', __( 'Header & footer', 'premiumpress-directory' ), __( 'Made in your theme\'s own editor, which opens in a new tab.', 'premiumpress-directory' ), self::wp_tool( 'header' ), true ),
    … …  
    331318                        'designs'  => array( __( 'Ready-made designs', 'premiumpress-directory' ), self::url( array( 'view' => 'designs' ) ), false ),
    332319                        'identity' => array( __( 'Brand', 'premiumpress-directory' ), self::url( array( 'view' => 'identity' ) ), false ),
    333                         'pages'    => array( __( 'Directory pages', 'premiumpress-directory' ), PremiumPress_Settings::section_url( 'pages' ), false ),
     320                        'pages'    => array( sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ), PremiumPress_Settings::section_url( 'pages' ), false ),
    334321                        'header'   => array( __( 'Header & footer', 'premiumpress-directory' ), self::wp_tool( 'header' ), true ),
    335322                );
    … …  
    395382
    396383                // Brand colours.
    397                 echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand colours', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html__( 'Used on your directory pages: buttons, links, cards and backgrounds. Leave a box empty to keep the design\'s own colour.', 'premiumpress-directory' ) . '</p>';
     384                echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand colours', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Used on your %s pages: buttons, links, cards and backgrounds. Leave a box empty to keep the design\'s own colour.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    398385                self::colour_row( 'primary', __( 'Primary', 'premiumpress-directory' ), $b['primary'], $def['primary'] );
    399386                self::colour_row( 'secondary', __( 'Secondary', 'premiumpress-directory' ), $b['secondary'], $def['secondary'] );
    … …  
    403390
    404391                // Brand fonts.
    405                 echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand fonts', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html__( 'One font for your headlines and one for the rest of your text, on your directory pages. The fonts come with the plugin, so nothing loads from other websites.', 'premiumpress-directory' ) . '</p>';
     392                echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand fonts', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'One font for your headlines and one for the rest of your text, on your %s pages. The fonts come with the plugin, so nothing loads from other websites.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    406393                foreach ( array( 'head_font' => __( 'Headline font', 'premiumpress-directory' ), 'body_font' => __( 'Body text font', 'premiumpress-directory' ) ) as $k => $l ) {
    407394                        echo '<div class="ppd-brand-field"><label for="ppd-' . esc_attr( $k ) . '">' . esc_html( $l ) . '</label><select id="ppd-' . esc_attr( $k ) . '" class="ppd-a-input ppd-a-input--wide" name="brand[' . esc_attr( $k ) . ']" data-ppd-live="' . esc_attr( $k ) . '">';
    … …  
    424411                // Live preview.
    425412                $name = (string) get_option( 'blogname' );
    426                 echo '<aside class="ppd-a-card ppd-a-pad ppd-brand-preview" aria-label="' . esc_attr__( 'Brand preview', 'premiumpress-directory' ) . '"><h2>' . esc_html__( 'Brand preview', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html__( 'A live preview of how your brand settings look on your directory pages.', 'premiumpress-directory' ) . '</p>';
    427                 echo '<div class="ppd-bp" data-ppd-preview data-bg="' . esc_attr( $def['background'] ) . '"><div class="ppd-bp-head"><span class="ppd-bp-logo"><img src="' . esc_url( $logo_src ) . '" alt="" data-ppd-pv-logo><b data-ppd-pv-name>' . esc_html( $name ) . '</b></span><span class="ppd-bp-nav"><span>' . esc_html__( 'Home', 'premiumpress-directory' ) . '</span><span>' . esc_html__( 'Directory', 'premiumpress-directory' ) . '</span><span class="ppd-bp-btn">' . esc_html__( 'Add a listing', 'premiumpress-directory' ) . '</span></span></div>';
    428                 echo '<div class="ppd-bp-body" data-ppd-pv-card><h3 data-ppd-pv-head>' . esc_html__( 'Your headlines look like this', 'premiumpress-directory' ) . '</h3><p data-ppd-pv-text>' . esc_html__( 'This is how your body text will appear on your directory pages.', 'premiumpress-directory' ) . '</p><div class="ppd-bp-row"><span class="ppd-bp-btn ppd-bp-btn--big">' . esc_html__( 'A button', 'premiumpress-directory' ) . '</span><span class="ppd-bp-link">' . esc_html__( 'A text link', 'premiumpress-directory' ) . '</span></div></div>';
     413                echo '<aside class="ppd-a-card ppd-a-pad ppd-brand-preview" aria-label="' . esc_attr__( 'Brand preview', 'premiumpress-directory' ) . '"><h2>' . esc_html__( 'Brand preview', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'A live preview of how your brand settings look on your %s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
     414                echo '<div class="ppd-bp" data-ppd-preview data-bg="' . esc_attr( $def['background'] ) . '"><div class="ppd-bp-head"><span class="ppd-bp-logo"><img src="' . esc_url( $logo_src ) . '" alt="" data-ppd-pv-logo><b data-ppd-pv-name>' . esc_html( $name ) . '</b></span><span class="ppd-bp-nav"><span>' . esc_html__( 'Home', 'premiumpress-directory' ) . '</span><span>' . esc_html( PremiumPress_Profiles::noun( true ) ) . '</span><span class="ppd-bp-btn">' . esc_html( sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'Add %s', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ) . '</span></span></div>';
     415                echo '<div class="ppd-bp-body" data-ppd-pv-card><h3 data-ppd-pv-head>' . esc_html__( 'Your headlines look like this', 'premiumpress-directory' ) . '</h3><p data-ppd-pv-text>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'This is how your body text will appear on your %s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p><div class="ppd-bp-row"><span class="ppd-bp-btn ppd-bp-btn--big">' . esc_html__( 'A button', 'premiumpress-directory' ) . '</span><span class="ppd-bp-link">' . esc_html__( 'A text link', 'premiumpress-directory' ) . '</span></div></div>';
    429416                echo '<div class="ppd-bp-tokens">';
    430417                foreach ( array( 'primary' => __( 'Primary', 'premiumpress-directory' ), 'secondary' => __( 'Secondary', 'premiumpress-directory' ), 'background' => __( 'Background', 'premiumpress-directory' ), 'cards' => __( 'Cards', 'premiumpress-directory' ) ) as $k => $l ) {
    … …  
    481468        /** Custom code: WordPress's own "Additional CSS", edited here. */
    482469        private static function render_code( string $msg ): void {
    483                 PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), __( 'Your pages, logo and colours, and how your directory looks.', 'premiumpress-directory' ) );
     470                PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your pages, logo and colours, and how your %s looks.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    484471                self::crumbs( __( 'Custom code', 'premiumpress-directory' ), $msg );
    485472                self::tabs( 'code' );
    … …  
    511498                $p     = PremiumPress_Profiles::current();
    512499                $theme = (string) $p['theme_name'];
    513                 PremiumPress_Admin_UI::open( 'design', __( 'Ready-made designs', 'premiumpress-directory' ), __( 'Choose how your directory pages look to visitors.', 'premiumpress-directory' ) );
     500                PremiumPress_Admin_UI::open( 'design', __( 'Ready-made designs', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Choose how your %s pages look to visitors.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    514501                echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">';
    515502                PremiumPress_Admin_UI::e_icon( 'back', 16 );
    … …  
    518505                if ( $saved ) {
    519506                        $dir = PremiumPress_Pages::url( 'directory' );
    520                         echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Design saved.', 'premiumpress-directory' ) . ( '' !== $dir ? ' <a href="' . esc_url( $dir ) . '" target="_blank" rel="noopener">' . esc_html__( 'See your directory', 'premiumpress-directory' ) . '</a>' : '' ) . '</div>';
     507                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Design saved.', 'premiumpress-directory' ) . ( '' !== $dir ? ' <a href="' . esc_url( $dir ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'See your %s', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</a>' : '' ) . '</div>';
    521508                }
    522509                echo '<div class="ppd-a-card ppd-a-pad ppd-dz">';
    … …  
    546533                $lead = sprintf( __( 'This design comes with the PremiumPress %s. It isn\'t part of the free plugin.', 'premiumpress-directory' ), $theme );
    547534                /* translators: %s: theme name, e.g. Directory theme */
    548                 $more = sprintf( __( 'The %s uses the same listings, categories and reviews, so you can switch any time without losing anything.', 'premiumpress-directory' ), $theme );
     535                $more = sprintf( /* translators: 1: theme name, 2: plural item name, e.g. listings */ __( 'The %1$s uses the same %2$s and categories, so you can switch any time without losing anything.', 'premiumpress-directory' ), $theme, PremiumPress_Profiles::many() );
    549536                echo '<dialog class="ppd-dz-dialog" data-ppd-pro-dialog aria-labelledby="ppd-dz-dialog-h"><img src="' . esc_url( PREMIUMPRESS_URL . 'assets/designs/kiosk.webp' ) . '" alt="" data-ppd-pro-pic width="480" height="300"><div class="ppd-dz-dialog-in">';
    550537                echo '<h2 id="ppd-dz-dialog-h" data-ppd-pro-title></h2><p>' . esc_html( $lead ) . '</p><p class="ppd-a-muted">' . esc_html( $more ) . '</p>';
    … …  
    563550                $now   = self::current();
    564551                $cards = array(
    565                         'wordpress' => array( __( 'Your WordPress theme', 'premiumpress-directory' ), __( 'Your directory uses your WordPress theme\'s own fonts, colours and buttons, so it matches the rest of your site.', 'premiumpress-directory' ) ),
    566                         'builtin'   => array( __( 'Built-in design', 'premiumpress-directory' ), __( 'The PremiumPress look: a filter sidebar, photo cards with ratings, and a listing page with a contact card.', 'premiumpress-directory' ) ),
     552                        'wordpress' => array( __( 'Your WordPress theme', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s uses your WordPress theme\'s own fonts, colours and buttons, so it matches the rest of your site.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ),
     553                        'builtin'   => array( __( 'Built-in design', 'premiumpress-directory' ), sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'The PremiumPress look: a filter sidebar, photo cards with ratings, and %s page with a contact card.', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ),
    567554                );
    568555                echo '<div class="ppd-design-cards">';
    … …  
    582569                }
    583570                echo '</div>';
    584                 echo '<p class="ppd-design-more">' . esc_html__( 'More designs come with the PremiumPress Directory theme. See them any time under Design, Ready-made designs.', 'premiumpress-directory' ) . '</p>';
     571                echo '<p class="ppd-design-more">' . esc_html( sprintf( /* translators: %s: theme name, e.g. Directory theme */ __( 'More designs come with the PremiumPress %s. See them any time under Design, Ready-made designs.', 'premiumpress-directory' ), (string) PremiumPress_Profiles::current()['theme_name'] ) ) . '</p>';
    585572        }
    586573}
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-engage.php

    r3838627 r3848540  
    206206        public function maybe_sync_deleted( $id, $comment ): void {
    207207                $this->maybe_sync( $id, $comment );
     208        }
     209
     210        /** Does this site type use star reviews? (Classifieds uses questions in the theme instead.) */
     211        public static function reviews_on(): bool {
     212                return false !== ( PremiumPress_Profiles::current()['reviews'] ?? true );
    208213        }
    209214
    … …  
    324329                }
    325330                $help = PremiumPress_Settings::get()['emails']
    326                         ? __( 'Shown under the review with your listing\'s name. The reviewer is told by email.', 'premiumpress-directory' )
    327                         : __( 'Shown under the review with your listing\'s name.', 'premiumpress-directory' );
     331                        ? sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Shown under the review with your %s\'s name. The reviewer is told by email.', 'premiumpress-directory' ), PremiumPress_Profiles::one() )
     332                        : sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Shown under the review with your %s\'s name.', 'premiumpress-directory' ), PremiumPress_Profiles::one() );
    328333                $out .= '</p><p class="ppd-form__help">' . esc_html( $help ) . '</p></form></details>';
    329334                return $out;
    … …  
    384389        /** The reviews section for a listing page. */
    385390        public static function reviews_html( int $post_id ): string {
     391                if ( ! self::reviews_on() ) {
     392                        return '';
     393                }
    386394                $s       = self::stats( $post_id );
    387395                $reviews = get_comments(
    … …  
    433441                }
    434442
    435                 if ( self::A_REVIEW === $action ) {
     443                if ( self::A_REVIEW === $action && self::reviews_on() ) {
    436444                        $this->save_review( $id, $in, $back );
    437445                } elseif ( self::A_REPORT === $action ) {
    … …  
    635643                        'review_pending'  => array( 'success', __( 'Thanks! Your review will appear once it has been approved.', 'premiumpress-directory' ) ),
    636644                        'twice'           => array( 'error', __( 'You have already reviewed this.', 'premiumpress-directory' ) ),
    637                         'own'             => array( 'error', __( 'You can\'t review your own listing.', 'premiumpress-directory' ) ),
     645                        'own'             => array( 'error', sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'You can\'t review your own %s.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ),
    638646                        'rating'          => array( 'error', __( 'Please choose a star rating.', 'premiumpress-directory' ) ),
    639647                        'replied'         => array( 'success', __( 'Your reply has been posted.', 'premiumpress-directory' ) ),
    … …  
    754762                );
    755763                $n = count( $reports );
    756                 PremiumPress_Admin_UI::open( 'reports', __( 'Reports', 'premiumpress-directory' ), __( 'Listings visitors have told you about.', 'premiumpress-directory' ) );
     764                PremiumPress_Admin_UI::open( 'reports', __( 'Reports', 'premiumpress-directory' ), sprintf( /* translators: %s: plural item name, capitalised, e.g. Listings */ __( '%s visitors have told you about.', 'premiumpress-directory' ), PremiumPress_Profiles::many( true ) ) );
    757765                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only.
    758766                $msg = isset( $_GET['ppd_msg'] ) ? sanitize_key( wp_unslash( $_GET['ppd_msg'] ) ) : '';
    759767                if ( 'dismissed' === $msg ) {
    760                         echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Report dismissed. The listing stays as it is.', 'premiumpress-directory' ) . '</div>';
     768                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Report dismissed. The %s stays as it is.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</div>';
    761769                } elseif ( 'offline' === $msg ) {
    762                         echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'The listing is now offline (saved as a draft) and the report is closed. You can put it back live from Listings.', 'premiumpress-directory' ) . '</div>';
     770                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html( sprintf( /* translators: 1: singular item name, e.g. listing, job, 2: plural item name, capitalised, e.g. Listings */ __( 'The %1$s is now offline (saved as a draft) and the report is closed. You can put it back live from %2$s.', 'premiumpress-directory' ), PremiumPress_Profiles::one(), PremiumPress_Profiles::many( true ) ) ) . '</div>';
    763771                }
    764772                if ( ! $reports ) {
    765773                        echo '<section class="ppd-a-card"><div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">';
    766774                        PremiumPress_Admin_UI::e_icon( 'checkc', 22 );
    767                         echo '</span><strong>' . esc_html__( 'All clear', 'premiumpress-directory' ) . '</strong><span>' . esc_html__( 'No visitor has reported anything. When someone uses "Report this" on a listing, it shows up here and you get an email.', 'premiumpress-directory' ) . '</span></div></section>';
     775                        echo '</span><strong>' . esc_html__( 'All clear', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'No visitor has reported anything. When someone uses "Report this" on %s, it shows up here and you get an email.', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ) . '</span></div></section>';
    768776                        PremiumPress_Admin_UI::close();
    769777                        return;
    770778                }
    771779                /* translators: %d: number of open reports */
    772                 echo '<p class="ppd-rp-lead">' . esc_html( sprintf( _n( '%d report to look at.', '%d reports to look at.', $n, 'premiumpress-directory' ), $n ) ) . ' ' . esc_html__( 'Check the listing, then either take it offline or dismiss the report if nothing needs changing.', 'premiumpress-directory' ) . '</p>';
     780                echo '<p class="ppd-rp-lead">' . esc_html( sprintf( _n( '%d report to look at.', '%d reports to look at.', $n, 'premiumpress-directory' ), $n ) ) . ' ' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Check the %s, then either take it offline or dismiss the report if nothing needs changing.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p>';
    773781
    774782                $tones   = array(
    … …  
    811819                        echo '<div class="ppd-rp-actions">';
    812820                        if ( $live ) {
    813                                 echo '<a class="ppd-a-btn" href="' . esc_url( (string) get_permalink( $pid ) ) . '" target="_blank" rel="noopener">' . esc_html__( 'View listing', 'premiumpress-directory' ) . '</a>';
     821                                echo '<a class="ppd-a-btn" href="' . esc_url( (string) get_permalink( $pid ) ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'View %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</a>';
    814822                        }
    815                         echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Admin_Editor::url( $pid ) ) . '">' . esc_html__( 'Edit listing', 'premiumpress-directory' ) . '</a>';
     823                        echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Admin_Editor::url( $pid ) ) . '">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Edit %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</a>';
    816824                        if ( $live && current_user_can( 'edit_post', $pid ) ) {
    817825                                echo '<a class="ppd-a-btn ppd-a-btn--danger" href="' . esc_url( self::report_url( (int) $r->comment_ID, true ) ) . '" data-ppd-confirm="' . esc_attr( sprintf( /* translators: %s: listing title */ __( 'Take "%s" offline? It is saved as a draft, so you can put it back later.', 'premiumpress-directory' ), get_the_title( $pid ) ) ) . '">' . esc_html__( 'Take offline', 'premiumpress-directory' ) . '</a>';
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-fields.php

    r3838627 r3848540  
    4444                        array(
    4545                                'newLabel' => __( 'New field', 'premiumpress-directory' ),
    46                                 'confirm'  => __( 'Remove this field? Answers already saved on listings are kept and come back if you add the same key again.', 'premiumpress-directory' ),
    47                                 'reset'    => __( 'Put the field list back to the built-in fields? Fields you added are removed from the list; nothing saved on listings is deleted.', 'premiumpress-directory' ),
     46                                'confirm'  => sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Remove this field? Answers already saved on %s are kept and come back if you add the same key again.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ),
     47                                'reset'    => sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Put the field list back to the built-in fields? Fields you added are removed from the list; nothing saved on %s is deleted.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ),
    4848                        )
    4949                );
    … …  
    7272        }
    7373
     74        /**
     75         * A built-in field whose key or choices the theme relies on (a "_ppt_…" key, a
     76         * category-style field, or choices with their own stored keys). Its key, type and
     77         * choices stay as they are; the label, help, order and card setting can change.
     78         *
     79         * @param array<string, mixed> $f
     80         */
     81        public static function locked( array $f ): bool {
     82                $builtin = (array) PremiumPress_Profiles::current()['fields'];
     83                $key     = (string) ( $f['key'] ?? '' );
     84                if ( ! isset( $builtin[ $key ] ) ) {
     85                        return false;
     86                }
     87                $def  = (array) $builtin[ $key ];
     88                $opts = (array) ( $def['options'] ?? array() );
     89                return ! empty( $def['tax'] ) || array_values( $opts ) !== $opts || (bool) preg_match( '/^(_|ppt_)/', $key );
     90        }
     91
    7492        /** Keys the plugin itself uses; a custom field may not take them over. */
    7593        public static function reserved(): array {
    … …  
    126144                $f    = is_array( $f ) ? $f : array();
    127145                $type = isset( $f['type'] ) && isset( self::types()[ $f['type'] ] ) ? (string) $f['type'] : 'text';
     146                $raw  = (array) ( $f['options'] ?? array() );
     147                // Choices with their own stored keys (ad type "sale", job type "full-time") keep them.
     148                $opts = array_values( $raw ) !== $raw
     149                        ? array_map( 'strval', $raw )
     150                        : array_values( array_filter( array_map( 'strval', $raw ), 'strlen' ) );
    128151                return array_merge(
    129152                        $f,
    … …  
    132155                                'label'      => (string) ( $f['label'] ?? '' ),
    133156                                'type'       => $type,
    134                                 'options'    => self::has_options( $type ) ? array_values( array_filter( array_map( 'strval', (array) ( $f['options'] ?? array() ) ), 'strlen' ) ) : array(),
     157                                'options'    => self::has_options( $type ) ? $opts : array(),
    135158                                'help'       => (string) ( $f['help'] ?? '' ),
    136159                                'required'   => ! empty( $f['required'] ) && 'title' !== $type,
    … …  
    179202                                $key = 'field';
    180203                        }
    181                         // Names starting "_" are WordPress's hidden ones, "ppt_" the theme's.
    182                         $key  = (string) preg_replace( '/^(_+|ppt_)+/', '', $key );
    183                         $key  = '' !== $key ? $key : 'field';
    184                         $base = $key;
    185                         $n    = 2;
    186                         while ( in_array( $key, $used, true ) ) {
    187                                 $key = $base . '_' . $n;
    188                                 ++$n;
     204                        $builtin = (array) PremiumPress_Profiles::current()['fields'];
     205                        $locked  = isset( $builtin[ $key ] ) && self::locked( array( 'key' => $key ) ) && ! in_array( $key, $used, true );
     206                        if ( ! $locked ) {
     207                                // Names starting "_" are WordPress's hidden ones, "ppt_" the theme's.
     208                                $key  = (string) preg_replace( '/^(_+|ppt_)+/', '', $key );
     209                                $key  = '' !== $key ? $key : 'field';
     210                                $base = $key;
     211                                $n    = 2;
     212                                while ( in_array( $key, $used, true ) ) {
     213                                        $key = $base . '_' . $n;
     214                                        ++$n;
     215                                }
    189216                        }
    190217                        $used[] = $key;
    191218                        $type   = isset( $row['type'] ) && isset( self::types()[ $row['type'] ] ) ? (string) $row['type'] : 'text';
     219                        if ( $locked ) {
     220                                $type = (string) ( $builtin[ $key ]['type'] ?? $type );
     221                        }
    192222                        $opts   = array();
    193223                        if ( self::has_options( $type ) ) {
    … …  
    207237                                }
    208238                        }
     239                        if ( $locked && self::has_options( $type ) ) {
     240                                $opts = (array) ( $builtin[ $key ]['options'] ?? array() );
     241                        }
    209242                        // Built-in extras (e.g. "money" on a price) stay with their key.
    210                         $keep   = isset( $prev[ $key ] ) ? $prev[ $key ] : array();
     243                        $keep   = isset( $prev[ $key ] ) ? $prev[ $key ] : ( $locked ? (array) $builtin[ $key ] : array() );
    211244                        $list[] = self::normalise(
    212245                                array_merge(
    … …  
    298331                );
    299332                $name = 'fields[' . $uid . ']';
     333                $lock = self::locked( $f );
    300334                echo '<details class="ppd-cf" data-ppd-field' . ( $open ? ' open' : '' ) . '><summary class="ppd-cf-head"><span class="ppd-cf-grip" data-ppd-grip draggable="true" aria-hidden="true">';
    301335                PremiumPress_Admin_UI::e_icon( 'grip', 16 );
    … …  
    316350
    317351                echo '<div class="ppd-cf-grid"><label class="ppd-cf-f"><span>' . esc_html__( 'Label', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input" name="' . esc_attr( $name ) . '[label]" value="' . esc_attr( (string) $f['label'] ) . '" maxlength="120" data-ppd-labelin></label>';
    318                 echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Key', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input ppd-cf-mono" name="' . esc_attr( $name ) . '[key]" value="' . esc_attr( (string) $f['key'] ) . '" maxlength="60" pattern="[a-z0-9_\-]*" data-ppd-keyin><small>' . esc_html__( 'Where the answer is saved. Changing it hides answers saved under the old key.', 'premiumpress-directory' ) . '</small></label>';
    319                 echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Field type', 'premiumpress-directory' ) . '</span><select class="ppd-a-input" name="' . esc_attr( $name ) . '[type]" data-ppd-typein>';
     352                echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Key', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input ppd-cf-mono" name="' . esc_attr( $name ) . '[key]" value="' . esc_attr( (string) $f['key'] ) . '" maxlength="60" pattern="[a-z0-9_\-]*" data-ppd-keyin' . ( $lock ? ' readonly' : '' ) . '><small>' . esc_html__( 'Where the answer is saved. Changing it hides answers saved under the old key.', 'premiumpress-directory' ) . '</small></label>';
     353                echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Field type', 'premiumpress-directory' ) . '</span><select class="ppd-a-input" name="' . esc_attr( $name ) . '[type]" data-ppd-typein' . ( $lock ? ' disabled' : '' ) . '>';
    320354                foreach ( $types as $k => $label ) {
    321355                        echo '<option value="' . esc_attr( $k ) . '"' . selected( $f['type'], $k, false ) . '>' . esc_html( $label ) . '</option>';
    … …  
    324358                echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Help text (optional)', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input" name="' . esc_attr( $name ) . '[help]" value="' . esc_attr( (string) $f['help'] ) . '" maxlength="200"></label></div>';
    325359
    326                 echo '<label class="ppd-cf-f ppd-cf-opts" data-ppd-opts' . ( self::has_options( (string) $f['type'] ) ? '' : ' hidden' ) . '><span>' . esc_html__( 'Options, one per line', 'premiumpress-directory' ) . '</span><textarea class="ppd-a-input" rows="5" name="' . esc_attr( $name ) . '[options]">' . esc_textarea( implode( "\n", (array) $f['options'] ) ) . '</textarea></label>';
     360                echo '<label class="ppd-cf-f ppd-cf-opts" data-ppd-opts' . ( self::has_options( (string) $f['type'] ) ? '' : ' hidden' ) . '><span>' . esc_html__( 'Options, one per line', 'premiumpress-directory' ) . '</span><textarea class="ppd-a-input" rows="5" name="' . esc_attr( $name ) . '[options]"' . ( $lock ? ' readonly' : '' ) . '>' . esc_textarea( implode( "\n", (array) $f['options'] ) ) . '</textarea></label>';
     361                if ( $lock ) {
     362                        echo '<p class="ppd-cf-note">' . esc_html__( 'Built in: the theme reads this field\'s name and choices, so they stay as they are. You can change its label, help text, order and where it shows.', 'premiumpress-directory' ) . '</p>';
     363                }
    327364
    328365                $cats = get_terms(
    … …  
    340377                        echo '</div></fieldset>';
    341378                }
    342                 echo '<div class="ppd-cf-flags"><label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[required]" value="1"' . checked( ! empty( $f['required'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html__( 'Required on the "Add a listing" form', 'premiumpress-directory' ) . '</label>';
    343                 echo '<label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[card]" value="1"' . checked( ! empty( $f['card'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html__( 'Show on listing cards', 'premiumpress-directory' ) . '</label></div>';
     379                echo '<div class="ppd-cf-flags"><label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[required]" value="1"' . checked( ! empty( $f['required'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html( sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'Required on the "Add %s" form', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ) . '</label>';
     380                echo '<label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[card]" value="1"' . checked( ! empty( $f['card'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Show on %s cards', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</label></div>';
    344381                echo '</div></details>';
    345382        }
    … …  
    354391                $defs = self::defaults();
    355392                $dk   = wp_list_pluck( $defs, 'key' );
    356                 PremiumPress_Admin_UI::open( 'listings', __( 'Custom Fields', 'premiumpress-directory' ), __( 'The extra details people fill in when they add a listing.', 'premiumpress-directory' ) );
     393                PremiumPress_Admin_UI::open( 'listings', __( 'Custom Fields', 'premiumpress-directory' ), sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'The extra details people fill in when they add %s.', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) );
    357394                PremiumPress_Admin_UI::crumb();
    358395                if ( 'saved' === $msg ) {
    … …  
    403440                echo '</section><section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html__( 'Reset to defaults', 'premiumpress-directory' ) . '</h2>';
    404441                /* translators: %d: number of built-in fields */
    405                 echo '<p>' . esc_html( sprintf( _n( 'Puts the field list back to the %d field this site type comes with.', 'Puts the field list back to the %d fields this site type comes with.', count( $dk ), 'premiumpress-directory' ), count( $dk ) ) ) . '</p><p class="ppd-a-muted">' . esc_html__( 'Fields you added are removed from the list and edits to the built-in ones are undone. Nothing already filled in on listings is deleted: it comes back with its field.', 'premiumpress-directory' ) . '</p>';
     442                echo '<p>' . esc_html( sprintf( _n( 'Puts the field list back to the %d field this site type comes with.', 'Puts the field list back to the %d fields this site type comes with.', count( $dk ), 'premiumpress-directory' ), count( $dk ) ) ) . '</p><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Fields you added are removed from the list and edits to the built-in ones are undone. Nothing already filled in on %s is deleted: it comes back with its field.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p>';
    406443                echo '<form method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '" data-ppd-resetform><input type="hidden" name="action" value="' . esc_attr( self::A_RESET ) . '">';
    407444                wp_nonce_field( self::A_RESET );
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-frontend.php

    r3838627 r3848540  
    6464                                /* translators: %s: singular item name, e.g. Listing */
    6565                                'title'       => sprintf( __( 'Single %s', 'premiumpress-directory' ), (string) $p['singular'] ),
    66                                 'description' => __( 'Shows one directory item with its details, map and reviews.', 'premiumpress-directory' ),
     66                                'description' => __( 'Shows one item with its details and map.', 'premiumpress-directory' ),
    6767                                'content'     => (string) file_get_contents( PREMIUMPRESS_DIR . 'templates/block/single-listing.html' ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- local file.
    6868                                'post_types'  => array( PremiumPress_Post_Types::TYPE ),
    … …  
    7272                $archive = (string) file_get_contents( PREMIUMPRESS_DIR . 'templates/block/archive-listing.html' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- local file.
    7373                $names   = array(
    74                         PremiumPress_Post_Types::TAX_CATEGORY => __( 'Directory category', 'premiumpress-directory' ),
    75                         PremiumPress_Post_Types::TAX_LOCATION => __( 'Directory location', 'premiumpress-directory' ),
    76                         PremiumPress_Post_Types::TAX_TAG      => __( 'Directory tag', 'premiumpress-directory' ),
     74                        PremiumPress_Post_Types::TAX_CATEGORY => sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s category', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ),
     75                        PremiumPress_Post_Types::TAX_LOCATION => sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s location', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ),
     76                        PremiumPress_Post_Types::TAX_TAG      => sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s tag', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ),
    7777                );
    7878                foreach ( $names as $tax => $title ) {
    … …  
    8181                                array(
    8282                                        'title'       => $title,
    83                                         'description' => __( 'Shows the directory search and cards, filtered to one category, location or tag.', 'premiumpress-directory' ),
     83                                        'description' => sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Shows the %s search and cards, filtered to one category, location or tag.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ),
    8484                                        'content'     => $archive,
    8585                                )
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-lifecycle.php

    r3838627 r3848540  
    182182
    183183        public function meta_box(): void {
    184                 add_meta_box( 'ppd-options', __( 'Listing options', 'premiumpress-directory' ), array( $this, 'render_box' ), null, 'side', 'default' );
     184                add_meta_box( 'ppd-options', sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s options', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ), array( $this, 'render_box' ), null, 'side', 'default' );
    185185        }
    186186
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-listings-grid.php

    r3837691 r3848540  
    133133
    134134                if ( ! $query->have_posts() ) {
    135                         return '<div class="ppd"><p class="ppd-empty">' . esc_html__( 'No listings found.', 'premiumpress-directory' ) . '</p></div>';
     135                        return '<div class="ppd"><p class="ppd-empty">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'No %s found.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p></div>';
    136136                }
    137137
    … …  
    175175                                'current'   => $current,
    176176                                'total'     => (int) $query->max_num_pages,
    177                                 'prev_text' => __( 'Previous', 'premiumpress-directory' ),
    178                                 'next_text' => __( 'Next', 'premiumpress-directory' ),
     177                                'prev_text' => esc_html__( 'Previous', 'premiumpress-directory' ),
     178                                'next_text' => esc_html__( 'Next', 'premiumpress-directory' ),
    179179                        )
    180180                );
    181                 return $links ? '<nav class="ppd-pagination" aria-label="' . esc_attr__( 'Results pages', 'premiumpress-directory' ) . '">' . $links . '</nav>' : '';
     181                return $links ? '<nav class="ppd-pagination" aria-label="' . esc_attr__( 'Results pages', 'premiumpress-directory' ) . '">' . wp_kses_post( $links ) . '</nav>' : '';
    182182        }
    183183}
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-meta.php

    r3838627 r3848540  
    9898
    9999                foreach ( PremiumPress_Profiles::all_fields() as $key => $field ) {
     100                        if ( ! empty( $field['tax'] ) ) {
     101                                continue; // Stored as a term, not post meta.
     102                        }
    100103                        register_post_meta(
    101104                                PremiumPress_Post_Types::TYPE,
    … …  
    163166                echo '<div class="ppd-grid">';
    164167                foreach ( PremiumPress_Profiles::fields() as $key => $field ) {
    165                         $value = (string) get_post_meta( $post->ID, $key, true );
     168                        $value = PremiumPress_Profiles::get_field( (int) $post->ID, $key, $field );
    166169                        $id    = 'ppd-f-' . $key;
    167170                        $name  = 'ppd_f[' . $key . ']';
    … …  
    191194                                $on = array_map( 'trim', explode( ',', $value ) );
    192195                                echo '<fieldset><legend>' . esc_html( (string) $field['label'] ) . '</legend>';
    193                                 foreach ( (array) ( $field['options'] ?? array() ) as $opt ) {
     196                                foreach ( PremiumPress_Profiles::options( $field ) as $opt => $opt_label ) {
    194197                                        printf(
    195198                                                '<label class="ppd-check"><input type="checkbox" name="%1$s[]" value="%2$s" %3$s> %4$s</label>',
    196199                                                esc_attr( $name ),
    197                                                 esc_attr( $opt ),
    198                                                 checked( in_array( $opt, $on, true ), true, false ),
    199                                                 esc_html( $opt )
     200                                                esc_attr( (string) $opt ),
     201                                                checked( in_array( (string) $opt, $on, true ), true, false ),
     202                                                esc_html( $opt_label )
    200203                                        );
    201204                                }
    … …  
    203206                        } elseif ( 'select' === $type ) {
    204207                                printf( '<label for="%1$s">%2$s</label><select id="%1$s" name="%3$s" class="widefat"><option value="">%4$s</option>', esc_attr( $id ), esc_html( (string) $field['label'] ), esc_attr( $name ), esc_html__( '— Select —', 'premiumpress-directory' ) );
    205                                 foreach ( (array) ( $field['options'] ?? array() ) as $opt ) {
    206                                         printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $opt ), selected( $opt, $value, false ), esc_html( $opt ) );
     208                                foreach ( PremiumPress_Profiles::options( $field ) as $opt => $opt_label ) {
     209                                        printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( (string) $opt ), selected( (string) $opt, $value, false ), esc_html( $opt_label ) );
    207210                                }
    208211                                echo '</select>';
    … …  
    250253                }
    251254                echo '</div>';
    252                 echo '<p class="description">' . esc_html__( 'Coordinates place the listing on the map and in distance searches.', 'premiumpress-directory' ) . '</p>';
     255                echo '<p class="description">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Coordinates place the %s on the map and in distance searches.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p>';
    253256        }
    254257
    … …  
    320323
    321324                // Only sections the active profile shows are saved. Data from sections it
    322                 // hides (say, opening hours on a classifieds site) is left untouched.
     325                // hides (say, opening hours on a job board) is left untouched.
    323326                // Each value is sanitised by the callback registered in register_meta().
    324327                $in   = isset( $_POST['ppd'] ) && is_array( $_POST['ppd'] ) ? wp_unslash( $_POST['ppd'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    … …  
    336339                $custom = isset( $_POST['ppd_f'] ) && is_array( $_POST['ppd_f'] ) ? wp_unslash( $_POST['ppd_f'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    337340                foreach ( PremiumPress_Profiles::fields() as $key => $field ) {
    338                         self::store( $post_id, $key, self::sanitize_field( $field, $custom[ $key ] ?? '' ) );
     341                        PremiumPress_Profiles::set_field( (int) $post_id, $key, $field, self::sanitize_field( $field, $custom[ $key ] ?? '' ) );
    339342                }
    340343
    … …  
    367370        public static function sanitize_field( array $field, $value ): string {
    368371                $type    = (string) ( $field['type'] ?? 'text' );
    369                 $options = array_map( 'strval', (array) ( $field['options'] ?? array() ) );
     372                $options = array_map( 'strval', array_keys( PremiumPress_Profiles::options( $field ) ) );
    370373
    371374                switch ( $type ) {
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-pages.php

    r3837691 r3848540  
    2727                        'submit'    => array(
    2828                                /* translators: %s: singular item name, e.g. Listing */
    29                                 'title' => sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['singular'] ) ),
     29                                'title' => isset( $p['add_title'] ) ? (string) $p['add_title'] : sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['singular'] ) ),
    3030                                'slug'  => 'add-' . sanitize_title( (string) $p['singular'] ),
    3131                                'block' => '<!-- wp:premiumpress/submit /-->',
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-plugin.php

    r3838627 r3848540  
    1616        /** @var PremiumPress_Plugin|null */
    1717        private static $instance = null;
     18
     19        /** @var bool True once this plugin has taken charge of the site's listings. */
     20        private static $running = false;
     21
     22        public static function running(): bool {
     23                return self::$running;
     24        }
    1825
    1926        public static function instance(): PremiumPress_Plugin {
    … …  
    3542                        return;
    3643                }
     44                // Only one PremiumPress listings plugin can run at a time: they share the same
     45                // listings, so the first one loaded stays in charge and the others stand aside.
     46                if ( PremiumPress_Compat::sibling_active() ) {
     47                        PremiumPress_Compat::register_sibling_notice();
     48                        return;
     49                }
     50                self::$running = true;
    3751
    3852                ( new PremiumPress_Post_Types() )->register();
    … …  
    5973                ( new PremiumPress_Porting() )->register();
    6074                ( new PremiumPress_Switch() )->register();
     75                // This plugin's own features (e.g. ad types, job applications).
     76                foreach ( self::modules() as $module ) {
     77                        ( new $module() )->register();
     78                }
    6179
    6280                add_action( 'init', array( $this, 'maybe_flush' ), 999 );
    … …  
    6583                // Coming back from a PremiumPress theme: our rules need rebuilding.
    6684                add_action( 'after_switch_theme', array( __CLASS__, 'request_flush' ) );
     85        }
     86
     87        /** @return array<int, string> This plugin's own feature classes, set in the main plugin file. */
     88        public static function modules(): array {
     89                return array_values( array_filter( (array) PREMIUMPRESS_MODULES, 'class_exists' ) );
    6790        }
    6891
    … …  
    81104        public static function activate(): void {
    82105                self::request_flush();
    83                 // Only when this plugin is in charge (no PremiumPress theme active).
    84                 if ( ! PremiumPress_Compat::theme_active() ) {
     106                // Only when this plugin will be in charge: no PremiumPress theme and no other
     107                // PremiumPress listings plugin already running.
     108                if ( ! PremiumPress_Compat::theme_active() && ! PremiumPress_Compat::sibling_active() ) {
     109                        foreach ( self::modules() as $module ) {
     110                                if ( method_exists( $module, 'activate' ) ) {
     111                                        $module::activate();
     112                                }
     113                        }
    85114                        PremiumPress_Profiles::remember_single();
    86115                        PremiumPress_Pages::ensure();
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-porting.php

    r3838627 r3848540  
    938938                        } elseif ( isset( $fields[ $key ] ) ) {
    939939                                $value = PremiumPress_Meta::sanitize_field( $fields[ $key ], self::loose_option( $fields[ $key ], $raw ) );
     940                                if ( '' !== $value ) {
     941                                        // Fields kept as a category-style term (ad type, job type) are stored the theme's way.
     942                                        PremiumPress_Profiles::set_field( $id, (string) $key, (array) $fields[ $key ], $value );
     943                                }
     944                                continue;
    940945                        } else {
    941946                                continue;
    … …  
    957962         */
    958963        private static function loose_option( array $field, string $raw ): string {
    959                 $options = array_map( 'strval', (array) ( $field['options'] ?? array() ) );
     964                $options = PremiumPress_Profiles::options( $field );
    960965                if ( ! $options ) {
    961966                        return $raw;
    … …  
    963968                $out = array();
    964969                foreach ( preg_split( '/\s*[,|]\s*/', $raw ) as $piece ) {
    965                         foreach ( $options as $opt ) {
    966                                 if ( 0 === strcasecmp( $opt, trim( $piece ) ) ) {
    967                                         $out[] = $opt;
    968                                 }
    969                         }
    970                 }
    971                 return implode( ',', $out );
     970                        foreach ( $options as $key => $label ) {
     971                                // A value may be given as the stored key ("full-time") or its label ("Full-time").
     972                                if ( 0 === strcasecmp( (string) $key, trim( $piece ) ) || 0 === strcasecmp( (string) $label, trim( $piece ) ) ) {
     973                                        $out[] = (string) $key;
     974                                        break;
     975                                }
     976                        }
     977                }
     978                return implode( ',', array_unique( $out ) );
    972979        }
    973980
    … …  
    13511358                }
    13521359                $post_url = admin_url( 'admin-post.php' );
    1353                 PremiumPress_Admin_UI::open( 'listings', __( 'Import / Export', 'premiumpress-directory' ), __( 'Download your listings as a spreadsheet, or add many at once from one.', 'premiumpress-directory' ) );
     1360                PremiumPress_Admin_UI::open( 'listings', __( 'Import / Export', 'premiumpress-directory' ), sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Download your %s as a spreadsheet, or add many at once from one.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) );
    13541361                PremiumPress_Admin_UI::crumb();
    13551362                echo '<div class="ppd-porting">';
    … …  
    13681375                        echo '<div class="notice notice-info inline"><p>';
    13691376                        /* translators: %d: number of listings */
    1370                         echo esc_html( sprintf( _n( '%d imported listing still needs its photos downloaded or its map position looked up.', '%d imported listings still need their photos downloaded or their map positions looked up.', $left, 'premiumpress-directory' ), $left ) );
     1377                        echo esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( '%1$d imported %2$s still needs its photos downloaded or its map position looked up.', '%1$d imported %2$s still need their photos downloaded or their map positions looked up.', $left, 'premiumpress-directory' ), $left, ( 1 === $left ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) );
    13711378                        echo '</p><form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_PHOTOS ) . '">';
    13721379                        wp_nonce_field( self::A_PHOTOS );
    … …  
    13951402                echo '<div class="ppd-a-twocards"><section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">';
    13961403                PremiumPress_Admin_UI::e_icon( 'download', 22 );
    1397                 echo '</span><h2 class="ppd-a-h2">' . esc_html__( 'Download your listings', 'premiumpress-directory' ) . '</h2>';
     1404                echo '</span><h2 class="ppd-a-h2">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Download your %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</h2>';
    13981405                /* translators: %d: number of listings */
    1399                 echo '<p>' . esc_html( sprintf( _n( 'Save your %d listing as a spreadsheet you can open in Excel or Google Sheets.', 'Save all %d listings as a spreadsheet you can open in Excel or Google Sheets.', $count, 'premiumpress-directory' ), $count ) ) . '</p>';
    1400                 echo '<ul class="ppd-port-uses"><li>' . esc_html__( 'Keep a copy as a backup.', 'premiumpress-directory' ) . '</li><li>' . esc_html__( 'Change lots of listings at once, then add the file back on the right to update them.', 'premiumpress-directory' ) . '</li><li>' . esc_html__( 'Move them into a PremiumPress theme later.', 'premiumpress-directory' ) . '</li></ul>';
     1406                echo '<p>' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'Save your %1$d %2$s as a spreadsheet you can open in Excel or Google Sheets.', 'Save all %1$d %2$s as a spreadsheet you can open in Excel or Google Sheets.', $count, 'premiumpress-directory' ), $count, ( 1 === $count ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</p>';
     1407                echo '<ul class="ppd-port-uses"><li>' . esc_html__( 'Keep a copy as a backup.', 'premiumpress-directory' ) . '</li><li>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Change lots of %s at once, then add the file back on the right to update them.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</li><li>' . esc_html__( 'Move them into a PremiumPress theme later.', 'premiumpress-directory' ) . '</li></ul>';
    14011408                echo '<form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_EXPORT ) . '">';
    14021409                wp_nonce_field( self::A_EXPORT );
    … …  
    14071414                echo '<section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">';
    14081415                PremiumPress_Admin_UI::e_icon( 'upload', 22 );
    1409                 echo '</span><h2 class="ppd-a-h2">' . esc_html__( 'Add listings from a spreadsheet', 'premiumpress-directory' ) . '</h2>';
    1410                 echo '<ol class="ppd-port-steps"><li>' . esc_html__( 'Make a spreadsheet with one listing on each row. Put the column names in the first row; only "Title" is needed.', 'premiumpress-directory' ) . '</li>';
     1416                echo '</span><h2 class="ppd-a-h2">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Add %s from a spreadsheet', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</h2>';
     1417                echo '<ol class="ppd-port-steps"><li>' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Make a spreadsheet with one %s on each row. Put the column names in the first row; only "Title" is needed.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</li>';
    14111418                echo '<li>' . esc_html__( 'Save it as a CSV file (in Excel: File, Save as, CSV).', 'premiumpress-directory' ) . '</li>';
    1412                 echo '<li>' . esc_html__( 'Choose the file below and click Upload. New rows become new listings; rows from a downloaded file update their listing.', 'premiumpress-directory' ) . '</li></ol>';
    1413                 echo '<details class="ppd-columns"><summary>' . esc_html__( 'Columns you can use', 'premiumpress-directory' ) . '</summary><p>' . esc_html__( 'Photos: put the pictures\' web addresses in an "Images" column, separated by |. They are copied into your Media Library after the upload.', 'premiumpress-directory' ) . '</p><p><code>' . esc_html( implode( ', ', self::columns() ) ) . '</code></p><p>' . esc_html__( 'Opening hours: one column per day ("Monday hours": 09:00-17:00, 9am-5pm, Closed, Open 24 hours), or one "Opening hours" column for the week (Mon-Fri 9:00-17:00; Sat 10-4; Sun closed). Categories and locations: separate several with |, and write a sub-category as Parent > Child.', 'premiumpress-directory' ) . '</p></details>';
     1419                echo '<li>' . esc_html( sprintf( /* translators: 1: plural item name, e.g. listings, jobs, 2: singular item name, e.g. listing, job */ __( 'Choose the file below and click Upload. New rows become new %1$s; rows from a downloaded file update their %2$s.', 'premiumpress-directory' ), PremiumPress_Profiles::many(), PremiumPress_Profiles::one() ) ) . '</li></ol>';
     1420                echo '<details class="ppd-columns"><summary>' . esc_html__( 'Columns you can use', 'premiumpress-directory' ) . '</summary><p>' . esc_html__( 'Photos: put the pictures\' web addresses in an "Images" column, separated by |. They are copied into your Media Library after the upload.', 'premiumpress-directory' ) . '</p><p><code>' . esc_html( implode( ', ', self::columns() ) ) . '</code></p><p>' . ( PremiumPress_Profiles::has_section( 'hours' ) ? esc_html__( 'Opening hours: one column per day ("Monday hours": 09:00-17:00, 9am-5pm, Closed, Open 24 hours), or one "Opening hours" column for the week (Mon-Fri 9:00-17:00; Sat 10-4; Sun closed).', 'premiumpress-directory' ) . ' ' : '' ) . esc_html__( 'Categories and locations: separate several with |, and write a sub-category as Parent > Child.', 'premiumpress-directory' ) . '</p></details>';
    14141421                echo '<form method="post" action="' . esc_url( $post_url ) . '" enctype="multipart/form-data"><input type="hidden" name="action" value="' . esc_attr( self::A_IMPORT ) . '">';
    14151422                wp_nonce_field( self::A_IMPORT );
    … …  
    14171424                echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">';
    14181425                PremiumPress_Admin_UI::e_icon( 'upload', 16 );
    1419                 echo ' ' . esc_html__( 'Upload and add listings', 'premiumpress-directory' ) . '</button></form></section></div>';
     1426                echo ' ' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Upload and add %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</button></form></section></div>';
    14201427                echo '</div>';
    14211428                PremiumPress_Admin_UI::close();
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-profiles.php

    r3838627 r3848540  
    3737                }
    3838
    39                 $money = self::currency_symbol();
    40 
    41                 self::$defs = (array) apply_filters(
    42                         'premiumpress_profiles',
    43                         array(
    44                                 'directory'   => array(
    45                                         'label'       => __( 'Business directory', 'premiumpress-directory' ),
    46                                         'description' => __( 'Local businesses, services and places, with opening hours and contact details.', 'premiumpress-directory' ),
    47                                         'singular'    => __( 'Listing', 'premiumpress-directory' ),
    48                                         'plural'      => __( 'Listings', 'premiumpress-directory' ),
    49                                         'menu'        => __( 'Directory', 'premiumpress-directory' ),
    50                                         'theme_name'  => __( 'Directory theme', 'premiumpress-directory' ),
    51                                         'theme_url'   => 'https://www.premiumpress.com/wordpress-directory-theme/',
    52                                         'sections'    => array( 'contact', 'location', 'hours' ),
    53                                         'schema'      => 'LocalBusiness',
    54                                         'fields'      => array(
    55                                                 'price_range'      => array(
    56                                                         'label'   => __( 'Price range', 'premiumpress-directory' ),
    57                                                         'type'    => 'select',
    58                                                         'options' => array( $money, str_repeat( $money, 2 ), str_repeat( $money, 3 ), str_repeat( $money, 4 ) ),
    59                                                         'card'    => true,
    60                                                 ),
    61                                                 'established'      => array(
    62                                                         'label' => __( 'Established', 'premiumpress-directory' ),
    63                                                         'type'  => 'text',
    64                                                         'help'  => __( 'The year this business opened, e.g. 2014.', 'premiumpress-directory' ),
    65                                                 ),
    66                                                 'payment_methods'  => array(
    67                                                         'label'   => __( 'Payment methods', 'premiumpress-directory' ),
    68                                                         'type'    => 'checkbox',
    69                                                         'options' => array( 'Cash', 'Credit / debit card', 'Contactless', 'Mobile payments', 'Bank transfer' ),
    70                                                 ),
    71                                                 'parking'          => array(
    72                                                         'label'   => __( 'Parking', 'premiumpress-directory' ),
    73                                                         'type'    => 'select',
    74                                                         'options' => array( 'Free on-site', 'Paid on-site', 'Street parking', 'None nearby' ),
    75                                                 ),
    76                                                 'accessibility'    => array(
    77                                                         'label'   => __( 'Accessibility', 'premiumpress-directory' ),
    78                                                         'type'    => 'select',
    79                                                         'options' => array( 'Step-free access', 'Partially accessible', 'Not accessible' ),
    80                                                 ),
    81                                                 'wifi'             => array(
    82                                                         'label'   => __( 'Wi-Fi', 'premiumpress-directory' ),
    83                                                         'type'    => 'select',
    84                                                         'options' => array( 'Free', 'For customers', 'None' ),
    85                                                 ),
    86                                                 'appointments'     => array(
    87                                                         'label'   => __( 'Appointments', 'premiumpress-directory' ),
    88                                                         'type'    => 'select',
    89                                                         'options' => array( 'Walk-ins welcome', 'Appointment only', 'Walk-ins and appointments' ),
    90                                                 ),
    91                                                 'languages_spoken' => array(
    92                                                         'label'   => __( 'Languages spoken', 'premiumpress-directory' ),
    93                                                         'type'    => 'checkbox',
    94                                                         'options' => array( 'English', 'Spanish', 'French', 'German', 'Polish', 'Urdu' ),
    95                                                 ),
    96                                         ),
    97                                 ),
    98                                 'classifieds' => array(
    99                                         'label'       => __( 'Classified ads', 'premiumpress-directory' ),
    100                                         'description' => __( 'People post items for sale with a price, condition and location.', 'premiumpress-directory' ),
    101                                         'singular'    => __( 'Ad', 'premiumpress-directory' ),
    102                                         'plural'      => __( 'Ads', 'premiumpress-directory' ),
    103                                         'menu'        => __( 'Classifieds', 'premiumpress-directory' ),
    104                                         'theme_name'  => __( 'Classifieds theme', 'premiumpress-directory' ),
    105                                         'theme_url'   => 'https://www.premiumpress.com/wordpress-classifieds-theme/',
    106                                         'sections'    => array( 'contact', 'location' ),
    107                                         'schema'      => '',
    108                                         'fields'      => array(
    109                                                 'price'     => array(
    110                                                         'label' => __( 'Price', 'premiumpress-directory' ),
    111                                                         'type'  => 'number',
    112                                                         'money' => true,
    113                                                         'card'  => true,
    114                                                 ),
    115                                                 'condition' => array(
    116                                                         'label'   => __( 'Condition', 'premiumpress-directory' ),
    117                                                         'type'    => 'select',
    118                                                         'options' => array( 'New', 'Like new', 'Good', 'Fair', 'For parts' ),
    119                                                         'card'    => true,
    120                                                 ),
    121                                         ),
    122                                 ),
    123                         )
    124                 );
     39                // Each plugin's own site types, fields, filters and sorts.
     40                self::$defs = (array) apply_filters( 'premiumpress_profiles', (array) require PREMIUMPRESS_DIR . 'includes/profile-data.php' );
    12541
    12642                return self::$defs;
    … …  
    12945        /** @return array<int, string> Keys of released profiles, in registry order. */
    13046        public static function enabled(): array {
    131                 $on = (array) apply_filters( 'premiumpress_enabled_profiles', array( 'directory' ) );
     47                $on = (array) apply_filters( 'premiumpress_enabled_profiles', array( PREMIUMPRESS_PROFILE ) );
    13248                return array_values( array_intersect( array_keys( self::all() ), $on ) );
    13349        }
    … …  
    15571                if ( '' === $key ) {
    15672                        $enabled = self::enabled();
    157                         $key     = $enabled ? $enabled[0] : 'directory';
     73                        $key     = $enabled ? $enabled[0] : PREMIUMPRESS_PROFILE;
    15874                }
    15975                $all = self::all();
    … …  
    17692
    17793        /**
    178          * Record the profile in the shared option when it is still empty, so a later
    179          * theme upgrade opens in the same niche. Never overwrites a value the site
    180          * already has.
     94         * Record the profile in the shared option, so a later theme upgrade opens in
     95         * the same niche. This plugin runs one site type, and only runs when it is in
     96         * charge of the site's listings, so its type is the site's type.
    18197         */
    18298        public static function remember_single(): void {
    183                 if ( '' === (string) get_option( self::OPTION, '' ) && 1 === count( self::enabled() ) ) {
    184                         update_option( self::OPTION, self::enabled()[0] );
    185                 }
     99                $enabled = self::enabled();
     100                if ( 1 === count( $enabled ) && (string) get_option( self::OPTION, '' ) !== $enabled[0] ) {
     101                        update_option( self::OPTION, $enabled[0] );
     102                }
     103        }
     104
     105        /** The word for the whole site, e.g. "directory" or "job board" (capitalised on request). */
     106        public static function noun( bool $capital = false ): string {
     107                $noun = (string) ( self::current()['noun'] ?? __( 'directory', 'premiumpress-directory' ) );
     108                return $capital ? ucfirst( $noun ) : $noun;
     109        }
     110
     111        /** One item, e.g. "listing", "ad", "job". */
     112        public static function one( bool $capital = false ): string {
     113                $one = (string) self::current()['singular'];
     114                return $capital ? $one : mb_strtolower( $one );
     115        }
     116
     117        /** Several items, e.g. "listings", "ads", "jobs". */
     118        public static function many( bool $capital = false ): string {
     119                $many = (string) self::current()['plural'];
     120                return $capital ? $many : mb_strtolower( $many );
     121        }
     122
     123        /** One item with its article, e.g. "a listing", "an ad". */
     124        public static function a_one( bool $capital = false ): string {
     125                $a = (string) ( self::current()['a_singular'] ?? '' );
     126                if ( '' === $a ) {
     127                        /* translators: %s: singular item name, lowercase */
     128                        $a = sprintf( __( 'a %s', 'premiumpress-directory' ), self::one() );
     129                }
     130                return $capital ? ucfirst( $a ) : $a;
    186131        }
    187132
    … …  
    215160        }
    216161
    217         /** Upgrade link for the active profile, tagged for analytics. */
     162        /** Upgrade link for the active profile, tagged so our site can see which plugin sent the visit. */
    218163        public static function theme_url( string $anchor = '' ): string {
    219                 $url = add_query_arg( 'src', 'plugin', (string) self::current()['theme_url'] );
     164                $url = add_query_arg(
     165                        array(
     166                                'utm_source'   => PREMIUMPRESS_UTM,
     167                                'utm_medium'   => 'wp-admin',
     168                                'utm_campaign' => PREMIUMPRESS_UTM,
     169                                'utm_term'     => 'wp-admin',
     170                        ),
     171                        (string) self::current()['theme_url']
     172                );
    220173                return '' !== $anchor ? $url . '#' . $anchor : $url;
    221174        }
    … …  
    234187
    235188        /**
     189         * A field's options as stored value => label. Plain lists store the label itself
     190         * (the theme's custom-field style); keyed lists store the theme's own slugs.
     191         *
     192         * @param array<string, mixed> $field
     193         * @return array<string, string>
     194         */
     195        public static function options( array $field ): array {
     196                $opts = (array) ( $field['options'] ?? array() );
     197                if ( array_values( $opts ) === $opts ) {
     198                        $opts = array_combine( array_map( 'strval', $opts ), array_map( 'strval', $opts ) );
     199                }
     200                return array_map( 'strval', $opts );
     201        }
     202
     203        /**
     204         * Read a field for a listing. Fields with `tax` are stored as a term of that
     205         * taxonomy (the term slug is the value), everything else as post meta.
     206         *
     207         * @param array<string, mixed> $field
     208         */
     209        public static function get_field( int $post_id, string $key, array $field ): string {
     210                if ( ! empty( $field['tax'] ) ) {
     211                        $terms = get_the_terms( $post_id, (string) $field['tax'] );
     212                        return is_array( $terms ) && $terms ? (string) $terms[0]->slug : '';
     213                }
     214                return (string) get_post_meta( $post_id, $key, true );
     215        }
     216
     217        /**
     218         * Store a sanitised field value ('' removes it).
     219         *
     220         * @param array<string, mixed> $field
     221         */
     222        public static function set_field( int $post_id, string $key, array $field, string $value ): void {
     223                if ( ! empty( $field['tax'] ) ) {
     224                        $tax = (string) $field['tax'];
     225                        if ( ! taxonomy_exists( $tax ) ) {
     226                                return;
     227                        }
     228                        if ( '' === $value ) {
     229                                wp_set_object_terms( $post_id, array(), $tax );
     230                                return;
     231                        }
     232                        if ( ! term_exists( $value, $tax ) ) {
     233                                $labels = self::options( $field );
     234                                wp_insert_term( $labels[ $value ] ?? $value, $tax, array( 'slug' => $value ) );
     235                        }
     236                        wp_set_object_terms( $post_id, array( $value ), $tax );
     237                        return;
     238                }
     239                if ( '' === $value ) {
     240                        delete_post_meta( $post_id, $key );
     241                } else {
     242                        update_post_meta( $post_id, $key, $value );
     243                }
     244                /**
     245                 * A profile field was saved (admin or front end). Niche rules hook in here.
     246                 */
     247                do_action( 'premiumpress_field_saved', $post_id, $key, $value );
     248        }
     249
     250        /**
     251         * A listing's field ready for display. Niche code can reword it through the
     252         * `premiumpress_display_field` filter (for example "Free" for a free ad's price).
     253         *
     254         * @param array<string, mixed> $field
     255         */
     256        public static function display( int $post_id, string $key, array $field ): string {
     257                $text = self::display_value( $field, self::get_field( $post_id, $key, $field ) );
     258                return (string) apply_filters( 'premiumpress_display_field', $text, $key, $post_id, $field );
     259        }
     260
     261        /**
    236262         * A field's value ready for display: comma-lists spaced, money prefixed.
    237263         *
    … …  
    254280                        return implode( ', ', array_filter( array_map( 'trim', explode( ',', $value ) ) ) );
    255281                }
     282                if ( 'select' === ( $field['type'] ?? '' ) ) {
     283                        $labels = self::options( $field );
     284                        return $labels[ $value ] ?? $value;
     285                }
    256286                return $value;
    257287        }
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-sample.php

    r3837691 r3848540  
    11<?php
    22/**
    3  * Sample content: a handful of realistic example items (with photos, real map
    4  * positions, hours and details) so a new site can see how everything works.
     3 * Sample content: a handful of realistic example ads (real map positions, prices
     4 * and ad types) so a new site can see how everything works.
    55 * Everything created is tagged, so "Remove sample content" takes it all away
    66 * again — items, their photos, and any categories or places it added.
    7  *
    8  * The photos in assets/sample/ were made for this plugin and are GPL-licensed
    9  * with it.
     7
    108 *
    119 * @package PremiumPress
    … …  
    2422         */
    2523        public static function items(): array {
    26                 $items = array();
    27                 if ( 'directory' === PremiumPress_Profiles::current()['key'] ) {
    28                         $week = static function ( string $from, string $to, array $closed = array() ): array {
    29                                 $out = array();
    30                                 foreach ( array( 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ) as $d ) {
    31                                         $out[ $d ] = array(
    32                                                 'open'   => ! in_array( $d, $closed, true ),
    33                                                 'h24'    => false,
    34                                                 'ranges' => array(
    35                                                         array(
    36                                                                 'from' => $from,
    37                                                                 'to'   => $to,
    38                                                         ),
    39                                                 ),
    40                                         );
    41                                 }
    42                                 return $out;
    43                         };
    44                         $items = array(
    45                                 array(
    46                                         'title'    => __( 'The Corner Cup', 'premiumpress-directory' ),
    47                                         'content'  => __( 'A friendly neighbourhood coffee shop serving single-origin espresso, fresh pastries and simple lunches. Plenty of seats by the window and free Wi-Fi for laptops.', 'premiumpress-directory' ),
    48                                         'category' => __( 'Cafés', 'premiumpress-directory' ),
    49                                         'image'    => 'cafe',
    50                                         'meta'     => array(
    51                                                 'address'          => '14 Exmouth Market',
    52                                                 'city'             => 'London',
    53                                                 'postcode'         => 'EC1R 4QE',
    54                                                 'lat'              => '51.52608',
    55                                                 'lng'              => '-0.10967',
    56                                                 'phone'            => '020 7946 0101',
    57                                                 'price_range'      => str_repeat( PremiumPress_Profiles::currency_symbol(), 1 ),
    58                                                 'wifi'             => 'Free',
    59                                                 'payment_methods'  => 'Credit / debit card,Contactless',
    60                                                 'accessibility'    => 'Step-free access',
    61                                         ),
    62                                         'hours'    => $week( '07:30', '17:00' ),
    63                                 ),
    64                                 array(
    65                                         'title'    => __( 'Rise & Crumb Bakery', 'premiumpress-directory' ),
    66                                         'content'  => __( 'Slow-fermented sourdough, crusty baguettes and croissants baked every morning. Arrive early at weekends — the cinnamon buns sell out fast.', 'premiumpress-directory' ),
    67                                         'category' => __( 'Bakeries', 'premiumpress-directory' ),
    68                                         'image'    => 'bakery',
    69                                         'meta'     => array(
    70                                                 'address'         => '52 Lamb\'s Conduit Street',
    71                                                 'city'            => 'London',
    72                                                 'postcode'        => 'WC1N 3LW',
    73                                                 'lat'             => '51.52180',
    74                                                 'lng'             => '-0.11860',
    75                                                 'phone'           => '020 7946 0102',
    76                                                 'price_range'     => str_repeat( PremiumPress_Profiles::currency_symbol(), 2 ),
    77                                                 'payment_methods' => 'Cash,Contactless',
    78                                                 'established'     => '2016',
    79                                         ),
    80                                         'hours'    => $week( '07:00', '15:00', array( 'mon' ) ),
    81                                 ),
    82                                 array(
    83                                         'title'    => __( 'Chapter & Verse Books', 'premiumpress-directory' ),
    84                                         'content'  => __( 'An independent bookshop with new and second-hand fiction, a children\'s corner and monthly author evenings. Staff picks change every week.', 'premiumpress-directory' ),
    85                                         'category' => __( 'Bookshops', 'premiumpress-directory' ),
    86                                         'image'    => 'bookshop',
    87                                         'meta'     => array(
    88                                                 'address'          => '8 Cecil Court',
    89                                                 'city'             => 'London',
    90                                                 'postcode'         => 'WC2N 4HE',
    91                                                 'lat'              => '51.51078',
    92                                                 'lng'              => '-0.12731',
    93                                                 'phone'            => '020 7946 0103',
    94                                                 'established'      => '1998',
    95                                                 'payment_methods'  => 'Cash,Credit / debit card,Contactless',
    96                                                 'languages_spoken' => 'English,French',
    97                                         ),
    98                                         'hours'    => $week( '10:00', '19:00' ),
    99                                 ),
    100                                 array(
    101                                         'title'    => __( 'Sharp & Co. Barbers', 'premiumpress-directory' ),
    102                                         'content'  => __( 'Classic cuts, skin fades and hot-towel shaves in a relaxed shop. Book ahead or drop in — walk-ins are welcome most afternoons.', 'premiumpress-directory' ),
    103                                         'category' => __( 'Barbers', 'premiumpress-directory' ),
    104                                         'image'    => 'barber',
    105                                         'meta'     => array(
    106                                                 'address'      => '101 Brick Lane',
    107                                                 'city'         => 'London',
    108                                                 'postcode'     => 'E1 6SE',
    109                                                 'lat'          => '51.52150',
    110                                                 'lng'          => '-0.07170',
    111                                                 'phone'        => '020 7946 0104',
    112                                                 'price_range'  => str_repeat( PremiumPress_Profiles::currency_symbol(), 2 ),
    113                                                 'appointments' => 'Walk-ins and appointments',
    114                                         ),
    115                                         'hours'    => $week( '09:00', '18:30', array( 'sun' ) ),
    116                                 ),
    117                                 array(
    118                                         'title'    => __( 'Petal Street Florist', 'premiumpress-directory' ),
    119                                         'content'  => __( 'Seasonal bouquets, wedding flowers and same-day local delivery. Tell us the occasion and we\'ll make something beautiful.', 'premiumpress-directory' ),
    120                                         'category' => __( 'Florists', 'premiumpress-directory' ),
    121                                         'image'    => 'florist',
    122                                         'meta'     => array(
    123                                                 'address'         => '27 Columbia Road',
    124                                                 'city'            => 'London',
    125                                                 'postcode'        => 'E2 7RG',
    126                                                 'lat'             => '51.52960',
    127                                                 'lng'             => '-0.07140',
    128                                                 'phone'           => '020 7946 0105',
    129                                                 'price_range'     => str_repeat( PremiumPress_Profiles::currency_symbol(), 3 ),
    130                                                 'payment_methods' => 'Credit / debit card,Contactless',
    131                                         ),
    132                                         'hours'    => $week( '08:00', '16:00', array( 'mon' ) ),
    133                                 ),
    134                                 array(
    135                                         'title'    => __( 'Still Point Yoga', 'premiumpress-directory' ),
    136                                         'content'  => __( 'Small, friendly yoga classes for every level, from gentle morning flow to evening yin. Mats and blocks provided; your first class is free.', 'premiumpress-directory' ),
    137                                         'category' => __( 'Fitness', 'premiumpress-directory' ),
    138                                         'image'    => 'yoga',
    139                                         'meta'     => array(
    140                                                 'address'       => '3 Leonard Street',
    141                                                 'city'          => 'London',
    142                                                 'postcode'      => 'EC2A 4AQ',
    143                                                 'lat'           => '51.52490',
    144                                                 'lng'           => '-0.08520',
    145                                                 'phone'         => '020 7946 0106',
    146                                                 'appointments'  => 'Appointment only',
    147                                                 'accessibility' => 'Partially accessible',
    148                                         ),
    149                                         'hours'    => $week( '06:30', '21:00' ),
    150                                 ),
    151                         );
    152                 }
     24                $items = (array) require PREMIUMPRESS_DIR . 'includes/sample-data.php';
    15325                return (array) apply_filters( 'premiumpress_sample_items', $items, PremiumPress_Profiles::current()['key'] );
    15426        }
    … …  
    19062                        foreach ( (array) $item['meta'] as $key => $value ) {
    19163                                update_post_meta( $id, $key, $value );
     64                        }
     65                        foreach ( (array) ( $item['terms'] ?? array() ) as $tax => $slug ) {
     66                                if ( taxonomy_exists( (string) $tax ) ) {
     67                                        wp_set_object_terms( (int) $id, array( (string) $slug ), (string) $tax );
     68                                }
    19269                        }
    19370                        if ( ! empty( $item['hours'] ) ) {
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-search.php

    r3838627 r3848540  
    7777                        'lng'    => $lng,
    7878                        'radius' => in_array( $radius, self::RADII, true ) ? $radius : 25,
    79                         'sort'   => isset( $get['pp_sort'] ) && in_array( $get['pp_sort'], array( 'nearest', 'newest', 'title', 'rating' ), true ) ? (string) $get['pp_sort'] : '',
     79                        'sort'   => isset( $get['pp_sort'] ) && in_array( $get['pp_sort'], array_keys( self::sorts( true ) ), true ) ? (string) $get['pp_sort'] : '',
    8080                        'page'   => isset( $get[ self::PAGE_VAR ] ) ? max( 1, absint( $get[ self::PAGE_VAR ] ) ) : 1,
    8181                        'tag'    => '',
     82                        'f'      => array(),
    8283                );
     84                foreach ( self::filters() as $key => $filter ) {
     85                        if ( 'range' === $filter['type'] ) {
     86                                foreach ( array( 'min', 'max' ) as $end ) {
     87                                        $raw = isset( $get[ 'pp_' . $key . '_' . $end ] ) ? str_replace( array( ',', ' ' ), '', (string) $get[ 'pp_' . $key . '_' . $end ] ) : '';
     88                                        $out['f'][ $key . '_' . $end ] = is_numeric( $raw ) && (float) $raw >= 0 ? (string) ( $raw + 0 ) : '';
     89                                }
     90                        } else {
     91                                $raw    = isset( $get[ 'pp_' . $key ] ) ? sanitize_text_field( (string) $get[ 'pp_' . $key ] ) : '';
     92                                $values = array_keys( PremiumPress_Profiles::options( $filter['def'] ) );
     93                                $out['f'][ $key ] = in_array( $raw, array_map( 'strval', $values ), true ) ? $raw : '';
     94                        }
     95                }
    8396                // phpcs:enable
    8497                $term = self::archive_term();
    … …  
    102115                $t = get_queried_object();
    103116                return $t instanceof WP_Term ? $t : null;
     117        }
     118
     119        /**
     120         * The active profile's search filters, each with its field definition.
     121         *
     122         * @return array<string, array{type:string, def:array<string, mixed>, label:string}>
     123         */
     124        public static function filters(): array {
     125                $p      = PremiumPress_Profiles::current();
     126                $fields = (array) $p['fields'];
     127                $out    = array();
     128                foreach ( (array) ( $p['filters'] ?? array() ) as $f ) {
     129                        $key = (string) ( $f['field'] ?? '' );
     130                        if ( '' === $key || ! isset( $fields[ $key ] ) ) {
     131                                continue;
     132                        }
     133                        $out[ $key ] = array(
     134                                'type'  => 'range' === ( $f['type'] ?? '' ) ? 'range' : 'select',
     135                                'def'   => (array) $fields[ $key ],
     136                                'label' => (string) ( $f['label'] ?? $fields[ $key ]['label'] ),
     137                        );
     138                }
     139                return $out;
     140        }
     141
     142        /**
     143         * Sort options: the shared ones plus the profile's own (e.g. price low to high).
     144         *
     145         * @return array<string, array<string, string>>
     146         */
     147        public static function sorts( bool $with_nearest = false ): array {
     148                $out = array(
     149                        'newest' => array( 'label' => __( 'Newest', 'premiumpress-directory' ) ),
     150                );
     151                $out += (array) ( PremiumPress_Profiles::current()['sorts'] ?? array() );
     152                $out['title'] = array( 'label' => __( 'Name A–Z', 'premiumpress-directory' ) );
     153                if ( PremiumPress_Engage::reviews_on() ) {
     154                        $out['rating'] = array( 'label' => __( 'Highest rated', 'premiumpress-directory' ) );
     155                }
     156                if ( $with_nearest ) {
     157                        $out = array( 'nearest' => array( 'label' => __( 'Nearest', 'premiumpress-directory' ) ) ) + $out;
     158                }
     159                return $out;
    104160        }
    105161
    … …  
    171227                        $args['orderby'] = 'relevance';
    172228                }
    173                 $tax = array();
     229                $profile_sorts = (array) ( PremiumPress_Profiles::current()['sorts'] ?? array() );
     230                if ( isset( $profile_sorts[ $sort ]['meta'] ) ) {
     231                        $args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
     232                                'relation' => 'OR',
     233                                'has'      => array(
     234                                        'key'  => (string) $profile_sorts[ $sort ]['meta'],
     235                                        'type' => 'DECIMAL(14,2)',
     236                                ),
     237                                'missing'  => array(
     238                                        'key'     => (string) $profile_sorts[ $sort ]['meta'],
     239                                        'compare' => 'NOT EXISTS',
     240                                ),
     241                        );
     242                        $args['orderby']    = array(
     243                                'has'  => 'DESC' === ( $profile_sorts[ $sort ]['order'] ?? 'ASC' ) ? 'DESC' : 'ASC',
     244                                'date' => 'DESC',
     245                        );
     246                }
     247                $tax  = array();
     248                $meta = array();
     249                foreach ( self::filters() as $key => $filter ) {
     250                        if ( 'range' === $filter['type'] ) {
     251                                foreach ( array( 'min' => '>=', 'max' => '<=' ) as $end => $cmp ) {
     252                                        if ( '' !== $r['f'][ $key . '_' . $end ] ) {
     253                                                $meta[] = array(
     254                                                        'key'     => $key,
     255                                                        'value'   => $r['f'][ $key . '_' . $end ],
     256                                                        'compare' => $cmp,
     257                                                        'type'    => 'DECIMAL(14,2)',
     258                                                );
     259                                        }
     260                                }
     261                        } elseif ( '' !== $r['f'][ $key ] ) {
     262                                if ( ! empty( $filter['def']['tax'] ) ) {
     263                                        $tax[] = array(
     264                                                'taxonomy' => (string) $filter['def']['tax'],
     265                                                'field'    => 'slug',
     266                                                'terms'    => $r['f'][ $key ],
     267                                        );
     268                                } else {
     269                                        $meta[] = array(
     270                                                'key'   => $key,
     271                                                'value' => $r['f'][ $key ],
     272                                        );
     273                                }
     274                        }
     275                }
     276                if ( $meta ) {
     277                        $meta['relation'] = 'AND';
     278                        if ( ! empty( $args['meta_query'] ) ) {
     279                                $meta['sort'] = $args['meta_query'];
     280                        }
     281                        $args['meta_query'] = $meta; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
     282                }
    174283                if ( '' !== $r['cat'] ) {
    175284                        $tax[] = array(
    … …  
    259368                $uid     = wp_unique_id( 'ppd-s-' );
    260369                $lookup  = $places && PremiumPress_Geo::lookup_enabled();
    261                 $action  = remove_query_arg( array( 'pp_q', 'pp_cat', 'pp_loc', 'pp_near', 'pp_lat', 'pp_lng', 'pp_radius', 'pp_sort', self::PAGE_VAR ) );
     370                $params  = array( 'pp_q', 'pp_cat', 'pp_loc', 'pp_near', 'pp_lat', 'pp_lng', 'pp_radius', 'pp_sort', self::PAGE_VAR );
     371                foreach ( self::filters() as $key => $filter ) {
     372                        $params = array_merge( $params, 'range' === $filter['type'] ? array( 'pp_' . $key . '_min', 'pp_' . $key . '_max' ) : array( 'pp_' . $key ) );
     373                }
     374                $action  = remove_query_arg( $params );
    262375                // On a category or location page, a new search goes to the main directory
    263376                // page (the term is already picked in the form), so filters never clash.
    … …  
    266379                        $action = $dir;
    267380                }
     381                $filtered = (bool) array_filter( $r['f'], 'strlen' );
    268382                $units   = 'mi' === PremiumPress_Geo::units() ? __( 'miles', 'premiumpress-directory' ) : __( 'km', 'premiumpress-directory' );
    269383                $has_geo = null !== $r['lat'];
    … …  
    286400
    287401                        <?php echo self::terms_select( $uid . '-cat', 'pp_cat', PremiumPress_Post_Types::TAX_CATEGORY, $r['cat'], __( 'Category', 'premiumpress-directory' ), __( 'All categories', 'premiumpress-directory' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in terms_select(). ?>
     402
     403                        <?php foreach ( self::filters() as $premiumpress_key => $premiumpress_filter ) : ?>
     404                                <?php if ( 'range' === $premiumpress_filter['type'] ) : ?>
     405                                        <fieldset class="ppd-search__field ppd-search__field--range">
     406                                                <legend><?php echo esc_html( $premiumpress_filter['label'] . ( ! empty( $premiumpress_filter['def']['money'] ) ? ' (' . PremiumPress_Profiles::currency_symbol() . ')' : '' ) ); ?></legend>
     407                                                <div class="ppd-search__range">
     408                                                        <input type="number" min="0" step="any" name="pp_<?php echo esc_attr( $premiumpress_key ); ?>_min" value="<?php echo esc_attr( $r['f'][ $premiumpress_key . '_min' ] ); ?>" placeholder="<?php esc_attr_e( 'Min', 'premiumpress-directory' ); ?>" aria-label="<?php echo esc_attr( sprintf( /* translators: %s: field name, e.g. Price */ __( 'Minimum %s', 'premiumpress-directory' ), mb_strtolower( $premiumpress_filter['label'] ) ) ); ?>">
     409                                                        <span aria-hidden="true">–</span>
     410                                                        <input type="number" min="0" step="any" name="pp_<?php echo esc_attr( $premiumpress_key ); ?>_max" value="<?php echo esc_attr( $r['f'][ $premiumpress_key . '_max' ] ); ?>" placeholder="<?php esc_attr_e( 'Max', 'premiumpress-directory' ); ?>" aria-label="<?php echo esc_attr( sprintf( /* translators: %s: field name, e.g. Price */ __( 'Maximum %s', 'premiumpress-directory' ), mb_strtolower( $premiumpress_filter['label'] ) ) ); ?>">
     411                                                </div>
     412                                        </fieldset>
     413                                <?php else : ?>
     414                                        <div class="ppd-search__field">
     415                                                <label for="<?php echo esc_attr( $uid . '-' . $premiumpress_key ); ?>"><?php echo esc_html( $premiumpress_filter['label'] ); ?></label>
     416                                                <select id="<?php echo esc_attr( $uid . '-' . $premiumpress_key ); ?>" name="pp_<?php echo esc_attr( $premiumpress_key ); ?>">
     417                                                        <option value=""><?php esc_html_e( 'Any', 'premiumpress-directory' ); ?></option>
     418                                                        <?php foreach ( PremiumPress_Profiles::options( $premiumpress_filter['def'] ) as $premiumpress_value => $premiumpress_label ) : ?>
     419                                                                <option value="<?php echo esc_attr( (string) $premiumpress_value ); ?>" <?php selected( (string) $premiumpress_value, $r['f'][ $premiumpress_key ] ); ?>><?php echo esc_html( $premiumpress_label ); ?></option>
     420                                                        <?php endforeach; ?>
     421                                                </select>
     422                                        </div>
     423                                <?php endif; ?>
     424                        <?php endforeach; ?>
    288425
    289426                        <?php if ( $places ) : ?>
    … …  
    317454                        <div class="ppd-search__actions">
    318455                                <button type="submit" class="ppd-button wp-element-button"><?php esc_html_e( 'Search', 'premiumpress-directory' ); ?></button>
    319                                 <?php if ( '' === $dir && ( '' !== $r['q'] || '' !== $r['cat'] || '' !== $r['loc'] || '' !== $r['near'] || $has_geo ) ) : ?>
     456                                <?php if ( '' === $dir && ( '' !== $r['q'] || '' !== $r['cat'] || '' !== $r['loc'] || '' !== $r['near'] || $has_geo || $filtered ) ) : ?>
    320457                                        <a class="ppd-search__reset" href="<?php echo esc_url( $action ); ?>"><?php esc_html_e( 'Clear', 'premiumpress-directory' ); ?></a>
    321458                                <?php endif; ?>
    … …  
    334471         */
    335472        private static function sort_control( string $sort, bool $has_origin ): string {
    336                 $options = array(
    337                         'newest' => __( 'Newest', 'premiumpress-directory' ),
    338                         'title'  => __( 'Name A–Z', 'premiumpress-directory' ),
    339                         'rating' => __( 'Highest rated', 'premiumpress-directory' ),
    340                 );
    341                 if ( $has_origin ) {
    342                         $options = array( 'nearest' => __( 'Nearest', 'premiumpress-directory' ) ) + $options;
    343                 }
     473                $options = wp_list_pluck( self::sorts( $has_origin ), 'label' );
    344474                $id   = wp_unique_id( 'ppd-sort-' );
    345475                $html = '<form class="ppd-sort" method="get" action="' . esc_url( remove_query_arg( array( 'pp_sort', self::PAGE_VAR ) ) ) . '">';
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-settings.php

    r3838627 r3848540  
    102102                        'geocode'  => ! empty( $in['geocode'] ),
    103103                        'maps'     => ! empty( $in['maps'] ),
    104                         'units'     => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi',
     104                        'units'      => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi',
    105105                        'emails'     => ! empty( $in['emails'] ),
    106106                        'duration'   => isset( $in['duration'] ) ? min( 3650, max( 0, absint( $in['duration'] ) ) ) : 0,
    … …  
    172172                $out = array(
    173173                        'listings' => array(
    174                                 'title' => __( 'Listings & moderation', 'premiumpress-directory' ),
     174                                'title' => sprintf( /* translators: %s: plural item name, capitalised, e.g. Listings */ __( '%s & moderation', 'premiumpress-directory' ), PremiumPress_Profiles::many( true ) ),
    175175                                'desc'  => __( 'Approval before going live, how long items stay up, and the terms people agree to', 'premiumpress-directory' ),
    176176                                'icon'  => 'shield',
    177177                                'group' => 'general',
    178                                 'find'  => array( __( 'Moderation', 'premiumpress-directory' ), __( 'Listing duration', 'premiumpress-directory' ), __( 'Terms page', 'premiumpress-directory' ), __( 'Site type', 'premiumpress-directory' ) ),
     178                                'find'  => array( __( 'Moderation', 'premiumpress-directory' ), sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s duration', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ), __( 'Terms page', 'premiumpress-directory' ), __( 'Site type', 'premiumpress-directory' ) ),
    179179                        ),
    180180                        'email'    => array(
    … …  
    253253                if ( isset( $sections[ $section ] ) ) {
    254254                        // The theme's settings page: "All settings / Maps", the topic on the left, its rows on the right.
    255                         PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), __( 'Configure how your directory behaves.', 'premiumpress-directory' ) );
     255                        PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Configure how your %s behaves.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    256256                        echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::base_url() ) . '">';
    257257                        PremiumPress_Admin_UI::e_icon( 'back', 16 );
    … …  
    265265                }
    266266
    267                 PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), __( 'Configure how your directory behaves.', 'premiumpress-directory' ) );
     267                PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Configure how your %s behaves.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    268268                if ( $saved ) {
    269269                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Settings saved.', 'premiumpress-directory' ) . '</div>';
    270270                }
    271271                $groups = array(
    272                         'general' => array( __( 'General', 'premiumpress-directory' ), __( 'Core settings that control how listings are added and kept.', 'premiumpress-directory' ) ),
     272                        'general' => array( __( 'General', 'premiumpress-directory' ), sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Core settings that control how %s are added and kept.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ),
    273273                        'maps'    => array( __( 'Maps', 'premiumpress-directory' ), __( 'Where things are, and how far away.', 'premiumpress-directory' ) ),
    274274                        'content' => array( __( 'Pages & content', 'premiumpress-directory' ), __( 'The pages visitors use and the sample items.', 'premiumpress-directory' ) ),
    … …  
    420420                                echo '<span class="ppd-a-pill ppd-a-pill--blue">' . esc_html( (string) $p['label'] ) . '</span></div></div>';
    421421                        }
    422                         self::switch_row( 'moderate', __( 'Approve new listings', 'premiumpress-directory' ), $s['moderate'], __( 'Hold items submitted from the front end for approval before they go live.', 'premiumpress-directory' ) );
    423                         self::stack_row( __( 'Listing duration', 'premiumpress-directory' ), __( '0 = never expires. Owners get a reminder a week before, and can renew from their page.', 'premiumpress-directory' ), 'ppd-duration' );
     422                        self::switch_row( 'moderate', sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Approve new %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ), $s['moderate'], __( 'Hold items submitted from the front end for approval before they go live.', 'premiumpress-directory' ) );
     423                        self::stack_row( sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s duration', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ), __( '0 = never expires. Owners get a reminder a week before, and can renew from their page.', 'premiumpress-directory' ), 'ppd-duration' );
    424424                        printf( '<span class="ppd-a-inline"><input type="number" id="ppd-duration" class="ppd-a-input ppd-a-input--num" name="%1$s[duration]" value="%2$d" min="0" max="3650"> %3$s</span></div></div>', esc_attr( self::OPTION ), (int) $s['duration'], esc_html__( 'days', 'premiumpress-directory' ) );
    425425                        self::stack_row( __( 'Terms page', 'premiumpress-directory' ), __( 'When set, people must agree to this page before submitting.', 'premiumpress-directory' ), 'ppd-terms' );
    … …  
    440440                } elseif ( 'maps' === $section ) {
    441441                        self::hidden_rest( array( 'maps', 'geocode', 'units' ) );
    442                         self::switch_row( 'maps', __( 'Maps', 'premiumpress-directory' ), $s['maps'], __( 'Show OpenStreetMap maps on listing and search pages.', 'premiumpress-directory' ), __( 'Map images are loaded from OpenStreetMap\'s servers, which see the visitor\'s IP address. Off by default.', 'premiumpress-directory' ) );
     442                        self::switch_row( 'maps', __( 'Maps', 'premiumpress-directory' ), $s['maps'], sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Show OpenStreetMap maps on %s and search pages.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), __( 'Map images are loaded from OpenStreetMap\'s servers, which see the visitor\'s IP address. Off by default.', 'premiumpress-directory' ) );
    443443                        self::switch_row( 'geocode', __( 'Address lookup', 'premiumpress-directory' ), $s['geocode'], __( 'Find map positions from an address automatically.', 'premiumpress-directory' ), __( 'Sends the address to OpenStreetMap\'s Nominatim service. Off by default; without it, enter the position yourself.', 'premiumpress-directory' ) );
    444444                        self::stack_row( __( 'Distances in', 'premiumpress-directory' ), __( 'Used for "near me" searches and the distance on each result.', 'premiumpress-directory' ), 'ppd-units' );
    … …  
    490490
    491491                // Pages.
    492                 echo '<section class="ppd-a-sect"><div class="ppd-a-sect-copy"><h2>' . esc_html__( 'Your directory pages', 'premiumpress-directory' ) . '</h2>';
    493                 echo '<p>' . esc_html__( 'When you installed the plugin it made these three pages and added them to your site menu. Each one shows part of your directory.', 'premiumpress-directory' ) . '</p>';
    494                 echo '<p>' . esc_html__( 'You can rename them or add your own text, like any page. Just keep the directory box that is on each one.', 'premiumpress-directory' ) . '</p></div>';
     492                echo '<section class="ppd-a-sect"><div class="ppd-a-sect-copy"><h2>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h2>';
     493                echo '<p>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'When you installed the plugin it made these three pages and added them to your site menu. Each one shows part of your %s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
     494                echo '<p>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'You can rename them or add your own text, like any page. Just keep the %s box that is on each one.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p></div>';
    495495                echo '<div class="ppd-a-card ppd-pg-list">';
    496496                $missing = false;
    … …  
    540540                );
    541541                $n = count( $samples );
    542                 echo '<section class="ppd-a-sect ppd-pg-gap"><div class="ppd-a-sect-copy"><h2>' . esc_html__( 'Sample listings', 'premiumpress-directory' ) . '</h2>';
    543                 echo '<p>' . esc_html__( 'Examples with photos, opening hours and map positions, so you can see how your directory looks before you have real listings.', 'premiumpress-directory' ) . '</p></div>';
     542                echo '<section class="ppd-a-sect ppd-pg-gap"><div class="ppd-a-sect-copy"><h2>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Sample %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</h2>';
     543                echo '<p>' . esc_html( (string) ( PremiumPress_Profiles::current()['sample_note'] ?? '' ) ) . '</p></div>';
    544544                echo '<div class="ppd-a-card ppd-a-pad ppd-pg-sample">';
    545545                if ( $n ) {
    546546                        /* translators: %d: number of sample listings */
    547                         echo '<strong class="ppd-pg-count">' . esc_html( sprintf( _n( '%d sample listing is on your site', '%d sample listings are on your site', $n, 'premiumpress-directory' ), $n ) ) . '</strong>';
     547                        echo '<strong class="ppd-pg-count">' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( '%1$d sample %2$s is on your site', '%1$d sample %2$s are on your site', $n, 'premiumpress-directory' ), $n, ( 1 === $n ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</strong>';
    548548                        echo '<ul class="ppd-pg-names">';
    549549                        foreach ( $samples as $sp ) {
    550550                                echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>';
    551551                        }
    552                         echo '</ul><p class="ppd-a-muted">' . esc_html__( 'Remove them once your own listings are in. Only the samples are removed: your own listings, categories and pages are never touched.', 'premiumpress-directory' ) . '</p>';
     552                        echo '</ul><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: 1: plural item name, e.g. listings, jobs */ __( 'Remove them once your own %1$s are in. Only the samples are removed: your own %1$s, categories and pages are never touched.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p>';
    553553                        echo '<form method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '"><input type="hidden" name="action" value="' . esc_attr( self::SAMPLE_ACTION ) . '"><input type="hidden" name="do" value="remove">';
    554554                        wp_nonce_field( self::SAMPLE_ACTION );
    555555                        /* translators: %d: number of sample listings */
    556                         echo '<button type="submit" class="ppd-a-btn ppd-a-btn--danger" data-ppd-confirm-submit="' . esc_attr( sprintf( _n( 'Remove %d sample listing? Your own listings are not affected.', 'Remove all %d sample listings? Your own listings are not affected.', $n, 'premiumpress-directory' ), $n ) ) . '">' . esc_html( sprintf( _n( 'Remove the %d sample listing', 'Remove the %d sample listings', $n, 'premiumpress-directory' ), $n ) ) . '</button></form>';
     556                        echo '<button type="submit" class="ppd-a-btn ppd-a-btn--danger" data-ppd-confirm-submit="' . esc_attr( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match), 3: plural item name, lowercase */ _n( 'Remove %1$d sample %2$s? Your own %3$s are not affected.', 'Remove all %1$d sample %2$s? Your own %3$s are not affected.', $n, 'premiumpress-directory' ), $n, ( 1 === $n ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ), PremiumPress_Profiles::many() ) ) . '">' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'Remove the %1$d sample %2$s', 'Remove the %1$d sample %2$s', $n, 'premiumpress-directory' ), $n, ( 1 === $n ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</button></form>';
    557557                } else {
    558                         echo '<strong class="ppd-pg-count">' . esc_html__( 'No sample listings are on your site', 'premiumpress-directory' ) . '</strong>';
     558                        echo '<strong class="ppd-pg-count">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'No sample %s are on your site', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</strong>';
    559559                        $items = count( PremiumPress_Sample::items() );
    560560                        if ( $items ) {
    … …  
    564564                                wp_nonce_field( self::SAMPLE_ACTION );
    565565                                /* translators: %d: number of sample listings */
    566                                 echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">' . esc_html( sprintf( __( 'Add %d sample listings', 'premiumpress-directory' ), $items ) ) . '</button></form>';
     566                                echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">' . esc_html( sprintf( /* translators: 1: number, 2: plural item name, e.g. listings */ __( 'Add %1$d sample %2$s', 'premiumpress-directory' ), $items, PremiumPress_Profiles::many() ) ) . '</button></form>';
    567567                        }
    568568                }
    … …  
    571571                // Start again.
    572572                echo '<section class="ppd-a-sect ppd-pg-gap"><div class="ppd-a-sect-copy"><h2>' . esc_html__( 'Start again', 'premiumpress-directory' ) . '</h2></div>';
    573                 echo '<div class="ppd-a-card ppd-a-pad ppd-pg-again"><span><strong>' . esc_html__( 'Run the setup wizard again', 'premiumpress-directory' ) . '</strong><span class="ppd-a-muted">' . esc_html__( 'Change what your directory is about, the town, the homepage or the design. Your listings stay as they are.', 'premiumpress-directory' ) . '</span></span>';
     573                echo '<div class="ppd-a-card ppd-a-pad ppd-pg-again"><span><strong>' . esc_html__( 'Run the setup wizard again', 'premiumpress-directory' ) . '</strong><span class="ppd-a-muted">' . esc_html( sprintf( /* translators: 1: what the site is, e.g. directory, job board, 2: plural item name, e.g. listings, jobs */ __( 'Change what your %1$s is about, the town, the homepage or the design. Your %2$s stay as they are.', 'premiumpress-directory' ), PremiumPress_Profiles::noun(), PremiumPress_Profiles::many() ) ) . '</span></span>';
    574574                echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Wizard::url() ) . '">' . esc_html__( 'Open the setup wizard', 'premiumpress-directory' ) . '</a></div></section>';
    575575        }
    … …  
    625625                $no    = '<span class="ppd-up-no" role="img" aria-label="' . esc_attr__( 'Not included', 'premiumpress-directory' ) . '">&ndash;</span>';
    626626
    627                 // icon, title, description, in this plugin.
    628                 $rows = array(
    629                         array( 'list', __( 'Listings & reviews', 'premiumpress-directory' ), __( 'Create listings, collect reviews and let users favourite listings.', 'premiumpress-directory' ), true ),
    630                         array( 'map', __( 'Search & maps', 'premiumpress-directory' ), __( 'Search by keyword, category, location and distance with maps.', 'premiumpress-directory' ), true ),
    631                         array( 'monitor', __( 'Ready-made designs', 'premiumpress-directory' ), __( 'Launch faster with professional directory homepage designs.', 'premiumpress-directory' ), false ),
    632                         array( 'layers', __( 'Paid listing packages', 'premiumpress-directory' ), __( 'Create listing packages and accept paid submissions.', 'premiumpress-directory' ), false ),
    633                         array( 'card', __( 'Payment gateways', 'premiumpress-directory' ), __( 'Accept payments for listings and upgrades.', 'premiumpress-directory' ), false ),
    634                         array( 'search', __( 'Advanced search & alerts', 'premiumpress-directory' ), __( 'Add advanced filters, saved searches and email alerts.', 'premiumpress-directory' ), false ),
    635                         array( 'chat', __( 'Member messaging', 'premiumpress-directory' ), __( 'Let members message each other from their account dashboard.', 'premiumpress-directory' ), false ),
    636                         array( 'sparkle', __( 'AI site generator', 'premiumpress-directory' ), __( 'Get a head start with an AI-powered site setup for your directory.', 'premiumpress-directory' ), false ),
    637                 );
     627                // icon, title, description, in this plugin: each plugin lists its own theme's extras.
     628                $rows = (array) ( $p['upgrade_rows'] ?? array() );
    638629
    639630                echo '<div class="ppd-up">';
    … …  
    642633                $title = sprintf( esc_html__( 'See what the %s adds', 'premiumpress-directory' ), '<span>' . esc_html( $theme ) . '</span>' );
    643634                echo '<h2>' . wp_kses( $title, array( 'span' => array() ) ) . '</h2>';
    644                 echo '<p>' . esc_html__( 'A more powerful, business-ready version of your directory with modern designs, paid listings and advanced member tools.', 'premiumpress-directory' ) . '</p>';
     635                echo '<p>' . esc_html( (string) ( $p['upgrade_lead'] ?? '' ) ) . '</p>';
    645636                /* translators: %s: theme name, e.g. Directory theme */
    646637                echo '<a class="ppd-a-btn ppd-a-btn--primary ppd-up-btn" href="' . esc_url( $url ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( __( 'Upgrade to the %s', 'premiumpress-directory' ), $theme ) ) . ' ';
    … …  
    660651                PremiumPress_Admin_UI::e_icon( 'layers', 22 );
    661652                /* translators: %s: theme name, e.g. Directory theme */
    662                 echo '</span><span class="ppd-up-cta-copy"><strong>' . esc_html__( 'Ready to unlock more features?', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( __( 'Upgrade to the %s and start building a more powerful directory site today.', 'premiumpress-directory' ), $theme ) ) . '</span></span>';
     653                echo '</span><span class="ppd-up-cta-copy"><strong>' . esc_html__( 'Ready to unlock more features?', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( (string) ( $p['upgrade_cta'] ?? '%s' ), $theme ) ) . '</span></span>';
    663654                /* translators: %s: theme name, e.g. Directory theme */
    664655                echo '<a class="ppd-a-btn ppd-a-btn--primary" href="' . esc_url( $url ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( __( 'Upgrade to %s', 'premiumpress-directory' ), $theme ) ) . ' ';
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-submit.php

    r3838627 r3848540  
    141141                        'required' => array( 'error', __( 'Please fill in every field marked with *.', 'premiumpress-directory' ) ),
    142142                );
     143                /** Niche code adds its own notices (e.g. "Marked as sold"). */
     144                $map = (array) apply_filters( 'premiumpress_flash_messages', $map, $one );
    143145                if ( ! isset( $map[ $code ] ) ) {
    144146                        return '';
    … …  
    332334                }
    333335                foreach ( PremiumPress_Profiles::fields() as $key => $field ) {
    334                         $value = PremiumPress_Meta::sanitize_field( $field, $in['ppd_f'][ $key ] ?? '' );
    335                         if ( '' === $value ) {
    336                                 delete_post_meta( $id, $key );
    337                         } else {
    338                                 update_post_meta( $id, $key, $value );
    339                         }
     336                        PremiumPress_Profiles::set_field( $id, $key, $field, PremiumPress_Meta::sanitize_field( $field, $in['ppd_f'][ $key ] ?? '' ) );
    340337                }
    341338                if ( PremiumPress_Profiles::has_section( 'hours' ) && isset( $in['ppd_hours'] ) && is_array( $in['ppd_hours'] ) ) {
    … …  
    480477                        self::back( $back, 'renewed' );
    481478                }
     479                /** Niche actions (e.g. mark sold). Return a notice code when handled. */
     480                $code = (string) apply_filters( 'premiumpress_item_action', '', $do, $id );
     481                if ( '' !== $code ) {
     482                        self::back( $back, $code );
     483                }
    482484                self::back( $back, 'failed' );
    483485        }
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-switch.php

    r3838627 r3848540  
    2424        }
    2525
     26        /**
     27         * This plugin's sources (switch-data.php): key => [name, post_type, reader].
     28         *
     29         * @return array<string, array<string, mixed>>
     30         */
     31        public static function data(): array {
     32                static $data = null;
     33                if ( null === $data ) {
     34                        $file = PREMIUMPRESS_DIR . 'includes/switch-data.php';
     35                        $data = file_exists( $file ) ? (array) require $file : array();
     36                }
     37                return $data;
     38        }
     39
    2640        /** @return array<string, string> source => name */
    2741        public static function names(): array {
    28                 return array(
    29                         'directorist' => 'Directorist',
    30                         'geodirectory' => 'GeoDirectory',
    31                         'bdp'          => 'Business Directory Plugin',
    32                 );
     42                $out = array();
     43                foreach ( (array) ( self::data()['sources'] ?? array() ) as $key => $src ) {
     44                        $out[ (string) $key ] = (string) $src['name'];
     45                }
     46                return $out;
    3347        }
    3448
    3549        private static function post_type( string $source ): string {
    36                 $types = array(
    37                         'directorist'  => 'at_biz_dir',
    38                         'geodirectory' => 'gd_place',
    39                         'bdp'          => 'wpbdp_listing',
    40                 );
    41                 return $types[ $source ] ?? '';
     50                return (string) ( self::data()['sources'][ $source ]['post_type'] ?? '' );
    4251        }
    4352
    … …  
    7483                        $wpdb->prepare(
    7584                                "SELECT p.ID FROM {$wpdb->posts} p
    76                                 WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed')
     85                                WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed','rtcl-expired')
    7786                                AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) )
    7887                                ORDER BY p.ID ASC LIMIT %d",
    … …  
    91100                $type = self::post_type( $source );
    92101                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- counts another plugin's rows for the import screen.
    93                 $total = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status IN ('publish','pending','draft','private','future','expired','gd-closed')", $type ) );
     102                $total = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status IN ('publish','pending','draft','private','future','expired','gd-closed','rtcl-expired')", $type ) );
    94103                // Same rule as pending_ids(): not copied yet, whatever has happened to earlier copies.
    95104                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- as above.
    … …  
    97106                        $wpdb->prepare(
    98107                                "SELECT COUNT(*) FROM {$wpdb->posts} p
    99                                 WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed')
     108                                WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed','rtcl-expired')
    100109                                AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) )",
    101110                                $type,
    … …  
    141150                                }
    142151                                $data['source'] = $source . ':' . $sid;
    143                                 if ( PremiumPress_Porting::write_listing( $data ) ) {
     152                                $new = PremiumPress_Porting::write_listing( $data );
     153                                if ( $new ) {
     154                                        // A plugin's own last step for a copied item (e.g. keep a filled job filled).
     155                                        $after = self::data()['sources'][ $source ]['after'] ?? null;
     156                                        if ( is_callable( $after ) ) {
     157                                                call_user_func( $after, (int) $new, $data );
     158                                        }
    144159                                        ++$copied;
    145160                                } else {
    … …  
    186201                        'copy_images' => true,
    187202                );
    188                 if ( 'directorist' === $source ) {
    189                         return self::directorist( $sid, $post, $d );
    190                 }
    191                 if ( 'geodirectory' === $source ) {
    192                         return self::geodirectory( $sid, $post, $d );
    193                 }
    194                 if ( 'bdp' === $source ) {
    195                         return self::bdp( $sid, $d );
    196                 }
    197                 return null;
    198         }
    199 
    200         /* ===== Directorist ===== */
    201 
    202         /**
    203          * @param array<string, mixed> $d
    204          * @return array<string, mixed>
    205          */
    206         private static function directorist( int $sid, WP_Post $post, array $d ): array {
    207                 $m = static function ( string $k ) use ( $sid ): string {
    208                         $v = get_post_meta( $sid, $k, true );
    209                         return is_scalar( $v ) ? trim( (string) $v ) : '';
    210                 };
    211                 $d['categories'] = self::term_paths( $sid, 'at_biz_dir-category' );
    212                 $d['tags']       = self::term_paths( $sid, 'at_biz_dir-tags' );
    213                 $d['locations']  = self::term_paths( $sid, 'at_biz_dir-location' );
    214                 $d['meta']       = array_filter(
    215                         array(
    216                                 'phone'    => $m( '_phone' ),
    217                                 'email'    => $m( '_email' ),
    218                                 'website'  => $m( '_website' ),
    219                                 'address'  => $m( '_address' ),
    220                                 'postcode' => $m( '_zip' ),
    221                         ),
    222                         'strlen'
    223                 );
    224                 if ( in_array( $m( '_hide_map' ), array( '', '0' ), true ) && is_numeric( $m( '_manual_lat' ) ) && is_numeric( $m( '_manual_lng' ) ) ) {
    225                         $d['lat'] = $m( '_manual_lat' );
    226                         $d['lng'] = $m( '_manual_lng' );
    227                 }
    228                 $d['featured'] = '1' === $m( '_featured' );
    229                 if ( '' !== $m( '_never_expire' ) && '0' !== $m( '_never_expire' ) ) {
    230                         $d['expires'] = 0;
    231                 } elseif ( '' !== $m( '_expiry_date' ) ) {
    232                         $t            = strtotime( get_gmt_from_date( $m( '_expiry_date' ) ) . ' UTC' );
    233                         $d['expires'] = $t ? $t : 0;
    234                 }
    235                 if ( 'expired' === $post->post_status ) {
    236                         $d['status']  = 'draft';
    237                         $d['expired'] = true;
    238                 }
    239                 // Photos: the preview image first, then the gallery.
    240                 $gallery = get_post_meta( $sid, '_listing_img', true );
    241                 $ids     = array_merge( array( (int) $m( '_listing_prv_img' ), (int) get_post_thumbnail_id( $sid ) ), is_array( $gallery ) ? array_map( 'intval', $gallery ) : wp_parse_id_list( (string) $gallery ) );
    242                 $d['image_ids'] = array_values( array_unique( array_filter( $ids ) ) );
    243 
    244                 $hours = self::directorist_hours( $sid );
    245                 if ( null !== $hours ) {
    246                         $d['hours_days'] = $hours;
    247                 }
    248                 $d['reviews'] = self::comment_reviews( $sid, 'directorist', static function ( WP_Comment $c ): float {
    249                         return 'review' === $c->comment_type ? (float) get_comment_meta( (int) $c->comment_ID, 'rating', true ) : 0.0;
    250                 } );
    251                 return $d;
    252         }
    253 
    254         /** @return array<string, array<string, mixed>>|null */
    255         private static function directorist_hours( int $sid ): ?array {
    256                 if ( get_post_meta( $sid, '_disable_bz_hour_listing', true ) ) {
    257                         return null;
    258                 }
    259                 $days = array(
    260                         'monday'    => 'mon',
    261                         'tuesday'   => 'tue',
    262                         'wednesday' => 'wed',
    263                         'thursday'  => 'thu',
    264                         'friday'    => 'fri',
    265                         'saturday'  => 'sat',
    266                         'sunday'    => 'sun',
    267                 );
    268                 if ( 'always' === get_post_meta( $sid, '_enable247hour', true ) ) {
    269                         $out = array();
    270                         foreach ( $days as $k ) {
    271                                 $out[ $k ] = array( 'open' => true, 'h24' => true, 'ranges' => array() );
    272                         }
    273                         return $out;
    274                 }
    275                 $bdbh = get_post_meta( $sid, '_bdbh', true );
    276                 if ( ! is_array( $bdbh ) || ! $bdbh ) {
    277                         return null;
    278                 }
    279                 $out = array();
    280                 foreach ( $days as $long => $k ) {
    281                         $day = isset( $bdbh[ $long ] ) && is_array( $bdbh[ $long ] ) ? $bdbh[ $long ] : array();
    282                         $on  = ! empty( $day['enable'] );
    283                         $all = in_array( (string) ( $day['remain_close'] ?? '' ), array( 'open', 'always_open', 'all_day' ), true );
    284                         $st  = array_values( (array) ( $day['start'] ?? array() ) );
    285                         $cl  = array_values( (array) ( $day['close'] ?? array() ) );
    286                         $ranges = array();
    287                         foreach ( $st as $i => $from ) {
    288                                 // Read with the import's clock, so "9:00", "09:00" and "9:00 am" all work.
    289                                 $a = PremiumPress_Porting::clock( (string) $from );
    290                                 $b = isset( $cl[ $i ] ) ? PremiumPress_Porting::clock( (string) $cl[ $i ] ) : '';
    291                                 if ( '' !== $a && '' !== $b ) {
    292                                         $ranges[] = array( 'from' => $a, 'to' => $b );
    293                                 }
    294                         }
    295                         $out[ $k ] = array(
    296                                 'open'   => $on && ( $all || $ranges ),
    297                                 'h24'    => $on && $all,
    298                                 'ranges' => $all ? array() : $ranges,
    299                         );
    300                 }
    301                 return $out;
    302         }
    303 
    304         /* ===== GeoDirectory ===== */
    305 
    306         /**
    307          * @param array<string, mixed> $d
    308          * @return array<string, mixed>|null
    309          */
    310         private static function geodirectory( int $sid, WP_Post $post, array $d ): ?array {
    311                 global $wpdb;
    312                 $table = $wpdb->prefix . 'geodir_gd_place_detail';
    313                 $row   = null;
    314                 if ( self::table_exists( $table ) ) {
    315                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- GeoDirectory keeps listing details in its own table.
    316                         $row = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM %i WHERE post_id = %d', $table, $sid ), ARRAY_A );
    317                 }
    318                 $row = is_array( $row ) ? $row : array();
    319                 $g   = static function ( string $k ) use ( $row ): string {
    320                         return isset( $row[ $k ] ) && is_scalar( $row[ $k ] ) ? trim( (string) $row[ $k ] ) : '';
    321                 };
    322                 $d['categories'] = self::term_paths( $sid, 'gd_placecategory' );
    323                 $d['tags']       = self::term_paths( $sid, 'gd_place_tags' );
    324                 $street          = trim( $g( 'street' ) . ( '' !== $g( 'street2' ) ? ', ' . $g( 'street2' ) : '' ), ', ' );
    325                 $d['meta']       = array_filter(
    326                         array(
    327                                 'phone'    => $g( 'phone' ),
    328                                 'email'    => $g( 'email' ),
    329                                 'website'  => $g( 'website' ),
    330                                 'address'  => $street,
    331                                 'city'     => $g( 'city' ),
    332                                 'region'   => $g( 'region' ),
    333                                 'postcode' => $g( 'zip' ),
    334                                 'country'  => $g( 'country' ),
    335                         ),
    336                         'strlen'
    337                 );
    338                 if ( '' !== $g( 'city' ) ) {
    339                         $d['locations'] = array( array( $g( 'city' ) ) );
    340                 }
    341                 if ( is_numeric( $g( 'latitude' ) ) && is_numeric( $g( 'longitude' ) ) ) {
    342                         $d['lat'] = $g( 'latitude' );
    343                         $d['lng'] = $g( 'longitude' );
    344                 }
    345                 if ( '' !== $g( 'featured' ) ) {
    346                         $d['featured'] = '1' === $g( 'featured' );
    347                 }
    348                 if ( 'gd-closed' === $post->post_status ) {
    349                         $d['status'] = 'draft';
    350                 }
    351                 if ( '' !== $g( 'business_hours' ) ) {
    352                         $hours = self::geodir_hours( $g( 'business_hours' ) );
    353                         if ( null !== $hours ) {
    354                                 $d['hours_days'] = $hours;
    355                         }
    356                 }
    357                 // Photos: the main image is a Media Library item; the rest are files GeoDirectory
    358                 // tracks itself, which are copied in from disk (or fetched, when stored as a web address).
    359                 $ids  = array( (int) get_post_thumbnail_id( $sid ) );
    360                 $urls = array();
    361                 $att   = $wpdb->prefix . 'geodir_attachments';
    362                 $files = array();
    363                 if ( self::table_exists( $att ) ) {
    364                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- GeoDirectory's own gallery table.
    365                         $files = $wpdb->get_col( $wpdb->prepare( "SELECT file FROM %i WHERE post_id = %d AND type = 'post_images' AND is_approved = 1 ORDER BY featured DESC, menu_order ASC", $att, $sid ) );
    366                 }
    367                 $up    = wp_get_upload_dir();
    368                 foreach ( (array) $files as $file ) {
    369                         $file = (string) $file;
    370                         if ( preg_match( '#^https?://#i', $file ) ) {
    371                                 $urls[] = $file;
    372                                 continue;
    373                         }
    374                         $rel   = ltrim( $file, '/' );
    375                         $local = attachment_url_to_postid( trailingslashit( $up['baseurl'] ) . $rel );
    376                         if ( $local ) {
    377                                 $ids[] = $local;
    378                         } elseif ( '' !== $rel && file_exists( trailingslashit( $up['basedir'] ) . $rel ) ) {
    379                                 $ids[] = PremiumPress_Porting::copy_local_file( trailingslashit( $up['basedir'] ) . $rel );
    380                         }
    381                 }
    382                 $d['image_ids']  = array_values( array_unique( array_filter( $ids ) ) );
    383                 $d['image_urls'] = $urls;
    384 
    385                 $review = $wpdb->prefix . 'geodir_post_review';
    386                 if ( ! self::table_exists( $review ) ) {
    387                         return $d;
    388                 }
    389                 $d['reviews'] = self::comment_reviews( $sid, 'geodirectory', static function ( WP_Comment $c ) use ( $wpdb, $review ): float {
    390                         if ( (int) $c->comment_parent ) {
    391                                 return 0.0;
    392                         }
    393                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- GeoDirectory keeps ratings in its own table.
    394                         return (float) $wpdb->get_var( $wpdb->prepare( 'SELECT rating FROM %i WHERE comment_id = %d', $review, (int) $c->comment_ID ) );
    395                 } );
    396                 return $d;
    397         }
    398 
    399         /**
    400          * GeoDirectory hours: '["Mo 09:00-17:00","Tu 09:00-12:00,13:00-17:00"],["UTC":"+0"]'.
    401          * A day it doesn't list is closed; 00:00-00:00 is open all day.
    402          *
    403          * @return array<string, array<string, mixed>>|null
    404          */
    405         public static function geodir_hours( string $raw ): ?array {
    406                 $raw = trim( wp_unslash( $raw ) );
    407                 if ( ! preg_match( '/^\s*(\[.*?\])/s', $raw, $m ) ) {
    408                         return null;
    409                 }
    410                 $list = json_decode( $m[1], true );
    411                 if ( ! is_array( $list ) ) {
    412                         return null;
    413                 }
    414                 $codes = array( 'mo' => 'mon', 'tu' => 'tue', 'we' => 'wed', 'th' => 'thu', 'fr' => 'fri', 'sa' => 'sat', 'su' => 'sun' );
    415                 $keys  = array_values( $codes );
    416                 $out   = array();
    417                 foreach ( $keys as $k ) {
    418                         $out[ $k ] = array( 'open' => false, 'h24' => false, 'ranges' => array() );
    419                 }
    420                 $any = false;
    421                 foreach ( $list as $entry ) {
    422                         if ( ! is_string( $entry ) || ! preg_match( '/^\s*([a-z]{2})(?:\s*-\s*([a-z]{2}))?\s+(.+)$/i', $entry, $e ) ) {
    423                                 continue;
    424                         }
    425                         $from = strtolower( $e[1] );
    426                         $to   = '' !== $e[2] ? strtolower( $e[2] ) : $from;
    427                         if ( ! isset( $codes[ $from ], $codes[ $to ] ) ) {
    428                                 continue;
    429                         }
    430                         $ranges = array();
    431                         $h24    = false;
    432                         foreach ( explode( ',', $e[3] ) as $slot ) {
    433                                 if ( ! preg_match( '/^\s*(\d{1,2}:\d{2})\s*-\s*(\d{1,2}:\d{2})\s*$/', $slot, $s ) ) {
    434                                         continue;
    435                                 }
    436                                 $a = sprintf( '%05s', $s[1] );
    437                                 $b = sprintf( '%05s', $s[2] );
    438                                 if ( '00:00' === $a && in_array( $b, array( '00:00', '24:00', '23:59' ), true ) ) {
    439                                         $h24 = true;
    440                                         continue;
    441                                 }
    442                                 $ranges[] = array( 'from' => $a, 'to' => '24:00' === $b ? '00:00' : $b );
    443                         }
    444                         $day = array( 'open' => $h24 || (bool) $ranges, 'h24' => $h24, 'ranges' => $h24 ? array() : $ranges );
    445                         $i   = array_search( $codes[ $from ], $keys, true );
    446                         $end = array_search( $codes[ $to ], $keys, true );
    447                         for ( $n = 0; $n < 7; $n++ ) {
    448                                 $out[ $keys[ $i ] ] = $day;
    449                                 if ( $i === $end ) {
    450                                         break;
    451                                 }
    452                                 $i = ( $i + 1 ) % 7;
    453                         }
    454                         $any = true;
    455                 }
    456                 return $any ? $out : null;
    457         }
    458 
    459         /* ===== Business Directory Plugin ===== */
    460 
    461         /**
    462          * @param array<string, mixed> $d
    463          * @return array<string, mixed>
    464          */
    465         private static function bdp( int $sid, array $d ): array {
    466                 global $wpdb;
    467                 $d['categories'] = self::term_paths( $sid, 'wpbdp_category' );
    468                 $d['tags']       = self::term_paths( $sid, 'wpbdp_tag' );
    469 
    470                 // Fields are defined in its own table; values live in "_wpbdp[fields][<id>]" post meta.
    471                 $table  = $wpdb->prefix . 'wpbdp_form_fields';
    472                 $fields = array();
    473                 if ( self::table_exists( $table ) ) {
    474                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Business Directory Plugin's field list.
    475                         $fields = (array) $wpdb->get_results( $wpdb->prepare( 'SELECT id, tag, association, field_type FROM %i', $table ), ARRAY_A );
    476                 }
    477                 $map    = array(
    478                         'phone'   => 'phone',
    479                         'email'   => 'email',
    480                         'website' => 'website',
    481                         'address' => 'address',
    482                         'zip'     => 'postcode',
    483                 );
    484                 foreach ( $fields as $f ) {
    485                         $tag = strtolower( (string) ( $f['tag'] ?? '' ) );
    486                         if ( ! isset( $map[ $tag ] ) || 'meta' !== ( $f['association'] ?? '' ) ) {
    487                                 continue;
    488                         }
    489                         $v = get_post_meta( $sid, '_wpbdp[fields][' . (int) $f['id'] . ']', true );
    490                         if ( is_array( $v ) ) {
    491                                 $v = (string) reset( $v ); // A website field is stored as [ url, link text ].
    492                         }
    493                         $v = trim( (string) $v );
    494                         if ( '' !== $v ) {
    495                                 $d['meta'][ $map[ $tag ] ] = 'address' === $tag ? preg_replace( '/\s*\n\s*/', ', ', $v ) : $v;
    496                         }
    497                 }
    498 
    499                 $listing = $wpdb->prefix . 'wpbdp_listings';
    500                 $row     = null;
    501                 if ( self::table_exists( $listing ) ) {
    502                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- its own listings table holds featured and expiry.
    503                         $row = $wpdb->get_row( $wpdb->prepare( 'SELECT expiration_date, is_sticky, listing_status FROM %i WHERE listing_id = %d', $listing, $sid ), ARRAY_A );
    504                 }
    505                 if ( is_array( $row ) ) {
    506                         $d['featured'] = ! empty( $row['is_sticky'] );
    507                         $exp           = (string) ( $row['expiration_date'] ?? '' );
    508                         $d['expires']  = '' !== $exp && '0000-00-00 00:00:00' !== $exp ? (int) strtotime( $exp . ' UTC' ) : 0;
    509                         if ( 'expired' === ( $row['listing_status'] ?? '' ) ) {
    510                                 $d['status']  = 'draft';
    511                                 $d['expired'] = true;
    512                         }
    513                 }
    514 
    515                 $images = get_post_meta( $sid, '_wpbdp[images]', true );
    516                 $ids    = array( (int) get_post_thumbnail_id( $sid ), (int) get_post_meta( $sid, '_wpbdp[thumbnail_id]', true ) );
    517                 $ids    = array_merge( $ids, is_array( $images ) ? array_map( 'intval', $images ) : array() );
    518                 foreach ( get_children( array( 'post_parent' => $sid, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'fields' => 'ids' ) ) as $child ) {
    519                         $ids[] = (int) $child;
    520                 }
    521                 $d['image_ids'] = array_values( array_unique( array_filter( $ids ) ) );
    522                 return $d;
    523         }
     203                $reader = self::data()['sources'][ $source ]['reader'] ?? null;
     204                return is_callable( $reader ) ? call_user_func( $reader, $sid, $post, $d ) : null;
     205        }
     206
     207
     208
     209
     210
     211
     212
     213
    524214
    525215        /* ===== Shared ===== */
    526216
    527217        /** Does one of the other plugin's tables exist? (Older or partial installs may lack some.) */
    528         private static function table_exists( string $table ): bool {
     218        public static function table_exists( string $table ): bool {
    529219                global $wpdb;
    530220                static $seen = array();
    … …  
    542232         * @return array<int, array<int, string>>
    543233         */
    544         private static function term_paths( int $sid, string $tax ): array {
     234        public static function term_paths( int $sid, string $tax ): array {
    545235                global $wpdb;
    546236                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the taxonomy may not be registered while its plugin is off.
    … …  
    580270         * @return array<int, array<string, mixed>>
    581271         */
    582         private static function comment_reviews( int $sid, string $source, callable $rating ): array {
     272        public static function comment_reviews( int $sid, string $source, callable $rating ): array {
    583273                $out = array();
    584274                foreach ( get_comments( array( 'post_id' => $sid, 'status' => 'all', 'parent' => 0 ) ) as $c ) {
    … …  
    619309                        return;
    620310                }
    621                 echo '<section class="ppd-a-card ppd-a-pad ppd-port-switch"><h2 class="ppd-a-h2">' . esc_html__( 'Move from another directory plugin', 'premiumpress-directory' ) . '</h2>';
    622                 echo '<p>' . esc_html__( 'Listings from these directory plugins were found on this site. Copy them in with their categories, contact details, map position, opening hours, photos and reviews. The other plugin\'s data is not changed, and each listing is copied only once, so you can run this again later.', 'premiumpress-directory' ) . '</p>';
     311                echo '<section class="ppd-a-card ppd-a-pad ppd-port-switch"><h2 class="ppd-a-h2">' . esc_html( (string) ( self::data()['title'] ?? '' ) ) . '</h2>';
     312                echo '<p>' . esc_html( (string) ( self::data()['intro'] ?? '' ) ) . '</p>';
    623313                echo '<table class="widefat striped ppd-switch"><tbody>';
    624314                foreach ( $rows as $key => $c ) {
    625315                        echo '<tr><th scope="row">' . esc_html( $c['name'] ) . '</th><td>';
    626                         /* translators: %d: number of listings found */
    627                         echo esc_html( sprintf( _n( '%d listing found', '%d listings found', $c['total'], 'premiumpress-directory' ), $c['total'] ) ) . ', ';
     316                        /* translators: 1: number found, 2: item name, lowercase (singular or plural to match) */
     317                        echo esc_html( sprintf( _n( '%1$d %2$s found', '%1$d %2$s found', $c['total'], 'premiumpress-directory' ), $c['total'], ( 1 === $c['total'] ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . ', ';
    628318                        /* translators: %d: number of listings still to copy */
    629319                        echo esc_html( sprintf( _n( '%d still to copy', '%d still to copy', $c['left'], 'premiumpress-directory' ), $c['left'] ) );
    630320                        if ( $c['failed'] ) {
    631                                 /* translators: %d: number of listings that could not be copied */
    632                                 echo '<br><span class="description">' . esc_html( sprintf( _n( '%d listing could not be copied and was skipped.', '%d listings could not be copied and were skipped.', $c['failed'], 'premiumpress-directory' ), $c['failed'] ) ) . '</span>';
     321                                /* translators: 1: number skipped, 2: item name, lowercase (singular or plural to match) */
     322                                echo '<br><span class="description">' . esc_html( sprintf( _n( '%1$d %2$s could not be copied and was skipped.', '%1$d %2$s could not be copied and were skipped.', $c['failed'], 'premiumpress-directory' ), $c['failed'], ( 1 === $c['failed'] ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</span>';
    633323                        }
    634324                        echo '</td><td>';
  • premiumpress-directory/tags/1.1.1/includes/class-premiumpress-wizard.php

    r3838627 r3848540  
    3131         */
    3232        public static function niches(): array {
    33                 return array(
    34                         'general'      => array(
    35                                 'label' => __( 'Local businesses', 'premiumpress-directory' ),
    36                                 'text'  => __( 'A classic directory of shops, services and trades in one area.', 'premiumpress-directory' ),
    37                                 'cats'  => array( __( 'Bakeries', 'premiumpress-directory' ), __( 'Barbers', 'premiumpress-directory' ), __( 'Bookshops', 'premiumpress-directory' ), __( 'Cafés', 'premiumpress-directory' ), __( 'Dentists', 'premiumpress-directory' ), __( 'Electricians', 'premiumpress-directory' ), __( 'Fitness', 'premiumpress-directory' ), __( 'Florists', 'premiumpress-directory' ), __( 'Garages', 'premiumpress-directory' ), __( 'Plumbers', 'premiumpress-directory' ) ),
    38                         ),
    39                         'cityguide'    => array(
    40                                 'label' => __( 'City guide', 'premiumpress-directory' ),
    41                                 'text'  => __( 'Places to eat, drink, stay and go out in a town or city.', 'premiumpress-directory' ),
    42                                 'cats'  => array( __( 'Bars', 'premiumpress-directory' ), __( 'Cafés', 'premiumpress-directory' ), __( 'Restaurants', 'premiumpress-directory' ), __( 'Hotels', 'premiumpress-directory' ), __( 'Galleries', 'premiumpress-directory' ), __( 'Cinemas', 'premiumpress-directory' ), __( 'Live music', 'premiumpress-directory' ), __( 'Markets', 'premiumpress-directory' ), __( 'Shops', 'premiumpress-directory' ) ),
    43                         ),
    44                         'localfood'    => array(
    45                                 'label' => __( 'Food and drink', 'premiumpress-directory' ),
    46                                 'text'  => __( 'Restaurants, takeaways, cafés and bakeries.', 'premiumpress-directory' ),
    47                                 'cats'  => array( __( 'Restaurants', 'premiumpress-directory' ), __( 'Takeaways', 'premiumpress-directory' ), __( 'Pizza', 'premiumpress-directory' ), __( 'Cafés', 'premiumpress-directory' ), __( 'Bakeries', 'premiumpress-directory' ), __( 'Pubs', 'premiumpress-directory' ), __( 'Bars', 'premiumpress-directory' ), __( 'Vegan and vegetarian', 'premiumpress-directory' ) ),
    48                         ),
    49                         'trades'       => array(
    50                                 'label' => __( 'Tradespeople', 'premiumpress-directory' ),
    51                                 'text'  => __( 'Builders, electricians, plumbers and other trades.', 'premiumpress-directory' ),
    52                                 'cats'  => array( __( 'Builders', 'premiumpress-directory' ), __( 'Electricians', 'premiumpress-directory' ), __( 'Plumbers', 'premiumpress-directory' ), __( 'Roofers', 'premiumpress-directory' ), __( 'Carpenters', 'premiumpress-directory' ), __( 'Decorators', 'premiumpress-directory' ), __( 'Plasterers', 'premiumpress-directory' ), __( 'Heating engineers', 'premiumpress-directory' ), __( 'Locksmiths', 'premiumpress-directory' ), __( 'Tilers', 'premiumpress-directory' ) ),
    53                         ),
    54                         'homegarden'   => array(
    55                                 'label' => __( 'Home and garden', 'premiumpress-directory' ),
    56                                 'text'  => __( 'Cleaners, gardeners, removals and home improvement.', 'premiumpress-directory' ),
    57                                 'cats'  => array( __( 'Cleaners', 'premiumpress-directory' ), __( 'Gardeners', 'premiumpress-directory' ), __( 'Landscapers', 'premiumpress-directory' ), __( 'Handymen', 'premiumpress-directory' ), __( 'Removals', 'premiumpress-directory' ), __( 'Interior designers', 'premiumpress-directory' ), __( 'Pest control', 'premiumpress-directory' ), __( 'Tree surgeons', 'premiumpress-directory' ) ),
    58                         ),
    59                         'health'       => array(
    60                                 'label' => __( 'Healthcare', 'premiumpress-directory' ),
    61                                 'text'  => __( 'Doctors, dentists, therapists and clinics.', 'premiumpress-directory' ),
    62                                 'cats'  => array( __( 'Dentists', 'premiumpress-directory' ), __( 'Doctors', 'premiumpress-directory' ), __( 'Opticians', 'premiumpress-directory' ), __( 'Physiotherapists', 'premiumpress-directory' ), __( 'Chiropractors', 'premiumpress-directory' ), __( 'Osteopaths', 'premiumpress-directory' ), __( 'Counsellors', 'premiumpress-directory' ), __( 'Podiatrists', 'premiumpress-directory' ) ),
    63                         ),
    64                         'beauty'       => array(
    65                                 'label' => __( 'Beauty and wellness', 'premiumpress-directory' ),
    66                                 'text'  => __( 'Salons, barbers, spas and clinics.', 'premiumpress-directory' ),
    67                                 'cats'  => array( __( 'Hair salons', 'premiumpress-directory' ), __( 'Barbers', 'premiumpress-directory' ), __( 'Beauty salons', 'premiumpress-directory' ), __( 'Nail bars', 'premiumpress-directory' ), __( 'Brows and lashes', 'premiumpress-directory' ), __( 'Spas', 'premiumpress-directory' ), __( 'Aesthetics clinics', 'premiumpress-directory' ), __( 'Wellness clinics', 'premiumpress-directory' ) ),
    68                         ),
    69                         'auto'         => array(
    70                                 'label' => __( 'Automotive', 'premiumpress-directory' ),
    71                                 'text'  => __( 'Garages, MOT centres, tyres and car services.', 'premiumpress-directory' ),
    72                                 'cats'  => array( __( 'Garages', 'premiumpress-directory' ), __( 'MOT centres', 'premiumpress-directory' ), __( 'Tyre shops', 'premiumpress-directory' ), __( 'Mobile mechanics', 'premiumpress-directory' ), __( 'Bodywork and paint', 'premiumpress-directory' ), __( 'Valeting', 'premiumpress-directory' ), __( 'Car dealers', 'premiumpress-directory' ), __( 'Car hire', 'premiumpress-directory' ) ),
    73                         ),
    74                         'prof'         => array(
    75                                 'label' => __( 'Professional services', 'premiumpress-directory' ),
    76                                 'text'  => __( 'Accountants, architects, agencies and consultants.', 'premiumpress-directory' ),
    77                                 'cats'  => array( __( 'Accountants', 'premiumpress-directory' ), __( 'Architects', 'premiumpress-directory' ), __( 'Consultants', 'premiumpress-directory' ), __( 'Marketing agencies', 'premiumpress-directory' ), __( 'Designers', 'premiumpress-directory' ), __( 'Photographers', 'premiumpress-directory' ), __( 'Recruiters', 'premiumpress-directory' ), __( 'Translators', 'premiumpress-directory' ) ),
    78                         ),
    79                         'legal'        => array(
    80                                 'label' => __( 'Legal and financial', 'premiumpress-directory' ),
    81                                 'text'  => __( 'Solicitors, financial advisers and accountants.', 'premiumpress-directory' ),
    82                                 'cats'  => array( __( 'Solicitors', 'premiumpress-directory' ), __( 'Family lawyers', 'premiumpress-directory' ), __( 'Conveyancers', 'premiumpress-directory' ), __( 'Immigration lawyers', 'premiumpress-directory' ), __( 'Accountants', 'premiumpress-directory' ), __( 'Financial advisers', 'premiumpress-directory' ), __( 'Mortgage brokers', 'premiumpress-directory' ), __( 'Tax advisers', 'premiumpress-directory' ) ),
    83                         ),
    84                         'sports'       => array(
    85                                 'label' => __( 'Sports coaches', 'premiumpress-directory' ),
    86                                 'text'  => __( 'Coaches, clubs and classes for every sport.', 'premiumpress-directory' ),
    87                                 'cats'  => array( __( 'Football', 'premiumpress-directory' ), __( 'Tennis', 'premiumpress-directory' ), __( 'Swimming', 'premiumpress-directory' ), __( 'Running', 'premiumpress-directory' ), __( 'Golf', 'premiumpress-directory' ), __( 'Boxing', 'premiumpress-directory' ), __( 'Gymnastics', 'premiumpress-directory' ), __( 'Strength and conditioning', 'premiumpress-directory' ) ),
    88                         ),
    89                         'coaches'      => array(
    90                                 'label' => __( 'Life and career coaches', 'premiumpress-directory' ),
    91                                 'text'  => __( 'Public speaking, relationship and other coaches.', 'premiumpress-directory' ),
    92                                 'cats'  => array( __( 'Public speaking coaches', 'premiumpress-directory' ), __( 'Presentation coaches', 'premiumpress-directory' ), __( 'Voice coaches', 'premiumpress-directory' ), __( 'Relationship coaches', 'premiumpress-directory' ), __( 'Dating coaches', 'premiumpress-directory' ), __( 'Career coaches', 'premiumpress-directory' ) ),
    93                         ),
    94                 );
     33                return (array) ( self::data()['niches'] ?? array() );
     34        }
     35
     36        /** This plugin's setup data: niches (from its theme) and which ones the sample content suits. */
     37        private static function data(): array {
     38                static $data = null;
     39                if ( null === $data ) {
     40                        $data = (array) require PREMIUMPRESS_DIR . 'includes/wizard-data.php';
     41                }
     42                return $data;
    9543        }
    9644
    9745        /** True when the niche step applies (the business directory site type). */
    9846        private static function has_niches(): bool {
    99                 return 'directory' === PremiumPress_Profiles::current_key();
     47                return (bool) self::niches();
    10048        }
    10149
    … …  
    229177        private static function samples_fit(): bool {
    230178                $n = (string) get_option( self::NICHE, '' );
    231                 return ! self::has_niches() || '' === $n || 'general' === $n || 'cityguide' === $n;
     179                return ! self::has_niches() || '' === $n || in_array( $n, (array) ( self::data()['samples_fit'] ?? array() ), true );
    232180        }
    233181
    … …  
    250198                        $items[] = '<li><span>' . esc_html__( 'Visitors can\'t create an account yet, so they can\'t add anything. Tick "Anyone can register" in WordPress\'s General settings.', 'premiumpress-directory' ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( admin_url( 'options-general.php' ) ) . '">' . esc_html__( 'Open General settings', 'premiumpress-directory' ) . '</a></li>';
    251199                }
    252                 $items[] = '<li><span>' . esc_html__( 'Your directory pages are in your site menu. Rename or reorder them there.', 'premiumpress-directory' ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( self::menu_url() ) . '">' . esc_html__( 'Edit the menu', 'premiumpress-directory' ) . '</a></li>';
     200                $items[] = '<li><span>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s pages are in your site menu. Rename or reorder them there.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( self::menu_url() ) . '">' . esc_html__( 'Edit the menu', 'premiumpress-directory' ) . '</a></li>';
    253201                if ( PremiumPress_Profiles::has_section( 'location' ) && empty( PremiumPress_Settings::get()['maps'] ) ) {
    254                         $items[] = '<li><span>' . esc_html__( 'Show maps on listings and search results.', 'premiumpress-directory' ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( PremiumPress_Settings::section_url( 'maps' ) ) . '">' . esc_html__( 'Turn on maps', 'premiumpress-directory' ) . '</a></li>';
     202                        $items[] = '<li><span>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Show maps on %s and search results.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( PremiumPress_Settings::section_url( 'maps' ) ) . '">' . esc_html__( 'Turn on maps', 'premiumpress-directory' ) . '</a></li>';
    255203                }
    256204                echo '<h2 class="ppd-wizard__h2">' . esc_html__( 'Next steps', 'premiumpress-directory' ) . '</h2><ul class="ppd-wizard__todo">' . wp_kses( implode( '', $items ), self::todo_allowed() ) . '</ul>';
    … …  
    334282                $p   = PremiumPress_Profiles::current();
    335283
    336                 PremiumPress_Admin_UI::open( 'settings', __( 'Set up your site', 'premiumpress-directory' ), __( 'A few plain questions, then your directory is ready.', 'premiumpress-directory' ) );
     284                PremiumPress_Admin_UI::open( 'settings', __( 'Set up your site', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'A few plain questions, then your %s is ready.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    337285                echo '<div class="ppd-wizard">';
    338286                /* translators: 1: step number, 2: number of steps */
    … …  
    377325                } elseif ( 'niche' === $step ) {
    378326                        $now = (string) get_option( self::NICHE, '' );
    379                         echo '<h1>' . esc_html__( 'What is your directory about?', 'premiumpress-directory' ) . '</h1>';
     327                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'What is your %s about?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
    380328                        echo '<p class="ppd-lead">' . esc_html__( 'Pick the closest one and we\'ll add its categories for you. You can rename, add or remove categories any time.', 'premiumpress-directory' ) . '</p><div class="ppd-types">';
    381329                        foreach ( self::niches() as $key => $n ) {
    382330                                printf(
    383                                         '<button type="submit" name="niche" value="%1$s" class="ppd-type ppd-type--niche%4$s"><img class="ppd-type__icon" src="%6$s" alt="" width="56" height="56" loading="lazy"><strong>%2$s</strong><span>%3$s</span><small>%5$s</small></button>',
     331                                        '<button type="submit" name="niche" value="%1$s" class="ppd-type ppd-type--niche%4$s">%6$s<strong>%2$s</strong><span>%3$s</span><small>%5$s</small></button>',
    384332                                        esc_attr( $key ),
    385333                                        esc_html( $n['label'] ),
    … …  
    387335                                        $now === $key ? ' is-current' : '',
    388336                                        esc_html( implode( ', ', array_slice( $n['cats'], 0, 4 ) ) . '…' ),
    389                                         esc_url( PREMIUMPRESS_URL . 'assets/niches/' . $key . '.webp' )
     337                                        file_exists( PREMIUMPRESS_DIR . 'assets/niches/' . $key . '.webp' ) ? '<img class="ppd-type__icon" src="' . esc_url( PREMIUMPRESS_URL . 'assets/niches/' . $key . '.webp' ) . '" alt="" width="56" height="56" loading="lazy">' : ''
    390338                                );
    391339                        }
    … …  
    394342                        $place = self::home_place();
    395343                        $term  = $place ? get_term( $place, PremiumPress_Post_Types::TAX_LOCATION ) : null;
    396                         echo '<h1>' . esc_html__( 'Where is your directory?', 'premiumpress-directory' ) . '</h1>';
    397                         echo '<p class="ppd-lead">' . esc_html__( 'The town, city or area it covers. It becomes the first location, and new listings start there.', 'premiumpress-directory' ) . '</p>';
     344                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Where is your %s?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
     345                        echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'The town, city or area it covers. It becomes the first location, and new %s start there.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p>';
    398346                        printf(
    399347                                '<p><label for="ppd-w-place" class="screen-reader-text">%1$s</label><input type="text" id="ppd-w-place" name="place" class="regular-text" value="%2$s" placeholder="%3$s" maxlength="100" autocomplete="address-level2"></p>',
    … …  
    467415                                );
    468416                                /* translators: %d: number of sample listings */
    469                                 echo '<h1>' . esc_html( sprintf( _n( 'You have %d sample listing', 'You have %d sample listings', count( $have ), 'premiumpress-directory' ), count( $have ) ) ) . '</h1>';
    470                                 echo '<p class="ppd-lead">' . esc_html__( 'They were added so you can see how your directory looks. Keep them for now, or remove them if you\'re ready to add your own.', 'premiumpress-directory' ) . '</p>';
     417                                echo '<h1>' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'You have %1$d sample %2$s', 'You have %1$d sample %2$s', count( $have ), 'premiumpress-directory' ), count( $have ), ( 1 === count( $have ) ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</h1>';
     418                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'They were added so you can see how your %s looks. Keep them for now, or remove them if you\'re ready to add your own.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    471419                                echo '<ul class="ppd-wizard__names">';
    472420                                foreach ( $have as $sp ) {
    473421                                        echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>';
    474422                                }
    475                                 echo '</ul><p class="ppd-wizard__hint">' . esc_html__( 'You can also remove them later under Design, Directory pages. Your own listings are never touched.', 'premiumpress-directory' ) . '</p>';
     423                                echo '</ul><p class="ppd-wizard__hint">' . esc_html( sprintf( /* translators: 1: what the site is, capitalised, e.g. Directory, 2: plural item name, e.g. listings, jobs */ __( 'You can also remove them later under Design, %1$s pages. Your own %2$s are never touched.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ), PremiumPress_Profiles::many() ) ) . '</p>';
    476424                        } elseif ( $n && self::samples_fit() ) {
    477425                                /* translators: %s: plural item name, lowercase */
    478426                                echo '<h1>' . esc_html( sprintf( __( 'Add some sample %s?', 'premiumpress-directory' ), $many ) ) . '</h1>';
    479427                                /* translators: %d: number of sample items */
    480                                 echo '<p class="ppd-lead">' . esc_html( sprintf( _n( 'See how everything looks with %d example, complete with photo, map position, opening hours and details.', 'See how everything looks with %d examples, complete with photos, map positions, opening hours and details.', $n, 'premiumpress-directory' ), $n ) ) . '</p>';
    481                                 echo '<p class="ppd-wizard__hint">' . esc_html__( 'They\'re marked as samples, so you can remove them all in one go later, under Design, Directory pages.', 'premiumpress-directory' ) . '</p>';
     428                                echo '<p class="ppd-lead">' . esc_html( sprintf( translate_nooped_plural( (array) PremiumPress_Profiles::current()['sample_wizard'], $n, 'premiumpress-directory' ), $n ) ) . '</p>';
     429                                echo '<p class="ppd-wizard__hint">' . esc_html( sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( 'They\'re marked as samples, so you can remove them all in one go later, under Design, %s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ) ) . '</p>';
    482430                        } else {
    483431                                /* translators: %s: plural item name, lowercase */
    484432                                echo '<h1>' . esc_html( sprintf( __( 'Sample %s', 'premiumpress-directory' ), $many ) ) . '</h1>';
    485                                 echo '<p class="ppd-lead">' . esc_html__( 'There are no sample listings for this kind of directory yet. Your categories are ready, so the quickest way to see how it looks is to add your first listing.', 'premiumpress-directory' ) . '</p>';
     433                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: 1: plural item name, e.g. listings, jobs, 2: what the site is, e.g. directory, job board, 3: singular item name, e.g. listing, job */ __( 'There are no sample %1$s for this kind of %2$s yet. Your categories are ready, so the quickest way to see how it looks is to add your first %3$s.', 'premiumpress-directory' ), PremiumPress_Profiles::many(), PremiumPress_Profiles::noun(), PremiumPress_Profiles::one() ) ) . '</p>';
    486434                        }
    487435                } elseif ( 'design' === $step ) {
    488                         echo '<h1>' . esc_html__( 'How should your directory look?', 'premiumpress-directory' ) . '</h1>';
    489                         echo '<p class="ppd-lead">' . esc_html__( 'Click the one you want. Only your directory pages change, and you can switch any time under Design.', 'premiumpress-directory' ) . '</p>';
     436                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'How should your %s look?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
     437                        echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Click the one you want. Only your %s pages change, and you can switch any time under Design.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    490438                        PremiumPress_Design::cards( 'design' );
    491439                } elseif ( 'home' === $step ) {
    492440                        $dir = PremiumPress_Pages::id( 'directory' );
    493                         echo '<h1>' . esc_html__( 'Make the directory your homepage?', 'premiumpress-directory' ) . '</h1>';
     441                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Make the %s your homepage?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
    494442                        if ( ! $dir ) {
    495                                 echo '<p class="ppd-lead">' . esc_html__( 'The Directory page is missing, so there is nothing to show yet. You can recreate it under Design, Directory pages.', 'premiumpress-directory' ) . '</p>';
     443                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: 1: what the site is, capitalised, e.g. Directory */ __( 'The %1$s page is missing, so there is nothing to show yet. You can recreate it under Design, %1$s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ) ) . '</p>';
    496444                        } elseif ( self::is_homepage() ) {
    497                                 echo '<p class="ppd-lead">' . esc_html__( 'Your directory is already your homepage, so visitors see the search and the cards as soon as they arrive.', 'premiumpress-directory' ) . '</p>';
     445                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s is already your homepage, so visitors see the search and the cards as soon as they arrive.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    498446                        } else {
    499447                                $front = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
    500448                                $now   = $front ? sprintf( /* translators: %s: page title */ __( 'Right now visitors land on your "%s" page.', 'premiumpress-directory' ), get_the_title( $front ) ) : __( 'Right now visitors land on your latest blog posts.', 'premiumpress-directory' );
    501                                 echo '<p class="ppd-lead">' . esc_html( $now . ' ' . __( 'Show your directory there instead, with its search and cards, so people can start looking straight away.', 'premiumpress-directory' ) ) . '</p>';
     449                                echo '<p class="ppd-lead">' . esc_html( $now . ' ' . sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Show your %s there instead, with its search and cards, so people can start looking straight away.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    502450                                echo '<p>' . esc_html__( 'You can change this any time in WordPress under Settings, Reading.', 'premiumpress-directory' ) . '</p>';
    503451                        }
    504452                } else {
    505453                        $dir = PremiumPress_Pages::url( 'directory' );
    506                         echo '<h1>' . esc_html__( 'Your directory is ready', 'premiumpress-directory' ) . '</h1>';
    507                         echo '<p class="ppd-lead">' . esc_html__( 'Have a look at it, or add your first listing. Anything still to do is listed on your Overview page.', 'premiumpress-directory' ) . '</p><p class="ppd-wizard__next">';
     454                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s is ready', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
     455                        echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Have a look at it, or add your first %s. Anything still to do is listed on your Overview page.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p><p class="ppd-wizard__next">';
    508456                        if ( '' !== $dir ) {
    509                                 echo '<a class="button button-primary button-hero" href="' . esc_url( $dir ) . '">' . esc_html__( 'View your directory', 'premiumpress-directory' ) . '</a> ';
     457                                /* translators: %s: plural item name, lowercase */
     458                                echo '<a class="button button-primary button-hero" href="' . esc_url( $dir ) . '">' . esc_html( sprintf( __( 'View your %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['plural'] ) ) ) . '</a> ';
    510459                        }
    511460                        /* translators: %s: singular item name */
    … …  
    514463                        self::next_steps();
    515464                        /* translators: %s: theme name, e.g. Directory theme */
    516                         echo '<p class="ppd-wizard__upsell">' . esc_html( sprintf( __( 'Want ready-made designs, paid listings and payments? The PremiumPress %s uses the same data, so you can switch any time.', 'premiumpress-directory' ), (string) $p['theme_name'] ) ) . ' <a href="' . esc_url( PremiumPress_Profiles::theme_url() ) . '" target="_blank" rel="noopener">' . esc_html__( 'Take a look', 'premiumpress-directory' ) . '</a></p>';
     465                        echo '<p class="ppd-wizard__upsell">' . esc_html( sprintf( __( 'Want ready-made designs, paid %1$s and payments? The PremiumPress %2$s uses the same data, so you can switch any time.', 'premiumpress-directory' ), mb_strtolower( (string) $p['plural'] ), (string) $p['theme_name'] ) ) . ' <a href="' . esc_url( PremiumPress_Profiles::theme_url() ) . '" target="_blank" rel="noopener">' . esc_html__( 'Take a look', 'premiumpress-directory' ) . '</a></p>';
    517466                }
    518467
    … …  
    529478                        } elseif ( 'content' === $step && count( PremiumPress_Sample::items() ) && self::samples_fit() ) {
    530479                                /* translators: %d: number of sample listings */
    531                                 echo '<button type="submit" class="button button-primary button-large">' . esc_html( sprintf( __( 'Add %d sample listings', 'premiumpress-directory' ), count( PremiumPress_Sample::items() ) ) ) . '</button> ';
     480                                echo '<button type="submit" class="button button-primary button-large">' . esc_html( sprintf( /* translators: 1: number, 2: plural item name, e.g. listings */ __( 'Add %1$d sample %2$s', 'premiumpress-directory' ), count( PremiumPress_Sample::items() ), PremiumPress_Profiles::many() ) ) . '</button> ';
    532481                                echo '<button type="submit" name="skip" value="1" class="button-link">' . esc_html__( 'No thanks', 'premiumpress-directory' ) . '</button>';
    533482                        } elseif ( 'content' === $step ) {
  • premiumpress-directory/tags/1.1.1/premiumpress-directory.php

    r3838748 r3848540  
    44 * Plugin URI:        https://www.premiumpress.com/plugin/premiumpress-directory/
    55 * Description:       Add a business directory to any WordPress site: listings, categories, locations, search with a map, reviews and front-end submission.
    6  * Version:           1.1.0
     6 * Version:           1.1.1
    77 * Requires at least: 6.5
    88 * Requires PHP:      7.4
    … …  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 define( 'PREMIUMPRESS_VERSION', '1.1.0' );
     20define( 'PREMIUMPRESS_VERSION', '1.1.1' );
     21define( 'PREMIUMPRESS_NAME', 'PremiumPress Directory' );
     22define( 'PREMIUMPRESS_PROFILE', 'directory' );
     23define( 'PREMIUMPRESS_UTM', 'directory-plugin' );
     24define( 'PREMIUMPRESS_MODULES', array( 'PremiumPress_Switch_Directory' ) );
    2125define( 'PREMIUMPRESS_FILE', __FILE__ );
    2226define( 'PREMIUMPRESS_DIR', plugin_dir_path( __FILE__ ) );
    … …  
    5054require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-porting.php';
    5155require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch.php';
     56require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch-directory.php';
    5257require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-plugin.php';
    5358
  • premiumpress-directory/tags/1.1.1/readme.txt

    r3838748 r3848540  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    1515PremiumPress Directory turns any WordPress site into a local business directory. Add listings yourself or let businesses submit their own, and give visitors a search with a map, distances and reviews.
    1616
    17 🧩 [Plugin page](https://www.premiumpress.com/plugin/premiumpress-directory/) | 🎨 [Directory theme](https://www.premiumpress.com/wordpress-directory-theme/) | 🛠️ [Setup help](https://www.premiumpress.com/wordpress-theme-installation/) | ✉️ [Contact us](https://www.premiumpress.com/contact/)
     17🧩 [Plugin page](https://www.premiumpress.com/plugin/premiumpress-directory/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org) | 🎨 [Directory theme](https://www.premiumpress.com/wordpress-directory-theme/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org) | 🛠️ [Setup help](https://www.premiumpress.com/wordpress-theme-installation/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org) | ✉️ [Contact us](https://www.premiumpress.com/contact/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org)
    1818
    1919It works with any theme, block or classic, and looks at home in both: it uses your theme's fonts and colours instead of bringing its own.
    … …  
    7070= Need more? =
    7171
    72 The plugin is complete on its own. When you want more, the **PremiumPress Directory theme** adds ready-made homepage designs, paid and featured listing packages with [payment gateways](https://www.premiumpress.com/plugins/), unlimited custom fields, Country › City › Area locations, search filters and saved-search alerts, Google Maps and Mapbox, member messaging and dashboards, and an AI site generator.
    73 
    74 It stores listings exactly the way this plugin does. Activate the theme and your listings, reviews and favourites are already there, with nothing to import. [See the Directory theme](https://www.premiumpress.com/wordpress-directory-theme/).
     72The plugin is complete on its own. When you want more, the **PremiumPress Directory theme** adds ready-made homepage designs, paid and featured listing packages with [payment gateways](https://www.premiumpress.com/plugins/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org), unlimited custom fields, Country › City › Area locations, search filters and saved-search alerts, Google Maps and Mapbox, member messaging and dashboards, and an AI site generator.
     73
     74It stores listings exactly the way this plugin does. Activate the theme and your listings, reviews and favourites are already there, with nothing to import. [See the Directory theme](https://www.premiumpress.com/wordpress-directory-theme/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org).
    7575
    7676== Installation ==
    … …  
    167167== Changelog ==
    168168
     169= 1.1.1 =
     170* Improved: only one PremiumPress listings plugin runs at a time. If another one is already active, this one pauses and says so on the Plugins screen.
     171* Improved: imported choices are matched whether a file uses an option's name or its label.
     172
    169173= 1.1.0 =
    170174* New: a setup wizard that starts from your kind of directory and your area, adds matching categories, and lets you keep or remove the sample listings.
    … …  
    189193== Upgrade Notice ==
    190194
     195= 1.1.1 =
     196Small improvements.
     197
    191198= 1.1.0 =
    192199A new setup wizard, a Design section with a Brand page, a fresh listing page design and a cleaner admin.
  • premiumpress-directory/tags/1.1.1/templates/card.php

    r3838627 r3848540  
    2323foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) {
    2424        if ( ! empty( $premiumpress_field['card'] ) ) {
    25                 $premiumpress_value = PremiumPress_Profiles::display_value( $premiumpress_field, (string) get_post_meta( $premiumpress_id, $premiumpress_key, true ) );
     25                $premiumpress_value = PremiumPress_Profiles::display( (int) $premiumpress_id, $premiumpress_key, $premiumpress_field );
    2626                if ( '' !== $premiumpress_value ) {
    2727                        $premiumpress_facts[] = $premiumpress_value;
    … …  
    8686                        </span>
    8787                <?php endif; ?>
    88                 <?php if ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?>
     88                <?php
     89                $premiumpress_badge = (string) apply_filters( 'premiumpress_card_badge', '', $premiumpress_id );
     90                if ( '' !== $premiumpress_badge ) :
     91                        ?>
     92                        <span class="ppd-badge ppd-badge--status"><?php echo esc_html( $premiumpress_badge ); ?></span>
     93                <?php elseif ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?>
    8994                        <span class="ppd-badge ppd-badge--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span>
    9095                <?php elseif ( null !== $premiumpress_open ) : ?>
  • premiumpress-directory/tags/1.1.1/templates/listing-forms.php

    r3837691 r3848540  
    1616$premiumpress_user    = wp_get_current_user();
    1717$premiumpress_contact = PremiumPress_Profiles::has_section( 'contact' ) && '' !== PremiumPress_Engage::contact_email( $premiumpress_id )
    18         && (int) get_post_field( 'post_author', $premiumpress_id ) !== get_current_user_id();
     18        && (int) get_post_field( 'post_author', $premiumpress_id ) !== get_current_user_id()
     19        && (bool) apply_filters( 'premiumpress_show_contact', true, $premiumpress_id );
    1920?>
    2021<?php if ( $premiumpress_contact ) : ?>
  • premiumpress-directory/tags/1.1.1/templates/my-listings.php

    r3837691 r3848540  
    3232                <?php if ( '' !== $premiumpress_submit ) : ?>
    3333                        <?php /* translators: %s: item name */ ?>
    34                         <a class="ppd-button wp-element-button" href="<?php echo esc_url( $premiumpress_submit ); ?>"><?php echo esc_html( sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $premiumpress_profile['singular'] ) ) ); ?></a>
     34                        <a class="ppd-button wp-element-button" href="<?php echo esc_url( $premiumpress_submit ); ?>"><?php echo esc_html( isset( $premiumpress_profile['add_title'] ) ? (string) $premiumpress_profile['add_title'] : sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $premiumpress_profile['singular'] ) ) ); ?></a>
    3535                <?php endif; ?>
    3636        </div>
    … …  
    5353                                        $premiumpress_state = array( 'draft', __( 'Draft', 'premiumpress-directory' ) );
    5454                                } else {
     55                                        $premiumpress_state = (array) apply_filters( 'premiumpress_account_state', array(), $premiumpress_id );
     56                                }
     57                                if ( ! $premiumpress_state ) {
    5558                                        $premiumpress_state = array( 'live', __( 'Live', 'premiumpress-directory' ) );
    5659                                }
    … …  
    7679                                                        <a href="<?php echo esc_url( add_query_arg( 'edit', $premiumpress_id, $premiumpress_submit ) ); ?>"><?php esc_html_e( 'Edit', 'premiumpress-directory' ); ?></a>
    7780                                                <?php endif; ?>
     81                                                <?php do_action( 'premiumpress_account_item_actions', $premiumpress_id, $premiumpress_item ); ?>
    7882                                                <?php if ( $premiumpress_expired ) : ?>
    7983                                                        <a href="<?php echo esc_url( PremiumPress_Submit::item_url( $premiumpress_id, 'renew' ) ); ?>"><?php esc_html_e( 'Renew', 'premiumpress-directory' ); ?></a>
    … …  
    8690                </ul>
    8791        <?php endif; ?>
     92
     93        <?php do_action( 'premiumpress_account_after_items', (int) $args['user_id'] ); ?>
    8894
    8995        <h2 class="ppd-account__title ppd-account__title--saved"><?php esc_html_e( 'Saved', 'premiumpress-directory' ); ?></h2>
  • premiumpress-directory/tags/1.1.1/templates/single-listing.php

    r3838627 r3848540  
    3737                continue;
    3838        }
    39         $premiumpress_value = PremiumPress_Profiles::display_value( $premiumpress_field, (string) get_post_meta( $premiumpress_id, $premiumpress_key, true ) );
     39        $premiumpress_value = PremiumPress_Profiles::display( (int) $premiumpress_id, $premiumpress_key, $premiumpress_field );
    4040        if ( '' !== $premiumpress_value ) {
    4141                $premiumpress_details[ (string) $premiumpress_field['label'] ] = $premiumpress_value;
    … …  
    131131                <div class="ppd-actions">
    132132                        <?php echo PremiumPress_Engage::fav_button( $premiumpress_id, 'ppd-fav-form--single' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in fav_button(). ?>
    133                         <a class="ppd-action" href="#ppd-reviews"><?php echo wp_kses( $premiumpress_icon( 'pencil' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Review', 'premiumpress-directory' ); ?></span></a>
     133                        <?php if ( PremiumPress_Engage::reviews_on() ) : ?>
     134                                <a class="ppd-action" href="#ppd-reviews"><?php echo wp_kses( $premiumpress_icon( 'pencil' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Review', 'premiumpress-directory' ); ?></span></a>
     135                        <?php endif; ?>
    134136                        <button type="button" class="ppd-action" data-ppd-share data-url="<?php echo esc_url( (string) get_permalink( $premiumpress_id ) ); ?>" data-title="<?php echo esc_attr( get_the_title( $premiumpress_id ) ); ?>" data-done="<?php esc_attr_e( 'Link copied', 'premiumpress-directory' ); ?>"><?php echo wp_kses( $premiumpress_icon( 'share' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Share', 'premiumpress-directory' ); ?></span></button>
    135137                        <a class="ppd-action" href="#ppd-report" data-ppd-open-report><?php echo wp_kses( $premiumpress_icon( 'flag' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Report', 'premiumpress-directory' ); ?></span></a>
    … …  
    157159                                <h1 class="ppd-single__title"><?php echo esc_html( get_the_title( $premiumpress_id ) ); ?></h1>
    158160                        <?php endif; ?>
     161                        <?php
     162                        // The price (or salary) under the title, for site types that have one on their cards.
     163                        $premiumpress_price = '';
     164                        foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) {
     165                                if ( ! empty( $premiumpress_field['money'] ) && ! empty( $premiumpress_field['card'] ) ) {
     166                                        $premiumpress_price = PremiumPress_Profiles::display( (int) $premiumpress_id, (string) $premiumpress_key, (array) $premiumpress_field );
     167                                        break;
     168                                }
     169                        }
     170                        ?>
     171                        <?php if ( '' !== $premiumpress_price ) : ?>
     172                                <p class="ppd-single__price"><?php echo esc_html( $premiumpress_price ); ?></p>
     173                        <?php endif; ?>
    159174                        <ul class="ppd-single__meta">
     175                                <?php $premiumpress_badge = (string) apply_filters( 'premiumpress_card_badge', '', $premiumpress_id ); ?>
     176                                <?php if ( '' !== $premiumpress_badge ) : ?>
     177                                        <li><span class="ppd-chip ppd-chip--status"><?php echo esc_html( $premiumpress_badge ); ?></span></li>
     178                                <?php endif; ?>
    160179                                <?php if ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?>
    161180                                        <li><span class="ppd-chip ppd-chip--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span></li>
    … …  
    264283                        <?php echo PremiumPress_Engage::reviews_html( $premiumpress_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?>
    265284
     285                        <?php do_action( 'premiumpress_single_after_content', $premiumpress_id ); ?>
     286
    266287                        <?php echo PremiumPress_Frontend::template( 'listing-forms', array( 'post_id' => $premiumpress_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?>
    267288                </div>
  • premiumpress-directory/tags/1.1.1/templates/submit-form.php

    r3838627 r3848540  
    9999                                        <?php
    100100                                        foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) :
    101                                                 $premiumpress_value = $premiumpress_meta( $premiumpress_key );
     101                                                $premiumpress_value = $premiumpress_id ? PremiumPress_Profiles::get_field( (int) $premiumpress_id, $premiumpress_key, $premiumpress_field ) : '';
    102102                                                $premiumpress_fid   = $premiumpress_uid . '-f-' . $premiumpress_key;
    103103                                                $premiumpress_type  = (string) ( $premiumpress_field['type'] ?? 'text' );
    … …  
    128128                                                                <legend><?php echo esc_html( $premiumpress_label ); ?><?php echo $premiumpress_req ? ' <span class="ppd-req" aria-hidden="true">*</span>' : ''; ?></legend>
    129129                                                                <div class="ppd-form__checks">
    130                                                                         <?php foreach ( (array) $premiumpress_field['options'] as $premiumpress_opt ) : ?>
    131                                                                                 <label><input type="checkbox" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>][]" value="<?php echo esc_attr( $premiumpress_opt ); ?>" <?php checked( in_array( $premiumpress_opt, array_map( 'trim', explode( ',', $premiumpress_value ) ), true ) ); ?>> <?php echo esc_html( $premiumpress_opt ); ?></label>
     130                                                                        <?php foreach ( PremiumPress_Profiles::options( $premiumpress_field ) as $premiumpress_opt => $premiumpress_opt_label ) : ?>
     131                                                                                <label><input type="checkbox" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>][]" value="<?php echo esc_attr( (string) $premiumpress_opt ); ?>" <?php checked( in_array( (string) $premiumpress_opt, array_map( 'trim', explode( ',', $premiumpress_value ) ), true ) ); ?>> <?php echo esc_html( $premiumpress_opt_label ); ?></label>
    132132                                                                        <?php endforeach; ?>
    133133                                                                </div>
    … …  
    138138                                                                <select id="<?php echo esc_attr( $premiumpress_fid ); ?>" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>]"<?php echo $premiumpress_req ? ' required' : ''; ?>>
    139139                                                                        <option value=""><?php esc_html_e( '— Choose —', 'premiumpress-directory' ); ?></option>
    140                                                                         <?php foreach ( (array) $premiumpress_field['options'] as $premiumpress_opt ) : ?>
    141                                                                                 <option value="<?php echo esc_attr( $premiumpress_opt ); ?>" <?php selected( $premiumpress_opt, $premiumpress_value ); ?>><?php echo esc_html( $premiumpress_opt ); ?></option>
     140                                                                        <?php foreach ( PremiumPress_Profiles::options( $premiumpress_field ) as $premiumpress_opt => $premiumpress_opt_label ) : ?>
     141                                                                                <option value="<?php echo esc_attr( (string) $premiumpress_opt ); ?>" <?php selected( (string) $premiumpress_opt, $premiumpress_value ); ?>><?php echo esc_html( $premiumpress_opt_label ); ?></option>
    142142                                                                        <?php endforeach; ?>
    143143                                                                </select>
  • premiumpress-directory/trunk/assets/css/frontend.css

    r3838627 r3848540  
    331331.ppd-card__facts {
    332332        margin: 0 0 4px;
     333        font-size: 0.95rem; /* the theme's body size is too big next to the card title */
     334        line-height: 1.4;
    333335        font-weight: 700;
    334336}
    … …  
    370372
    371373.ppd-search__field label,
     374.ppd-search__field legend,
    372375.ppd-sort label {
    373376        font-size: 0.8rem;
    … …  
    377380.ppd-search__form input[type="search"],
    378381.ppd-search__form input[type="text"],
     382.ppd-search__form input[type="number"],
    379383.ppd-search__form select,
    380384.ppd-sort select {
    … …  
    12481252}
    12491253
     1254.ppd-single__price {
     1255        margin: 0 0 10px;
     1256        font-size: 1.5rem;
     1257        font-weight: 700;
     1258        line-height: 1.2;
     1259}
     1260
    12501261.ppd-single__meta {
    12511262        display: flex;
    … …  
    14511462        font-size: 1.35rem;
    14521463}
     1464
     1465/* Sold / status badge (classifieds: Sold, jobs: Filled …) */
     1466.ppd-badge--status,
     1467.ppd-chip--status {
     1468        background: #1f2937;
     1469        border-color: #1f2937;
     1470        color: #fff;
     1471}
     1472
     1473.ppd-status--sold {
     1474        color: #1f2937;
     1475}
     1476
     1477/* Min–max range filters (price, salary …) */
     1478.ppd-search__field--range {
     1479        display: flex;
     1480        flex-direction: column;
     1481        gap: 4px;
     1482        border: 0;
     1483        margin: 0;
     1484        padding: 0;
     1485        min-width: 0;
     1486}
     1487
     1488.ppd-search__field--range legend {
     1489        padding: 0;
     1490        margin-bottom: 0;
     1491        float: left;
     1492        width: 100%;
     1493}
     1494
     1495.ppd-search__range {
     1496        display: flex;
     1497        align-items: center;
     1498        gap: 6px;
     1499}
     1500
     1501.ppd-search__range input {
     1502        width: 100%;
     1503        min-width: 0;
     1504}
  • premiumpress-directory/trunk/blocks/listings/block.json

    r3837691 r3848540  
    77        "icon": "location-alt",
    88        "description": "A grid of directory listings, optionally filtered by category, location or tag.",
    9         "keywords": [ "directory", "listings", "grid" ],
     9        "keywords": [
     10                "directory",
     11                "listings",
     12                "grid"
     13        ],
    1014        "textdomain": "premiumpress-directory",
    1115        "attributes": {
    12                 "number": { "type": "number", "default": 12 },
    13                 "columns": { "type": "number", "default": 3 },
    14                 "category": { "type": "string", "default": "" },
    15                 "location": { "type": "string", "default": "" },
    16                 "tag": { "type": "string", "default": "" },
    17                 "orderby": { "type": "string", "default": "date", "enum": [ "date", "title", "rand", "rating" ] },
    18                 "excerpt": { "type": "boolean", "default": true },
    19                 "pagination": { "type": "boolean", "default": false }
     16                "number": {
     17                        "type": "number",
     18                        "default": 12
     19                },
     20                "columns": {
     21                        "type": "number",
     22                        "default": 3
     23                },
     24                "category": {
     25                        "type": "string",
     26                        "default": ""
     27                },
     28                "location": {
     29                        "type": "string",
     30                        "default": ""
     31                },
     32                "tag": {
     33                        "type": "string",
     34                        "default": ""
     35                },
     36                "orderby": {
     37                        "type": "string",
     38                        "default": "date",
     39                        "enum": [
     40                                "date",
     41                                "title",
     42                                "rand",
     43                                "rating"
     44                        ]
     45                },
     46                "excerpt": {
     47                        "type": "boolean",
     48                        "default": true
     49                },
     50                "pagination": {
     51                        "type": "boolean",
     52                        "default": false
     53                }
    2054        },
    2155        "supports": {
    2256                "html": false,
    23                 "align": [ "wide", "full" ],
    24                 "spacing": { "margin": true, "padding": true }
     57                "align": [
     58                        "wide",
     59                        "full"
     60                ],
     61                "spacing": {
     62                        "margin": true,
     63                        "padding": true
     64                }
    2565        },
    2666        "editorScript": "file:./index.js",
  • premiumpress-directory/trunk/blocks/my-listings/block.json

    r3837691 r3848540  
    77        "icon": "id",
    88        "description": "A member's own listings with edit, renew and delete, plus their saved favourites.",
    9         "keywords": [ "directory", "account", "dashboard", "favourites" ],
     9        "keywords": [
     10                "directory",
     11                "account",
     12                "dashboard",
     13                "favourites"
     14        ],
    1015        "textdomain": "premiumpress-directory",
    11         "supports": { "html": false, "multiple": false },
     16        "supports": {
     17                "html": false,
     18                "multiple": false
     19        },
    1220        "editorScript": "file:./index.js",
    1321        "style": "premiumpress-frontend"
  • premiumpress-directory/trunk/blocks/search/block.json

    r3837691 r3848540  
    77        "icon": "search",
    88        "description": "A search form with results: keyword, category, location, distance and a map.",
    9         "keywords": [ "directory", "search", "map", "near me" ],
     9        "keywords": [
     10                "directory",
     11                "search",
     12                "map",
     13                "near me"
     14        ],
    1015        "textdomain": "premiumpress-directory",
    1116        "attributes": {
    12                 "number": { "type": "number", "default": 12 },
    13                 "columns": { "type": "number", "default": 3 },
    14                 "map": { "type": "boolean", "default": true }
     17                "number": {
     18                        "type": "number",
     19                        "default": 12
     20                },
     21                "columns": {
     22                        "type": "number",
     23                        "default": 3
     24                },
     25                "map": {
     26                        "type": "boolean",
     27                        "default": true
     28                }
    1529        },
    1630        "supports": {
    1731                "html": false,
    1832                "multiple": false,
    19                 "align": [ "wide", "full" ],
    20                 "spacing": { "margin": true, "padding": true }
     33                "align": [
     34                        "wide",
     35                        "full"
     36                ],
     37                "spacing": {
     38                        "margin": true,
     39                        "padding": true
     40                }
    2141        },
    2242        "editorScript": "file:./index.js",
  • premiumpress-directory/trunk/blocks/submit/block.json

    r3837691 r3848540  
    77        "icon": "plus-alt",
    88        "description": "The form members use to add or edit their own listing.",
    9         "keywords": [ "directory", "submit", "add listing", "form" ],
     9        "keywords": [
     10                "directory",
     11                "submit",
     12                "add listing",
     13                "form"
     14        ],
    1015        "textdomain": "premiumpress-directory",
    11         "supports": { "html": false, "multiple": false },
     16        "supports": {
     17                "html": false,
     18                "multiple": false
     19        },
    1220        "editorScript": "file:./index.js",
    1321        "style": "premiumpress-frontend"
  • premiumpress-directory/trunk/includes/class-premiumpress-admin-editor.php

    r3838627 r3848540  
    4949
    5050        public function menu(): void {
    51                 $hook = add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Edit listing', 'premiumpress-directory' ), '', 'edit_posts', self::PAGE, array( $this, 'render' ) );
     51                $hook = add_submenu_page( PremiumPress_Admin_UI::parent(), sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Edit %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), '', 'edit_posts', self::PAGE, array( $this, 'render' ) );
    5252                // Hidden from the menu only after WordPress has checked access (admin_head).
    5353                add_action(
    … …  
    6262                                static function () {
    6363                                        global $title;
    64                                         $title = __( 'Edit listing', 'premiumpress-directory' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- the admin page title WordPress lost.
     64                                        $title = sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Edit %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- the admin page title WordPress lost.
    6565                                }
    6666                        );
    … …  
    113113                                'max'       => self::MAX_IMAGES,
    114114                                'pick'      => __( 'Choose photos', 'premiumpress-directory' ),
    115                                 'use'       => __( 'Add to listing', 'premiumpress-directory' ),
     115                                'use'       => sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Add to %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ),
    116116                                'main'      => __( 'Main photo', 'premiumpress-directory' ),
    117117                                'remove'    => __( 'Remove photo', 'premiumpress-directory' ),
    … …  
    167167                if ( $skip ) {
    168168                        /* translators: %d: number of photos */
    169                         echo '<div class="ppd-a-note ppd-a-note--warn">' . esc_html( sprintf( _n( '%d photo already belongs to another listing, so it stays there. Upload a copy to use it here too.', '%d photos already belong to another listing, so they stay there. Upload a copy to use them here too.', $skip, 'premiumpress-directory' ), $skip ) ) . '</div>';
     169                        echo '<div class="ppd-a-note ppd-a-note--warn">' . esc_html( sprintf( /* translators: 1: number, 2: singular item name, lowercase */ _n( '%1$d photo already belongs to another %2$s, so it stays there. Upload a copy to use it here too.', '%1$d photos already belong to another %2$s, so they stay there. Upload a copy to use them here too.', $skip, 'premiumpress-directory' ), $skip, PremiumPress_Profiles::one() ) ) . '</div>';
    170170                }
    171171                if ( 'title' === $err ) {
    … …  
    217217
    218218                // 1. Basics.
    219                 self::panel_open( 1, 'comment', __( 'About your listing', 'premiumpress-directory' ), __( 'Give it a clear name and say what makes it stand out.', 'premiumpress-directory' ) );
     219                self::panel_open( 1, 'comment', sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'About your %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), __( 'Give it a clear name and say what makes it stand out.', 'premiumpress-directory' ) );
    220220                echo '<label class="ppd-ed-label" for="ppd-ed-title">' . esc_html__( 'Title', 'premiumpress-directory' ) . ' <span class="ppd-ed-req">*</span></label><input type="text" id="ppd-ed-title" class="ppd-ed-input ppd-ed-input--big" name="ppd_title" value="' . esc_attr( 'auto-draft' === $post->post_status ? '' : $post->post_title ) . '" maxlength="200" required data-ppd-check="title">';
    221221                echo '<label class="ppd-ed-label" for="ppd_content">' . esc_html__( 'Description', 'premiumpress-directory' ) . '</label><div class="ppd-ed-editor" data-ppd-check="content">';
    … …  
    341341                        echo '</div><p class="ppd-ed-tip">';
    342342                        PremiumPress_Admin_UI::e_icon( 'info', 18 );
    343                         echo ' ' . esc_html__( 'Shown as buttons on the listing page. Leave any of them empty to hide its button.', 'premiumpress-directory' ) . '</p>';
     343                        echo ' ' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Shown as buttons on the %s page. Leave any of them empty to hide its button.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p>';
    344344                        self::panel_close( 5, $order );
    345345                }
    … …  
    461461                $id = (int) $post->ID;
    462462                echo '<section class="ppd-a-card ppd-a-pad ppd-ed-side"><div class="ppd-ed-ring"><svg viewBox="0 0 36 36" aria-hidden="true" focusable="false"><circle cx="18" cy="18" r="15.5" class="ppd-ed-ring-bg"/><circle cx="18" cy="18" r="15.5" class="ppd-ed-ring-fg" data-ppd-ring pathLength="100" stroke-dasharray="0 100"/></svg><b data-ppd-pct>0%</b></div>';
    463                 echo '<div class="ppd-ed-ringcopy"><strong>' . esc_html__( 'Your listing', 'premiumpress-directory' ) . '</strong><span>' . esc_html__( 'Complete listings get more views.', 'premiumpress-directory' ) . '</span></div>';
     463                echo '<div class="ppd-ed-ringcopy"><strong>' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Your %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</strong><span>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Complete %s get more views.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</span></div>';
    464464                echo '<ul class="ppd-ed-checks">';
    465465                $checks = array(
  • premiumpress-directory/trunk/includes/class-premiumpress-admin-listings.php

    r3838627 r3848540  
    339339                echo '</select><button type="submit" class="ppd-a-btn">' . esc_html__( 'Apply', 'premiumpress-directory' ) . '</button></div>';
    340340
    341                 echo '<div class="ppd-a-tablewrap"><table class="ppd-a-table ppd-a-table--listings"><thead><tr><th class="ppd-a-check"><input type="checkbox" data-ppd-checkall aria-label="' . esc_attr__( 'Select all', 'premiumpress-directory' ) . '"></th><th>' . esc_html__( 'Name', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Photos', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Reviews', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Status', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Complete', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Featured', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Date', 'premiumpress-directory' ) . '</th><th><span class="screen-reader-text">' . esc_html__( 'Actions', 'premiumpress-directory' ) . '</span></th></tr></thead><tbody>';
     341                echo '<div class="ppd-a-tablewrap"><table class="ppd-a-table ppd-a-table--listings"><thead><tr><th class="ppd-a-check"><input type="checkbox" data-ppd-checkall aria-label="' . esc_attr__( 'Select all', 'premiumpress-directory' ) . '"></th><th>' . esc_html__( 'Name', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Photos', 'premiumpress-directory' ) . '</th>' . ( PremiumPress_Engage::reviews_on() ? '<th>' . esc_html__( 'Reviews', 'premiumpress-directory' ) . '</th>' : '' ) . '<th>' . esc_html__( 'Status', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Complete', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Featured', 'premiumpress-directory' ) . '</th><th>' . esc_html__( 'Date', 'premiumpress-directory' ) . '</th><th><span class="screen-reader-text">' . esc_html__( 'Actions', 'premiumpress-directory' ) . '</span></th></tr></thead><tbody>';
    342342                $pills = array(
    343343                        'publish' => array( __( 'Published', 'premiumpress-directory' ), 'green' ),
    … …  
    369369                        PremiumPress_Admin_UI::e_icon( 'image', 15 );
    370370                        echo ' ' . esc_html( number_format_i18n( count( PremiumPress_Listing::image_ids( $id ) ) ) ) . '</span></td>';
    371                         echo '<td class="ppd-a-meta">' . ( $stats['count'] ? '<span class="ppd-a-stars-sm">★</span> ' . esc_html( number_format_i18n( $stats['avg'], 1 ) ) . ' <small>(' . esc_html( number_format_i18n( $stats['count'] ) ) . ')</small>' : '<span class="ppd-a-muted">—</span>' ) . '</td>';
     371                        if ( PremiumPress_Engage::reviews_on() ) {
     372                                echo '<td class="ppd-a-meta">' . ( $stats['count'] ? '<span class="ppd-a-stars-sm">★</span> ' . esc_html( number_format_i18n( $stats['avg'], 1 ) ) . ' <small>(' . esc_html( number_format_i18n( $stats['count'] ) ) . ')</small>' : '<span class="ppd-a-muted">—</span>' ) . '</td>';
     373                        }
    372374                        echo '<td>' . wp_kses_post( PremiumPress_Admin_UI::pill( $pill[0], $pill[1] ) ) . '</td>';
    373375                        echo '<td><span class="ppd-a-bar"><span class="ppd-a-bar-in ppd-a-bar--' . ( $pct >= 70 ? 'green' : ( $pct >= 40 ? 'orange' : 'red' ) ) . '" style="width:' . esc_attr( (string) $pct ) . '%"></span></span><b class="ppd-a-pct">' . esc_html( $pct . '%' ) . '</b></td>';
    … …  
    513515                                if ( current_user_can( $obj->cap->delete_terms ) && (int) get_option( 'default_' . $tax ) !== (int) $t->term_id ) {
    514516                                        /* translators: %s: term name */
    515                                         echo '<a class="is-danger" data-ppd-confirm="' . esc_attr( sprintf( __( 'Delete "%s"? Listings in it are kept.', 'premiumpress-directory' ), $t->name ) ) . '" href="' . esc_url( self::term_url( 'delete', $tax, (int) $t->term_id ) ) . '">' . esc_html__( 'Delete', 'premiumpress-directory' ) . '</a>';
     517                                        echo '<a class="is-danger" data-ppd-confirm="' . esc_attr( sprintf( /* translators: 1: category or location name, 2: plural item name, e.g. Listings */ __( 'Delete "%1$s"? %2$s in it are kept.', 'premiumpress-directory' ), $t->name, PremiumPress_Profiles::many( true ) ) ) . '" href="' . esc_url( self::term_url( 'delete', $tax, (int) $t->term_id ) ) . '">' . esc_html__( 'Delete', 'premiumpress-directory' ) . '</a>';
    516518                                }
    517519                                echo '</td></tr>';
    … …  
    571573                wp_nonce_field( self::A_TERM . '_edit_' . $tax . '_' . $id );
    572574                /* translators: %s: number of listings */
    573                 echo '<div class="ppd-a-sect-copy"><h2>' . esc_html( $t->name ) . '</h2><p>' . esc_html( sprintf( _n( 'Used on %s listing.', 'Used on %s listings.', (int) $t->count, 'premiumpress-directory' ), number_format_i18n( (int) $t->count ) ) ) . '</p>';
     575                echo '<div class="ppd-a-sect-copy"><h2>' . esc_html( $t->name ) . '</h2><p>' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'Used on %1$s %2$s.', 'Used on %1$s %2$s.', (int) $t->count, 'premiumpress-directory' ), number_format_i18n( (int) $t->count ), ( 1 === (int) $t->count ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</p>';
    574576                $link = get_term_link( $t );
    575577                if ( ! is_wp_error( $link ) ) {
  • premiumpress-directory/trunk/includes/class-premiumpress-admin-reviews.php

    r3838627 r3848540  
    4242
    4343        public function menu(): void {
    44                 add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Reviews', 'premiumpress-directory' ), __( 'Reviews', 'premiumpress-directory' ), 'moderate_comments', self::PAGE, array( $this, 'render' ), 5 );
     44                if ( PremiumPress_Engage::reviews_on() ) {
     45                        add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Reviews', 'premiumpress-directory' ), __( 'Reviews', 'premiumpress-directory' ), 'moderate_comments', self::PAGE, array( $this, 'render' ), 5 );
     46                }
    4547                add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Members', 'premiumpress-directory' ), '', 'list_users', self::MEMBERS, array( $this, 'render_members' ) );
    4648                add_action(
    … …  
    255257                $total = (int) get_comments( array_merge( $args, array( 'count' => true, 'number' => 0, 'offset' => 0 ) ) );
    256258
    257                 PremiumPress_Admin_UI::open( 'reviews', __( 'Reviews', 'premiumpress-directory' ), __( 'Reviews left across your directory.', 'premiumpress-directory' ) );
     259                PremiumPress_Admin_UI::open( 'reviews', __( 'Reviews', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Reviews left across your %s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    258260                if ( $done >= 0 && isset( self::actions()[ $did ] ) ) {
    259261                        /* translators: 1: number, 2: action, e.g. Approve */
    … …  
    286288                        echo '<div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">';
    287289                        PremiumPress_Admin_UI::e_icon( 'star', 22 );
    288                         echo '</span><strong>' . esc_html__( 'No reviews here', 'premiumpress-directory' ) . '</strong><span>' . esc_html__( 'Reviews appear here as visitors leave them on your listings.', 'premiumpress-directory' ) . '</span></div></section>';
     290                        echo '</span><strong>' . esc_html__( 'No reviews here', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Reviews appear here as visitors leave them on your %s.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</span></div></section>';
    289291                        PremiumPress_Admin_UI::close();
    290292                        return;
    … …  
    328330                                echo '<a href="' . esc_url( self::edit_url( $id ) ) . '">' . esc_html__( 'Edit', 'premiumpress-directory' ) . '</a>';
    329331                                if ( '1' === $state && 'publish' === get_post_status( $pid ) ) {
    330                                         echo '<a href="' . esc_url( (string) get_comment_link( $c ) ) . '" target="_blank" rel="noopener">' . esc_html__( 'View on the listing', 'premiumpress-directory' ) . '</a>';
     332                                        echo '<a href="' . esc_url( (string) get_comment_link( $c ) ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'View on the %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</a>';
    331333                                }
    332334                                echo '<a href="' . esc_url( self::one_url( $id, 'spam' ) ) . '">' . esc_html__( 'Mark as spam', 'premiumpress-directory' ) . '</a><a class="is-danger" href="' . esc_url( self::one_url( $id, 'trash' ) ) . '">' . esc_html__( 'Move to trash', 'premiumpress-directory' ) . '</a>';
  • premiumpress-directory/trunk/includes/class-premiumpress-admin-ui.php

    r3838627 r3848540  
    6464        /** The screens that wear this look, by their `page` value. */
    6565        public static function pages(): array {
    66                 return array( self::OVERVIEW, self::HUB, PremiumPress_Admin_Reviews::PAGE, PremiumPress_Admin_Reviews::MEMBERS, PremiumPress_Settings::SETUP, self::LISTINGS, self::TAXONOMIES, PremiumPress_Fields::PAGE, PremiumPress_Admin_Editor::PAGE, PremiumPress_Engage::REPORTS_PAGE, PremiumPress_Porting::PAGE, PremiumPress_Settings::PAGE, PremiumPress_Design::PAGE );
     66                /** A plugin's own screens (e.g. Applications) wear the same look. */
     67                return (array) apply_filters( 'premiumpress_admin_pages', array( self::OVERVIEW, self::HUB, PremiumPress_Admin_Reviews::PAGE, PremiumPress_Admin_Reviews::MEMBERS, PremiumPress_Settings::SETUP, self::LISTINGS, self::TAXONOMIES, PremiumPress_Fields::PAGE, PremiumPress_Admin_Editor::PAGE, PremiumPress_Engage::REPORTS_PAGE, PremiumPress_Porting::PAGE, PremiumPress_Settings::PAGE, PremiumPress_Design::PAGE ) );
    6768        }
    6869
    … …  
    215216                $out = array(
    216217                        array( 't' => __( 'Overview', 'premiumpress-directory' ), 'd' => __( 'What is new and what needs your attention', 'premiumpress-directory' ), 'u' => self::url( self::OVERVIEW ) ),
    217                         array( 't' => (string) $p['plural'], 'd' => __( 'Manage every listing', 'premiumpress-directory' ), 'u' => self::url( self::LISTINGS ) ),
     218                        array( 't' => (string) $p['plural'], 'd' => sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Manage every %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), 'u' => self::url( self::LISTINGS ) ),
    218219                        /* translators: %s: singular item name, e.g. Listing */
    219220                        array( 't' => sprintf( __( 'Add %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['singular'] ) ), 'd' => __( 'Open the editor for a new one', 'premiumpress-directory' ), 'u' => PremiumPress_Admin_Editor::url( 0, array( 'new' => 1 ) ) ),
    220221                        array( 't' => __( 'Taxonomies', 'premiumpress-directory' ), 'd' => __( 'Categories, locations and tags', 'premiumpress-directory' ), 'u' => self::url( self::TAXONOMIES ) ),
    221                         array( 't' => __( 'Reviews', 'premiumpress-directory' ), 'd' => __( 'Approve, edit or remove reviews', 'premiumpress-directory' ), 'u' => PremiumPress_Admin_Reviews::url() ),
     222                        ...( PremiumPress_Engage::reviews_on() ? array( array( 't' => __( 'Reviews', 'premiumpress-directory' ), 'd' => __( 'Approve, edit or remove reviews', 'premiumpress-directory' ), 'u' => PremiumPress_Admin_Reviews::url() ) ) : array() ),
    222223                        array( 't' => __( 'Members', 'premiumpress-directory' ), 'd' => __( 'Everyone with an account', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Admin_Reviews::MEMBERS ) ),
    223224                        array( 't' => __( 'Reports', 'premiumpress-directory' ), 'd' => __( 'Things visitors have flagged', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Engage::REPORTS_PAGE ) ),
    224                         array( 't' => __( 'Import / Export', 'premiumpress-directory' ), 'd' => __( 'Spreadsheets in and out, and moving from another directory plugin', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Porting::PAGE ) ),
     225                        array( 't' => __( 'Import / Export', 'premiumpress-directory' ), 'd' => ( PremiumPress_Switch::names() ? __( 'Spreadsheets in and out, and moving from another directory plugin', 'premiumpress-directory' ) : __( 'Spreadsheets in and out', 'premiumpress-directory' ) ), 'u' => self::url( PremiumPress_Porting::PAGE ) ),
    225226                        array( 't' => __( 'Design', 'premiumpress-directory' ), 'd' => __( 'WordPress style or the built-in design', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Design::PAGE ) ),
    226                         array( 't' => __( 'Settings', 'premiumpress-directory' ), 'd' => __( 'How your directory works', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Settings::PAGE ) ),
     227                        array( 't' => __( 'Settings', 'premiumpress-directory' ), 'd' => sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'How your %s works', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ), 'u' => self::url( PremiumPress_Settings::PAGE ) ),
    227228                        array( 't' => __( 'Setup wizard', 'premiumpress-directory' ), 'd' => __( 'Answer a few questions to set up the basics', 'premiumpress-directory' ), 'u' => PremiumPress_Wizard::url() ),
    228229                        array( 't' => __( 'Upgrade', 'premiumpress-directory' ), 'd' => __( 'What the PremiumPress theme adds', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Settings::PAGE, array( 'tab' => 'upgrade' ) ) ),
    … …  
    376377                        unset( $rows['reviews'], $rows['reports'] );
    377378                }
    378                 return $rows;
     379                if ( ! PremiumPress_Engage::reviews_on() ) {
     380                        unset( $rows['reviews'] );
     381                }
     382                /** A plugin's own screens add their sidebar rows: key => [label, url, icon, count]. */
     383                return (array) apply_filters( 'premiumpress_admin_nav', $rows );
    379384        }
    380385
    … …  
    397402
    398403                // Sidebar.
    399                 echo '<aside class="ppd-a-side" id="ppd-a-side" aria-label="' . esc_attr__( 'Directory menu', 'premiumpress-directory' ) . '"><div class="ppd-a-side-in">';
     404                echo '<aside class="ppd-a-side" id="ppd-a-side" aria-label="' . esc_attr( sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s menu', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ) ) . '"><div class="ppd-a-side-in">';
    400405                echo '<div class="ppd-a-brand"><span class="ppd-a-logo" aria-hidden="true">PP</span><span class="ppd-a-brandmeta"><span class="ppd-a-brandname">' . esc_html__( 'Dashboard', 'premiumpress-directory' ) . '</span>';
    401406                /* translators: %s: profile menu name, e.g. Directory */
    … …  
    515520                                        /* translators: %s: plural item name, lowercase */
    516521                                        array( 'clock', __( 'Setup & Expiry', 'premiumpress-directory' ), sprintf( __( 'What needs your approval, how long %s stay live, and the terms people agree to.', 'premiumpress-directory' ), $many ), PremiumPress_Settings::section_url( 'listings' ), 0, 'manage_options' ),
    517                                         array( 'star', __( 'Reviews', 'premiumpress-directory' ), __( 'Approve, edit or remove the reviews visitors leave.', 'premiumpress-directory' ), PremiumPress_Admin_Reviews::url(), $waiting, 'moderate_comments' ),
     522                                        ...( PremiumPress_Engage::reviews_on() ? array( array( 'star', __( 'Reviews', 'premiumpress-directory' ), __( 'Approve, edit or remove the reviews visitors leave.', 'premiumpress-directory' ), PremiumPress_Admin_Reviews::url(), $waiting, 'moderate_comments' ) ) : array() ),
    518523                                ),
    519524                        ),
    … …  
    528533                                        array( 'file', __( 'Custom Fields', 'premiumpress-directory' ), sprintf( __( 'The extra details asked for on each %s, and where they show.', 'premiumpress-directory' ), $one ), self::url( PremiumPress_Fields::PAGE ), 0, 'manage_options' ),
    529534                                        /* translators: %s: plural item name, lowercase */
    530                                         array( 'upload', __( 'Import / Export', 'premiumpress-directory' ), sprintf( __( 'Bring %s in from a file or another directory plugin, or download them as a spreadsheet.', 'premiumpress-directory' ), $many ), self::url( PremiumPress_Porting::PAGE ), 0, 'manage_options' ),
     535                                        array( 'upload', __( 'Import / Export', 'premiumpress-directory' ), sprintf( ( PremiumPress_Switch::names() ? __( 'Bring %s in from a file or another directory plugin, or download them as a spreadsheet.', 'premiumpress-directory' ) : __( 'Bring %s in from a file, or download them as a spreadsheet.', 'premiumpress-directory' ) ), $many ), self::url( PremiumPress_Porting::PAGE ), 0, 'manage_options' ),
    531536                                ),
    532537                        ),
    … …  
    737742                        array( 'list', 'blue', (string) $p['plural'], self::daily_listings( 30 ), self::daily_listings( 30, 30 ), self::url( self::LISTINGS ), __( 'View all', 'premiumpress-directory' ), (int) wp_count_posts( PremiumPress_Post_Types::TYPE )->publish ),
    738743                        array( 'users', 'green', __( 'Members', 'premiumpress-directory' ), self::daily_members( 30 ), self::daily_members( 30, 30 ), self::url( PremiumPress_Admin_Reviews::MEMBERS ), __( 'View all', 'premiumpress-directory' ), (int) count_users()['total_users'] ),
    739                         array( 'star', 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( 30 ), self::daily_reviews( 30, 30 ), PremiumPress_Admin_Reviews::url(), __( 'View all', 'premiumpress-directory' ), (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'approve', 'count' => true ) ) ),
     744                        ...( PremiumPress_Engage::reviews_on() ? array( array( 'star', 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( 30 ), self::daily_reviews( 30, 30 ), PremiumPress_Admin_Reviews::url(), __( 'View all', 'premiumpress-directory' ), (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'approve', 'count' => true ) ) ) ) : array() ),
    740745                        array( 'flag', 'purple', __( 'Reports', 'premiumpress-directory' ), self::daily_reports( 30 ), self::daily_reports( 30, 30 ), self::url( PremiumPress_Engage::REPORTS_PAGE ), __( 'View all', 'premiumpress-directory' ), PremiumPress_Engage::open_reports() ),
    741746                );
    … …  
    781786                self::moderation_card();
    782787                self::status_card();
    783                 self::recent_reviews_card();
     788                if ( PremiumPress_Engage::reviews_on() ) {
     789                        self::recent_reviews_card();
     790                }
    784791                echo '</div></div>';
    785792
    … …  
    789796        private static function moderation_card(): void {
    790797                $pending = (int) wp_count_posts( PremiumPress_Post_Types::TYPE )->pending;
    791                 $reviews = (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'hold', 'count' => true ) );
     798                $reviews = PremiumPress_Engage::reviews_on() ? (int) get_comments( array( 'type' => PremiumPress_Engage::REVIEW_TYPE, 'status' => 'hold', 'count' => true ) ) : 0;
    792799                $reports = PremiumPress_Engage::open_reports();
    793800                $p       = PremiumPress_Profiles::current();
    … …  
    801808                        $rows = array(
    802809                                array( (string) $p['plural'], $pending, self::url( self::LISTINGS, array( 'status' => 'pending' ) ) ),
    803                                 array( __( 'Reviews', 'premiumpress-directory' ), $reviews, PremiumPress_Admin_Reviews::url( array( 'status' => 'hold' ) ) ),
     810                                ...( PremiumPress_Engage::reviews_on() ? array( array( __( 'Reviews', 'premiumpress-directory' ), $reviews, PremiumPress_Admin_Reviews::url( array( 'status' => 'hold' ) ) ) ) : array() ),
    804811                                array( __( 'Reports', 'premiumpress-directory' ), $reports, self::url( PremiumPress_Engage::REPORTS_PAGE ) ),
    805812                        );
    … …  
    846853                        array( 'ring', __( 'Expiring within 30 days', 'premiumpress-directory' ), $expiring, 'publish' ),
    847854                );
    848                 echo '<section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html__( 'Listing status', 'premiumpress-directory' ) . '</h2><ul class="ppd-a-rows">';
     855                echo '<section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html( sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s status', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ) ) . '</h2><ul class="ppd-a-rows">';
    849856                foreach ( $rows as $r ) {
    850857                        echo '<li><a href="' . esc_url( self::url( self::LISTINGS, array( 'status' => $r[3] ) ) ) . '"><span class="ppd-a-dot ppd-a-dot--' . esc_attr( $r[0] ) . '"></span>' . esc_html( $r[1] ) . '<b>' . esc_html( number_format_i18n( $r[2] ) ) . '</b>';
    … …  
    10011008                        'members'  => __( 'Members', 'premiumpress-directory' ),
    10021009                );
     1010                if ( ! PremiumPress_Engage::reviews_on() ) {
     1011                        unset( $labels['reviews'] );
     1012                }
    10031013                foreach ( $labels as $k => $label ) {
    10041014                        echo '<a class="ppd-a-tab' . ( $k === $tab ? ' is-active' : '' ) . '" href="' . esc_url( self::url( self::OVERVIEW, array( 'feed' => $k ) ) . '#ppd-recent' ) . '">' . esc_html( $label ) . ' <span class="ppd-a-tabcount">' . esc_html( number_format_i18n( $counts[ $k ] ) ) . '</span></a>';
    … …  
    10721082                        array( 'blue', (string) $p['plural'], self::daily_listings( $days ) ),
    10731083                        array( 'green', __( 'Members', 'premiumpress-directory' ), self::daily_members( $days ) ),
    1074                         array( 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( $days ) ),
     1084                        ...( PremiumPress_Engage::reviews_on() ? array( array( 'orange', __( 'Reviews', 'premiumpress-directory' ), self::daily_reviews( $days ) ) ) : array() ),
    10751085                );
    10761086                $max = 1;
    … …  
    11241134                $p = PremiumPress_Profiles::current();
    11251135                $n = array();
    1126                 if ( 'directory' === PremiumPress_Profiles::current_key() ) {
     1136                if ( PremiumPress_Wizard::niches() ) {
    11271137                        $n[] = __( 'What it is about', 'premiumpress-directory' );
    11281138                }
    … …  
    11421152                self::e_icon( 'sparkle', 16 );
    11431153                echo esc_html__( 'Setup wizard', 'premiumpress-directory' ) . '</span>';
    1144                 echo '<h2 id="ppd-a-cta-h">' . esc_html( $done ? __( 'Change how your directory is set up', 'premiumpress-directory' ) : __( 'Set up your directory in a few minutes', 'premiumpress-directory' ) ) . '</h2>';
    1145                 echo '<p>' . esc_html( $done ? __( 'Run the setup again any time to change what it is about, the town, the homepage or the design.', 'premiumpress-directory' ) : __( 'Answer a few plain questions and your directory is ready for visitors. Nothing is sent anywhere, and you can change every answer later.', 'premiumpress-directory' ) ) . '</p>';
     1154                echo '<h2 id="ppd-a-cta-h">' . esc_html( $done ? sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Change how your %s is set up', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) : sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Set up your %s in a few minutes', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h2>';
     1155                echo '<p>' . esc_html( $done ? __( 'Run the setup again any time to change what it is about, the town, the homepage or the design.', 'premiumpress-directory' ) : sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Answer a few plain questions and your %s is ready for visitors. Nothing is sent anywhere, and you can change every answer later.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    11461156                echo '<ol class="ppd-a-cta-steps">';
    11471157                foreach ( self::setup_names() as $i => $name ) {
    … …  
    11621172                self::e_icon( 'sparkle', 20 );
    11631173                echo '</span><h2>' . esc_html__( 'Setup wizard', 'premiumpress-directory' ) . '</h2></div>';
    1164                 echo '<p>' . esc_html( $done ? __( 'Change what your directory is about, the town, the homepage or the design.', 'premiumpress-directory' ) : __( 'A few plain questions and your directory is ready for visitors.', 'premiumpress-directory' ) ) . '</p>';
     1174                echo '<p>' . esc_html( $done ? sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Change what your %s is about, the town, the homepage or the design.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) : sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'A few plain questions and your %s is ready for visitors.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    11651175                echo '<a class="ppd-a-btn ppd-a-btn--primary ppd-a-btn--block" href="' . esc_url( PremiumPress_Wizard::url() ) . '">' . esc_html( $done ? __( 'Open the setup wizard', 'premiumpress-directory' ) : __( 'Start the setup wizard', 'premiumpress-directory' ) ) . '</a></section>';
    11661176        }
  • premiumpress-directory/trunk/includes/class-premiumpress-compat.php

    r3837691 r3848540  
    3131                }
    3232                echo '<div class="notice notice-info is-dismissible"><p>';
    33                 echo esc_html__( 'PremiumPress Directory is paused because your PremiumPress theme now manages your listings, reviews and favourites. Nothing has been lost — you can deactivate this plugin.', 'premiumpress-directory' );
     33                $many = mb_strtolower( (string) PremiumPress_Profiles::current()['plural'] );
     34                echo esc_html(
     35                        sprintf(
     36                                /* translators: 1: plugin name, 2: plural item name, lowercase */
     37                                __( '%1$s is paused because your PremiumPress theme now manages your %2$s and favourites. Nothing has been lost — you can deactivate this plugin.', 'premiumpress-directory' ),
     38                                PREMIUMPRESS_NAME,
     39                                $many
     40                        )
     41                );
     42                echo '</p></div>';
     43        }
     44
     45        /**
     46         * The other PremiumPress listings plugins. Each exposes `running()` once it has
     47         * taken charge; the original Directory plugin is treated as running whenever it
     48         * is active.
     49         */
     50        const SIBLINGS = array( 'PremiumPress' . '_Plugin', 'PPClassifieds' . '_Plugin', 'PPJobBoard' . '_Plugin', 'PPRealEstate' . '_Plugin' );
     51
     52        /** Is another PremiumPress listings plugin already in charge on this request? */
     53        public static function sibling_active(): bool {
     54                foreach ( self::SIBLINGS as $class ) {
     55                        if ( str_replace( '_Compat', '_Plugin', __CLASS__ ) === $class || ! class_exists( $class, false ) ) {
     56                                continue;
     57                        }
     58                        if ( ! method_exists( $class, 'running' ) || $class::running() ) {
     59                                return true;
     60                        }
     61                }
     62                return false;
     63        }
     64
     65        public static function register_sibling_notice(): void {
     66                add_action( 'admin_notices', array( __CLASS__, 'sibling_notice' ) );
     67        }
     68
     69        public static function sibling_notice(): void {
     70                $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
     71                if ( ! $screen || 'plugins' !== $screen->id || ! current_user_can( 'activate_plugins' ) ) {
     72                        return;
     73                }
     74                echo '<div class="notice notice-warning"><p>';
     75                /* translators: %s: plugin name */
     76                echo esc_html( sprintf( __( '%s is paused because another PremiumPress listings plugin is active. They share the same listings, so please keep only one of them active.', 'premiumpress-directory' ), PREMIUMPRESS_NAME ) );
    3477                echo '</p></div>';
    3578        }
  • premiumpress-directory/trunk/includes/class-premiumpress-design.php

    r3838627 r3848540  
    208208         */
    209209        public static function theme_designs(): array {
    210                 return array(
    211                         'kiosk'      => array( 'Kiosk', __( 'Classic directory', 'premiumpress-directory' ) ),
    212                         'herald'     => array( 'Herald', __( 'Classic directory', 'premiumpress-directory' ) ),
    213                         'bureau'     => array( 'Bureau', __( 'Classic directory', 'premiumpress-directory' ) ),
    214                         'marylebone' => array( 'Marylebone', __( 'City guide', 'premiumpress-directory' ) ),
    215                         'gridline'   => array( 'Gridline', __( 'City guide', 'premiumpress-directory' ) ),
    216                         'bazaar'     => array( 'Bazaar', __( 'City guide', 'premiumpress-directory' ) ),
    217                         'slice'      => array( 'Slice', __( 'Local food', 'premiumpress-directory' ) ),
    218                         'carryout'   => array( 'Carryout', __( 'Local food', 'premiumpress-directory' ) ),
    219                         'supper'     => array( 'Supper', __( 'Local food', 'premiumpress-directory' ) ),
    220                         'volt'       => array( 'Volt', __( 'Sports coaches', 'premiumpress-directory' ) ),
    221                         'sideline'   => array( 'Sideline', __( 'Sports coaches', 'premiumpress-directory' ) ),
    222                         'podium'     => array( 'Podium', __( 'Sports coaches', 'premiumpress-directory' ) ),
    223                 );
     210                return (array) require PREMIUMPRESS_DIR . 'includes/design-data.php';
    224211        }
    225212
    … …  
    256243                }
    257244                if ( 'pages' === $view ) {
    258                         PremiumPress_Admin_UI::open( 'design', __( 'Directory pages', 'premiumpress-directory' ), __( 'The pages your directory uses, and the sample listings.', 'premiumpress-directory' ) );
     245                        PremiumPress_Admin_UI::open( 'design', sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ), sprintf( /* translators: 1: what the site is, e.g. directory, job board, 2: plural item name, e.g. listings, jobs */ __( 'The pages your %1$s uses, and the sample %2$s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun(), PremiumPress_Profiles::many() ) );
    259246                        echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">';
    260247                        PremiumPress_Admin_UI::e_icon( 'back', 16 );
    … …  
    269256                        return;
    270257                }
    271                 PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), __( 'Your pages, logo and colours, and how your directory looks.', 'premiumpress-directory' ) );
     258                PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your pages, logo and colours, and how your %s looks.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    272259                $groups = array(
    273260                        array(
    274261                                __( 'Ready-made designs', 'premiumpress-directory' ),
    275                                 __( 'Give your directory a new look in one click.', 'premiumpress-directory' ),
     262                                sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Give your %s a new look in one click.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ),
    276263                                array(
    277                                         array( 'sparkle', __( 'Ready-made designs', 'premiumpress-directory' ), __( 'Choose the look of your directory pages: your WordPress theme\'s style, the built-in design, or a Directory theme design.', 'premiumpress-directory' ), self::url( array( 'view' => 'designs' ) ) ),
     264                                        array( 'sparkle', __( 'Ready-made designs', 'premiumpress-directory' ), sprintf( /* translators: 1: what the site is, e.g. directory, 2: theme name, e.g. Directory theme */ __( 'Choose the look of your %1$s pages: your WordPress theme\'s style, the built-in design, or a %2$s design.', 'premiumpress-directory' ), PremiumPress_Profiles::noun(), (string) PremiumPress_Profiles::current()['theme_name'] ), self::url( array( 'view' => 'designs' ) ) ),
    278265                                ),
    279266                        ),
    … …  
    283270                                array(
    284271                                        array( 'file', __( 'All pages', 'premiumpress-directory' ), __( 'Manage the pages your website uses.', 'premiumpress-directory' ), self::wp_tool( 'pages' ) ),
    285                                         array( 'list', __( 'Directory pages', 'premiumpress-directory' ), __( 'The Directory, Add a listing and My listings pages, and the sample listings.', 'premiumpress-directory' ), PremiumPress_Settings::section_url( 'pages' ) ),
     272                                        array( 'list', sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ), sprintf( /* translators: 1: what the site is, capitalised, e.g. Directory, 2: one item with its article, e.g. a listing, an ad, 3: plural item name, e.g. listings, jobs */ __( 'The %1$s, Add %2$s and My %3$s pages, and the sample %3$s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ), PremiumPress_Profiles::a_one(), PremiumPress_Profiles::many() ), PremiumPress_Settings::section_url( 'pages' ) ),
    286273                                        array( 'edit', __( 'Brand & logo', 'premiumpress-directory' ), __( 'Your logo, site title, brand colours and fonts.', 'premiumpress-directory' ), self::url( array( 'view' => 'identity' ) ) ),
    287274                                        array( 'image', __( 'Header & footer', 'premiumpress-directory' ), __( 'Made in your theme\'s own editor, which opens in a new tab.', 'premiumpress-directory' ), self::wp_tool( 'header' ), true ),
    … …  
    331318                        'designs'  => array( __( 'Ready-made designs', 'premiumpress-directory' ), self::url( array( 'view' => 'designs' ) ), false ),
    332319                        'identity' => array( __( 'Brand', 'premiumpress-directory' ), self::url( array( 'view' => 'identity' ) ), false ),
    333                         'pages'    => array( __( 'Directory pages', 'premiumpress-directory' ), PremiumPress_Settings::section_url( 'pages' ), false ),
     320                        'pages'    => array( sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ), PremiumPress_Settings::section_url( 'pages' ), false ),
    334321                        'header'   => array( __( 'Header & footer', 'premiumpress-directory' ), self::wp_tool( 'header' ), true ),
    335322                );
    … …  
    395382
    396383                // Brand colours.
    397                 echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand colours', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html__( 'Used on your directory pages: buttons, links, cards and backgrounds. Leave a box empty to keep the design\'s own colour.', 'premiumpress-directory' ) . '</p>';
     384                echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand colours', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Used on your %s pages: buttons, links, cards and backgrounds. Leave a box empty to keep the design\'s own colour.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    398385                self::colour_row( 'primary', __( 'Primary', 'premiumpress-directory' ), $b['primary'], $def['primary'] );
    399386                self::colour_row( 'secondary', __( 'Secondary', 'premiumpress-directory' ), $b['secondary'], $def['secondary'] );
    … …  
    403390
    404391                // Brand fonts.
    405                 echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand fonts', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html__( 'One font for your headlines and one for the rest of your text, on your directory pages. The fonts come with the plugin, so nothing loads from other websites.', 'premiumpress-directory' ) . '</p>';
     392                echo '<section class="ppd-a-card ppd-a-pad ppd-brand-box"><h2>' . esc_html__( 'Brand fonts', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'One font for your headlines and one for the rest of your text, on your %s pages. The fonts come with the plugin, so nothing loads from other websites.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    406393                foreach ( array( 'head_font' => __( 'Headline font', 'premiumpress-directory' ), 'body_font' => __( 'Body text font', 'premiumpress-directory' ) ) as $k => $l ) {
    407394                        echo '<div class="ppd-brand-field"><label for="ppd-' . esc_attr( $k ) . '">' . esc_html( $l ) . '</label><select id="ppd-' . esc_attr( $k ) . '" class="ppd-a-input ppd-a-input--wide" name="brand[' . esc_attr( $k ) . ']" data-ppd-live="' . esc_attr( $k ) . '">';
    … …  
    424411                // Live preview.
    425412                $name = (string) get_option( 'blogname' );
    426                 echo '<aside class="ppd-a-card ppd-a-pad ppd-brand-preview" aria-label="' . esc_attr__( 'Brand preview', 'premiumpress-directory' ) . '"><h2>' . esc_html__( 'Brand preview', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html__( 'A live preview of how your brand settings look on your directory pages.', 'premiumpress-directory' ) . '</p>';
    427                 echo '<div class="ppd-bp" data-ppd-preview data-bg="' . esc_attr( $def['background'] ) . '"><div class="ppd-bp-head"><span class="ppd-bp-logo"><img src="' . esc_url( $logo_src ) . '" alt="" data-ppd-pv-logo><b data-ppd-pv-name>' . esc_html( $name ) . '</b></span><span class="ppd-bp-nav"><span>' . esc_html__( 'Home', 'premiumpress-directory' ) . '</span><span>' . esc_html__( 'Directory', 'premiumpress-directory' ) . '</span><span class="ppd-bp-btn">' . esc_html__( 'Add a listing', 'premiumpress-directory' ) . '</span></span></div>';
    428                 echo '<div class="ppd-bp-body" data-ppd-pv-card><h3 data-ppd-pv-head>' . esc_html__( 'Your headlines look like this', 'premiumpress-directory' ) . '</h3><p data-ppd-pv-text>' . esc_html__( 'This is how your body text will appear on your directory pages.', 'premiumpress-directory' ) . '</p><div class="ppd-bp-row"><span class="ppd-bp-btn ppd-bp-btn--big">' . esc_html__( 'A button', 'premiumpress-directory' ) . '</span><span class="ppd-bp-link">' . esc_html__( 'A text link', 'premiumpress-directory' ) . '</span></div></div>';
     413                echo '<aside class="ppd-a-card ppd-a-pad ppd-brand-preview" aria-label="' . esc_attr__( 'Brand preview', 'premiumpress-directory' ) . '"><h2>' . esc_html__( 'Brand preview', 'premiumpress-directory' ) . '</h2><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'A live preview of how your brand settings look on your %s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
     414                echo '<div class="ppd-bp" data-ppd-preview data-bg="' . esc_attr( $def['background'] ) . '"><div class="ppd-bp-head"><span class="ppd-bp-logo"><img src="' . esc_url( $logo_src ) . '" alt="" data-ppd-pv-logo><b data-ppd-pv-name>' . esc_html( $name ) . '</b></span><span class="ppd-bp-nav"><span>' . esc_html__( 'Home', 'premiumpress-directory' ) . '</span><span>' . esc_html( PremiumPress_Profiles::noun( true ) ) . '</span><span class="ppd-bp-btn">' . esc_html( sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'Add %s', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ) . '</span></span></div>';
     415                echo '<div class="ppd-bp-body" data-ppd-pv-card><h3 data-ppd-pv-head>' . esc_html__( 'Your headlines look like this', 'premiumpress-directory' ) . '</h3><p data-ppd-pv-text>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'This is how your body text will appear on your %s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p><div class="ppd-bp-row"><span class="ppd-bp-btn ppd-bp-btn--big">' . esc_html__( 'A button', 'premiumpress-directory' ) . '</span><span class="ppd-bp-link">' . esc_html__( 'A text link', 'premiumpress-directory' ) . '</span></div></div>';
    429416                echo '<div class="ppd-bp-tokens">';
    430417                foreach ( array( 'primary' => __( 'Primary', 'premiumpress-directory' ), 'secondary' => __( 'Secondary', 'premiumpress-directory' ), 'background' => __( 'Background', 'premiumpress-directory' ), 'cards' => __( 'Cards', 'premiumpress-directory' ) ) as $k => $l ) {
    … …  
    481468        /** Custom code: WordPress's own "Additional CSS", edited here. */
    482469        private static function render_code( string $msg ): void {
    483                 PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), __( 'Your pages, logo and colours, and how your directory looks.', 'premiumpress-directory' ) );
     470                PremiumPress_Admin_UI::open( 'design', __( 'Design', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your pages, logo and colours, and how your %s looks.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    484471                self::crumbs( __( 'Custom code', 'premiumpress-directory' ), $msg );
    485472                self::tabs( 'code' );
    … …  
    511498                $p     = PremiumPress_Profiles::current();
    512499                $theme = (string) $p['theme_name'];
    513                 PremiumPress_Admin_UI::open( 'design', __( 'Ready-made designs', 'premiumpress-directory' ), __( 'Choose how your directory pages look to visitors.', 'premiumpress-directory' ) );
     500                PremiumPress_Admin_UI::open( 'design', __( 'Ready-made designs', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Choose how your %s pages look to visitors.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    514501                echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">';
    515502                PremiumPress_Admin_UI::e_icon( 'back', 16 );
    … …  
    518505                if ( $saved ) {
    519506                        $dir = PremiumPress_Pages::url( 'directory' );
    520                         echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Design saved.', 'premiumpress-directory' ) . ( '' !== $dir ? ' <a href="' . esc_url( $dir ) . '" target="_blank" rel="noopener">' . esc_html__( 'See your directory', 'premiumpress-directory' ) . '</a>' : '' ) . '</div>';
     507                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Design saved.', 'premiumpress-directory' ) . ( '' !== $dir ? ' <a href="' . esc_url( $dir ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'See your %s', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</a>' : '' ) . '</div>';
    521508                }
    522509                echo '<div class="ppd-a-card ppd-a-pad ppd-dz">';
    … …  
    546533                $lead = sprintf( __( 'This design comes with the PremiumPress %s. It isn\'t part of the free plugin.', 'premiumpress-directory' ), $theme );
    547534                /* translators: %s: theme name, e.g. Directory theme */
    548                 $more = sprintf( __( 'The %s uses the same listings, categories and reviews, so you can switch any time without losing anything.', 'premiumpress-directory' ), $theme );
     535                $more = sprintf( /* translators: 1: theme name, 2: plural item name, e.g. listings */ __( 'The %1$s uses the same %2$s and categories, so you can switch any time without losing anything.', 'premiumpress-directory' ), $theme, PremiumPress_Profiles::many() );
    549536                echo '<dialog class="ppd-dz-dialog" data-ppd-pro-dialog aria-labelledby="ppd-dz-dialog-h"><img src="' . esc_url( PREMIUMPRESS_URL . 'assets/designs/kiosk.webp' ) . '" alt="" data-ppd-pro-pic width="480" height="300"><div class="ppd-dz-dialog-in">';
    550537                echo '<h2 id="ppd-dz-dialog-h" data-ppd-pro-title></h2><p>' . esc_html( $lead ) . '</p><p class="ppd-a-muted">' . esc_html( $more ) . '</p>';
    … …  
    563550                $now   = self::current();
    564551                $cards = array(
    565                         'wordpress' => array( __( 'Your WordPress theme', 'premiumpress-directory' ), __( 'Your directory uses your WordPress theme\'s own fonts, colours and buttons, so it matches the rest of your site.', 'premiumpress-directory' ) ),
    566                         'builtin'   => array( __( 'Built-in design', 'premiumpress-directory' ), __( 'The PremiumPress look: a filter sidebar, photo cards with ratings, and a listing page with a contact card.', 'premiumpress-directory' ) ),
     552                        'wordpress' => array( __( 'Your WordPress theme', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s uses your WordPress theme\'s own fonts, colours and buttons, so it matches the rest of your site.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ),
     553                        'builtin'   => array( __( 'Built-in design', 'premiumpress-directory' ), sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'The PremiumPress look: a filter sidebar, photo cards with ratings, and %s page with a contact card.', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ),
    567554                );
    568555                echo '<div class="ppd-design-cards">';
    … …  
    582569                }
    583570                echo '</div>';
    584                 echo '<p class="ppd-design-more">' . esc_html__( 'More designs come with the PremiumPress Directory theme. See them any time under Design, Ready-made designs.', 'premiumpress-directory' ) . '</p>';
     571                echo '<p class="ppd-design-more">' . esc_html( sprintf( /* translators: %s: theme name, e.g. Directory theme */ __( 'More designs come with the PremiumPress %s. See them any time under Design, Ready-made designs.', 'premiumpress-directory' ), (string) PremiumPress_Profiles::current()['theme_name'] ) ) . '</p>';
    585572        }
    586573}
  • premiumpress-directory/trunk/includes/class-premiumpress-engage.php

    r3838627 r3848540  
    206206        public function maybe_sync_deleted( $id, $comment ): void {
    207207                $this->maybe_sync( $id, $comment );
     208        }
     209
     210        /** Does this site type use star reviews? (Classifieds uses questions in the theme instead.) */
     211        public static function reviews_on(): bool {
     212                return false !== ( PremiumPress_Profiles::current()['reviews'] ?? true );
    208213        }
    209214
    … …  
    324329                }
    325330                $help = PremiumPress_Settings::get()['emails']
    326                         ? __( 'Shown under the review with your listing\'s name. The reviewer is told by email.', 'premiumpress-directory' )
    327                         : __( 'Shown under the review with your listing\'s name.', 'premiumpress-directory' );
     331                        ? sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Shown under the review with your %s\'s name. The reviewer is told by email.', 'premiumpress-directory' ), PremiumPress_Profiles::one() )
     332                        : sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Shown under the review with your %s\'s name.', 'premiumpress-directory' ), PremiumPress_Profiles::one() );
    328333                $out .= '</p><p class="ppd-form__help">' . esc_html( $help ) . '</p></form></details>';
    329334                return $out;
    … …  
    384389        /** The reviews section for a listing page. */
    385390        public static function reviews_html( int $post_id ): string {
     391                if ( ! self::reviews_on() ) {
     392                        return '';
     393                }
    386394                $s       = self::stats( $post_id );
    387395                $reviews = get_comments(
    … …  
    433441                }
    434442
    435                 if ( self::A_REVIEW === $action ) {
     443                if ( self::A_REVIEW === $action && self::reviews_on() ) {
    436444                        $this->save_review( $id, $in, $back );
    437445                } elseif ( self::A_REPORT === $action ) {
    … …  
    635643                        'review_pending'  => array( 'success', __( 'Thanks! Your review will appear once it has been approved.', 'premiumpress-directory' ) ),
    636644                        'twice'           => array( 'error', __( 'You have already reviewed this.', 'premiumpress-directory' ) ),
    637                         'own'             => array( 'error', __( 'You can\'t review your own listing.', 'premiumpress-directory' ) ),
     645                        'own'             => array( 'error', sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'You can\'t review your own %s.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ),
    638646                        'rating'          => array( 'error', __( 'Please choose a star rating.', 'premiumpress-directory' ) ),
    639647                        'replied'         => array( 'success', __( 'Your reply has been posted.', 'premiumpress-directory' ) ),
    … …  
    754762                );
    755763                $n = count( $reports );
    756                 PremiumPress_Admin_UI::open( 'reports', __( 'Reports', 'premiumpress-directory' ), __( 'Listings visitors have told you about.', 'premiumpress-directory' ) );
     764                PremiumPress_Admin_UI::open( 'reports', __( 'Reports', 'premiumpress-directory' ), sprintf( /* translators: %s: plural item name, capitalised, e.g. Listings */ __( '%s visitors have told you about.', 'premiumpress-directory' ), PremiumPress_Profiles::many( true ) ) );
    757765                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only.
    758766                $msg = isset( $_GET['ppd_msg'] ) ? sanitize_key( wp_unslash( $_GET['ppd_msg'] ) ) : '';
    759767                if ( 'dismissed' === $msg ) {
    760                         echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Report dismissed. The listing stays as it is.', 'premiumpress-directory' ) . '</div>';
     768                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Report dismissed. The %s stays as it is.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</div>';
    761769                } elseif ( 'offline' === $msg ) {
    762                         echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'The listing is now offline (saved as a draft) and the report is closed. You can put it back live from Listings.', 'premiumpress-directory' ) . '</div>';
     770                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html( sprintf( /* translators: 1: singular item name, e.g. listing, job, 2: plural item name, capitalised, e.g. Listings */ __( 'The %1$s is now offline (saved as a draft) and the report is closed. You can put it back live from %2$s.', 'premiumpress-directory' ), PremiumPress_Profiles::one(), PremiumPress_Profiles::many( true ) ) ) . '</div>';
    763771                }
    764772                if ( ! $reports ) {
    765773                        echo '<section class="ppd-a-card"><div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">';
    766774                        PremiumPress_Admin_UI::e_icon( 'checkc', 22 );
    767                         echo '</span><strong>' . esc_html__( 'All clear', 'premiumpress-directory' ) . '</strong><span>' . esc_html__( 'No visitor has reported anything. When someone uses "Report this" on a listing, it shows up here and you get an email.', 'premiumpress-directory' ) . '</span></div></section>';
     775                        echo '</span><strong>' . esc_html__( 'All clear', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'No visitor has reported anything. When someone uses "Report this" on %s, it shows up here and you get an email.', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ) . '</span></div></section>';
    768776                        PremiumPress_Admin_UI::close();
    769777                        return;
    770778                }
    771779                /* translators: %d: number of open reports */
    772                 echo '<p class="ppd-rp-lead">' . esc_html( sprintf( _n( '%d report to look at.', '%d reports to look at.', $n, 'premiumpress-directory' ), $n ) ) . ' ' . esc_html__( 'Check the listing, then either take it offline or dismiss the report if nothing needs changing.', 'premiumpress-directory' ) . '</p>';
     780                echo '<p class="ppd-rp-lead">' . esc_html( sprintf( _n( '%d report to look at.', '%d reports to look at.', $n, 'premiumpress-directory' ), $n ) ) . ' ' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Check the %s, then either take it offline or dismiss the report if nothing needs changing.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p>';
    773781
    774782                $tones   = array(
    … …  
    811819                        echo '<div class="ppd-rp-actions">';
    812820                        if ( $live ) {
    813                                 echo '<a class="ppd-a-btn" href="' . esc_url( (string) get_permalink( $pid ) ) . '" target="_blank" rel="noopener">' . esc_html__( 'View listing', 'premiumpress-directory' ) . '</a>';
     821                                echo '<a class="ppd-a-btn" href="' . esc_url( (string) get_permalink( $pid ) ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'View %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</a>';
    814822                        }
    815                         echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Admin_Editor::url( $pid ) ) . '">' . esc_html__( 'Edit listing', 'premiumpress-directory' ) . '</a>';
     823                        echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Admin_Editor::url( $pid ) ) . '">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Edit %s', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</a>';
    816824                        if ( $live && current_user_can( 'edit_post', $pid ) ) {
    817825                                echo '<a class="ppd-a-btn ppd-a-btn--danger" href="' . esc_url( self::report_url( (int) $r->comment_ID, true ) ) . '" data-ppd-confirm="' . esc_attr( sprintf( /* translators: %s: listing title */ __( 'Take "%s" offline? It is saved as a draft, so you can put it back later.', 'premiumpress-directory' ), get_the_title( $pid ) ) ) . '">' . esc_html__( 'Take offline', 'premiumpress-directory' ) . '</a>';
  • premiumpress-directory/trunk/includes/class-premiumpress-fields.php

    r3838627 r3848540  
    4444                        array(
    4545                                'newLabel' => __( 'New field', 'premiumpress-directory' ),
    46                                 'confirm'  => __( 'Remove this field? Answers already saved on listings are kept and come back if you add the same key again.', 'premiumpress-directory' ),
    47                                 'reset'    => __( 'Put the field list back to the built-in fields? Fields you added are removed from the list; nothing saved on listings is deleted.', 'premiumpress-directory' ),
     46                                'confirm'  => sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Remove this field? Answers already saved on %s are kept and come back if you add the same key again.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ),
     47                                'reset'    => sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Put the field list back to the built-in fields? Fields you added are removed from the list; nothing saved on %s is deleted.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ),
    4848                        )
    4949                );
    … …  
    7272        }
    7373
     74        /**
     75         * A built-in field whose key or choices the theme relies on (a "_ppt_…" key, a
     76         * category-style field, or choices with their own stored keys). Its key, type and
     77         * choices stay as they are; the label, help, order and card setting can change.
     78         *
     79         * @param array<string, mixed> $f
     80         */
     81        public static function locked( array $f ): bool {
     82                $builtin = (array) PremiumPress_Profiles::current()['fields'];
     83                $key     = (string) ( $f['key'] ?? '' );
     84                if ( ! isset( $builtin[ $key ] ) ) {
     85                        return false;
     86                }
     87                $def  = (array) $builtin[ $key ];
     88                $opts = (array) ( $def['options'] ?? array() );
     89                return ! empty( $def['tax'] ) || array_values( $opts ) !== $opts || (bool) preg_match( '/^(_|ppt_)/', $key );
     90        }
     91
    7492        /** Keys the plugin itself uses; a custom field may not take them over. */
    7593        public static function reserved(): array {
    … …  
    126144                $f    = is_array( $f ) ? $f : array();
    127145                $type = isset( $f['type'] ) && isset( self::types()[ $f['type'] ] ) ? (string) $f['type'] : 'text';
     146                $raw  = (array) ( $f['options'] ?? array() );
     147                // Choices with their own stored keys (ad type "sale", job type "full-time") keep them.
     148                $opts = array_values( $raw ) !== $raw
     149                        ? array_map( 'strval', $raw )
     150                        : array_values( array_filter( array_map( 'strval', $raw ), 'strlen' ) );
    128151                return array_merge(
    129152                        $f,
    … …  
    132155                                'label'      => (string) ( $f['label'] ?? '' ),
    133156                                'type'       => $type,
    134                                 'options'    => self::has_options( $type ) ? array_values( array_filter( array_map( 'strval', (array) ( $f['options'] ?? array() ) ), 'strlen' ) ) : array(),
     157                                'options'    => self::has_options( $type ) ? $opts : array(),
    135158                                'help'       => (string) ( $f['help'] ?? '' ),
    136159                                'required'   => ! empty( $f['required'] ) && 'title' !== $type,
    … …  
    179202                                $key = 'field';
    180203                        }
    181                         // Names starting "_" are WordPress's hidden ones, "ppt_" the theme's.
    182                         $key  = (string) preg_replace( '/^(_+|ppt_)+/', '', $key );
    183                         $key  = '' !== $key ? $key : 'field';
    184                         $base = $key;
    185                         $n    = 2;
    186                         while ( in_array( $key, $used, true ) ) {
    187                                 $key = $base . '_' . $n;
    188                                 ++$n;
     204                        $builtin = (array) PremiumPress_Profiles::current()['fields'];
     205                        $locked  = isset( $builtin[ $key ] ) && self::locked( array( 'key' => $key ) ) && ! in_array( $key, $used, true );
     206                        if ( ! $locked ) {
     207                                // Names starting "_" are WordPress's hidden ones, "ppt_" the theme's.
     208                                $key  = (string) preg_replace( '/^(_+|ppt_)+/', '', $key );
     209                                $key  = '' !== $key ? $key : 'field';
     210                                $base = $key;
     211                                $n    = 2;
     212                                while ( in_array( $key, $used, true ) ) {
     213                                        $key = $base . '_' . $n;
     214                                        ++$n;
     215                                }
    189216                        }
    190217                        $used[] = $key;
    191218                        $type   = isset( $row['type'] ) && isset( self::types()[ $row['type'] ] ) ? (string) $row['type'] : 'text';
     219                        if ( $locked ) {
     220                                $type = (string) ( $builtin[ $key ]['type'] ?? $type );
     221                        }
    192222                        $opts   = array();
    193223                        if ( self::has_options( $type ) ) {
    … …  
    207237                                }
    208238                        }
     239                        if ( $locked && self::has_options( $type ) ) {
     240                                $opts = (array) ( $builtin[ $key ]['options'] ?? array() );
     241                        }
    209242                        // Built-in extras (e.g. "money" on a price) stay with their key.
    210                         $keep   = isset( $prev[ $key ] ) ? $prev[ $key ] : array();
     243                        $keep   = isset( $prev[ $key ] ) ? $prev[ $key ] : ( $locked ? (array) $builtin[ $key ] : array() );
    211244                        $list[] = self::normalise(
    212245                                array_merge(
    … …  
    298331                );
    299332                $name = 'fields[' . $uid . ']';
     333                $lock = self::locked( $f );
    300334                echo '<details class="ppd-cf" data-ppd-field' . ( $open ? ' open' : '' ) . '><summary class="ppd-cf-head"><span class="ppd-cf-grip" data-ppd-grip draggable="true" aria-hidden="true">';
    301335                PremiumPress_Admin_UI::e_icon( 'grip', 16 );
    … …  
    316350
    317351                echo '<div class="ppd-cf-grid"><label class="ppd-cf-f"><span>' . esc_html__( 'Label', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input" name="' . esc_attr( $name ) . '[label]" value="' . esc_attr( (string) $f['label'] ) . '" maxlength="120" data-ppd-labelin></label>';
    318                 echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Key', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input ppd-cf-mono" name="' . esc_attr( $name ) . '[key]" value="' . esc_attr( (string) $f['key'] ) . '" maxlength="60" pattern="[a-z0-9_\-]*" data-ppd-keyin><small>' . esc_html__( 'Where the answer is saved. Changing it hides answers saved under the old key.', 'premiumpress-directory' ) . '</small></label>';
    319                 echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Field type', 'premiumpress-directory' ) . '</span><select class="ppd-a-input" name="' . esc_attr( $name ) . '[type]" data-ppd-typein>';
     352                echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Key', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input ppd-cf-mono" name="' . esc_attr( $name ) . '[key]" value="' . esc_attr( (string) $f['key'] ) . '" maxlength="60" pattern="[a-z0-9_\-]*" data-ppd-keyin' . ( $lock ? ' readonly' : '' ) . '><small>' . esc_html__( 'Where the answer is saved. Changing it hides answers saved under the old key.', 'premiumpress-directory' ) . '</small></label>';
     353                echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Field type', 'premiumpress-directory' ) . '</span><select class="ppd-a-input" name="' . esc_attr( $name ) . '[type]" data-ppd-typein' . ( $lock ? ' disabled' : '' ) . '>';
    320354                foreach ( $types as $k => $label ) {
    321355                        echo '<option value="' . esc_attr( $k ) . '"' . selected( $f['type'], $k, false ) . '>' . esc_html( $label ) . '</option>';
    … …  
    324358                echo '<label class="ppd-cf-f"><span>' . esc_html__( 'Help text (optional)', 'premiumpress-directory' ) . '</span><input type="text" class="ppd-a-input" name="' . esc_attr( $name ) . '[help]" value="' . esc_attr( (string) $f['help'] ) . '" maxlength="200"></label></div>';
    325359
    326                 echo '<label class="ppd-cf-f ppd-cf-opts" data-ppd-opts' . ( self::has_options( (string) $f['type'] ) ? '' : ' hidden' ) . '><span>' . esc_html__( 'Options, one per line', 'premiumpress-directory' ) . '</span><textarea class="ppd-a-input" rows="5" name="' . esc_attr( $name ) . '[options]">' . esc_textarea( implode( "\n", (array) $f['options'] ) ) . '</textarea></label>';
     360                echo '<label class="ppd-cf-f ppd-cf-opts" data-ppd-opts' . ( self::has_options( (string) $f['type'] ) ? '' : ' hidden' ) . '><span>' . esc_html__( 'Options, one per line', 'premiumpress-directory' ) . '</span><textarea class="ppd-a-input" rows="5" name="' . esc_attr( $name ) . '[options]"' . ( $lock ? ' readonly' : '' ) . '>' . esc_textarea( implode( "\n", (array) $f['options'] ) ) . '</textarea></label>';
     361                if ( $lock ) {
     362                        echo '<p class="ppd-cf-note">' . esc_html__( 'Built in: the theme reads this field\'s name and choices, so they stay as they are. You can change its label, help text, order and where it shows.', 'premiumpress-directory' ) . '</p>';
     363                }
    327364
    328365                $cats = get_terms(
    … …  
    340377                        echo '</div></fieldset>';
    341378                }
    342                 echo '<div class="ppd-cf-flags"><label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[required]" value="1"' . checked( ! empty( $f['required'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html__( 'Required on the "Add a listing" form', 'premiumpress-directory' ) . '</label>';
    343                 echo '<label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[card]" value="1"' . checked( ! empty( $f['card'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html__( 'Show on listing cards', 'premiumpress-directory' ) . '</label></div>';
     379                echo '<div class="ppd-cf-flags"><label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[required]" value="1"' . checked( ! empty( $f['required'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html( sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'Required on the "Add %s" form', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) ) . '</label>';
     380                echo '<label class="ppd-a-switch"><input type="checkbox" name="' . esc_attr( $name ) . '[card]" value="1"' . checked( ! empty( $f['card'] ), true, false ) . '><span class="ppd-a-switch-ui" aria-hidden="true"></span> ' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Show on %s cards', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</label></div>';
    344381                echo '</div></details>';
    345382        }
    … …  
    354391                $defs = self::defaults();
    355392                $dk   = wp_list_pluck( $defs, 'key' );
    356                 PremiumPress_Admin_UI::open( 'listings', __( 'Custom Fields', 'premiumpress-directory' ), __( 'The extra details people fill in when they add a listing.', 'premiumpress-directory' ) );
     393                PremiumPress_Admin_UI::open( 'listings', __( 'Custom Fields', 'premiumpress-directory' ), sprintf( /* translators: %s: one item with its article, e.g. a listing, an ad */ __( 'The extra details people fill in when they add %s.', 'premiumpress-directory' ), PremiumPress_Profiles::a_one() ) );
    357394                PremiumPress_Admin_UI::crumb();
    358395                if ( 'saved' === $msg ) {
    … …  
    403440                echo '</section><section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html__( 'Reset to defaults', 'premiumpress-directory' ) . '</h2>';
    404441                /* translators: %d: number of built-in fields */
    405                 echo '<p>' . esc_html( sprintf( _n( 'Puts the field list back to the %d field this site type comes with.', 'Puts the field list back to the %d fields this site type comes with.', count( $dk ), 'premiumpress-directory' ), count( $dk ) ) ) . '</p><p class="ppd-a-muted">' . esc_html__( 'Fields you added are removed from the list and edits to the built-in ones are undone. Nothing already filled in on listings is deleted: it comes back with its field.', 'premiumpress-directory' ) . '</p>';
     442                echo '<p>' . esc_html( sprintf( _n( 'Puts the field list back to the %d field this site type comes with.', 'Puts the field list back to the %d fields this site type comes with.', count( $dk ), 'premiumpress-directory' ), count( $dk ) ) ) . '</p><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Fields you added are removed from the list and edits to the built-in ones are undone. Nothing already filled in on %s is deleted: it comes back with its field.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p>';
    406443                echo '<form method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '" data-ppd-resetform><input type="hidden" name="action" value="' . esc_attr( self::A_RESET ) . '">';
    407444                wp_nonce_field( self::A_RESET );
  • premiumpress-directory/trunk/includes/class-premiumpress-frontend.php

    r3838627 r3848540  
    6464                                /* translators: %s: singular item name, e.g. Listing */
    6565                                'title'       => sprintf( __( 'Single %s', 'premiumpress-directory' ), (string) $p['singular'] ),
    66                                 'description' => __( 'Shows one directory item with its details, map and reviews.', 'premiumpress-directory' ),
     66                                'description' => __( 'Shows one item with its details and map.', 'premiumpress-directory' ),
    6767                                'content'     => (string) file_get_contents( PREMIUMPRESS_DIR . 'templates/block/single-listing.html' ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- local file.
    6868                                'post_types'  => array( PremiumPress_Post_Types::TYPE ),
    … …  
    7272                $archive = (string) file_get_contents( PREMIUMPRESS_DIR . 'templates/block/archive-listing.html' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- local file.
    7373                $names   = array(
    74                         PremiumPress_Post_Types::TAX_CATEGORY => __( 'Directory category', 'premiumpress-directory' ),
    75                         PremiumPress_Post_Types::TAX_LOCATION => __( 'Directory location', 'premiumpress-directory' ),
    76                         PremiumPress_Post_Types::TAX_TAG      => __( 'Directory tag', 'premiumpress-directory' ),
     74                        PremiumPress_Post_Types::TAX_CATEGORY => sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s category', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ),
     75                        PremiumPress_Post_Types::TAX_LOCATION => sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s location', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ),
     76                        PremiumPress_Post_Types::TAX_TAG      => sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( '%s tag', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ),
    7777                );
    7878                foreach ( $names as $tax => $title ) {
    … …  
    8181                                array(
    8282                                        'title'       => $title,
    83                                         'description' => __( 'Shows the directory search and cards, filtered to one category, location or tag.', 'premiumpress-directory' ),
     83                                        'description' => sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Shows the %s search and cards, filtered to one category, location or tag.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ),
    8484                                        'content'     => $archive,
    8585                                )
  • premiumpress-directory/trunk/includes/class-premiumpress-lifecycle.php

    r3838627 r3848540  
    182182
    183183        public function meta_box(): void {
    184                 add_meta_box( 'ppd-options', __( 'Listing options', 'premiumpress-directory' ), array( $this, 'render_box' ), null, 'side', 'default' );
     184                add_meta_box( 'ppd-options', sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s options', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ), array( $this, 'render_box' ), null, 'side', 'default' );
    185185        }
    186186
  • premiumpress-directory/trunk/includes/class-premiumpress-listings-grid.php

    r3837691 r3848540  
    133133
    134134                if ( ! $query->have_posts() ) {
    135                         return '<div class="ppd"><p class="ppd-empty">' . esc_html__( 'No listings found.', 'premiumpress-directory' ) . '</p></div>';
     135                        return '<div class="ppd"><p class="ppd-empty">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'No %s found.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p></div>';
    136136                }
    137137
    … …  
    175175                                'current'   => $current,
    176176                                'total'     => (int) $query->max_num_pages,
    177                                 'prev_text' => __( 'Previous', 'premiumpress-directory' ),
    178                                 'next_text' => __( 'Next', 'premiumpress-directory' ),
     177                                'prev_text' => esc_html__( 'Previous', 'premiumpress-directory' ),
     178                                'next_text' => esc_html__( 'Next', 'premiumpress-directory' ),
    179179                        )
    180180                );
    181                 return $links ? '<nav class="ppd-pagination" aria-label="' . esc_attr__( 'Results pages', 'premiumpress-directory' ) . '">' . $links . '</nav>' : '';
     181                return $links ? '<nav class="ppd-pagination" aria-label="' . esc_attr__( 'Results pages', 'premiumpress-directory' ) . '">' . wp_kses_post( $links ) . '</nav>' : '';
    182182        }
    183183}
  • premiumpress-directory/trunk/includes/class-premiumpress-meta.php

    r3838627 r3848540  
    9898
    9999                foreach ( PremiumPress_Profiles::all_fields() as $key => $field ) {
     100                        if ( ! empty( $field['tax'] ) ) {
     101                                continue; // Stored as a term, not post meta.
     102                        }
    100103                        register_post_meta(
    101104                                PremiumPress_Post_Types::TYPE,
    … …  
    163166                echo '<div class="ppd-grid">';
    164167                foreach ( PremiumPress_Profiles::fields() as $key => $field ) {
    165                         $value = (string) get_post_meta( $post->ID, $key, true );
     168                        $value = PremiumPress_Profiles::get_field( (int) $post->ID, $key, $field );
    166169                        $id    = 'ppd-f-' . $key;
    167170                        $name  = 'ppd_f[' . $key . ']';
    … …  
    191194                                $on = array_map( 'trim', explode( ',', $value ) );
    192195                                echo '<fieldset><legend>' . esc_html( (string) $field['label'] ) . '</legend>';
    193                                 foreach ( (array) ( $field['options'] ?? array() ) as $opt ) {
     196                                foreach ( PremiumPress_Profiles::options( $field ) as $opt => $opt_label ) {
    194197                                        printf(
    195198                                                '<label class="ppd-check"><input type="checkbox" name="%1$s[]" value="%2$s" %3$s> %4$s</label>',
    196199                                                esc_attr( $name ),
    197                                                 esc_attr( $opt ),
    198                                                 checked( in_array( $opt, $on, true ), true, false ),
    199                                                 esc_html( $opt )
     200                                                esc_attr( (string) $opt ),
     201                                                checked( in_array( (string) $opt, $on, true ), true, false ),
     202                                                esc_html( $opt_label )
    200203                                        );
    201204                                }
    … …  
    203206                        } elseif ( 'select' === $type ) {
    204207                                printf( '<label for="%1$s">%2$s</label><select id="%1$s" name="%3$s" class="widefat"><option value="">%4$s</option>', esc_attr( $id ), esc_html( (string) $field['label'] ), esc_attr( $name ), esc_html__( '— Select —', 'premiumpress-directory' ) );
    205                                 foreach ( (array) ( $field['options'] ?? array() ) as $opt ) {
    206                                         printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $opt ), selected( $opt, $value, false ), esc_html( $opt ) );
     208                                foreach ( PremiumPress_Profiles::options( $field ) as $opt => $opt_label ) {
     209                                        printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( (string) $opt ), selected( (string) $opt, $value, false ), esc_html( $opt_label ) );
    207210                                }
    208211                                echo '</select>';
    … …  
    250253                }
    251254                echo '</div>';
    252                 echo '<p class="description">' . esc_html__( 'Coordinates place the listing on the map and in distance searches.', 'premiumpress-directory' ) . '</p>';
     255                echo '<p class="description">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Coordinates place the %s on the map and in distance searches.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p>';
    253256        }
    254257
    … …  
    320323
    321324                // Only sections the active profile shows are saved. Data from sections it
    322                 // hides (say, opening hours on a classifieds site) is left untouched.
     325                // hides (say, opening hours on a job board) is left untouched.
    323326                // Each value is sanitised by the callback registered in register_meta().
    324327                $in   = isset( $_POST['ppd'] ) && is_array( $_POST['ppd'] ) ? wp_unslash( $_POST['ppd'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    … …  
    336339                $custom = isset( $_POST['ppd_f'] ) && is_array( $_POST['ppd_f'] ) ? wp_unslash( $_POST['ppd_f'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    337340                foreach ( PremiumPress_Profiles::fields() as $key => $field ) {
    338                         self::store( $post_id, $key, self::sanitize_field( $field, $custom[ $key ] ?? '' ) );
     341                        PremiumPress_Profiles::set_field( (int) $post_id, $key, $field, self::sanitize_field( $field, $custom[ $key ] ?? '' ) );
    339342                }
    340343
    … …  
    367370        public static function sanitize_field( array $field, $value ): string {
    368371                $type    = (string) ( $field['type'] ?? 'text' );
    369                 $options = array_map( 'strval', (array) ( $field['options'] ?? array() ) );
     372                $options = array_map( 'strval', array_keys( PremiumPress_Profiles::options( $field ) ) );
    370373
    371374                switch ( $type ) {
  • premiumpress-directory/trunk/includes/class-premiumpress-pages.php

    r3837691 r3848540  
    2727                        'submit'    => array(
    2828                                /* translators: %s: singular item name, e.g. Listing */
    29                                 'title' => sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['singular'] ) ),
     29                                'title' => isset( $p['add_title'] ) ? (string) $p['add_title'] : sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['singular'] ) ),
    3030                                'slug'  => 'add-' . sanitize_title( (string) $p['singular'] ),
    3131                                'block' => '<!-- wp:premiumpress/submit /-->',
  • premiumpress-directory/trunk/includes/class-premiumpress-plugin.php

    r3838627 r3848540  
    1616        /** @var PremiumPress_Plugin|null */
    1717        private static $instance = null;
     18
     19        /** @var bool True once this plugin has taken charge of the site's listings. */
     20        private static $running = false;
     21
     22        public static function running(): bool {
     23                return self::$running;
     24        }
    1825
    1926        public static function instance(): PremiumPress_Plugin {
    … …  
    3542                        return;
    3643                }
     44                // Only one PremiumPress listings plugin can run at a time: they share the same
     45                // listings, so the first one loaded stays in charge and the others stand aside.
     46                if ( PremiumPress_Compat::sibling_active() ) {
     47                        PremiumPress_Compat::register_sibling_notice();
     48                        return;
     49                }
     50                self::$running = true;
    3751
    3852                ( new PremiumPress_Post_Types() )->register();
    … …  
    5973                ( new PremiumPress_Porting() )->register();
    6074                ( new PremiumPress_Switch() )->register();
     75                // This plugin's own features (e.g. ad types, job applications).
     76                foreach ( self::modules() as $module ) {
     77                        ( new $module() )->register();
     78                }
    6179
    6280                add_action( 'init', array( $this, 'maybe_flush' ), 999 );
    … …  
    6583                // Coming back from a PremiumPress theme: our rules need rebuilding.
    6684                add_action( 'after_switch_theme', array( __CLASS__, 'request_flush' ) );
     85        }
     86
     87        /** @return array<int, string> This plugin's own feature classes, set in the main plugin file. */
     88        public static function modules(): array {
     89                return array_values( array_filter( (array) PREMIUMPRESS_MODULES, 'class_exists' ) );
    6790        }
    6891
    … …  
    81104        public static function activate(): void {
    82105                self::request_flush();
    83                 // Only when this plugin is in charge (no PremiumPress theme active).
    84                 if ( ! PremiumPress_Compat::theme_active() ) {
     106                // Only when this plugin will be in charge: no PremiumPress theme and no other
     107                // PremiumPress listings plugin already running.
     108                if ( ! PremiumPress_Compat::theme_active() && ! PremiumPress_Compat::sibling_active() ) {
     109                        foreach ( self::modules() as $module ) {
     110                                if ( method_exists( $module, 'activate' ) ) {
     111                                        $module::activate();
     112                                }
     113                        }
    85114                        PremiumPress_Profiles::remember_single();
    86115                        PremiumPress_Pages::ensure();
  • premiumpress-directory/trunk/includes/class-premiumpress-porting.php

    r3838627 r3848540  
    938938                        } elseif ( isset( $fields[ $key ] ) ) {
    939939                                $value = PremiumPress_Meta::sanitize_field( $fields[ $key ], self::loose_option( $fields[ $key ], $raw ) );
     940                                if ( '' !== $value ) {
     941                                        // Fields kept as a category-style term (ad type, job type) are stored the theme's way.
     942                                        PremiumPress_Profiles::set_field( $id, (string) $key, (array) $fields[ $key ], $value );
     943                                }
     944                                continue;
    940945                        } else {
    941946                                continue;
    … …  
    957962         */
    958963        private static function loose_option( array $field, string $raw ): string {
    959                 $options = array_map( 'strval', (array) ( $field['options'] ?? array() ) );
     964                $options = PremiumPress_Profiles::options( $field );
    960965                if ( ! $options ) {
    961966                        return $raw;
    … …  
    963968                $out = array();
    964969                foreach ( preg_split( '/\s*[,|]\s*/', $raw ) as $piece ) {
    965                         foreach ( $options as $opt ) {
    966                                 if ( 0 === strcasecmp( $opt, trim( $piece ) ) ) {
    967                                         $out[] = $opt;
    968                                 }
    969                         }
    970                 }
    971                 return implode( ',', $out );
     970                        foreach ( $options as $key => $label ) {
     971                                // A value may be given as the stored key ("full-time") or its label ("Full-time").
     972                                if ( 0 === strcasecmp( (string) $key, trim( $piece ) ) || 0 === strcasecmp( (string) $label, trim( $piece ) ) ) {
     973                                        $out[] = (string) $key;
     974                                        break;
     975                                }
     976                        }
     977                }
     978                return implode( ',', array_unique( $out ) );
    972979        }
    973980
    … …  
    13511358                }
    13521359                $post_url = admin_url( 'admin-post.php' );
    1353                 PremiumPress_Admin_UI::open( 'listings', __( 'Import / Export', 'premiumpress-directory' ), __( 'Download your listings as a spreadsheet, or add many at once from one.', 'premiumpress-directory' ) );
     1360                PremiumPress_Admin_UI::open( 'listings', __( 'Import / Export', 'premiumpress-directory' ), sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Download your %s as a spreadsheet, or add many at once from one.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) );
    13541361                PremiumPress_Admin_UI::crumb();
    13551362                echo '<div class="ppd-porting">';
    … …  
    13681375                        echo '<div class="notice notice-info inline"><p>';
    13691376                        /* translators: %d: number of listings */
    1370                         echo esc_html( sprintf( _n( '%d imported listing still needs its photos downloaded or its map position looked up.', '%d imported listings still need their photos downloaded or their map positions looked up.', $left, 'premiumpress-directory' ), $left ) );
     1377                        echo esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( '%1$d imported %2$s still needs its photos downloaded or its map position looked up.', '%1$d imported %2$s still need their photos downloaded or their map positions looked up.', $left, 'premiumpress-directory' ), $left, ( 1 === $left ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) );
    13711378                        echo '</p><form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_PHOTOS ) . '">';
    13721379                        wp_nonce_field( self::A_PHOTOS );
    … …  
    13951402                echo '<div class="ppd-a-twocards"><section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">';
    13961403                PremiumPress_Admin_UI::e_icon( 'download', 22 );
    1397                 echo '</span><h2 class="ppd-a-h2">' . esc_html__( 'Download your listings', 'premiumpress-directory' ) . '</h2>';
     1404                echo '</span><h2 class="ppd-a-h2">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Download your %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</h2>';
    13981405                /* translators: %d: number of listings */
    1399                 echo '<p>' . esc_html( sprintf( _n( 'Save your %d listing as a spreadsheet you can open in Excel or Google Sheets.', 'Save all %d listings as a spreadsheet you can open in Excel or Google Sheets.', $count, 'premiumpress-directory' ), $count ) ) . '</p>';
    1400                 echo '<ul class="ppd-port-uses"><li>' . esc_html__( 'Keep a copy as a backup.', 'premiumpress-directory' ) . '</li><li>' . esc_html__( 'Change lots of listings at once, then add the file back on the right to update them.', 'premiumpress-directory' ) . '</li><li>' . esc_html__( 'Move them into a PremiumPress theme later.', 'premiumpress-directory' ) . '</li></ul>';
     1406                echo '<p>' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'Save your %1$d %2$s as a spreadsheet you can open in Excel or Google Sheets.', 'Save all %1$d %2$s as a spreadsheet you can open in Excel or Google Sheets.', $count, 'premiumpress-directory' ), $count, ( 1 === $count ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</p>';
     1407                echo '<ul class="ppd-port-uses"><li>' . esc_html__( 'Keep a copy as a backup.', 'premiumpress-directory' ) . '</li><li>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Change lots of %s at once, then add the file back on the right to update them.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</li><li>' . esc_html__( 'Move them into a PremiumPress theme later.', 'premiumpress-directory' ) . '</li></ul>';
    14011408                echo '<form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_EXPORT ) . '">';
    14021409                wp_nonce_field( self::A_EXPORT );
    … …  
    14071414                echo '<section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">';
    14081415                PremiumPress_Admin_UI::e_icon( 'upload', 22 );
    1409                 echo '</span><h2 class="ppd-a-h2">' . esc_html__( 'Add listings from a spreadsheet', 'premiumpress-directory' ) . '</h2>';
    1410                 echo '<ol class="ppd-port-steps"><li>' . esc_html__( 'Make a spreadsheet with one listing on each row. Put the column names in the first row; only "Title" is needed.', 'premiumpress-directory' ) . '</li>';
     1416                echo '</span><h2 class="ppd-a-h2">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Add %s from a spreadsheet', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</h2>';
     1417                echo '<ol class="ppd-port-steps"><li>' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Make a spreadsheet with one %s on each row. Put the column names in the first row; only "Title" is needed.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</li>';
    14111418                echo '<li>' . esc_html__( 'Save it as a CSV file (in Excel: File, Save as, CSV).', 'premiumpress-directory' ) . '</li>';
    1412                 echo '<li>' . esc_html__( 'Choose the file below and click Upload. New rows become new listings; rows from a downloaded file update their listing.', 'premiumpress-directory' ) . '</li></ol>';
    1413                 echo '<details class="ppd-columns"><summary>' . esc_html__( 'Columns you can use', 'premiumpress-directory' ) . '</summary><p>' . esc_html__( 'Photos: put the pictures\' web addresses in an "Images" column, separated by |. They are copied into your Media Library after the upload.', 'premiumpress-directory' ) . '</p><p><code>' . esc_html( implode( ', ', self::columns() ) ) . '</code></p><p>' . esc_html__( 'Opening hours: one column per day ("Monday hours": 09:00-17:00, 9am-5pm, Closed, Open 24 hours), or one "Opening hours" column for the week (Mon-Fri 9:00-17:00; Sat 10-4; Sun closed). Categories and locations: separate several with |, and write a sub-category as Parent > Child.', 'premiumpress-directory' ) . '</p></details>';
     1419                echo '<li>' . esc_html( sprintf( /* translators: 1: plural item name, e.g. listings, jobs, 2: singular item name, e.g. listing, job */ __( 'Choose the file below and click Upload. New rows become new %1$s; rows from a downloaded file update their %2$s.', 'premiumpress-directory' ), PremiumPress_Profiles::many(), PremiumPress_Profiles::one() ) ) . '</li></ol>';
     1420                echo '<details class="ppd-columns"><summary>' . esc_html__( 'Columns you can use', 'premiumpress-directory' ) . '</summary><p>' . esc_html__( 'Photos: put the pictures\' web addresses in an "Images" column, separated by |. They are copied into your Media Library after the upload.', 'premiumpress-directory' ) . '</p><p><code>' . esc_html( implode( ', ', self::columns() ) ) . '</code></p><p>' . ( PremiumPress_Profiles::has_section( 'hours' ) ? esc_html__( 'Opening hours: one column per day ("Monday hours": 09:00-17:00, 9am-5pm, Closed, Open 24 hours), or one "Opening hours" column for the week (Mon-Fri 9:00-17:00; Sat 10-4; Sun closed).', 'premiumpress-directory' ) . ' ' : '' ) . esc_html__( 'Categories and locations: separate several with |, and write a sub-category as Parent > Child.', 'premiumpress-directory' ) . '</p></details>';
    14141421                echo '<form method="post" action="' . esc_url( $post_url ) . '" enctype="multipart/form-data"><input type="hidden" name="action" value="' . esc_attr( self::A_IMPORT ) . '">';
    14151422                wp_nonce_field( self::A_IMPORT );
    … …  
    14171424                echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">';
    14181425                PremiumPress_Admin_UI::e_icon( 'upload', 16 );
    1419                 echo ' ' . esc_html__( 'Upload and add listings', 'premiumpress-directory' ) . '</button></form></section></div>';
     1426                echo ' ' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Upload and add %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</button></form></section></div>';
    14201427                echo '</div>';
    14211428                PremiumPress_Admin_UI::close();
  • premiumpress-directory/trunk/includes/class-premiumpress-profiles.php

    r3838627 r3848540  
    3737                }
    3838
    39                 $money = self::currency_symbol();
    40 
    41                 self::$defs = (array) apply_filters(
    42                         'premiumpress_profiles',
    43                         array(
    44                                 'directory'   => array(
    45                                         'label'       => __( 'Business directory', 'premiumpress-directory' ),
    46                                         'description' => __( 'Local businesses, services and places, with opening hours and contact details.', 'premiumpress-directory' ),
    47                                         'singular'    => __( 'Listing', 'premiumpress-directory' ),
    48                                         'plural'      => __( 'Listings', 'premiumpress-directory' ),
    49                                         'menu'        => __( 'Directory', 'premiumpress-directory' ),
    50                                         'theme_name'  => __( 'Directory theme', 'premiumpress-directory' ),
    51                                         'theme_url'   => 'https://www.premiumpress.com/wordpress-directory-theme/',
    52                                         'sections'    => array( 'contact', 'location', 'hours' ),
    53                                         'schema'      => 'LocalBusiness',
    54                                         'fields'      => array(
    55                                                 'price_range'      => array(
    56                                                         'label'   => __( 'Price range', 'premiumpress-directory' ),
    57                                                         'type'    => 'select',
    58                                                         'options' => array( $money, str_repeat( $money, 2 ), str_repeat( $money, 3 ), str_repeat( $money, 4 ) ),
    59                                                         'card'    => true,
    60                                                 ),
    61                                                 'established'      => array(
    62                                                         'label' => __( 'Established', 'premiumpress-directory' ),
    63                                                         'type'  => 'text',
    64                                                         'help'  => __( 'The year this business opened, e.g. 2014.', 'premiumpress-directory' ),
    65                                                 ),
    66                                                 'payment_methods'  => array(
    67                                                         'label'   => __( 'Payment methods', 'premiumpress-directory' ),
    68                                                         'type'    => 'checkbox',
    69                                                         'options' => array( 'Cash', 'Credit / debit card', 'Contactless', 'Mobile payments', 'Bank transfer' ),
    70                                                 ),
    71                                                 'parking'          => array(
    72                                                         'label'   => __( 'Parking', 'premiumpress-directory' ),
    73                                                         'type'    => 'select',
    74                                                         'options' => array( 'Free on-site', 'Paid on-site', 'Street parking', 'None nearby' ),
    75                                                 ),
    76                                                 'accessibility'    => array(
    77                                                         'label'   => __( 'Accessibility', 'premiumpress-directory' ),
    78                                                         'type'    => 'select',
    79                                                         'options' => array( 'Step-free access', 'Partially accessible', 'Not accessible' ),
    80                                                 ),
    81                                                 'wifi'             => array(
    82                                                         'label'   => __( 'Wi-Fi', 'premiumpress-directory' ),
    83                                                         'type'    => 'select',
    84                                                         'options' => array( 'Free', 'For customers', 'None' ),
    85                                                 ),
    86                                                 'appointments'     => array(
    87                                                         'label'   => __( 'Appointments', 'premiumpress-directory' ),
    88                                                         'type'    => 'select',
    89                                                         'options' => array( 'Walk-ins welcome', 'Appointment only', 'Walk-ins and appointments' ),
    90                                                 ),
    91                                                 'languages_spoken' => array(
    92                                                         'label'   => __( 'Languages spoken', 'premiumpress-directory' ),
    93                                                         'type'    => 'checkbox',
    94                                                         'options' => array( 'English', 'Spanish', 'French', 'German', 'Polish', 'Urdu' ),
    95                                                 ),
    96                                         ),
    97                                 ),
    98                                 'classifieds' => array(
    99                                         'label'       => __( 'Classified ads', 'premiumpress-directory' ),
    100                                         'description' => __( 'People post items for sale with a price, condition and location.', 'premiumpress-directory' ),
    101                                         'singular'    => __( 'Ad', 'premiumpress-directory' ),
    102                                         'plural'      => __( 'Ads', 'premiumpress-directory' ),
    103                                         'menu'        => __( 'Classifieds', 'premiumpress-directory' ),
    104                                         'theme_name'  => __( 'Classifieds theme', 'premiumpress-directory' ),
    105                                         'theme_url'   => 'https://www.premiumpress.com/wordpress-classifieds-theme/',
    106                                         'sections'    => array( 'contact', 'location' ),
    107                                         'schema'      => '',
    108                                         'fields'      => array(
    109                                                 'price'     => array(
    110                                                         'label' => __( 'Price', 'premiumpress-directory' ),
    111                                                         'type'  => 'number',
    112                                                         'money' => true,
    113                                                         'card'  => true,
    114                                                 ),
    115                                                 'condition' => array(
    116                                                         'label'   => __( 'Condition', 'premiumpress-directory' ),
    117                                                         'type'    => 'select',
    118                                                         'options' => array( 'New', 'Like new', 'Good', 'Fair', 'For parts' ),
    119                                                         'card'    => true,
    120                                                 ),
    121                                         ),
    122                                 ),
    123                         )
    124                 );
     39                // Each plugin's own site types, fields, filters and sorts.
     40                self::$defs = (array) apply_filters( 'premiumpress_profiles', (array) require PREMIUMPRESS_DIR . 'includes/profile-data.php' );
    12541
    12642                return self::$defs;
    … …  
    12945        /** @return array<int, string> Keys of released profiles, in registry order. */
    13046        public static function enabled(): array {
    131                 $on = (array) apply_filters( 'premiumpress_enabled_profiles', array( 'directory' ) );
     47                $on = (array) apply_filters( 'premiumpress_enabled_profiles', array( PREMIUMPRESS_PROFILE ) );
    13248                return array_values( array_intersect( array_keys( self::all() ), $on ) );
    13349        }
    … …  
    15571                if ( '' === $key ) {
    15672                        $enabled = self::enabled();
    157                         $key     = $enabled ? $enabled[0] : 'directory';
     73                        $key     = $enabled ? $enabled[0] : PREMIUMPRESS_PROFILE;
    15874                }
    15975                $all = self::all();
    … …  
    17692
    17793        /**
    178          * Record the profile in the shared option when it is still empty, so a later
    179          * theme upgrade opens in the same niche. Never overwrites a value the site
    180          * already has.
     94         * Record the profile in the shared option, so a later theme upgrade opens in
     95         * the same niche. This plugin runs one site type, and only runs when it is in
     96         * charge of the site's listings, so its type is the site's type.
    18197         */
    18298        public static function remember_single(): void {
    183                 if ( '' === (string) get_option( self::OPTION, '' ) && 1 === count( self::enabled() ) ) {
    184                         update_option( self::OPTION, self::enabled()[0] );
    185                 }
     99                $enabled = self::enabled();
     100                if ( 1 === count( $enabled ) && (string) get_option( self::OPTION, '' ) !== $enabled[0] ) {
     101                        update_option( self::OPTION, $enabled[0] );
     102                }
     103        }
     104
     105        /** The word for the whole site, e.g. "directory" or "job board" (capitalised on request). */
     106        public static function noun( bool $capital = false ): string {
     107                $noun = (string) ( self::current()['noun'] ?? __( 'directory', 'premiumpress-directory' ) );
     108                return $capital ? ucfirst( $noun ) : $noun;
     109        }
     110
     111        /** One item, e.g. "listing", "ad", "job". */
     112        public static function one( bool $capital = false ): string {
     113                $one = (string) self::current()['singular'];
     114                return $capital ? $one : mb_strtolower( $one );
     115        }
     116
     117        /** Several items, e.g. "listings", "ads", "jobs". */
     118        public static function many( bool $capital = false ): string {
     119                $many = (string) self::current()['plural'];
     120                return $capital ? $many : mb_strtolower( $many );
     121        }
     122
     123        /** One item with its article, e.g. "a listing", "an ad". */
     124        public static function a_one( bool $capital = false ): string {
     125                $a = (string) ( self::current()['a_singular'] ?? '' );
     126                if ( '' === $a ) {
     127                        /* translators: %s: singular item name, lowercase */
     128                        $a = sprintf( __( 'a %s', 'premiumpress-directory' ), self::one() );
     129                }
     130                return $capital ? ucfirst( $a ) : $a;
    186131        }
    187132
    … …  
    215160        }
    216161
    217         /** Upgrade link for the active profile, tagged for analytics. */
     162        /** Upgrade link for the active profile, tagged so our site can see which plugin sent the visit. */
    218163        public static function theme_url( string $anchor = '' ): string {
    219                 $url = add_query_arg( 'src', 'plugin', (string) self::current()['theme_url'] );
     164                $url = add_query_arg(
     165                        array(
     166                                'utm_source'   => PREMIUMPRESS_UTM,
     167                                'utm_medium'   => 'wp-admin',
     168                                'utm_campaign' => PREMIUMPRESS_UTM,
     169                                'utm_term'     => 'wp-admin',
     170                        ),
     171                        (string) self::current()['theme_url']
     172                );
    220173                return '' !== $anchor ? $url . '#' . $anchor : $url;
    221174        }
    … …  
    234187
    235188        /**
     189         * A field's options as stored value => label. Plain lists store the label itself
     190         * (the theme's custom-field style); keyed lists store the theme's own slugs.
     191         *
     192         * @param array<string, mixed> $field
     193         * @return array<string, string>
     194         */
     195        public static function options( array $field ): array {
     196                $opts = (array) ( $field['options'] ?? array() );
     197                if ( array_values( $opts ) === $opts ) {
     198                        $opts = array_combine( array_map( 'strval', $opts ), array_map( 'strval', $opts ) );
     199                }
     200                return array_map( 'strval', $opts );
     201        }
     202
     203        /**
     204         * Read a field for a listing. Fields with `tax` are stored as a term of that
     205         * taxonomy (the term slug is the value), everything else as post meta.
     206         *
     207         * @param array<string, mixed> $field
     208         */
     209        public static function get_field( int $post_id, string $key, array $field ): string {
     210                if ( ! empty( $field['tax'] ) ) {
     211                        $terms = get_the_terms( $post_id, (string) $field['tax'] );
     212                        return is_array( $terms ) && $terms ? (string) $terms[0]->slug : '';
     213                }
     214                return (string) get_post_meta( $post_id, $key, true );
     215        }
     216
     217        /**
     218         * Store a sanitised field value ('' removes it).
     219         *
     220         * @param array<string, mixed> $field
     221         */
     222        public static function set_field( int $post_id, string $key, array $field, string $value ): void {
     223                if ( ! empty( $field['tax'] ) ) {
     224                        $tax = (string) $field['tax'];
     225                        if ( ! taxonomy_exists( $tax ) ) {
     226                                return;
     227                        }
     228                        if ( '' === $value ) {
     229                                wp_set_object_terms( $post_id, array(), $tax );
     230                                return;
     231                        }
     232                        if ( ! term_exists( $value, $tax ) ) {
     233                                $labels = self::options( $field );
     234                                wp_insert_term( $labels[ $value ] ?? $value, $tax, array( 'slug' => $value ) );
     235                        }
     236                        wp_set_object_terms( $post_id, array( $value ), $tax );
     237                        return;
     238                }
     239                if ( '' === $value ) {
     240                        delete_post_meta( $post_id, $key );
     241                } else {
     242                        update_post_meta( $post_id, $key, $value );
     243                }
     244                /**
     245                 * A profile field was saved (admin or front end). Niche rules hook in here.
     246                 */
     247                do_action( 'premiumpress_field_saved', $post_id, $key, $value );
     248        }
     249
     250        /**
     251         * A listing's field ready for display. Niche code can reword it through the
     252         * `premiumpress_display_field` filter (for example "Free" for a free ad's price).
     253         *
     254         * @param array<string, mixed> $field
     255         */
     256        public static function display( int $post_id, string $key, array $field ): string {
     257                $text = self::display_value( $field, self::get_field( $post_id, $key, $field ) );
     258                return (string) apply_filters( 'premiumpress_display_field', $text, $key, $post_id, $field );
     259        }
     260
     261        /**
    236262         * A field's value ready for display: comma-lists spaced, money prefixed.
    237263         *
    … …  
    254280                        return implode( ', ', array_filter( array_map( 'trim', explode( ',', $value ) ) ) );
    255281                }
     282                if ( 'select' === ( $field['type'] ?? '' ) ) {
     283                        $labels = self::options( $field );
     284                        return $labels[ $value ] ?? $value;
     285                }
    256286                return $value;
    257287        }
  • premiumpress-directory/trunk/includes/class-premiumpress-sample.php

    r3837691 r3848540  
    11<?php
    22/**
    3  * Sample content: a handful of realistic example items (with photos, real map
    4  * positions, hours and details) so a new site can see how everything works.
     3 * Sample content: a handful of realistic example ads (real map positions, prices
     4 * and ad types) so a new site can see how everything works.
    55 * Everything created is tagged, so "Remove sample content" takes it all away
    66 * again — items, their photos, and any categories or places it added.
    7  *
    8  * The photos in assets/sample/ were made for this plugin and are GPL-licensed
    9  * with it.
     7
    108 *
    119 * @package PremiumPress
    … …  
    2422         */
    2523        public static function items(): array {
    26                 $items = array();
    27                 if ( 'directory' === PremiumPress_Profiles::current()['key'] ) {
    28                         $week = static function ( string $from, string $to, array $closed = array() ): array {
    29                                 $out = array();
    30                                 foreach ( array( 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ) as $d ) {
    31                                         $out[ $d ] = array(
    32                                                 'open'   => ! in_array( $d, $closed, true ),
    33                                                 'h24'    => false,
    34                                                 'ranges' => array(
    35                                                         array(
    36                                                                 'from' => $from,
    37                                                                 'to'   => $to,
    38                                                         ),
    39                                                 ),
    40                                         );
    41                                 }
    42                                 return $out;
    43                         };
    44                         $items = array(
    45                                 array(
    46                                         'title'    => __( 'The Corner Cup', 'premiumpress-directory' ),
    47                                         'content'  => __( 'A friendly neighbourhood coffee shop serving single-origin espresso, fresh pastries and simple lunches. Plenty of seats by the window and free Wi-Fi for laptops.', 'premiumpress-directory' ),
    48                                         'category' => __( 'Cafés', 'premiumpress-directory' ),
    49                                         'image'    => 'cafe',
    50                                         'meta'     => array(
    51                                                 'address'          => '14 Exmouth Market',
    52                                                 'city'             => 'London',
    53                                                 'postcode'         => 'EC1R 4QE',
    54                                                 'lat'              => '51.52608',
    55                                                 'lng'              => '-0.10967',
    56                                                 'phone'            => '020 7946 0101',
    57                                                 'price_range'      => str_repeat( PremiumPress_Profiles::currency_symbol(), 1 ),
    58                                                 'wifi'             => 'Free',
    59                                                 'payment_methods'  => 'Credit / debit card,Contactless',
    60                                                 'accessibility'    => 'Step-free access',
    61                                         ),
    62                                         'hours'    => $week( '07:30', '17:00' ),
    63                                 ),
    64                                 array(
    65                                         'title'    => __( 'Rise & Crumb Bakery', 'premiumpress-directory' ),
    66                                         'content'  => __( 'Slow-fermented sourdough, crusty baguettes and croissants baked every morning. Arrive early at weekends — the cinnamon buns sell out fast.', 'premiumpress-directory' ),
    67                                         'category' => __( 'Bakeries', 'premiumpress-directory' ),
    68                                         'image'    => 'bakery',
    69                                         'meta'     => array(
    70                                                 'address'         => '52 Lamb\'s Conduit Street',
    71                                                 'city'            => 'London',
    72                                                 'postcode'        => 'WC1N 3LW',
    73                                                 'lat'             => '51.52180',
    74                                                 'lng'             => '-0.11860',
    75                                                 'phone'           => '020 7946 0102',
    76                                                 'price_range'     => str_repeat( PremiumPress_Profiles::currency_symbol(), 2 ),
    77                                                 'payment_methods' => 'Cash,Contactless',
    78                                                 'established'     => '2016',
    79                                         ),
    80                                         'hours'    => $week( '07:00', '15:00', array( 'mon' ) ),
    81                                 ),
    82                                 array(
    83                                         'title'    => __( 'Chapter & Verse Books', 'premiumpress-directory' ),
    84                                         'content'  => __( 'An independent bookshop with new and second-hand fiction, a children\'s corner and monthly author evenings. Staff picks change every week.', 'premiumpress-directory' ),
    85                                         'category' => __( 'Bookshops', 'premiumpress-directory' ),
    86                                         'image'    => 'bookshop',
    87                                         'meta'     => array(
    88                                                 'address'          => '8 Cecil Court',
    89                                                 'city'             => 'London',
    90                                                 'postcode'         => 'WC2N 4HE',
    91                                                 'lat'              => '51.51078',
    92                                                 'lng'              => '-0.12731',
    93                                                 'phone'            => '020 7946 0103',
    94                                                 'established'      => '1998',
    95                                                 'payment_methods'  => 'Cash,Credit / debit card,Contactless',
    96                                                 'languages_spoken' => 'English,French',
    97                                         ),
    98                                         'hours'    => $week( '10:00', '19:00' ),
    99                                 ),
    100                                 array(
    101                                         'title'    => __( 'Sharp & Co. Barbers', 'premiumpress-directory' ),
    102                                         'content'  => __( 'Classic cuts, skin fades and hot-towel shaves in a relaxed shop. Book ahead or drop in — walk-ins are welcome most afternoons.', 'premiumpress-directory' ),
    103                                         'category' => __( 'Barbers', 'premiumpress-directory' ),
    104                                         'image'    => 'barber',
    105                                         'meta'     => array(
    106                                                 'address'      => '101 Brick Lane',
    107                                                 'city'         => 'London',
    108                                                 'postcode'     => 'E1 6SE',
    109                                                 'lat'          => '51.52150',
    110                                                 'lng'          => '-0.07170',
    111                                                 'phone'        => '020 7946 0104',
    112                                                 'price_range'  => str_repeat( PremiumPress_Profiles::currency_symbol(), 2 ),
    113                                                 'appointments' => 'Walk-ins and appointments',
    114                                         ),
    115                                         'hours'    => $week( '09:00', '18:30', array( 'sun' ) ),
    116                                 ),
    117                                 array(
    118                                         'title'    => __( 'Petal Street Florist', 'premiumpress-directory' ),
    119                                         'content'  => __( 'Seasonal bouquets, wedding flowers and same-day local delivery. Tell us the occasion and we\'ll make something beautiful.', 'premiumpress-directory' ),
    120                                         'category' => __( 'Florists', 'premiumpress-directory' ),
    121                                         'image'    => 'florist',
    122                                         'meta'     => array(
    123                                                 'address'         => '27 Columbia Road',
    124                                                 'city'            => 'London',
    125                                                 'postcode'        => 'E2 7RG',
    126                                                 'lat'             => '51.52960',
    127                                                 'lng'             => '-0.07140',
    128                                                 'phone'           => '020 7946 0105',
    129                                                 'price_range'     => str_repeat( PremiumPress_Profiles::currency_symbol(), 3 ),
    130                                                 'payment_methods' => 'Credit / debit card,Contactless',
    131                                         ),
    132                                         'hours'    => $week( '08:00', '16:00', array( 'mon' ) ),
    133                                 ),
    134                                 array(
    135                                         'title'    => __( 'Still Point Yoga', 'premiumpress-directory' ),
    136                                         'content'  => __( 'Small, friendly yoga classes for every level, from gentle morning flow to evening yin. Mats and blocks provided; your first class is free.', 'premiumpress-directory' ),
    137                                         'category' => __( 'Fitness', 'premiumpress-directory' ),
    138                                         'image'    => 'yoga',
    139                                         'meta'     => array(
    140                                                 'address'       => '3 Leonard Street',
    141                                                 'city'          => 'London',
    142                                                 'postcode'      => 'EC2A 4AQ',
    143                                                 'lat'           => '51.52490',
    144                                                 'lng'           => '-0.08520',
    145                                                 'phone'         => '020 7946 0106',
    146                                                 'appointments'  => 'Appointment only',
    147                                                 'accessibility' => 'Partially accessible',
    148                                         ),
    149                                         'hours'    => $week( '06:30', '21:00' ),
    150                                 ),
    151                         );
    152                 }
     24                $items = (array) require PREMIUMPRESS_DIR . 'includes/sample-data.php';
    15325                return (array) apply_filters( 'premiumpress_sample_items', $items, PremiumPress_Profiles::current()['key'] );
    15426        }
    … …  
    19062                        foreach ( (array) $item['meta'] as $key => $value ) {
    19163                                update_post_meta( $id, $key, $value );
     64                        }
     65                        foreach ( (array) ( $item['terms'] ?? array() ) as $tax => $slug ) {
     66                                if ( taxonomy_exists( (string) $tax ) ) {
     67                                        wp_set_object_terms( (int) $id, array( (string) $slug ), (string) $tax );
     68                                }
    19269                        }
    19370                        if ( ! empty( $item['hours'] ) ) {
  • premiumpress-directory/trunk/includes/class-premiumpress-search.php

    r3838627 r3848540  
    7777                        'lng'    => $lng,
    7878                        'radius' => in_array( $radius, self::RADII, true ) ? $radius : 25,
    79                         'sort'   => isset( $get['pp_sort'] ) && in_array( $get['pp_sort'], array( 'nearest', 'newest', 'title', 'rating' ), true ) ? (string) $get['pp_sort'] : '',
     79                        'sort'   => isset( $get['pp_sort'] ) && in_array( $get['pp_sort'], array_keys( self::sorts( true ) ), true ) ? (string) $get['pp_sort'] : '',
    8080                        'page'   => isset( $get[ self::PAGE_VAR ] ) ? max( 1, absint( $get[ self::PAGE_VAR ] ) ) : 1,
    8181                        'tag'    => '',
     82                        'f'      => array(),
    8283                );
     84                foreach ( self::filters() as $key => $filter ) {
     85                        if ( 'range' === $filter['type'] ) {
     86                                foreach ( array( 'min', 'max' ) as $end ) {
     87                                        $raw = isset( $get[ 'pp_' . $key . '_' . $end ] ) ? str_replace( array( ',', ' ' ), '', (string) $get[ 'pp_' . $key . '_' . $end ] ) : '';
     88                                        $out['f'][ $key . '_' . $end ] = is_numeric( $raw ) && (float) $raw >= 0 ? (string) ( $raw + 0 ) : '';
     89                                }
     90                        } else {
     91                                $raw    = isset( $get[ 'pp_' . $key ] ) ? sanitize_text_field( (string) $get[ 'pp_' . $key ] ) : '';
     92                                $values = array_keys( PremiumPress_Profiles::options( $filter['def'] ) );
     93                                $out['f'][ $key ] = in_array( $raw, array_map( 'strval', $values ), true ) ? $raw : '';
     94                        }
     95                }
    8396                // phpcs:enable
    8497                $term = self::archive_term();
    … …  
    102115                $t = get_queried_object();
    103116                return $t instanceof WP_Term ? $t : null;
     117        }
     118
     119        /**
     120         * The active profile's search filters, each with its field definition.
     121         *
     122         * @return array<string, array{type:string, def:array<string, mixed>, label:string}>
     123         */
     124        public static function filters(): array {
     125                $p      = PremiumPress_Profiles::current();
     126                $fields = (array) $p['fields'];
     127                $out    = array();
     128                foreach ( (array) ( $p['filters'] ?? array() ) as $f ) {
     129                        $key = (string) ( $f['field'] ?? '' );
     130                        if ( '' === $key || ! isset( $fields[ $key ] ) ) {
     131                                continue;
     132                        }
     133                        $out[ $key ] = array(
     134                                'type'  => 'range' === ( $f['type'] ?? '' ) ? 'range' : 'select',
     135                                'def'   => (array) $fields[ $key ],
     136                                'label' => (string) ( $f['label'] ?? $fields[ $key ]['label'] ),
     137                        );
     138                }
     139                return $out;
     140        }
     141
     142        /**
     143         * Sort options: the shared ones plus the profile's own (e.g. price low to high).
     144         *
     145         * @return array<string, array<string, string>>
     146         */
     147        public static function sorts( bool $with_nearest = false ): array {
     148                $out = array(
     149                        'newest' => array( 'label' => __( 'Newest', 'premiumpress-directory' ) ),
     150                );
     151                $out += (array) ( PremiumPress_Profiles::current()['sorts'] ?? array() );
     152                $out['title'] = array( 'label' => __( 'Name A–Z', 'premiumpress-directory' ) );
     153                if ( PremiumPress_Engage::reviews_on() ) {
     154                        $out['rating'] = array( 'label' => __( 'Highest rated', 'premiumpress-directory' ) );
     155                }
     156                if ( $with_nearest ) {
     157                        $out = array( 'nearest' => array( 'label' => __( 'Nearest', 'premiumpress-directory' ) ) ) + $out;
     158                }
     159                return $out;
    104160        }
    105161
    … …  
    171227                        $args['orderby'] = 'relevance';
    172228                }
    173                 $tax = array();
     229                $profile_sorts = (array) ( PremiumPress_Profiles::current()['sorts'] ?? array() );
     230                if ( isset( $profile_sorts[ $sort ]['meta'] ) ) {
     231                        $args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
     232                                'relation' => 'OR',
     233                                'has'      => array(
     234                                        'key'  => (string) $profile_sorts[ $sort ]['meta'],
     235                                        'type' => 'DECIMAL(14,2)',
     236                                ),
     237                                'missing'  => array(
     238                                        'key'     => (string) $profile_sorts[ $sort ]['meta'],
     239                                        'compare' => 'NOT EXISTS',
     240                                ),
     241                        );
     242                        $args['orderby']    = array(
     243                                'has'  => 'DESC' === ( $profile_sorts[ $sort ]['order'] ?? 'ASC' ) ? 'DESC' : 'ASC',
     244                                'date' => 'DESC',
     245                        );
     246                }
     247                $tax  = array();
     248                $meta = array();
     249                foreach ( self::filters() as $key => $filter ) {
     250                        if ( 'range' === $filter['type'] ) {
     251                                foreach ( array( 'min' => '>=', 'max' => '<=' ) as $end => $cmp ) {
     252                                        if ( '' !== $r['f'][ $key . '_' . $end ] ) {
     253                                                $meta[] = array(
     254                                                        'key'     => $key,
     255                                                        'value'   => $r['f'][ $key . '_' . $end ],
     256                                                        'compare' => $cmp,
     257                                                        'type'    => 'DECIMAL(14,2)',
     258                                                );
     259                                        }
     260                                }
     261                        } elseif ( '' !== $r['f'][ $key ] ) {
     262                                if ( ! empty( $filter['def']['tax'] ) ) {
     263                                        $tax[] = array(
     264                                                'taxonomy' => (string) $filter['def']['tax'],
     265                                                'field'    => 'slug',
     266                                                'terms'    => $r['f'][ $key ],
     267                                        );
     268                                } else {
     269                                        $meta[] = array(
     270                                                'key'   => $key,
     271                                                'value' => $r['f'][ $key ],
     272                                        );
     273                                }
     274                        }
     275                }
     276                if ( $meta ) {
     277                        $meta['relation'] = 'AND';
     278                        if ( ! empty( $args['meta_query'] ) ) {
     279                                $meta['sort'] = $args['meta_query'];
     280                        }
     281                        $args['meta_query'] = $meta; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
     282                }
    174283                if ( '' !== $r['cat'] ) {
    175284                        $tax[] = array(
    … …  
    259368                $uid     = wp_unique_id( 'ppd-s-' );
    260369                $lookup  = $places && PremiumPress_Geo::lookup_enabled();
    261                 $action  = remove_query_arg( array( 'pp_q', 'pp_cat', 'pp_loc', 'pp_near', 'pp_lat', 'pp_lng', 'pp_radius', 'pp_sort', self::PAGE_VAR ) );
     370                $params  = array( 'pp_q', 'pp_cat', 'pp_loc', 'pp_near', 'pp_lat', 'pp_lng', 'pp_radius', 'pp_sort', self::PAGE_VAR );
     371                foreach ( self::filters() as $key => $filter ) {
     372                        $params = array_merge( $params, 'range' === $filter['type'] ? array( 'pp_' . $key . '_min', 'pp_' . $key . '_max' ) : array( 'pp_' . $key ) );
     373                }
     374                $action  = remove_query_arg( $params );
    262375                // On a category or location page, a new search goes to the main directory
    263376                // page (the term is already picked in the form), so filters never clash.
    … …  
    266379                        $action = $dir;
    267380                }
     381                $filtered = (bool) array_filter( $r['f'], 'strlen' );
    268382                $units   = 'mi' === PremiumPress_Geo::units() ? __( 'miles', 'premiumpress-directory' ) : __( 'km', 'premiumpress-directory' );
    269383                $has_geo = null !== $r['lat'];
    … …  
    286400
    287401                        <?php echo self::terms_select( $uid . '-cat', 'pp_cat', PremiumPress_Post_Types::TAX_CATEGORY, $r['cat'], __( 'Category', 'premiumpress-directory' ), __( 'All categories', 'premiumpress-directory' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in terms_select(). ?>
     402
     403                        <?php foreach ( self::filters() as $premiumpress_key => $premiumpress_filter ) : ?>
     404                                <?php if ( 'range' === $premiumpress_filter['type'] ) : ?>
     405                                        <fieldset class="ppd-search__field ppd-search__field--range">
     406                                                <legend><?php echo esc_html( $premiumpress_filter['label'] . ( ! empty( $premiumpress_filter['def']['money'] ) ? ' (' . PremiumPress_Profiles::currency_symbol() . ')' : '' ) ); ?></legend>
     407                                                <div class="ppd-search__range">
     408                                                        <input type="number" min="0" step="any" name="pp_<?php echo esc_attr( $premiumpress_key ); ?>_min" value="<?php echo esc_attr( $r['f'][ $premiumpress_key . '_min' ] ); ?>" placeholder="<?php esc_attr_e( 'Min', 'premiumpress-directory' ); ?>" aria-label="<?php echo esc_attr( sprintf( /* translators: %s: field name, e.g. Price */ __( 'Minimum %s', 'premiumpress-directory' ), mb_strtolower( $premiumpress_filter['label'] ) ) ); ?>">
     409                                                        <span aria-hidden="true">–</span>
     410                                                        <input type="number" min="0" step="any" name="pp_<?php echo esc_attr( $premiumpress_key ); ?>_max" value="<?php echo esc_attr( $r['f'][ $premiumpress_key . '_max' ] ); ?>" placeholder="<?php esc_attr_e( 'Max', 'premiumpress-directory' ); ?>" aria-label="<?php echo esc_attr( sprintf( /* translators: %s: field name, e.g. Price */ __( 'Maximum %s', 'premiumpress-directory' ), mb_strtolower( $premiumpress_filter['label'] ) ) ); ?>">
     411                                                </div>
     412                                        </fieldset>
     413                                <?php else : ?>
     414                                        <div class="ppd-search__field">
     415                                                <label for="<?php echo esc_attr( $uid . '-' . $premiumpress_key ); ?>"><?php echo esc_html( $premiumpress_filter['label'] ); ?></label>
     416                                                <select id="<?php echo esc_attr( $uid . '-' . $premiumpress_key ); ?>" name="pp_<?php echo esc_attr( $premiumpress_key ); ?>">
     417                                                        <option value=""><?php esc_html_e( 'Any', 'premiumpress-directory' ); ?></option>
     418                                                        <?php foreach ( PremiumPress_Profiles::options( $premiumpress_filter['def'] ) as $premiumpress_value => $premiumpress_label ) : ?>
     419                                                                <option value="<?php echo esc_attr( (string) $premiumpress_value ); ?>" <?php selected( (string) $premiumpress_value, $r['f'][ $premiumpress_key ] ); ?>><?php echo esc_html( $premiumpress_label ); ?></option>
     420                                                        <?php endforeach; ?>
     421                                                </select>
     422                                        </div>
     423                                <?php endif; ?>
     424                        <?php endforeach; ?>
    288425
    289426                        <?php if ( $places ) : ?>
    … …  
    317454                        <div class="ppd-search__actions">
    318455                                <button type="submit" class="ppd-button wp-element-button"><?php esc_html_e( 'Search', 'premiumpress-directory' ); ?></button>
    319                                 <?php if ( '' === $dir && ( '' !== $r['q'] || '' !== $r['cat'] || '' !== $r['loc'] || '' !== $r['near'] || $has_geo ) ) : ?>
     456                                <?php if ( '' === $dir && ( '' !== $r['q'] || '' !== $r['cat'] || '' !== $r['loc'] || '' !== $r['near'] || $has_geo || $filtered ) ) : ?>
    320457                                        <a class="ppd-search__reset" href="<?php echo esc_url( $action ); ?>"><?php esc_html_e( 'Clear', 'premiumpress-directory' ); ?></a>
    321458                                <?php endif; ?>
    … …  
    334471         */
    335472        private static function sort_control( string $sort, bool $has_origin ): string {
    336                 $options = array(
    337                         'newest' => __( 'Newest', 'premiumpress-directory' ),
    338                         'title'  => __( 'Name A–Z', 'premiumpress-directory' ),
    339                         'rating' => __( 'Highest rated', 'premiumpress-directory' ),
    340                 );
    341                 if ( $has_origin ) {
    342                         $options = array( 'nearest' => __( 'Nearest', 'premiumpress-directory' ) ) + $options;
    343                 }
     473                $options = wp_list_pluck( self::sorts( $has_origin ), 'label' );
    344474                $id   = wp_unique_id( 'ppd-sort-' );
    345475                $html = '<form class="ppd-sort" method="get" action="' . esc_url( remove_query_arg( array( 'pp_sort', self::PAGE_VAR ) ) ) . '">';
  • premiumpress-directory/trunk/includes/class-premiumpress-settings.php

    r3838627 r3848540  
    102102                        'geocode'  => ! empty( $in['geocode'] ),
    103103                        'maps'     => ! empty( $in['maps'] ),
    104                         'units'     => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi',
     104                        'units'      => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi',
    105105                        'emails'     => ! empty( $in['emails'] ),
    106106                        'duration'   => isset( $in['duration'] ) ? min( 3650, max( 0, absint( $in['duration'] ) ) ) : 0,
    … …  
    172172                $out = array(
    173173                        'listings' => array(
    174                                 'title' => __( 'Listings & moderation', 'premiumpress-directory' ),
     174                                'title' => sprintf( /* translators: %s: plural item name, capitalised, e.g. Listings */ __( '%s & moderation', 'premiumpress-directory' ), PremiumPress_Profiles::many( true ) ),
    175175                                'desc'  => __( 'Approval before going live, how long items stay up, and the terms people agree to', 'premiumpress-directory' ),
    176176                                'icon'  => 'shield',
    177177                                'group' => 'general',
    178                                 'find'  => array( __( 'Moderation', 'premiumpress-directory' ), __( 'Listing duration', 'premiumpress-directory' ), __( 'Terms page', 'premiumpress-directory' ), __( 'Site type', 'premiumpress-directory' ) ),
     178                                'find'  => array( __( 'Moderation', 'premiumpress-directory' ), sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s duration', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ), __( 'Terms page', 'premiumpress-directory' ), __( 'Site type', 'premiumpress-directory' ) ),
    179179                        ),
    180180                        'email'    => array(
    … …  
    253253                if ( isset( $sections[ $section ] ) ) {
    254254                        // The theme's settings page: "All settings / Maps", the topic on the left, its rows on the right.
    255                         PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), __( 'Configure how your directory behaves.', 'premiumpress-directory' ) );
     255                        PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Configure how your %s behaves.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    256256                        echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::base_url() ) . '">';
    257257                        PremiumPress_Admin_UI::e_icon( 'back', 16 );
    … …  
    265265                }
    266266
    267                 PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), __( 'Configure how your directory behaves.', 'premiumpress-directory' ) );
     267                PremiumPress_Admin_UI::open( 'settings', __( 'Settings', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Configure how your %s behaves.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    268268                if ( $saved ) {
    269269                        echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Settings saved.', 'premiumpress-directory' ) . '</div>';
    270270                }
    271271                $groups = array(
    272                         'general' => array( __( 'General', 'premiumpress-directory' ), __( 'Core settings that control how listings are added and kept.', 'premiumpress-directory' ) ),
     272                        'general' => array( __( 'General', 'premiumpress-directory' ), sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Core settings that control how %s are added and kept.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ),
    273273                        'maps'    => array( __( 'Maps', 'premiumpress-directory' ), __( 'Where things are, and how far away.', 'premiumpress-directory' ) ),
    274274                        'content' => array( __( 'Pages & content', 'premiumpress-directory' ), __( 'The pages visitors use and the sample items.', 'premiumpress-directory' ) ),
    … …  
    420420                                echo '<span class="ppd-a-pill ppd-a-pill--blue">' . esc_html( (string) $p['label'] ) . '</span></div></div>';
    421421                        }
    422                         self::switch_row( 'moderate', __( 'Approve new listings', 'premiumpress-directory' ), $s['moderate'], __( 'Hold items submitted from the front end for approval before they go live.', 'premiumpress-directory' ) );
    423                         self::stack_row( __( 'Listing duration', 'premiumpress-directory' ), __( '0 = never expires. Owners get a reminder a week before, and can renew from their page.', 'premiumpress-directory' ), 'ppd-duration' );
     422                        self::switch_row( 'moderate', sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Approve new %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ), $s['moderate'], __( 'Hold items submitted from the front end for approval before they go live.', 'premiumpress-directory' ) );
     423                        self::stack_row( sprintf( /* translators: %s: singular item name, capitalised, e.g. Listing */ __( '%s duration', 'premiumpress-directory' ), PremiumPress_Profiles::one( true ) ), __( '0 = never expires. Owners get a reminder a week before, and can renew from their page.', 'premiumpress-directory' ), 'ppd-duration' );
    424424                        printf( '<span class="ppd-a-inline"><input type="number" id="ppd-duration" class="ppd-a-input ppd-a-input--num" name="%1$s[duration]" value="%2$d" min="0" max="3650"> %3$s</span></div></div>', esc_attr( self::OPTION ), (int) $s['duration'], esc_html__( 'days', 'premiumpress-directory' ) );
    425425                        self::stack_row( __( 'Terms page', 'premiumpress-directory' ), __( 'When set, people must agree to this page before submitting.', 'premiumpress-directory' ), 'ppd-terms' );
    … …  
    440440                } elseif ( 'maps' === $section ) {
    441441                        self::hidden_rest( array( 'maps', 'geocode', 'units' ) );
    442                         self::switch_row( 'maps', __( 'Maps', 'premiumpress-directory' ), $s['maps'], __( 'Show OpenStreetMap maps on listing and search pages.', 'premiumpress-directory' ), __( 'Map images are loaded from OpenStreetMap\'s servers, which see the visitor\'s IP address. Off by default.', 'premiumpress-directory' ) );
     442                        self::switch_row( 'maps', __( 'Maps', 'premiumpress-directory' ), $s['maps'], sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Show OpenStreetMap maps on %s and search pages.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ), __( 'Map images are loaded from OpenStreetMap\'s servers, which see the visitor\'s IP address. Off by default.', 'premiumpress-directory' ) );
    443443                        self::switch_row( 'geocode', __( 'Address lookup', 'premiumpress-directory' ), $s['geocode'], __( 'Find map positions from an address automatically.', 'premiumpress-directory' ), __( 'Sends the address to OpenStreetMap\'s Nominatim service. Off by default; without it, enter the position yourself.', 'premiumpress-directory' ) );
    444444                        self::stack_row( __( 'Distances in', 'premiumpress-directory' ), __( 'Used for "near me" searches and the distance on each result.', 'premiumpress-directory' ), 'ppd-units' );
    … …  
    490490
    491491                // Pages.
    492                 echo '<section class="ppd-a-sect"><div class="ppd-a-sect-copy"><h2>' . esc_html__( 'Your directory pages', 'premiumpress-directory' ) . '</h2>';
    493                 echo '<p>' . esc_html__( 'When you installed the plugin it made these three pages and added them to your site menu. Each one shows part of your directory.', 'premiumpress-directory' ) . '</p>';
    494                 echo '<p>' . esc_html__( 'You can rename them or add your own text, like any page. Just keep the directory box that is on each one.', 'premiumpress-directory' ) . '</p></div>';
     492                echo '<section class="ppd-a-sect"><div class="ppd-a-sect-copy"><h2>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s pages', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h2>';
     493                echo '<p>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'When you installed the plugin it made these three pages and added them to your site menu. Each one shows part of your %s.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
     494                echo '<p>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'You can rename them or add your own text, like any page. Just keep the %s box that is on each one.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p></div>';
    495495                echo '<div class="ppd-a-card ppd-pg-list">';
    496496                $missing = false;
    … …  
    540540                );
    541541                $n = count( $samples );
    542                 echo '<section class="ppd-a-sect ppd-pg-gap"><div class="ppd-a-sect-copy"><h2>' . esc_html__( 'Sample listings', 'premiumpress-directory' ) . '</h2>';
    543                 echo '<p>' . esc_html__( 'Examples with photos, opening hours and map positions, so you can see how your directory looks before you have real listings.', 'premiumpress-directory' ) . '</p></div>';
     542                echo '<section class="ppd-a-sect ppd-pg-gap"><div class="ppd-a-sect-copy"><h2>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Sample %s', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</h2>';
     543                echo '<p>' . esc_html( (string) ( PremiumPress_Profiles::current()['sample_note'] ?? '' ) ) . '</p></div>';
    544544                echo '<div class="ppd-a-card ppd-a-pad ppd-pg-sample">';
    545545                if ( $n ) {
    546546                        /* translators: %d: number of sample listings */
    547                         echo '<strong class="ppd-pg-count">' . esc_html( sprintf( _n( '%d sample listing is on your site', '%d sample listings are on your site', $n, 'premiumpress-directory' ), $n ) ) . '</strong>';
     547                        echo '<strong class="ppd-pg-count">' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( '%1$d sample %2$s is on your site', '%1$d sample %2$s are on your site', $n, 'premiumpress-directory' ), $n, ( 1 === $n ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</strong>';
    548548                        echo '<ul class="ppd-pg-names">';
    549549                        foreach ( $samples as $sp ) {
    550550                                echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>';
    551551                        }
    552                         echo '</ul><p class="ppd-a-muted">' . esc_html__( 'Remove them once your own listings are in. Only the samples are removed: your own listings, categories and pages are never touched.', 'premiumpress-directory' ) . '</p>';
     552                        echo '</ul><p class="ppd-a-muted">' . esc_html( sprintf( /* translators: 1: plural item name, e.g. listings, jobs */ __( 'Remove them once your own %1$s are in. Only the samples are removed: your own %1$s, categories and pages are never touched.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p>';
    553553                        echo '<form method="post" action="' . esc_url( admin_url( 'admin-post.php' ) ) . '"><input type="hidden" name="action" value="' . esc_attr( self::SAMPLE_ACTION ) . '"><input type="hidden" name="do" value="remove">';
    554554                        wp_nonce_field( self::SAMPLE_ACTION );
    555555                        /* translators: %d: number of sample listings */
    556                         echo '<button type="submit" class="ppd-a-btn ppd-a-btn--danger" data-ppd-confirm-submit="' . esc_attr( sprintf( _n( 'Remove %d sample listing? Your own listings are not affected.', 'Remove all %d sample listings? Your own listings are not affected.', $n, 'premiumpress-directory' ), $n ) ) . '">' . esc_html( sprintf( _n( 'Remove the %d sample listing', 'Remove the %d sample listings', $n, 'premiumpress-directory' ), $n ) ) . '</button></form>';
     556                        echo '<button type="submit" class="ppd-a-btn ppd-a-btn--danger" data-ppd-confirm-submit="' . esc_attr( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match), 3: plural item name, lowercase */ _n( 'Remove %1$d sample %2$s? Your own %3$s are not affected.', 'Remove all %1$d sample %2$s? Your own %3$s are not affected.', $n, 'premiumpress-directory' ), $n, ( 1 === $n ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ), PremiumPress_Profiles::many() ) ) . '">' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'Remove the %1$d sample %2$s', 'Remove the %1$d sample %2$s', $n, 'premiumpress-directory' ), $n, ( 1 === $n ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</button></form>';
    557557                } else {
    558                         echo '<strong class="ppd-pg-count">' . esc_html__( 'No sample listings are on your site', 'premiumpress-directory' ) . '</strong>';
     558                        echo '<strong class="ppd-pg-count">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'No sample %s are on your site', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</strong>';
    559559                        $items = count( PremiumPress_Sample::items() );
    560560                        if ( $items ) {
    … …  
    564564                                wp_nonce_field( self::SAMPLE_ACTION );
    565565                                /* translators: %d: number of sample listings */
    566                                 echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">' . esc_html( sprintf( __( 'Add %d sample listings', 'premiumpress-directory' ), $items ) ) . '</button></form>';
     566                                echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">' . esc_html( sprintf( /* translators: 1: number, 2: plural item name, e.g. listings */ __( 'Add %1$d sample %2$s', 'premiumpress-directory' ), $items, PremiumPress_Profiles::many() ) ) . '</button></form>';
    567567                        }
    568568                }
    … …  
    571571                // Start again.
    572572                echo '<section class="ppd-a-sect ppd-pg-gap"><div class="ppd-a-sect-copy"><h2>' . esc_html__( 'Start again', 'premiumpress-directory' ) . '</h2></div>';
    573                 echo '<div class="ppd-a-card ppd-a-pad ppd-pg-again"><span><strong>' . esc_html__( 'Run the setup wizard again', 'premiumpress-directory' ) . '</strong><span class="ppd-a-muted">' . esc_html__( 'Change what your directory is about, the town, the homepage or the design. Your listings stay as they are.', 'premiumpress-directory' ) . '</span></span>';
     573                echo '<div class="ppd-a-card ppd-a-pad ppd-pg-again"><span><strong>' . esc_html__( 'Run the setup wizard again', 'premiumpress-directory' ) . '</strong><span class="ppd-a-muted">' . esc_html( sprintf( /* translators: 1: what the site is, e.g. directory, job board, 2: plural item name, e.g. listings, jobs */ __( 'Change what your %1$s is about, the town, the homepage or the design. Your %2$s stay as they are.', 'premiumpress-directory' ), PremiumPress_Profiles::noun(), PremiumPress_Profiles::many() ) ) . '</span></span>';
    574574                echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Wizard::url() ) . '">' . esc_html__( 'Open the setup wizard', 'premiumpress-directory' ) . '</a></div></section>';
    575575        }
    … …  
    625625                $no    = '<span class="ppd-up-no" role="img" aria-label="' . esc_attr__( 'Not included', 'premiumpress-directory' ) . '">&ndash;</span>';
    626626
    627                 // icon, title, description, in this plugin.
    628                 $rows = array(
    629                         array( 'list', __( 'Listings & reviews', 'premiumpress-directory' ), __( 'Create listings, collect reviews and let users favourite listings.', 'premiumpress-directory' ), true ),
    630                         array( 'map', __( 'Search & maps', 'premiumpress-directory' ), __( 'Search by keyword, category, location and distance with maps.', 'premiumpress-directory' ), true ),
    631                         array( 'monitor', __( 'Ready-made designs', 'premiumpress-directory' ), __( 'Launch faster with professional directory homepage designs.', 'premiumpress-directory' ), false ),
    632                         array( 'layers', __( 'Paid listing packages', 'premiumpress-directory' ), __( 'Create listing packages and accept paid submissions.', 'premiumpress-directory' ), false ),
    633                         array( 'card', __( 'Payment gateways', 'premiumpress-directory' ), __( 'Accept payments for listings and upgrades.', 'premiumpress-directory' ), false ),
    634                         array( 'search', __( 'Advanced search & alerts', 'premiumpress-directory' ), __( 'Add advanced filters, saved searches and email alerts.', 'premiumpress-directory' ), false ),
    635                         array( 'chat', __( 'Member messaging', 'premiumpress-directory' ), __( 'Let members message each other from their account dashboard.', 'premiumpress-directory' ), false ),
    636                         array( 'sparkle', __( 'AI site generator', 'premiumpress-directory' ), __( 'Get a head start with an AI-powered site setup for your directory.', 'premiumpress-directory' ), false ),
    637                 );
     627                // icon, title, description, in this plugin: each plugin lists its own theme's extras.
     628                $rows = (array) ( $p['upgrade_rows'] ?? array() );
    638629
    639630                echo '<div class="ppd-up">';
    … …  
    642633                $title = sprintf( esc_html__( 'See what the %s adds', 'premiumpress-directory' ), '<span>' . esc_html( $theme ) . '</span>' );
    643634                echo '<h2>' . wp_kses( $title, array( 'span' => array() ) ) . '</h2>';
    644                 echo '<p>' . esc_html__( 'A more powerful, business-ready version of your directory with modern designs, paid listings and advanced member tools.', 'premiumpress-directory' ) . '</p>';
     635                echo '<p>' . esc_html( (string) ( $p['upgrade_lead'] ?? '' ) ) . '</p>';
    645636                /* translators: %s: theme name, e.g. Directory theme */
    646637                echo '<a class="ppd-a-btn ppd-a-btn--primary ppd-up-btn" href="' . esc_url( $url ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( __( 'Upgrade to the %s', 'premiumpress-directory' ), $theme ) ) . ' ';
    … …  
    660651                PremiumPress_Admin_UI::e_icon( 'layers', 22 );
    661652                /* translators: %s: theme name, e.g. Directory theme */
    662                 echo '</span><span class="ppd-up-cta-copy"><strong>' . esc_html__( 'Ready to unlock more features?', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( __( 'Upgrade to the %s and start building a more powerful directory site today.', 'premiumpress-directory' ), $theme ) ) . '</span></span>';
     653                echo '</span><span class="ppd-up-cta-copy"><strong>' . esc_html__( 'Ready to unlock more features?', 'premiumpress-directory' ) . '</strong><span>' . esc_html( sprintf( (string) ( $p['upgrade_cta'] ?? '%s' ), $theme ) ) . '</span></span>';
    663654                /* translators: %s: theme name, e.g. Directory theme */
    664655                echo '<a class="ppd-a-btn ppd-a-btn--primary" href="' . esc_url( $url ) . '" target="_blank" rel="noopener">' . esc_html( sprintf( __( 'Upgrade to %s', 'premiumpress-directory' ), $theme ) ) . ' ';
  • premiumpress-directory/trunk/includes/class-premiumpress-submit.php

    r3838627 r3848540  
    141141                        'required' => array( 'error', __( 'Please fill in every field marked with *.', 'premiumpress-directory' ) ),
    142142                );
     143                /** Niche code adds its own notices (e.g. "Marked as sold"). */
     144                $map = (array) apply_filters( 'premiumpress_flash_messages', $map, $one );
    143145                if ( ! isset( $map[ $code ] ) ) {
    144146                        return '';
    … …  
    332334                }
    333335                foreach ( PremiumPress_Profiles::fields() as $key => $field ) {
    334                         $value = PremiumPress_Meta::sanitize_field( $field, $in['ppd_f'][ $key ] ?? '' );
    335                         if ( '' === $value ) {
    336                                 delete_post_meta( $id, $key );
    337                         } else {
    338                                 update_post_meta( $id, $key, $value );
    339                         }
     336                        PremiumPress_Profiles::set_field( $id, $key, $field, PremiumPress_Meta::sanitize_field( $field, $in['ppd_f'][ $key ] ?? '' ) );
    340337                }
    341338                if ( PremiumPress_Profiles::has_section( 'hours' ) && isset( $in['ppd_hours'] ) && is_array( $in['ppd_hours'] ) ) {
    … …  
    480477                        self::back( $back, 'renewed' );
    481478                }
     479                /** Niche actions (e.g. mark sold). Return a notice code when handled. */
     480                $code = (string) apply_filters( 'premiumpress_item_action', '', $do, $id );
     481                if ( '' !== $code ) {
     482                        self::back( $back, $code );
     483                }
    482484                self::back( $back, 'failed' );
    483485        }
  • premiumpress-directory/trunk/includes/class-premiumpress-switch.php

    r3838627 r3848540  
    2424        }
    2525
     26        /**
     27         * This plugin's sources (switch-data.php): key => [name, post_type, reader].
     28         *
     29         * @return array<string, array<string, mixed>>
     30         */
     31        public static function data(): array {
     32                static $data = null;
     33                if ( null === $data ) {
     34                        $file = PREMIUMPRESS_DIR . 'includes/switch-data.php';
     35                        $data = file_exists( $file ) ? (array) require $file : array();
     36                }
     37                return $data;
     38        }
     39
    2640        /** @return array<string, string> source => name */
    2741        public static function names(): array {
    28                 return array(
    29                         'directorist' => 'Directorist',
    30                         'geodirectory' => 'GeoDirectory',
    31                         'bdp'          => 'Business Directory Plugin',
    32                 );
     42                $out = array();
     43                foreach ( (array) ( self::data()['sources'] ?? array() ) as $key => $src ) {
     44                        $out[ (string) $key ] = (string) $src['name'];
     45                }
     46                return $out;
    3347        }
    3448
    3549        private static function post_type( string $source ): string {
    36                 $types = array(
    37                         'directorist'  => 'at_biz_dir',
    38                         'geodirectory' => 'gd_place',
    39                         'bdp'          => 'wpbdp_listing',
    40                 );
    41                 return $types[ $source ] ?? '';
     50                return (string) ( self::data()['sources'][ $source ]['post_type'] ?? '' );
    4251        }
    4352
    … …  
    7483                        $wpdb->prepare(
    7584                                "SELECT p.ID FROM {$wpdb->posts} p
    76                                 WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed')
     85                                WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed','rtcl-expired')
    7786                                AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) )
    7887                                ORDER BY p.ID ASC LIMIT %d",
    … …  
    91100                $type = self::post_type( $source );
    92101                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- counts another plugin's rows for the import screen.
    93                 $total = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status IN ('publish','pending','draft','private','future','expired','gd-closed')", $type ) );
     102                $total = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s AND post_status IN ('publish','pending','draft','private','future','expired','gd-closed','rtcl-expired')", $type ) );
    94103                // Same rule as pending_ids(): not copied yet, whatever has happened to earlier copies.
    95104                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- as above.
    … …  
    97106                        $wpdb->prepare(
    98107                                "SELECT COUNT(*) FROM {$wpdb->posts} p
    99                                 WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed')
     108                                WHERE p.post_type = %s AND p.post_status IN ('publish','pending','draft','private','future','expired','gd-closed','rtcl-expired')
    100109                                AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) )",
    101110                                $type,
    … …  
    141150                                }
    142151                                $data['source'] = $source . ':' . $sid;
    143                                 if ( PremiumPress_Porting::write_listing( $data ) ) {
     152                                $new = PremiumPress_Porting::write_listing( $data );
     153                                if ( $new ) {
     154                                        // A plugin's own last step for a copied item (e.g. keep a filled job filled).
     155                                        $after = self::data()['sources'][ $source ]['after'] ?? null;
     156                                        if ( is_callable( $after ) ) {
     157                                                call_user_func( $after, (int) $new, $data );
     158                                        }
    144159                                        ++$copied;
    145160                                } else {
    … …  
    186201                        'copy_images' => true,
    187202                );
    188                 if ( 'directorist' === $source ) {
    189                         return self::directorist( $sid, $post, $d );
    190                 }
    191                 if ( 'geodirectory' === $source ) {
    192                         return self::geodirectory( $sid, $post, $d );
    193                 }
    194                 if ( 'bdp' === $source ) {
    195                         return self::bdp( $sid, $d );
    196                 }
    197                 return null;
    198         }
    199 
    200         /* ===== Directorist ===== */
    201 
    202         /**
    203          * @param array<string, mixed> $d
    204          * @return array<string, mixed>
    205          */
    206         private static function directorist( int $sid, WP_Post $post, array $d ): array {
    207                 $m = static function ( string $k ) use ( $sid ): string {
    208                         $v = get_post_meta( $sid, $k, true );
    209                         return is_scalar( $v ) ? trim( (string) $v ) : '';
    210                 };
    211                 $d['categories'] = self::term_paths( $sid, 'at_biz_dir-category' );
    212                 $d['tags']       = self::term_paths( $sid, 'at_biz_dir-tags' );
    213                 $d['locations']  = self::term_paths( $sid, 'at_biz_dir-location' );
    214                 $d['meta']       = array_filter(
    215                         array(
    216                                 'phone'    => $m( '_phone' ),
    217                                 'email'    => $m( '_email' ),
    218                                 'website'  => $m( '_website' ),
    219                                 'address'  => $m( '_address' ),
    220                                 'postcode' => $m( '_zip' ),
    221                         ),
    222                         'strlen'
    223                 );
    224                 if ( in_array( $m( '_hide_map' ), array( '', '0' ), true ) && is_numeric( $m( '_manual_lat' ) ) && is_numeric( $m( '_manual_lng' ) ) ) {
    225                         $d['lat'] = $m( '_manual_lat' );
    226                         $d['lng'] = $m( '_manual_lng' );
    227                 }
    228                 $d['featured'] = '1' === $m( '_featured' );
    229                 if ( '' !== $m( '_never_expire' ) && '0' !== $m( '_never_expire' ) ) {
    230                         $d['expires'] = 0;
    231                 } elseif ( '' !== $m( '_expiry_date' ) ) {
    232                         $t            = strtotime( get_gmt_from_date( $m( '_expiry_date' ) ) . ' UTC' );
    233                         $d['expires'] = $t ? $t : 0;
    234                 }
    235                 if ( 'expired' === $post->post_status ) {
    236                         $d['status']  = 'draft';
    237                         $d['expired'] = true;
    238                 }
    239                 // Photos: the preview image first, then the gallery.
    240                 $gallery = get_post_meta( $sid, '_listing_img', true );
    241                 $ids     = array_merge( array( (int) $m( '_listing_prv_img' ), (int) get_post_thumbnail_id( $sid ) ), is_array( $gallery ) ? array_map( 'intval', $gallery ) : wp_parse_id_list( (string) $gallery ) );
    242                 $d['image_ids'] = array_values( array_unique( array_filter( $ids ) ) );
    243 
    244                 $hours = self::directorist_hours( $sid );
    245                 if ( null !== $hours ) {
    246                         $d['hours_days'] = $hours;
    247                 }
    248                 $d['reviews'] = self::comment_reviews( $sid, 'directorist', static function ( WP_Comment $c ): float {
    249                         return 'review' === $c->comment_type ? (float) get_comment_meta( (int) $c->comment_ID, 'rating', true ) : 0.0;
    250                 } );
    251                 return $d;
    252         }
    253 
    254         /** @return array<string, array<string, mixed>>|null */
    255         private static function directorist_hours( int $sid ): ?array {
    256                 if ( get_post_meta( $sid, '_disable_bz_hour_listing', true ) ) {
    257                         return null;
    258                 }
    259                 $days = array(
    260                         'monday'    => 'mon',
    261                         'tuesday'   => 'tue',
    262                         'wednesday' => 'wed',
    263                         'thursday'  => 'thu',
    264                         'friday'    => 'fri',
    265                         'saturday'  => 'sat',
    266                         'sunday'    => 'sun',
    267                 );
    268                 if ( 'always' === get_post_meta( $sid, '_enable247hour', true ) ) {
    269                         $out = array();
    270                         foreach ( $days as $k ) {
    271                                 $out[ $k ] = array( 'open' => true, 'h24' => true, 'ranges' => array() );
    272                         }
    273                         return $out;
    274                 }
    275                 $bdbh = get_post_meta( $sid, '_bdbh', true );
    276                 if ( ! is_array( $bdbh ) || ! $bdbh ) {
    277                         return null;
    278                 }
    279                 $out = array();
    280                 foreach ( $days as $long => $k ) {
    281                         $day = isset( $bdbh[ $long ] ) && is_array( $bdbh[ $long ] ) ? $bdbh[ $long ] : array();
    282                         $on  = ! empty( $day['enable'] );
    283                         $all = in_array( (string) ( $day['remain_close'] ?? '' ), array( 'open', 'always_open', 'all_day' ), true );
    284                         $st  = array_values( (array) ( $day['start'] ?? array() ) );
    285                         $cl  = array_values( (array) ( $day['close'] ?? array() ) );
    286                         $ranges = array();
    287                         foreach ( $st as $i => $from ) {
    288                                 // Read with the import's clock, so "9:00", "09:00" and "9:00 am" all work.
    289                                 $a = PremiumPress_Porting::clock( (string) $from );
    290                                 $b = isset( $cl[ $i ] ) ? PremiumPress_Porting::clock( (string) $cl[ $i ] ) : '';
    291                                 if ( '' !== $a && '' !== $b ) {
    292                                         $ranges[] = array( 'from' => $a, 'to' => $b );
    293                                 }
    294                         }
    295                         $out[ $k ] = array(
    296                                 'open'   => $on && ( $all || $ranges ),
    297                                 'h24'    => $on && $all,
    298                                 'ranges' => $all ? array() : $ranges,
    299                         );
    300                 }
    301                 return $out;
    302         }
    303 
    304         /* ===== GeoDirectory ===== */
    305 
    306         /**
    307          * @param array<string, mixed> $d
    308          * @return array<string, mixed>|null
    309          */
    310         private static function geodirectory( int $sid, WP_Post $post, array $d ): ?array {
    311                 global $wpdb;
    312                 $table = $wpdb->prefix . 'geodir_gd_place_detail';
    313                 $row   = null;
    314                 if ( self::table_exists( $table ) ) {
    315                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- GeoDirectory keeps listing details in its own table.
    316                         $row = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM %i WHERE post_id = %d', $table, $sid ), ARRAY_A );
    317                 }
    318                 $row = is_array( $row ) ? $row : array();
    319                 $g   = static function ( string $k ) use ( $row ): string {
    320                         return isset( $row[ $k ] ) && is_scalar( $row[ $k ] ) ? trim( (string) $row[ $k ] ) : '';
    321                 };
    322                 $d['categories'] = self::term_paths( $sid, 'gd_placecategory' );
    323                 $d['tags']       = self::term_paths( $sid, 'gd_place_tags' );
    324                 $street          = trim( $g( 'street' ) . ( '' !== $g( 'street2' ) ? ', ' . $g( 'street2' ) : '' ), ', ' );
    325                 $d['meta']       = array_filter(
    326                         array(
    327                                 'phone'    => $g( 'phone' ),
    328                                 'email'    => $g( 'email' ),
    329                                 'website'  => $g( 'website' ),
    330                                 'address'  => $street,
    331                                 'city'     => $g( 'city' ),
    332                                 'region'   => $g( 'region' ),
    333                                 'postcode' => $g( 'zip' ),
    334                                 'country'  => $g( 'country' ),
    335                         ),
    336                         'strlen'
    337                 );
    338                 if ( '' !== $g( 'city' ) ) {
    339                         $d['locations'] = array( array( $g( 'city' ) ) );
    340                 }
    341                 if ( is_numeric( $g( 'latitude' ) ) && is_numeric( $g( 'longitude' ) ) ) {
    342                         $d['lat'] = $g( 'latitude' );
    343                         $d['lng'] = $g( 'longitude' );
    344                 }
    345                 if ( '' !== $g( 'featured' ) ) {
    346                         $d['featured'] = '1' === $g( 'featured' );
    347                 }
    348                 if ( 'gd-closed' === $post->post_status ) {
    349                         $d['status'] = 'draft';
    350                 }
    351                 if ( '' !== $g( 'business_hours' ) ) {
    352                         $hours = self::geodir_hours( $g( 'business_hours' ) );
    353                         if ( null !== $hours ) {
    354                                 $d['hours_days'] = $hours;
    355                         }
    356                 }
    357                 // Photos: the main image is a Media Library item; the rest are files GeoDirectory
    358                 // tracks itself, which are copied in from disk (or fetched, when stored as a web address).
    359                 $ids  = array( (int) get_post_thumbnail_id( $sid ) );
    360                 $urls = array();
    361                 $att   = $wpdb->prefix . 'geodir_attachments';
    362                 $files = array();
    363                 if ( self::table_exists( $att ) ) {
    364                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- GeoDirectory's own gallery table.
    365                         $files = $wpdb->get_col( $wpdb->prepare( "SELECT file FROM %i WHERE post_id = %d AND type = 'post_images' AND is_approved = 1 ORDER BY featured DESC, menu_order ASC", $att, $sid ) );
    366                 }
    367                 $up    = wp_get_upload_dir();
    368                 foreach ( (array) $files as $file ) {
    369                         $file = (string) $file;
    370                         if ( preg_match( '#^https?://#i', $file ) ) {
    371                                 $urls[] = $file;
    372                                 continue;
    373                         }
    374                         $rel   = ltrim( $file, '/' );
    375                         $local = attachment_url_to_postid( trailingslashit( $up['baseurl'] ) . $rel );
    376                         if ( $local ) {
    377                                 $ids[] = $local;
    378                         } elseif ( '' !== $rel && file_exists( trailingslashit( $up['basedir'] ) . $rel ) ) {
    379                                 $ids[] = PremiumPress_Porting::copy_local_file( trailingslashit( $up['basedir'] ) . $rel );
    380                         }
    381                 }
    382                 $d['image_ids']  = array_values( array_unique( array_filter( $ids ) ) );
    383                 $d['image_urls'] = $urls;
    384 
    385                 $review = $wpdb->prefix . 'geodir_post_review';
    386                 if ( ! self::table_exists( $review ) ) {
    387                         return $d;
    388                 }
    389                 $d['reviews'] = self::comment_reviews( $sid, 'geodirectory', static function ( WP_Comment $c ) use ( $wpdb, $review ): float {
    390                         if ( (int) $c->comment_parent ) {
    391                                 return 0.0;
    392                         }
    393                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- GeoDirectory keeps ratings in its own table.
    394                         return (float) $wpdb->get_var( $wpdb->prepare( 'SELECT rating FROM %i WHERE comment_id = %d', $review, (int) $c->comment_ID ) );
    395                 } );
    396                 return $d;
    397         }
    398 
    399         /**
    400          * GeoDirectory hours: '["Mo 09:00-17:00","Tu 09:00-12:00,13:00-17:00"],["UTC":"+0"]'.
    401          * A day it doesn't list is closed; 00:00-00:00 is open all day.
    402          *
    403          * @return array<string, array<string, mixed>>|null
    404          */
    405         public static function geodir_hours( string $raw ): ?array {
    406                 $raw = trim( wp_unslash( $raw ) );
    407                 if ( ! preg_match( '/^\s*(\[.*?\])/s', $raw, $m ) ) {
    408                         return null;
    409                 }
    410                 $list = json_decode( $m[1], true );
    411                 if ( ! is_array( $list ) ) {
    412                         return null;
    413                 }
    414                 $codes = array( 'mo' => 'mon', 'tu' => 'tue', 'we' => 'wed', 'th' => 'thu', 'fr' => 'fri', 'sa' => 'sat', 'su' => 'sun' );
    415                 $keys  = array_values( $codes );
    416                 $out   = array();
    417                 foreach ( $keys as $k ) {
    418                         $out[ $k ] = array( 'open' => false, 'h24' => false, 'ranges' => array() );
    419                 }
    420                 $any = false;
    421                 foreach ( $list as $entry ) {
    422                         if ( ! is_string( $entry ) || ! preg_match( '/^\s*([a-z]{2})(?:\s*-\s*([a-z]{2}))?\s+(.+)$/i', $entry, $e ) ) {
    423                                 continue;
    424                         }
    425                         $from = strtolower( $e[1] );
    426                         $to   = '' !== $e[2] ? strtolower( $e[2] ) : $from;
    427                         if ( ! isset( $codes[ $from ], $codes[ $to ] ) ) {
    428                                 continue;
    429                         }
    430                         $ranges = array();
    431                         $h24    = false;
    432                         foreach ( explode( ',', $e[3] ) as $slot ) {
    433                                 if ( ! preg_match( '/^\s*(\d{1,2}:\d{2})\s*-\s*(\d{1,2}:\d{2})\s*$/', $slot, $s ) ) {
    434                                         continue;
    435                                 }
    436                                 $a = sprintf( '%05s', $s[1] );
    437                                 $b = sprintf( '%05s', $s[2] );
    438                                 if ( '00:00' === $a && in_array( $b, array( '00:00', '24:00', '23:59' ), true ) ) {
    439                                         $h24 = true;
    440                                         continue;
    441                                 }
    442                                 $ranges[] = array( 'from' => $a, 'to' => '24:00' === $b ? '00:00' : $b );
    443                         }
    444                         $day = array( 'open' => $h24 || (bool) $ranges, 'h24' => $h24, 'ranges' => $h24 ? array() : $ranges );
    445                         $i   = array_search( $codes[ $from ], $keys, true );
    446                         $end = array_search( $codes[ $to ], $keys, true );
    447                         for ( $n = 0; $n < 7; $n++ ) {
    448                                 $out[ $keys[ $i ] ] = $day;
    449                                 if ( $i === $end ) {
    450                                         break;
    451                                 }
    452                                 $i = ( $i + 1 ) % 7;
    453                         }
    454                         $any = true;
    455                 }
    456                 return $any ? $out : null;
    457         }
    458 
    459         /* ===== Business Directory Plugin ===== */
    460 
    461         /**
    462          * @param array<string, mixed> $d
    463          * @return array<string, mixed>
    464          */
    465         private static function bdp( int $sid, array $d ): array {
    466                 global $wpdb;
    467                 $d['categories'] = self::term_paths( $sid, 'wpbdp_category' );
    468                 $d['tags']       = self::term_paths( $sid, 'wpbdp_tag' );
    469 
    470                 // Fields are defined in its own table; values live in "_wpbdp[fields][<id>]" post meta.
    471                 $table  = $wpdb->prefix . 'wpbdp_form_fields';
    472                 $fields = array();
    473                 if ( self::table_exists( $table ) ) {
    474                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Business Directory Plugin's field list.
    475                         $fields = (array) $wpdb->get_results( $wpdb->prepare( 'SELECT id, tag, association, field_type FROM %i', $table ), ARRAY_A );
    476                 }
    477                 $map    = array(
    478                         'phone'   => 'phone',
    479                         'email'   => 'email',
    480                         'website' => 'website',
    481                         'address' => 'address',
    482                         'zip'     => 'postcode',
    483                 );
    484                 foreach ( $fields as $f ) {
    485                         $tag = strtolower( (string) ( $f['tag'] ?? '' ) );
    486                         if ( ! isset( $map[ $tag ] ) || 'meta' !== ( $f['association'] ?? '' ) ) {
    487                                 continue;
    488                         }
    489                         $v = get_post_meta( $sid, '_wpbdp[fields][' . (int) $f['id'] . ']', true );
    490                         if ( is_array( $v ) ) {
    491                                 $v = (string) reset( $v ); // A website field is stored as [ url, link text ].
    492                         }
    493                         $v = trim( (string) $v );
    494                         if ( '' !== $v ) {
    495                                 $d['meta'][ $map[ $tag ] ] = 'address' === $tag ? preg_replace( '/\s*\n\s*/', ', ', $v ) : $v;
    496                         }
    497                 }
    498 
    499                 $listing = $wpdb->prefix . 'wpbdp_listings';
    500                 $row     = null;
    501                 if ( self::table_exists( $listing ) ) {
    502                         // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- its own listings table holds featured and expiry.
    503                         $row = $wpdb->get_row( $wpdb->prepare( 'SELECT expiration_date, is_sticky, listing_status FROM %i WHERE listing_id = %d', $listing, $sid ), ARRAY_A );
    504                 }
    505                 if ( is_array( $row ) ) {
    506                         $d['featured'] = ! empty( $row['is_sticky'] );
    507                         $exp           = (string) ( $row['expiration_date'] ?? '' );
    508                         $d['expires']  = '' !== $exp && '0000-00-00 00:00:00' !== $exp ? (int) strtotime( $exp . ' UTC' ) : 0;
    509                         if ( 'expired' === ( $row['listing_status'] ?? '' ) ) {
    510                                 $d['status']  = 'draft';
    511                                 $d['expired'] = true;
    512                         }
    513                 }
    514 
    515                 $images = get_post_meta( $sid, '_wpbdp[images]', true );
    516                 $ids    = array( (int) get_post_thumbnail_id( $sid ), (int) get_post_meta( $sid, '_wpbdp[thumbnail_id]', true ) );
    517                 $ids    = array_merge( $ids, is_array( $images ) ? array_map( 'intval', $images ) : array() );
    518                 foreach ( get_children( array( 'post_parent' => $sid, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'fields' => 'ids' ) ) as $child ) {
    519                         $ids[] = (int) $child;
    520                 }
    521                 $d['image_ids'] = array_values( array_unique( array_filter( $ids ) ) );
    522                 return $d;
    523         }
     203                $reader = self::data()['sources'][ $source ]['reader'] ?? null;
     204                return is_callable( $reader ) ? call_user_func( $reader, $sid, $post, $d ) : null;
     205        }
     206
     207
     208
     209
     210
     211
     212
     213
    524214
    525215        /* ===== Shared ===== */
    526216
    527217        /** Does one of the other plugin's tables exist? (Older or partial installs may lack some.) */
    528         private static function table_exists( string $table ): bool {
     218        public static function table_exists( string $table ): bool {
    529219                global $wpdb;
    530220                static $seen = array();
    … …  
    542232         * @return array<int, array<int, string>>
    543233         */
    544         private static function term_paths( int $sid, string $tax ): array {
     234        public static function term_paths( int $sid, string $tax ): array {
    545235                global $wpdb;
    546236                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the taxonomy may not be registered while its plugin is off.
    … …  
    580270         * @return array<int, array<string, mixed>>
    581271         */
    582         private static function comment_reviews( int $sid, string $source, callable $rating ): array {
     272        public static function comment_reviews( int $sid, string $source, callable $rating ): array {
    583273                $out = array();
    584274                foreach ( get_comments( array( 'post_id' => $sid, 'status' => 'all', 'parent' => 0 ) ) as $c ) {
    … …  
    619309                        return;
    620310                }
    621                 echo '<section class="ppd-a-card ppd-a-pad ppd-port-switch"><h2 class="ppd-a-h2">' . esc_html__( 'Move from another directory plugin', 'premiumpress-directory' ) . '</h2>';
    622                 echo '<p>' . esc_html__( 'Listings from these directory plugins were found on this site. Copy them in with their categories, contact details, map position, opening hours, photos and reviews. The other plugin\'s data is not changed, and each listing is copied only once, so you can run this again later.', 'premiumpress-directory' ) . '</p>';
     311                echo '<section class="ppd-a-card ppd-a-pad ppd-port-switch"><h2 class="ppd-a-h2">' . esc_html( (string) ( self::data()['title'] ?? '' ) ) . '</h2>';
     312                echo '<p>' . esc_html( (string) ( self::data()['intro'] ?? '' ) ) . '</p>';
    623313                echo '<table class="widefat striped ppd-switch"><tbody>';
    624314                foreach ( $rows as $key => $c ) {
    625315                        echo '<tr><th scope="row">' . esc_html( $c['name'] ) . '</th><td>';
    626                         /* translators: %d: number of listings found */
    627                         echo esc_html( sprintf( _n( '%d listing found', '%d listings found', $c['total'], 'premiumpress-directory' ), $c['total'] ) ) . ', ';
     316                        /* translators: 1: number found, 2: item name, lowercase (singular or plural to match) */
     317                        echo esc_html( sprintf( _n( '%1$d %2$s found', '%1$d %2$s found', $c['total'], 'premiumpress-directory' ), $c['total'], ( 1 === $c['total'] ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . ', ';
    628318                        /* translators: %d: number of listings still to copy */
    629319                        echo esc_html( sprintf( _n( '%d still to copy', '%d still to copy', $c['left'], 'premiumpress-directory' ), $c['left'] ) );
    630320                        if ( $c['failed'] ) {
    631                                 /* translators: %d: number of listings that could not be copied */
    632                                 echo '<br><span class="description">' . esc_html( sprintf( _n( '%d listing could not be copied and was skipped.', '%d listings could not be copied and were skipped.', $c['failed'], 'premiumpress-directory' ), $c['failed'] ) ) . '</span>';
     321                                /* translators: 1: number skipped, 2: item name, lowercase (singular or plural to match) */
     322                                echo '<br><span class="description">' . esc_html( sprintf( _n( '%1$d %2$s could not be copied and was skipped.', '%1$d %2$s could not be copied and were skipped.', $c['failed'], 'premiumpress-directory' ), $c['failed'], ( 1 === $c['failed'] ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</span>';
    633323                        }
    634324                        echo '</td><td>';
  • premiumpress-directory/trunk/includes/class-premiumpress-wizard.php

    r3838627 r3848540  
    3131         */
    3232        public static function niches(): array {
    33                 return array(
    34                         'general'      => array(
    35                                 'label' => __( 'Local businesses', 'premiumpress-directory' ),
    36                                 'text'  => __( 'A classic directory of shops, services and trades in one area.', 'premiumpress-directory' ),
    37                                 'cats'  => array( __( 'Bakeries', 'premiumpress-directory' ), __( 'Barbers', 'premiumpress-directory' ), __( 'Bookshops', 'premiumpress-directory' ), __( 'Cafés', 'premiumpress-directory' ), __( 'Dentists', 'premiumpress-directory' ), __( 'Electricians', 'premiumpress-directory' ), __( 'Fitness', 'premiumpress-directory' ), __( 'Florists', 'premiumpress-directory' ), __( 'Garages', 'premiumpress-directory' ), __( 'Plumbers', 'premiumpress-directory' ) ),
    38                         ),
    39                         'cityguide'    => array(
    40                                 'label' => __( 'City guide', 'premiumpress-directory' ),
    41                                 'text'  => __( 'Places to eat, drink, stay and go out in a town or city.', 'premiumpress-directory' ),
    42                                 'cats'  => array( __( 'Bars', 'premiumpress-directory' ), __( 'Cafés', 'premiumpress-directory' ), __( 'Restaurants', 'premiumpress-directory' ), __( 'Hotels', 'premiumpress-directory' ), __( 'Galleries', 'premiumpress-directory' ), __( 'Cinemas', 'premiumpress-directory' ), __( 'Live music', 'premiumpress-directory' ), __( 'Markets', 'premiumpress-directory' ), __( 'Shops', 'premiumpress-directory' ) ),
    43                         ),
    44                         'localfood'    => array(
    45                                 'label' => __( 'Food and drink', 'premiumpress-directory' ),
    46                                 'text'  => __( 'Restaurants, takeaways, cafés and bakeries.', 'premiumpress-directory' ),
    47                                 'cats'  => array( __( 'Restaurants', 'premiumpress-directory' ), __( 'Takeaways', 'premiumpress-directory' ), __( 'Pizza', 'premiumpress-directory' ), __( 'Cafés', 'premiumpress-directory' ), __( 'Bakeries', 'premiumpress-directory' ), __( 'Pubs', 'premiumpress-directory' ), __( 'Bars', 'premiumpress-directory' ), __( 'Vegan and vegetarian', 'premiumpress-directory' ) ),
    48                         ),
    49                         'trades'       => array(
    50                                 'label' => __( 'Tradespeople', 'premiumpress-directory' ),
    51                                 'text'  => __( 'Builders, electricians, plumbers and other trades.', 'premiumpress-directory' ),
    52                                 'cats'  => array( __( 'Builders', 'premiumpress-directory' ), __( 'Electricians', 'premiumpress-directory' ), __( 'Plumbers', 'premiumpress-directory' ), __( 'Roofers', 'premiumpress-directory' ), __( 'Carpenters', 'premiumpress-directory' ), __( 'Decorators', 'premiumpress-directory' ), __( 'Plasterers', 'premiumpress-directory' ), __( 'Heating engineers', 'premiumpress-directory' ), __( 'Locksmiths', 'premiumpress-directory' ), __( 'Tilers', 'premiumpress-directory' ) ),
    53                         ),
    54                         'homegarden'   => array(
    55                                 'label' => __( 'Home and garden', 'premiumpress-directory' ),
    56                                 'text'  => __( 'Cleaners, gardeners, removals and home improvement.', 'premiumpress-directory' ),
    57                                 'cats'  => array( __( 'Cleaners', 'premiumpress-directory' ), __( 'Gardeners', 'premiumpress-directory' ), __( 'Landscapers', 'premiumpress-directory' ), __( 'Handymen', 'premiumpress-directory' ), __( 'Removals', 'premiumpress-directory' ), __( 'Interior designers', 'premiumpress-directory' ), __( 'Pest control', 'premiumpress-directory' ), __( 'Tree surgeons', 'premiumpress-directory' ) ),
    58                         ),
    59                         'health'       => array(
    60                                 'label' => __( 'Healthcare', 'premiumpress-directory' ),
    61                                 'text'  => __( 'Doctors, dentists, therapists and clinics.', 'premiumpress-directory' ),
    62                                 'cats'  => array( __( 'Dentists', 'premiumpress-directory' ), __( 'Doctors', 'premiumpress-directory' ), __( 'Opticians', 'premiumpress-directory' ), __( 'Physiotherapists', 'premiumpress-directory' ), __( 'Chiropractors', 'premiumpress-directory' ), __( 'Osteopaths', 'premiumpress-directory' ), __( 'Counsellors', 'premiumpress-directory' ), __( 'Podiatrists', 'premiumpress-directory' ) ),
    63                         ),
    64                         'beauty'       => array(
    65                                 'label' => __( 'Beauty and wellness', 'premiumpress-directory' ),
    66                                 'text'  => __( 'Salons, barbers, spas and clinics.', 'premiumpress-directory' ),
    67                                 'cats'  => array( __( 'Hair salons', 'premiumpress-directory' ), __( 'Barbers', 'premiumpress-directory' ), __( 'Beauty salons', 'premiumpress-directory' ), __( 'Nail bars', 'premiumpress-directory' ), __( 'Brows and lashes', 'premiumpress-directory' ), __( 'Spas', 'premiumpress-directory' ), __( 'Aesthetics clinics', 'premiumpress-directory' ), __( 'Wellness clinics', 'premiumpress-directory' ) ),
    68                         ),
    69                         'auto'         => array(
    70                                 'label' => __( 'Automotive', 'premiumpress-directory' ),
    71                                 'text'  => __( 'Garages, MOT centres, tyres and car services.', 'premiumpress-directory' ),
    72                                 'cats'  => array( __( 'Garages', 'premiumpress-directory' ), __( 'MOT centres', 'premiumpress-directory' ), __( 'Tyre shops', 'premiumpress-directory' ), __( 'Mobile mechanics', 'premiumpress-directory' ), __( 'Bodywork and paint', 'premiumpress-directory' ), __( 'Valeting', 'premiumpress-directory' ), __( 'Car dealers', 'premiumpress-directory' ), __( 'Car hire', 'premiumpress-directory' ) ),
    73                         ),
    74                         'prof'         => array(
    75                                 'label' => __( 'Professional services', 'premiumpress-directory' ),
    76                                 'text'  => __( 'Accountants, architects, agencies and consultants.', 'premiumpress-directory' ),
    77                                 'cats'  => array( __( 'Accountants', 'premiumpress-directory' ), __( 'Architects', 'premiumpress-directory' ), __( 'Consultants', 'premiumpress-directory' ), __( 'Marketing agencies', 'premiumpress-directory' ), __( 'Designers', 'premiumpress-directory' ), __( 'Photographers', 'premiumpress-directory' ), __( 'Recruiters', 'premiumpress-directory' ), __( 'Translators', 'premiumpress-directory' ) ),
    78                         ),
    79                         'legal'        => array(
    80                                 'label' => __( 'Legal and financial', 'premiumpress-directory' ),
    81                                 'text'  => __( 'Solicitors, financial advisers and accountants.', 'premiumpress-directory' ),
    82                                 'cats'  => array( __( 'Solicitors', 'premiumpress-directory' ), __( 'Family lawyers', 'premiumpress-directory' ), __( 'Conveyancers', 'premiumpress-directory' ), __( 'Immigration lawyers', 'premiumpress-directory' ), __( 'Accountants', 'premiumpress-directory' ), __( 'Financial advisers', 'premiumpress-directory' ), __( 'Mortgage brokers', 'premiumpress-directory' ), __( 'Tax advisers', 'premiumpress-directory' ) ),
    83                         ),
    84                         'sports'       => array(
    85                                 'label' => __( 'Sports coaches', 'premiumpress-directory' ),
    86                                 'text'  => __( 'Coaches, clubs and classes for every sport.', 'premiumpress-directory' ),
    87                                 'cats'  => array( __( 'Football', 'premiumpress-directory' ), __( 'Tennis', 'premiumpress-directory' ), __( 'Swimming', 'premiumpress-directory' ), __( 'Running', 'premiumpress-directory' ), __( 'Golf', 'premiumpress-directory' ), __( 'Boxing', 'premiumpress-directory' ), __( 'Gymnastics', 'premiumpress-directory' ), __( 'Strength and conditioning', 'premiumpress-directory' ) ),
    88                         ),
    89                         'coaches'      => array(
    90                                 'label' => __( 'Life and career coaches', 'premiumpress-directory' ),
    91                                 'text'  => __( 'Public speaking, relationship and other coaches.', 'premiumpress-directory' ),
    92                                 'cats'  => array( __( 'Public speaking coaches', 'premiumpress-directory' ), __( 'Presentation coaches', 'premiumpress-directory' ), __( 'Voice coaches', 'premiumpress-directory' ), __( 'Relationship coaches', 'premiumpress-directory' ), __( 'Dating coaches', 'premiumpress-directory' ), __( 'Career coaches', 'premiumpress-directory' ) ),
    93                         ),
    94                 );
     33                return (array) ( self::data()['niches'] ?? array() );
     34        }
     35
     36        /** This plugin's setup data: niches (from its theme) and which ones the sample content suits. */
     37        private static function data(): array {
     38                static $data = null;
     39                if ( null === $data ) {
     40                        $data = (array) require PREMIUMPRESS_DIR . 'includes/wizard-data.php';
     41                }
     42                return $data;
    9543        }
    9644
    9745        /** True when the niche step applies (the business directory site type). */
    9846        private static function has_niches(): bool {
    99                 return 'directory' === PremiumPress_Profiles::current_key();
     47                return (bool) self::niches();
    10048        }
    10149
    … …  
    229177        private static function samples_fit(): bool {
    230178                $n = (string) get_option( self::NICHE, '' );
    231                 return ! self::has_niches() || '' === $n || 'general' === $n || 'cityguide' === $n;
     179                return ! self::has_niches() || '' === $n || in_array( $n, (array) ( self::data()['samples_fit'] ?? array() ), true );
    232180        }
    233181
    … …  
    250198                        $items[] = '<li><span>' . esc_html__( 'Visitors can\'t create an account yet, so they can\'t add anything. Tick "Anyone can register" in WordPress\'s General settings.', 'premiumpress-directory' ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( admin_url( 'options-general.php' ) ) . '">' . esc_html__( 'Open General settings', 'premiumpress-directory' ) . '</a></li>';
    251199                }
    252                 $items[] = '<li><span>' . esc_html__( 'Your directory pages are in your site menu. Rename or reorder them there.', 'premiumpress-directory' ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( self::menu_url() ) . '">' . esc_html__( 'Edit the menu', 'premiumpress-directory' ) . '</a></li>';
     200                $items[] = '<li><span>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s pages are in your site menu. Rename or reorder them there.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( self::menu_url() ) . '">' . esc_html__( 'Edit the menu', 'premiumpress-directory' ) . '</a></li>';
    253201                if ( PremiumPress_Profiles::has_section( 'location' ) && empty( PremiumPress_Settings::get()['maps'] ) ) {
    254                         $items[] = '<li><span>' . esc_html__( 'Show maps on listings and search results.', 'premiumpress-directory' ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( PremiumPress_Settings::section_url( 'maps' ) ) . '">' . esc_html__( 'Turn on maps', 'premiumpress-directory' ) . '</a></li>';
     202                        $items[] = '<li><span>' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'Show maps on %s and search results.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</span><a class="ppd-a-btn ppd-a-btn--sm" href="' . esc_url( PremiumPress_Settings::section_url( 'maps' ) ) . '">' . esc_html__( 'Turn on maps', 'premiumpress-directory' ) . '</a></li>';
    255203                }
    256204                echo '<h2 class="ppd-wizard__h2">' . esc_html__( 'Next steps', 'premiumpress-directory' ) . '</h2><ul class="ppd-wizard__todo">' . wp_kses( implode( '', $items ), self::todo_allowed() ) . '</ul>';
    … …  
    334282                $p   = PremiumPress_Profiles::current();
    335283
    336                 PremiumPress_Admin_UI::open( 'settings', __( 'Set up your site', 'premiumpress-directory' ), __( 'A few plain questions, then your directory is ready.', 'premiumpress-directory' ) );
     284                PremiumPress_Admin_UI::open( 'settings', __( 'Set up your site', 'premiumpress-directory' ), sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'A few plain questions, then your %s is ready.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) );
    337285                echo '<div class="ppd-wizard">';
    338286                /* translators: 1: step number, 2: number of steps */
    … …  
    377325                } elseif ( 'niche' === $step ) {
    378326                        $now = (string) get_option( self::NICHE, '' );
    379                         echo '<h1>' . esc_html__( 'What is your directory about?', 'premiumpress-directory' ) . '</h1>';
     327                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'What is your %s about?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
    380328                        echo '<p class="ppd-lead">' . esc_html__( 'Pick the closest one and we\'ll add its categories for you. You can rename, add or remove categories any time.', 'premiumpress-directory' ) . '</p><div class="ppd-types">';
    381329                        foreach ( self::niches() as $key => $n ) {
    382330                                printf(
    383                                         '<button type="submit" name="niche" value="%1$s" class="ppd-type ppd-type--niche%4$s"><img class="ppd-type__icon" src="%6$s" alt="" width="56" height="56" loading="lazy"><strong>%2$s</strong><span>%3$s</span><small>%5$s</small></button>',
     331                                        '<button type="submit" name="niche" value="%1$s" class="ppd-type ppd-type--niche%4$s">%6$s<strong>%2$s</strong><span>%3$s</span><small>%5$s</small></button>',
    384332                                        esc_attr( $key ),
    385333                                        esc_html( $n['label'] ),
    … …  
    387335                                        $now === $key ? ' is-current' : '',
    388336                                        esc_html( implode( ', ', array_slice( $n['cats'], 0, 4 ) ) . '…' ),
    389                                         esc_url( PREMIUMPRESS_URL . 'assets/niches/' . $key . '.webp' )
     337                                        file_exists( PREMIUMPRESS_DIR . 'assets/niches/' . $key . '.webp' ) ? '<img class="ppd-type__icon" src="' . esc_url( PREMIUMPRESS_URL . 'assets/niches/' . $key . '.webp' ) . '" alt="" width="56" height="56" loading="lazy">' : ''
    390338                                );
    391339                        }
    … …  
    394342                        $place = self::home_place();
    395343                        $term  = $place ? get_term( $place, PremiumPress_Post_Types::TAX_LOCATION ) : null;
    396                         echo '<h1>' . esc_html__( 'Where is your directory?', 'premiumpress-directory' ) . '</h1>';
    397                         echo '<p class="ppd-lead">' . esc_html__( 'The town, city or area it covers. It becomes the first location, and new listings start there.', 'premiumpress-directory' ) . '</p>';
     344                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Where is your %s?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
     345                        echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: plural item name, e.g. listings, jobs */ __( 'The town, city or area it covers. It becomes the first location, and new %s start there.', 'premiumpress-directory' ), PremiumPress_Profiles::many() ) ) . '</p>';
    398346                        printf(
    399347                                '<p><label for="ppd-w-place" class="screen-reader-text">%1$s</label><input type="text" id="ppd-w-place" name="place" class="regular-text" value="%2$s" placeholder="%3$s" maxlength="100" autocomplete="address-level2"></p>',
    … …  
    467415                                );
    468416                                /* translators: %d: number of sample listings */
    469                                 echo '<h1>' . esc_html( sprintf( _n( 'You have %d sample listing', 'You have %d sample listings', count( $have ), 'premiumpress-directory' ), count( $have ) ) ) . '</h1>';
    470                                 echo '<p class="ppd-lead">' . esc_html__( 'They were added so you can see how your directory looks. Keep them for now, or remove them if you\'re ready to add your own.', 'premiumpress-directory' ) . '</p>';
     417                                echo '<h1>' . esc_html( sprintf( /* translators: 1: number, 2: item name, lowercase (singular or plural to match) */ _n( 'You have %1$d sample %2$s', 'You have %1$d sample %2$s', count( $have ), 'premiumpress-directory' ), count( $have ), ( 1 === count( $have ) ? PremiumPress_Profiles::one() : PremiumPress_Profiles::many() ) ) ) . '</h1>';
     418                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'They were added so you can see how your %s looks. Keep them for now, or remove them if you\'re ready to add your own.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    471419                                echo '<ul class="ppd-wizard__names">';
    472420                                foreach ( $have as $sp ) {
    473421                                        echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>';
    474422                                }
    475                                 echo '</ul><p class="ppd-wizard__hint">' . esc_html__( 'You can also remove them later under Design, Directory pages. Your own listings are never touched.', 'premiumpress-directory' ) . '</p>';
     423                                echo '</ul><p class="ppd-wizard__hint">' . esc_html( sprintf( /* translators: 1: what the site is, capitalised, e.g. Directory, 2: plural item name, e.g. listings, jobs */ __( 'You can also remove them later under Design, %1$s pages. Your own %2$s are never touched.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ), PremiumPress_Profiles::many() ) ) . '</p>';
    476424                        } elseif ( $n && self::samples_fit() ) {
    477425                                /* translators: %s: plural item name, lowercase */
    478426                                echo '<h1>' . esc_html( sprintf( __( 'Add some sample %s?', 'premiumpress-directory' ), $many ) ) . '</h1>';
    479427                                /* translators: %d: number of sample items */
    480                                 echo '<p class="ppd-lead">' . esc_html( sprintf( _n( 'See how everything looks with %d example, complete with photo, map position, opening hours and details.', 'See how everything looks with %d examples, complete with photos, map positions, opening hours and details.', $n, 'premiumpress-directory' ), $n ) ) . '</p>';
    481                                 echo '<p class="ppd-wizard__hint">' . esc_html__( 'They\'re marked as samples, so you can remove them all in one go later, under Design, Directory pages.', 'premiumpress-directory' ) . '</p>';
     428                                echo '<p class="ppd-lead">' . esc_html( sprintf( translate_nooped_plural( (array) PremiumPress_Profiles::current()['sample_wizard'], $n, 'premiumpress-directory' ), $n ) ) . '</p>';
     429                                echo '<p class="ppd-wizard__hint">' . esc_html( sprintf( /* translators: %s: what the site is, capitalised, e.g. Directory */ __( 'They\'re marked as samples, so you can remove them all in one go later, under Design, %s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ) ) . '</p>';
    482430                        } else {
    483431                                /* translators: %s: plural item name, lowercase */
    484432                                echo '<h1>' . esc_html( sprintf( __( 'Sample %s', 'premiumpress-directory' ), $many ) ) . '</h1>';
    485                                 echo '<p class="ppd-lead">' . esc_html__( 'There are no sample listings for this kind of directory yet. Your categories are ready, so the quickest way to see how it looks is to add your first listing.', 'premiumpress-directory' ) . '</p>';
     433                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: 1: plural item name, e.g. listings, jobs, 2: what the site is, e.g. directory, job board, 3: singular item name, e.g. listing, job */ __( 'There are no sample %1$s for this kind of %2$s yet. Your categories are ready, so the quickest way to see how it looks is to add your first %3$s.', 'premiumpress-directory' ), PremiumPress_Profiles::many(), PremiumPress_Profiles::noun(), PremiumPress_Profiles::one() ) ) . '</p>';
    486434                        }
    487435                } elseif ( 'design' === $step ) {
    488                         echo '<h1>' . esc_html__( 'How should your directory look?', 'premiumpress-directory' ) . '</h1>';
    489                         echo '<p class="ppd-lead">' . esc_html__( 'Click the one you want. Only your directory pages change, and you can switch any time under Design.', 'premiumpress-directory' ) . '</p>';
     436                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'How should your %s look?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
     437                        echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Click the one you want. Only your %s pages change, and you can switch any time under Design.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    490438                        PremiumPress_Design::cards( 'design' );
    491439                } elseif ( 'home' === $step ) {
    492440                        $dir = PremiumPress_Pages::id( 'directory' );
    493                         echo '<h1>' . esc_html__( 'Make the directory your homepage?', 'premiumpress-directory' ) . '</h1>';
     441                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Make the %s your homepage?', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
    494442                        if ( ! $dir ) {
    495                                 echo '<p class="ppd-lead">' . esc_html__( 'The Directory page is missing, so there is nothing to show yet. You can recreate it under Design, Directory pages.', 'premiumpress-directory' ) . '</p>';
     443                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: 1: what the site is, capitalised, e.g. Directory */ __( 'The %1$s page is missing, so there is nothing to show yet. You can recreate it under Design, %1$s pages.', 'premiumpress-directory' ), PremiumPress_Profiles::noun( true ) ) ) . '</p>';
    496444                        } elseif ( self::is_homepage() ) {
    497                                 echo '<p class="ppd-lead">' . esc_html__( 'Your directory is already your homepage, so visitors see the search and the cards as soon as they arrive.', 'premiumpress-directory' ) . '</p>';
     445                                echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s is already your homepage, so visitors see the search and the cards as soon as they arrive.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    498446                        } else {
    499447                                $front = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0;
    500448                                $now   = $front ? sprintf( /* translators: %s: page title */ __( 'Right now visitors land on your "%s" page.', 'premiumpress-directory' ), get_the_title( $front ) ) : __( 'Right now visitors land on your latest blog posts.', 'premiumpress-directory' );
    501                                 echo '<p class="ppd-lead">' . esc_html( $now . ' ' . __( 'Show your directory there instead, with its search and cards, so people can start looking straight away.', 'premiumpress-directory' ) ) . '</p>';
     449                                echo '<p class="ppd-lead">' . esc_html( $now . ' ' . sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Show your %s there instead, with its search and cards, so people can start looking straight away.', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</p>';
    502450                                echo '<p>' . esc_html__( 'You can change this any time in WordPress under Settings, Reading.', 'premiumpress-directory' ) . '</p>';
    503451                        }
    504452                } else {
    505453                        $dir = PremiumPress_Pages::url( 'directory' );
    506                         echo '<h1>' . esc_html__( 'Your directory is ready', 'premiumpress-directory' ) . '</h1>';
    507                         echo '<p class="ppd-lead">' . esc_html__( 'Have a look at it, or add your first listing. Anything still to do is listed on your Overview page.', 'premiumpress-directory' ) . '</p><p class="ppd-wizard__next">';
     454                        echo '<h1>' . esc_html( sprintf( /* translators: %s: what the site is, e.g. directory, job board */ __( 'Your %s is ready', 'premiumpress-directory' ), PremiumPress_Profiles::noun() ) ) . '</h1>';
     455                        echo '<p class="ppd-lead">' . esc_html( sprintf( /* translators: %s: singular item name, e.g. listing, job */ __( 'Have a look at it, or add your first %s. Anything still to do is listed on your Overview page.', 'premiumpress-directory' ), PremiumPress_Profiles::one() ) ) . '</p><p class="ppd-wizard__next">';
    508456                        if ( '' !== $dir ) {
    509                                 echo '<a class="button button-primary button-hero" href="' . esc_url( $dir ) . '">' . esc_html__( 'View your directory', 'premiumpress-directory' ) . '</a> ';
     457                                /* translators: %s: plural item name, lowercase */
     458                                echo '<a class="button button-primary button-hero" href="' . esc_url( $dir ) . '">' . esc_html( sprintf( __( 'View your %s', 'premiumpress-directory' ), mb_strtolower( (string) $p['plural'] ) ) ) . '</a> ';
    510459                        }
    511460                        /* translators: %s: singular item name */
    … …  
    514463                        self::next_steps();
    515464                        /* translators: %s: theme name, e.g. Directory theme */
    516                         echo '<p class="ppd-wizard__upsell">' . esc_html( sprintf( __( 'Want ready-made designs, paid listings and payments? The PremiumPress %s uses the same data, so you can switch any time.', 'premiumpress-directory' ), (string) $p['theme_name'] ) ) . ' <a href="' . esc_url( PremiumPress_Profiles::theme_url() ) . '" target="_blank" rel="noopener">' . esc_html__( 'Take a look', 'premiumpress-directory' ) . '</a></p>';
     465                        echo '<p class="ppd-wizard__upsell">' . esc_html( sprintf( __( 'Want ready-made designs, paid %1$s and payments? The PremiumPress %2$s uses the same data, so you can switch any time.', 'premiumpress-directory' ), mb_strtolower( (string) $p['plural'] ), (string) $p['theme_name'] ) ) . ' <a href="' . esc_url( PremiumPress_Profiles::theme_url() ) . '" target="_blank" rel="noopener">' . esc_html__( 'Take a look', 'premiumpress-directory' ) . '</a></p>';
    517466                }
    518467
    … …  
    529478                        } elseif ( 'content' === $step && count( PremiumPress_Sample::items() ) && self::samples_fit() ) {
    530479                                /* translators: %d: number of sample listings */
    531                                 echo '<button type="submit" class="button button-primary button-large">' . esc_html( sprintf( __( 'Add %d sample listings', 'premiumpress-directory' ), count( PremiumPress_Sample::items() ) ) ) . '</button> ';
     480                                echo '<button type="submit" class="button button-primary button-large">' . esc_html( sprintf( /* translators: 1: number, 2: plural item name, e.g. listings */ __( 'Add %1$d sample %2$s', 'premiumpress-directory' ), count( PremiumPress_Sample::items() ), PremiumPress_Profiles::many() ) ) . '</button> ';
    532481                                echo '<button type="submit" name="skip" value="1" class="button-link">' . esc_html__( 'No thanks', 'premiumpress-directory' ) . '</button>';
    533482                        } elseif ( 'content' === $step ) {
  • premiumpress-directory/trunk/premiumpress-directory.php

    r3838748 r3848540  
    44 * Plugin URI:        https://www.premiumpress.com/plugin/premiumpress-directory/
    55 * Description:       Add a business directory to any WordPress site: listings, categories, locations, search with a map, reviews and front-end submission.
    6  * Version:           1.1.0
     6 * Version:           1.1.1
    77 * Requires at least: 6.5
    88 * Requires PHP:      7.4
    … …  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 define( 'PREMIUMPRESS_VERSION', '1.1.0' );
     20define( 'PREMIUMPRESS_VERSION', '1.1.1' );
     21define( 'PREMIUMPRESS_NAME', 'PremiumPress Directory' );
     22define( 'PREMIUMPRESS_PROFILE', 'directory' );
     23define( 'PREMIUMPRESS_UTM', 'directory-plugin' );
     24define( 'PREMIUMPRESS_MODULES', array( 'PremiumPress_Switch_Directory' ) );
    2125define( 'PREMIUMPRESS_FILE', __FILE__ );
    2226define( 'PREMIUMPRESS_DIR', plugin_dir_path( __FILE__ ) );
    … …  
    5054require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-porting.php';
    5155require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch.php';
     56require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch-directory.php';
    5257require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-plugin.php';
    5358
  • premiumpress-directory/trunk/readme.txt

    r3838748 r3848540  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.1.0
     7Stable tag: 1.1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    1515PremiumPress Directory turns any WordPress site into a local business directory. Add listings yourself or let businesses submit their own, and give visitors a search with a map, distances and reviews.
    1616
    17 🧩 [Plugin page](https://www.premiumpress.com/plugin/premiumpress-directory/) | 🎨 [Directory theme](https://www.premiumpress.com/wordpress-directory-theme/) | 🛠️ [Setup help](https://www.premiumpress.com/wordpress-theme-installation/) | ✉️ [Contact us](https://www.premiumpress.com/contact/)
     17🧩 [Plugin page](https://www.premiumpress.com/plugin/premiumpress-directory/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org) | 🎨 [Directory theme](https://www.premiumpress.com/wordpress-directory-theme/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org) | 🛠️ [Setup help](https://www.premiumpress.com/wordpress-theme-installation/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org) | ✉️ [Contact us](https://www.premiumpress.com/contact/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org)
    1818
    1919It works with any theme, block or classic, and looks at home in both: it uses your theme's fonts and colours instead of bringing its own.
    … …  
    7070= Need more? =
    7171
    72 The plugin is complete on its own. When you want more, the **PremiumPress Directory theme** adds ready-made homepage designs, paid and featured listing packages with [payment gateways](https://www.premiumpress.com/plugins/), unlimited custom fields, Country › City › Area locations, search filters and saved-search alerts, Google Maps and Mapbox, member messaging and dashboards, and an AI site generator.
    73 
    74 It stores listings exactly the way this plugin does. Activate the theme and your listings, reviews and favourites are already there, with nothing to import. [See the Directory theme](https://www.premiumpress.com/wordpress-directory-theme/).
     72The plugin is complete on its own. When you want more, the **PremiumPress Directory theme** adds ready-made homepage designs, paid and featured listing packages with [payment gateways](https://www.premiumpress.com/plugins/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org), unlimited custom fields, Country › City › Area locations, search filters and saved-search alerts, Google Maps and Mapbox, member messaging and dashboards, and an AI site generator.
     73
     74It stores listings exactly the way this plugin does. Activate the theme and your listings, reviews and favourites are already there, with nothing to import. [See the Directory theme](https://www.premiumpress.com/wordpress-directory-theme/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org).
    7575
    7676== Installation ==
    … …  
    167167== Changelog ==
    168168
     169= 1.1.1 =
     170* Improved: only one PremiumPress listings plugin runs at a time. If another one is already active, this one pauses and says so on the Plugins screen.
     171* Improved: imported choices are matched whether a file uses an option's name or its label.
     172
    169173= 1.1.0 =
    170174* New: a setup wizard that starts from your kind of directory and your area, adds matching categories, and lets you keep or remove the sample listings.
    … …  
    189193== Upgrade Notice ==
    190194
     195= 1.1.1 =
     196Small improvements.
     197
    191198= 1.1.0 =
    192199A new setup wizard, a Design section with a Brand page, a fresh listing page design and a cleaner admin.
  • premiumpress-directory/trunk/templates/card.php

    r3838627 r3848540  
    2323foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) {
    2424        if ( ! empty( $premiumpress_field['card'] ) ) {
    25                 $premiumpress_value = PremiumPress_Profiles::display_value( $premiumpress_field, (string) get_post_meta( $premiumpress_id, $premiumpress_key, true ) );
     25                $premiumpress_value = PremiumPress_Profiles::display( (int) $premiumpress_id, $premiumpress_key, $premiumpress_field );
    2626                if ( '' !== $premiumpress_value ) {
    2727                        $premiumpress_facts[] = $premiumpress_value;
    … …  
    8686                        </span>
    8787                <?php endif; ?>
    88                 <?php if ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?>
     88                <?php
     89                $premiumpress_badge = (string) apply_filters( 'premiumpress_card_badge', '', $premiumpress_id );
     90                if ( '' !== $premiumpress_badge ) :
     91                        ?>
     92                        <span class="ppd-badge ppd-badge--status"><?php echo esc_html( $premiumpress_badge ); ?></span>
     93                <?php elseif ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?>
    8994                        <span class="ppd-badge ppd-badge--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span>
    9095                <?php elseif ( null !== $premiumpress_open ) : ?>
  • premiumpress-directory/trunk/templates/listing-forms.php

    r3837691 r3848540  
    1616$premiumpress_user    = wp_get_current_user();
    1717$premiumpress_contact = PremiumPress_Profiles::has_section( 'contact' ) && '' !== PremiumPress_Engage::contact_email( $premiumpress_id )
    18         && (int) get_post_field( 'post_author', $premiumpress_id ) !== get_current_user_id();
     18        && (int) get_post_field( 'post_author', $premiumpress_id ) !== get_current_user_id()
     19        && (bool) apply_filters( 'premiumpress_show_contact', true, $premiumpress_id );
    1920?>
    2021<?php if ( $premiumpress_contact ) : ?>
  • premiumpress-directory/trunk/templates/my-listings.php

    r3837691 r3848540  
    3232                <?php if ( '' !== $premiumpress_submit ) : ?>
    3333                        <?php /* translators: %s: item name */ ?>
    34                         <a class="ppd-button wp-element-button" href="<?php echo esc_url( $premiumpress_submit ); ?>"><?php echo esc_html( sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $premiumpress_profile['singular'] ) ) ); ?></a>
     34                        <a class="ppd-button wp-element-button" href="<?php echo esc_url( $premiumpress_submit ); ?>"><?php echo esc_html( isset( $premiumpress_profile['add_title'] ) ? (string) $premiumpress_profile['add_title'] : sprintf( __( 'Add a %s', 'premiumpress-directory' ), mb_strtolower( (string) $premiumpress_profile['singular'] ) ) ); ?></a>
    3535                <?php endif; ?>
    3636        </div>
    … …  
    5353                                        $premiumpress_state = array( 'draft', __( 'Draft', 'premiumpress-directory' ) );
    5454                                } else {
     55                                        $premiumpress_state = (array) apply_filters( 'premiumpress_account_state', array(), $premiumpress_id );
     56                                }
     57                                if ( ! $premiumpress_state ) {
    5558                                        $premiumpress_state = array( 'live', __( 'Live', 'premiumpress-directory' ) );
    5659                                }
    … …  
    7679                                                        <a href="<?php echo esc_url( add_query_arg( 'edit', $premiumpress_id, $premiumpress_submit ) ); ?>"><?php esc_html_e( 'Edit', 'premiumpress-directory' ); ?></a>
    7780                                                <?php endif; ?>
     81                                                <?php do_action( 'premiumpress_account_item_actions', $premiumpress_id, $premiumpress_item ); ?>
    7882                                                <?php if ( $premiumpress_expired ) : ?>
    7983                                                        <a href="<?php echo esc_url( PremiumPress_Submit::item_url( $premiumpress_id, 'renew' ) ); ?>"><?php esc_html_e( 'Renew', 'premiumpress-directory' ); ?></a>
    … …  
    8690                </ul>
    8791        <?php endif; ?>
     92
     93        <?php do_action( 'premiumpress_account_after_items', (int) $args['user_id'] ); ?>
    8894
    8995        <h2 class="ppd-account__title ppd-account__title--saved"><?php esc_html_e( 'Saved', 'premiumpress-directory' ); ?></h2>
  • premiumpress-directory/trunk/templates/single-listing.php

    r3838627 r3848540  
    3737                continue;
    3838        }
    39         $premiumpress_value = PremiumPress_Profiles::display_value( $premiumpress_field, (string) get_post_meta( $premiumpress_id, $premiumpress_key, true ) );
     39        $premiumpress_value = PremiumPress_Profiles::display( (int) $premiumpress_id, $premiumpress_key, $premiumpress_field );
    4040        if ( '' !== $premiumpress_value ) {
    4141                $premiumpress_details[ (string) $premiumpress_field['label'] ] = $premiumpress_value;
    … …  
    131131                <div class="ppd-actions">
    132132                        <?php echo PremiumPress_Engage::fav_button( $premiumpress_id, 'ppd-fav-form--single' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in fav_button(). ?>
    133                         <a class="ppd-action" href="#ppd-reviews"><?php echo wp_kses( $premiumpress_icon( 'pencil' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Review', 'premiumpress-directory' ); ?></span></a>
     133                        <?php if ( PremiumPress_Engage::reviews_on() ) : ?>
     134                                <a class="ppd-action" href="#ppd-reviews"><?php echo wp_kses( $premiumpress_icon( 'pencil' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Review', 'premiumpress-directory' ); ?></span></a>
     135                        <?php endif; ?>
    134136                        <button type="button" class="ppd-action" data-ppd-share data-url="<?php echo esc_url( (string) get_permalink( $premiumpress_id ) ); ?>" data-title="<?php echo esc_attr( get_the_title( $premiumpress_id ) ); ?>" data-done="<?php esc_attr_e( 'Link copied', 'premiumpress-directory' ); ?>"><?php echo wp_kses( $premiumpress_icon( 'share' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Share', 'premiumpress-directory' ); ?></span></button>
    135137                        <a class="ppd-action" href="#ppd-report" data-ppd-open-report><?php echo wp_kses( $premiumpress_icon( 'flag' ), $premiumpress_svg ); ?><span><?php esc_html_e( 'Report', 'premiumpress-directory' ); ?></span></a>
    … …  
    157159                                <h1 class="ppd-single__title"><?php echo esc_html( get_the_title( $premiumpress_id ) ); ?></h1>
    158160                        <?php endif; ?>
     161                        <?php
     162                        // The price (or salary) under the title, for site types that have one on their cards.
     163                        $premiumpress_price = '';
     164                        foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) {
     165                                if ( ! empty( $premiumpress_field['money'] ) && ! empty( $premiumpress_field['card'] ) ) {
     166                                        $premiumpress_price = PremiumPress_Profiles::display( (int) $premiumpress_id, (string) $premiumpress_key, (array) $premiumpress_field );
     167                                        break;
     168                                }
     169                        }
     170                        ?>
     171                        <?php if ( '' !== $premiumpress_price ) : ?>
     172                                <p class="ppd-single__price"><?php echo esc_html( $premiumpress_price ); ?></p>
     173                        <?php endif; ?>
    159174                        <ul class="ppd-single__meta">
     175                                <?php $premiumpress_badge = (string) apply_filters( 'premiumpress_card_badge', '', $premiumpress_id ); ?>
     176                                <?php if ( '' !== $premiumpress_badge ) : ?>
     177                                        <li><span class="ppd-chip ppd-chip--status"><?php echo esc_html( $premiumpress_badge ); ?></span></li>
     178                                <?php endif; ?>
    160179                                <?php if ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?>
    161180                                        <li><span class="ppd-chip ppd-chip--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span></li>
    … …  
    264283                        <?php echo PremiumPress_Engage::reviews_html( $premiumpress_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?>
    265284
     285                        <?php do_action( 'premiumpress_single_after_content', $premiumpress_id ); ?>
     286
    266287                        <?php echo PremiumPress_Frontend::template( 'listing-forms', array( 'post_id' => $premiumpress_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?>
    267288                </div>
  • premiumpress-directory/trunk/templates/submit-form.php

    r3838627 r3848540  
    9999                                        <?php
    100100                                        foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) :
    101                                                 $premiumpress_value = $premiumpress_meta( $premiumpress_key );
     101                                                $premiumpress_value = $premiumpress_id ? PremiumPress_Profiles::get_field( (int) $premiumpress_id, $premiumpress_key, $premiumpress_field ) : '';
    102102                                                $premiumpress_fid   = $premiumpress_uid . '-f-' . $premiumpress_key;
    103103                                                $premiumpress_type  = (string) ( $premiumpress_field['type'] ?? 'text' );
    … …  
    128128                                                                <legend><?php echo esc_html( $premiumpress_label ); ?><?php echo $premiumpress_req ? ' <span class="ppd-req" aria-hidden="true">*</span>' : ''; ?></legend>
    129129                                                                <div class="ppd-form__checks">
    130                                                                         <?php foreach ( (array) $premiumpress_field['options'] as $premiumpress_opt ) : ?>
    131                                                                                 <label><input type="checkbox" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>][]" value="<?php echo esc_attr( $premiumpress_opt ); ?>" <?php checked( in_array( $premiumpress_opt, array_map( 'trim', explode( ',', $premiumpress_value ) ), true ) ); ?>> <?php echo esc_html( $premiumpress_opt ); ?></label>
     130                                                                        <?php foreach ( PremiumPress_Profiles::options( $premiumpress_field ) as $premiumpress_opt => $premiumpress_opt_label ) : ?>
     131                                                                                <label><input type="checkbox" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>][]" value="<?php echo esc_attr( (string) $premiumpress_opt ); ?>" <?php checked( in_array( (string) $premiumpress_opt, array_map( 'trim', explode( ',', $premiumpress_value ) ), true ) ); ?>> <?php echo esc_html( $premiumpress_opt_label ); ?></label>
    132132                                                                        <?php endforeach; ?>
    133133                                                                </div>
    … …  
    138138                                                                <select id="<?php echo esc_attr( $premiumpress_fid ); ?>" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>]"<?php echo $premiumpress_req ? ' required' : ''; ?>>
    139139                                                                        <option value=""><?php esc_html_e( '— Choose —', 'premiumpress-directory' ); ?></option>
    140                                                                         <?php foreach ( (array) $premiumpress_field['options'] as $premiumpress_opt ) : ?>
    141                                                                                 <option value="<?php echo esc_attr( $premiumpress_opt ); ?>" <?php selected( $premiumpress_opt, $premiumpress_value ); ?>><?php echo esc_html( $premiumpress_opt ); ?></option>
     140                                                                        <?php foreach ( PremiumPress_Profiles::options( $premiumpress_field ) as $premiumpress_opt => $premiumpress_opt_label ) : ?>
     141                                                                                <option value="<?php echo esc_attr( (string) $premiumpress_opt ); ?>" <?php selected( (string) $premiumpress_opt, $premiumpress_value ); ?>><?php echo esc_html( $premiumpress_opt_label ); ?></option>
    142142                                                                        <?php endforeach; ?>
    143143                                                                </select>
Note: See TracChangeset for help on using the changeset viewer.