Changeset 3848540
- Timestamp:
- 12/06/2026 09:54:43 PM (less than one hour ago)
- Location:
- premiumpress-directory
- Files:
-
- 12 added
- 68 edited
- 1 copied
-
tags/1.1.1 (copied) (copied from premiumpress-directory/trunk )
-
tags/1.1.1/assets/css/frontend.css (modified) (5 diffs)
-
tags/1.1.1/blocks/listings/block.json (modified) (1 diff)
-
tags/1.1.1/blocks/my-listings/block.json (modified) (1 diff)
-
tags/1.1.1/blocks/search/block.json (modified) (1 diff)
-
tags/1.1.1/blocks/submit/block.json (modified) (1 diff)
-
tags/1.1.1/includes/class-premiumpress-admin-editor.php (modified) (7 diffs)
-
tags/1.1.1/includes/class-premiumpress-admin-listings.php (modified) (4 diffs)
-
tags/1.1.1/includes/class-premiumpress-admin-reviews.php (modified) (4 diffs)
-
tags/1.1.1/includes/class-premiumpress-admin-ui.php (modified) (16 diffs)
-
tags/1.1.1/includes/class-premiumpress-compat.php (modified) (1 diff)
-
tags/1.1.1/includes/class-premiumpress-design.php (modified) (14 diffs)
-
tags/1.1.1/includes/class-premiumpress-engage.php (modified) (7 diffs)
-
tags/1.1.1/includes/class-premiumpress-fields.php (modified) (12 diffs)
-
tags/1.1.1/includes/class-premiumpress-frontend.php (modified) (3 diffs)
-
tags/1.1.1/includes/class-premiumpress-lifecycle.php (modified) (1 diff)
-
tags/1.1.1/includes/class-premiumpress-listings-grid.php (modified) (2 diffs)
-
tags/1.1.1/includes/class-premiumpress-meta.php (modified) (8 diffs)
-
tags/1.1.1/includes/class-premiumpress-pages.php (modified) (1 diff)
-
tags/1.1.1/includes/class-premiumpress-plugin.php (modified) (5 diffs)
-
tags/1.1.1/includes/class-premiumpress-porting.php (modified) (8 diffs)
-
tags/1.1.1/includes/class-premiumpress-profiles.php (modified) (7 diffs)
-
tags/1.1.1/includes/class-premiumpress-sample.php (modified) (3 diffs)
-
tags/1.1.1/includes/class-premiumpress-search.php (modified) (8 diffs)
-
tags/1.1.1/includes/class-premiumpress-settings.php (modified) (13 diffs)
-
tags/1.1.1/includes/class-premiumpress-submit.php (modified) (3 diffs)
-
tags/1.1.1/includes/class-premiumpress-switch-directory.php (added)
-
tags/1.1.1/includes/class-premiumpress-switch.php (modified) (9 diffs)
-
tags/1.1.1/includes/class-premiumpress-wizard.php (modified) (10 diffs)
-
tags/1.1.1/includes/design-data.php (added)
-
tags/1.1.1/includes/profile-data.php (added)
-
tags/1.1.1/includes/sample-data.php (added)
-
tags/1.1.1/includes/switch-data.php (added)
-
tags/1.1.1/includes/wizard-data.php (added)
-
tags/1.1.1/premiumpress-directory.php (modified) (3 diffs)
-
tags/1.1.1/readme.txt (modified) (5 diffs)
-
tags/1.1.1/templates/card.php (modified) (2 diffs)
-
tags/1.1.1/templates/listing-forms.php (modified) (1 diff)
-
tags/1.1.1/templates/my-listings.php (modified) (4 diffs)
-
tags/1.1.1/templates/single-listing.php (modified) (4 diffs)
-
tags/1.1.1/templates/submit-form.php (modified) (3 diffs)
-
trunk/assets/css/frontend.css (modified) (5 diffs)
-
trunk/blocks/listings/block.json (modified) (1 diff)
-
trunk/blocks/my-listings/block.json (modified) (1 diff)
-
trunk/blocks/search/block.json (modified) (1 diff)
-
trunk/blocks/submit/block.json (modified) (1 diff)
-
trunk/includes/class-premiumpress-admin-editor.php (modified) (7 diffs)
-
trunk/includes/class-premiumpress-admin-listings.php (modified) (4 diffs)
-
trunk/includes/class-premiumpress-admin-reviews.php (modified) (4 diffs)
-
trunk/includes/class-premiumpress-admin-ui.php (modified) (16 diffs)
-
trunk/includes/class-premiumpress-compat.php (modified) (1 diff)
-
trunk/includes/class-premiumpress-design.php (modified) (14 diffs)
-
trunk/includes/class-premiumpress-engage.php (modified) (7 diffs)
-
trunk/includes/class-premiumpress-fields.php (modified) (12 diffs)
-
trunk/includes/class-premiumpress-frontend.php (modified) (3 diffs)
-
trunk/includes/class-premiumpress-lifecycle.php (modified) (1 diff)
-
trunk/includes/class-premiumpress-listings-grid.php (modified) (2 diffs)
-
trunk/includes/class-premiumpress-meta.php (modified) (8 diffs)
-
trunk/includes/class-premiumpress-pages.php (modified) (1 diff)
-
trunk/includes/class-premiumpress-plugin.php (modified) (5 diffs)
-
trunk/includes/class-premiumpress-porting.php (modified) (8 diffs)
-
trunk/includes/class-premiumpress-profiles.php (modified) (7 diffs)
-
trunk/includes/class-premiumpress-sample.php (modified) (3 diffs)
-
trunk/includes/class-premiumpress-search.php (modified) (8 diffs)
-
trunk/includes/class-premiumpress-settings.php (modified) (13 diffs)
-
trunk/includes/class-premiumpress-submit.php (modified) (3 diffs)
-
trunk/includes/class-premiumpress-switch-directory.php (added)
-
trunk/includes/class-premiumpress-switch.php (modified) (9 diffs)
-
trunk/includes/class-premiumpress-wizard.php (modified) (10 diffs)
-
trunk/includes/design-data.php (added)
-
trunk/includes/profile-data.php (added)
-
trunk/includes/sample-data.php (added)
-
trunk/includes/switch-data.php (added)
-
trunk/includes/wizard-data.php (added)
-
trunk/premiumpress-directory.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/templates/card.php (modified) (2 diffs)
-
trunk/templates/listing-forms.php (modified) (1 diff)
-
trunk/templates/my-listings.php (modified) (4 diffs)
-
trunk/templates/single-listing.php (modified) (4 diffs)
-
trunk/templates/submit-form.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
premiumpress-directory/tags/1.1.1/assets/css/frontend.css
r3838627 r3848540 331 331 .ppd-card__facts { 332 332 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; 333 335 font-weight: 700; 334 336 } … … 370 372 371 373 .ppd-search__field label, 374 .ppd-search__field legend, 372 375 .ppd-sort label { 373 376 font-size: 0.8rem; … … 377 380 .ppd-search__form input[type="search"], 378 381 .ppd-search__form input[type="text"], 382 .ppd-search__form input[type="number"], 379 383 .ppd-search__form select, 380 384 .ppd-sort select { … … 1248 1252 } 1249 1253 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 1250 1261 .ppd-single__meta { 1251 1262 display: flex; … … 1451 1462 font-size: 1.35rem; 1452 1463 } 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 7 7 "icon": "location-alt", 8 8 "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 ], 10 14 "textdomain": "premiumpress-directory", 11 15 "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 } 20 54 }, 21 55 "supports": { 22 56 "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 } 25 65 }, 26 66 "editorScript": "file:./index.js", -
premiumpress-directory/tags/1.1.1/blocks/my-listings/block.json
r3837691 r3848540 7 7 "icon": "id", 8 8 "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 ], 10 15 "textdomain": "premiumpress-directory", 11 "supports": { "html": false, "multiple": false }, 16 "supports": { 17 "html": false, 18 "multiple": false 19 }, 12 20 "editorScript": "file:./index.js", 13 21 "style": "premiumpress-frontend" -
premiumpress-directory/tags/1.1.1/blocks/search/block.json
r3837691 r3848540 7 7 "icon": "search", 8 8 "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 ], 10 15 "textdomain": "premiumpress-directory", 11 16 "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 } 15 29 }, 16 30 "supports": { 17 31 "html": false, 18 32 "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 } 21 41 }, 22 42 "editorScript": "file:./index.js", -
premiumpress-directory/tags/1.1.1/blocks/submit/block.json
r3837691 r3848540 7 7 "icon": "plus-alt", 8 8 "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 ], 10 15 "textdomain": "premiumpress-directory", 11 "supports": { "html": false, "multiple": false }, 16 "supports": { 17 "html": false, 18 "multiple": false 19 }, 12 20 "editorScript": "file:./index.js", 13 21 "style": "premiumpress-frontend" -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-editor.php
r3838627 r3848540 49 49 50 50 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' ) ); 52 52 // Hidden from the menu only after WordPress has checked access (admin_head). 53 53 add_action( … … 62 62 static function () { 63 63 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. 65 65 } 66 66 ); … … 113 113 'max' => self::MAX_IMAGES, 114 114 '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() ), 116 116 'main' => __( 'Main photo', 'premiumpress-directory' ), 117 117 'remove' => __( 'Remove photo', 'premiumpress-directory' ), … … 167 167 if ( $skip ) { 168 168 /* 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>'; 170 170 } 171 171 if ( 'title' === $err ) { … … 217 217 218 218 // 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' ) ); 220 220 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">'; 221 221 echo '<label class="ppd-ed-label" for="ppd_content">' . esc_html__( 'Description', 'premiumpress-directory' ) . '</label><div class="ppd-ed-editor" data-ppd-check="content">'; … … 341 341 echo '</div><p class="ppd-ed-tip">'; 342 342 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>'; 344 344 self::panel_close( 5, $order ); 345 345 } … … 461 461 $id = (int) $post->ID; 462 462 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>'; 464 464 echo '<ul class="ppd-ed-checks">'; 465 465 $checks = array( -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-listings.php
r3838627 r3848540 339 339 echo '</select><button type="submit" class="ppd-a-btn">' . esc_html__( 'Apply', 'premiumpress-directory' ) . '</button></div>'; 340 340 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>'; 342 342 $pills = array( 343 343 'publish' => array( __( 'Published', 'premiumpress-directory' ), 'green' ), … … 369 369 PremiumPress_Admin_UI::e_icon( 'image', 15 ); 370 370 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 } 372 374 echo '<td>' . wp_kses_post( PremiumPress_Admin_UI::pill( $pill[0], $pill[1] ) ) . '</td>'; 373 375 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>'; … … 513 515 if ( current_user_can( $obj->cap->delete_terms ) && (int) get_option( 'default_' . $tax ) !== (int) $t->term_id ) { 514 516 /* 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>'; 516 518 } 517 519 echo '</td></tr>'; … … 571 573 wp_nonce_field( self::A_TERM . '_edit_' . $tax . '_' . $id ); 572 574 /* 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>'; 574 576 $link = get_term_link( $t ); 575 577 if ( ! is_wp_error( $link ) ) { -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-admin-reviews.php
r3838627 r3848540 42 42 43 43 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 } 45 47 add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Members', 'premiumpress-directory' ), '', 'list_users', self::MEMBERS, array( $this, 'render_members' ) ); 46 48 add_action( … … 255 257 $total = (int) get_comments( array_merge( $args, array( 'count' => true, 'number' => 0, 'offset' => 0 ) ) ); 256 258 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() ) ); 258 260 if ( $done >= 0 && isset( self::actions()[ $did ] ) ) { 259 261 /* translators: 1: number, 2: action, e.g. Approve */ … … 286 288 echo '<div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">'; 287 289 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>'; 289 291 PremiumPress_Admin_UI::close(); 290 292 return; … … 328 330 echo '<a href="' . esc_url( self::edit_url( $id ) ) . '">' . esc_html__( 'Edit', 'premiumpress-directory' ) . '</a>'; 329 331 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>'; 331 333 } 332 334 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 64 64 /** The screens that wear this look, by their `page` value. */ 65 65 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 ) ); 67 68 } 68 69 … … 215 216 $out = array( 216 217 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 ) ), 218 219 /* translators: %s: singular item name, e.g. Listing */ 219 220 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 ) ) ), 220 221 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() ), 222 223 array( 't' => __( 'Members', 'premiumpress-directory' ), 'd' => __( 'Everyone with an account', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Admin_Reviews::MEMBERS ) ), 223 224 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 ) ), 225 226 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 ) ), 227 228 array( 't' => __( 'Setup wizard', 'premiumpress-directory' ), 'd' => __( 'Answer a few questions to set up the basics', 'premiumpress-directory' ), 'u' => PremiumPress_Wizard::url() ), 228 229 array( 't' => __( 'Upgrade', 'premiumpress-directory' ), 'd' => __( 'What the PremiumPress theme adds', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Settings::PAGE, array( 'tab' => 'upgrade' ) ) ), … … 376 377 unset( $rows['reviews'], $rows['reports'] ); 377 378 } 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 ); 379 384 } 380 385 … … 397 402 398 403 // 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">'; 400 405 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>'; 401 406 /* translators: %s: profile menu name, e.g. Directory */ … … 515 520 /* translators: %s: plural item name, lowercase */ 516 521 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() ), 518 523 ), 519 524 ), … … 528 533 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' ), 529 534 /* 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' ), 531 536 ), 532 537 ), … … 737 742 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 ), 738 743 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() ), 740 745 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() ), 741 746 ); … … 781 786 self::moderation_card(); 782 787 self::status_card(); 783 self::recent_reviews_card(); 788 if ( PremiumPress_Engage::reviews_on() ) { 789 self::recent_reviews_card(); 790 } 784 791 echo '</div></div>'; 785 792 … … 789 796 private static function moderation_card(): void { 790 797 $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; 792 799 $reports = PremiumPress_Engage::open_reports(); 793 800 $p = PremiumPress_Profiles::current(); … … 801 808 $rows = array( 802 809 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() ), 804 811 array( __( 'Reports', 'premiumpress-directory' ), $reports, self::url( PremiumPress_Engage::REPORTS_PAGE ) ), 805 812 ); … … 846 853 array( 'ring', __( 'Expiring within 30 days', 'premiumpress-directory' ), $expiring, 'publish' ), 847 854 ); 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">'; 849 856 foreach ( $rows as $r ) { 850 857 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>'; … … 1001 1008 'members' => __( 'Members', 'premiumpress-directory' ), 1002 1009 ); 1010 if ( ! PremiumPress_Engage::reviews_on() ) { 1011 unset( $labels['reviews'] ); 1012 } 1003 1013 foreach ( $labels as $k => $label ) { 1004 1014 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>'; … … 1072 1082 array( 'blue', (string) $p['plural'], self::daily_listings( $days ) ), 1073 1083 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() ), 1075 1085 ); 1076 1086 $max = 1; … … 1124 1134 $p = PremiumPress_Profiles::current(); 1125 1135 $n = array(); 1126 if ( 'directory' === PremiumPress_Profiles::current_key() ) {1136 if ( PremiumPress_Wizard::niches() ) { 1127 1137 $n[] = __( 'What it is about', 'premiumpress-directory' ); 1128 1138 } … … 1142 1152 self::e_icon( 'sparkle', 16 ); 1143 1153 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>'; 1146 1156 echo '<ol class="ppd-a-cta-steps">'; 1147 1157 foreach ( self::setup_names() as $i => $name ) { … … 1162 1172 self::e_icon( 'sparkle', 20 ); 1163 1173 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>'; 1165 1175 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>'; 1166 1176 } -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-compat.php
r3837691 r3848540 31 31 } 32 32 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 ) ); 34 77 echo '</p></div>'; 35 78 } -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-design.php
r3838627 r3848540 208 208 */ 209 209 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'; 224 211 } 225 212 … … 256 243 } 257 244 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() ) ); 259 246 echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">'; 260 247 PremiumPress_Admin_UI::e_icon( 'back', 16 ); … … 269 256 return; 270 257 } 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() ) ); 272 259 $groups = array( 273 260 array( 274 261 __( '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() ), 276 263 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' ) ) ), 278 265 ), 279 266 ), … … 283 270 array( 284 271 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' ) ), 286 273 array( 'edit', __( 'Brand & logo', 'premiumpress-directory' ), __( 'Your logo, site title, brand colours and fonts.', 'premiumpress-directory' ), self::url( array( 'view' => 'identity' ) ) ), 287 274 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 ), … … 331 318 'designs' => array( __( 'Ready-made designs', 'premiumpress-directory' ), self::url( array( 'view' => 'designs' ) ), false ), 332 319 '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 ), 334 321 'header' => array( __( 'Header & footer', 'premiumpress-directory' ), self::wp_tool( 'header' ), true ), 335 322 ); … … 395 382 396 383 // 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>'; 398 385 self::colour_row( 'primary', __( 'Primary', 'premiumpress-directory' ), $b['primary'], $def['primary'] ); 399 386 self::colour_row( 'secondary', __( 'Secondary', 'premiumpress-directory' ), $b['secondary'], $def['secondary'] ); … … 403 390 404 391 // 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>'; 406 393 foreach ( array( 'head_font' => __( 'Headline font', 'premiumpress-directory' ), 'body_font' => __( 'Body text font', 'premiumpress-directory' ) ) as $k => $l ) { 407 394 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 ) . '">'; … … 424 411 // Live preview. 425 412 $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>'; 429 416 echo '<div class="ppd-bp-tokens">'; 430 417 foreach ( array( 'primary' => __( 'Primary', 'premiumpress-directory' ), 'secondary' => __( 'Secondary', 'premiumpress-directory' ), 'background' => __( 'Background', 'premiumpress-directory' ), 'cards' => __( 'Cards', 'premiumpress-directory' ) ) as $k => $l ) { … … 481 468 /** Custom code: WordPress's own "Additional CSS", edited here. */ 482 469 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() ) ); 484 471 self::crumbs( __( 'Custom code', 'premiumpress-directory' ), $msg ); 485 472 self::tabs( 'code' ); … … 511 498 $p = PremiumPress_Profiles::current(); 512 499 $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() ) ); 514 501 echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">'; 515 502 PremiumPress_Admin_UI::e_icon( 'back', 16 ); … … 518 505 if ( $saved ) { 519 506 $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>'; 521 508 } 522 509 echo '<div class="ppd-a-card ppd-a-pad ppd-dz">'; … … 546 533 $lead = sprintf( __( 'This design comes with the PremiumPress %s. It isn\'t part of the free plugin.', 'premiumpress-directory' ), $theme ); 547 534 /* 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() ); 549 536 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">'; 550 537 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>'; … … 563 550 $now = self::current(); 564 551 $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() ) ), 567 554 ); 568 555 echo '<div class="ppd-design-cards">'; … … 582 569 } 583 570 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>'; 585 572 } 586 573 } -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-engage.php
r3838627 r3848540 206 206 public function maybe_sync_deleted( $id, $comment ): void { 207 207 $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 ); 208 213 } 209 214 … … 324 329 } 325 330 $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() ); 328 333 $out .= '</p><p class="ppd-form__help">' . esc_html( $help ) . '</p></form></details>'; 329 334 return $out; … … 384 389 /** The reviews section for a listing page. */ 385 390 public static function reviews_html( int $post_id ): string { 391 if ( ! self::reviews_on() ) { 392 return ''; 393 } 386 394 $s = self::stats( $post_id ); 387 395 $reviews = get_comments( … … 433 441 } 434 442 435 if ( self::A_REVIEW === $action ) {443 if ( self::A_REVIEW === $action && self::reviews_on() ) { 436 444 $this->save_review( $id, $in, $back ); 437 445 } elseif ( self::A_REPORT === $action ) { … … 635 643 'review_pending' => array( 'success', __( 'Thanks! Your review will appear once it has been approved.', 'premiumpress-directory' ) ), 636 644 '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() ) ), 638 646 'rating' => array( 'error', __( 'Please choose a star rating.', 'premiumpress-directory' ) ), 639 647 'replied' => array( 'success', __( 'Your reply has been posted.', 'premiumpress-directory' ) ), … … 754 762 ); 755 763 $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 ) ) ); 757 765 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. 758 766 $msg = isset( $_GET['ppd_msg'] ) ? sanitize_key( wp_unslash( $_GET['ppd_msg'] ) ) : ''; 759 767 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>'; 761 769 } 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>'; 763 771 } 764 772 if ( ! $reports ) { 765 773 echo '<section class="ppd-a-card"><div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">'; 766 774 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>'; 768 776 PremiumPress_Admin_UI::close(); 769 777 return; 770 778 } 771 779 /* 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>'; 773 781 774 782 $tones = array( … … 811 819 echo '<div class="ppd-rp-actions">'; 812 820 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>'; 814 822 } 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>'; 816 824 if ( $live && current_user_can( 'edit_post', $pid ) ) { 817 825 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 44 44 array( 45 45 '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() ), 48 48 ) 49 49 ); … … 72 72 } 73 73 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 74 92 /** Keys the plugin itself uses; a custom field may not take them over. */ 75 93 public static function reserved(): array { … … 126 144 $f = is_array( $f ) ? $f : array(); 127 145 $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' ) ); 128 151 return array_merge( 129 152 $f, … … 132 155 'label' => (string) ( $f['label'] ?? '' ), 133 156 '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(), 135 158 'help' => (string) ( $f['help'] ?? '' ), 136 159 'required' => ! empty( $f['required'] ) && 'title' !== $type, … … 179 202 $key = 'field'; 180 203 } 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 } 189 216 } 190 217 $used[] = $key; 191 218 $type = isset( $row['type'] ) && isset( self::types()[ $row['type'] ] ) ? (string) $row['type'] : 'text'; 219 if ( $locked ) { 220 $type = (string) ( $builtin[ $key ]['type'] ?? $type ); 221 } 192 222 $opts = array(); 193 223 if ( self::has_options( $type ) ) { … … 207 237 } 208 238 } 239 if ( $locked && self::has_options( $type ) ) { 240 $opts = (array) ( $builtin[ $key ]['options'] ?? array() ); 241 } 209 242 // 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() ); 211 244 $list[] = self::normalise( 212 245 array_merge( … … 298 331 ); 299 332 $name = 'fields[' . $uid . ']'; 333 $lock = self::locked( $f ); 300 334 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">'; 301 335 PremiumPress_Admin_UI::e_icon( 'grip', 16 ); … … 316 350 317 351 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' : '' ) . '>'; 320 354 foreach ( $types as $k => $label ) { 321 355 echo '<option value="' . esc_attr( $k ) . '"' . selected( $f['type'], $k, false ) . '>' . esc_html( $label ) . '</option>'; … … 324 358 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>'; 325 359 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 } 327 364 328 365 $cats = get_terms( … … 340 377 echo '</div></fieldset>'; 341 378 } 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>'; 344 381 echo '</div></details>'; 345 382 } … … 354 391 $defs = self::defaults(); 355 392 $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() ) ); 357 394 PremiumPress_Admin_UI::crumb(); 358 395 if ( 'saved' === $msg ) { … … 403 440 echo '</section><section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html__( 'Reset to defaults', 'premiumpress-directory' ) . '</h2>'; 404 441 /* 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>'; 406 443 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 ) . '">'; 407 444 wp_nonce_field( self::A_RESET ); -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-frontend.php
r3838627 r3848540 64 64 /* translators: %s: singular item name, e.g. Listing */ 65 65 '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' ), 67 67 '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. 68 68 'post_types' => array( PremiumPress_Post_Types::TYPE ), … … 72 72 $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. 73 73 $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 ) ), 77 77 ); 78 78 foreach ( $names as $tax => $title ) { … … 81 81 array( 82 82 '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() ), 84 84 'content' => $archive, 85 85 ) -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-lifecycle.php
r3838627 r3848540 182 182 183 183 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' ); 185 185 } 186 186 -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-listings-grid.php
r3837691 r3848540 133 133 134 134 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>'; 136 136 } 137 137 … … 175 175 'current' => $current, 176 176 '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' ), 179 179 ) 180 180 ); 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>' : ''; 182 182 } 183 183 } -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-meta.php
r3838627 r3848540 98 98 99 99 foreach ( PremiumPress_Profiles::all_fields() as $key => $field ) { 100 if ( ! empty( $field['tax'] ) ) { 101 continue; // Stored as a term, not post meta. 102 } 100 103 register_post_meta( 101 104 PremiumPress_Post_Types::TYPE, … … 163 166 echo '<div class="ppd-grid">'; 164 167 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 ); 166 169 $id = 'ppd-f-' . $key; 167 170 $name = 'ppd_f[' . $key . ']'; … … 191 194 $on = array_map( 'trim', explode( ',', $value ) ); 192 195 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 ) { 194 197 printf( 195 198 '<label class="ppd-check"><input type="checkbox" name="%1$s[]" value="%2$s" %3$s> %4$s</label>', 196 199 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 ) 200 203 ); 201 204 } … … 203 206 } elseif ( 'select' === $type ) { 204 207 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 ) ); 207 210 } 208 211 echo '</select>'; … … 250 253 } 251 254 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>'; 253 256 } 254 257 … … 320 323 321 324 // 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. 323 326 // Each value is sanitised by the callback registered in register_meta(). 324 327 $in = isset( $_POST['ppd'] ) && is_array( $_POST['ppd'] ) ? wp_unslash( $_POST['ppd'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized … … 336 339 $custom = isset( $_POST['ppd_f'] ) && is_array( $_POST['ppd_f'] ) ? wp_unslash( $_POST['ppd_f'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 337 340 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 ] ?? '' ) ); 339 342 } 340 343 … … 367 370 public static function sanitize_field( array $field, $value ): string { 368 371 $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 ) ) ); 370 373 371 374 switch ( $type ) { -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-pages.php
r3837691 r3848540 27 27 'submit' => array( 28 28 /* 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'] ) ), 30 30 'slug' => 'add-' . sanitize_title( (string) $p['singular'] ), 31 31 'block' => '<!-- wp:premiumpress/submit /-->', -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-plugin.php
r3838627 r3848540 16 16 /** @var PremiumPress_Plugin|null */ 17 17 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 } 18 25 19 26 public static function instance(): PremiumPress_Plugin { … … 35 42 return; 36 43 } 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; 37 51 38 52 ( new PremiumPress_Post_Types() )->register(); … … 59 73 ( new PremiumPress_Porting() )->register(); 60 74 ( 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 } 61 79 62 80 add_action( 'init', array( $this, 'maybe_flush' ), 999 ); … … 65 83 // Coming back from a PremiumPress theme: our rules need rebuilding. 66 84 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' ) ); 67 90 } 68 91 … … 81 104 public static function activate(): void { 82 105 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 } 85 114 PremiumPress_Profiles::remember_single(); 86 115 PremiumPress_Pages::ensure(); -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-porting.php
r3838627 r3848540 938 938 } elseif ( isset( $fields[ $key ] ) ) { 939 939 $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; 940 945 } else { 941 946 continue; … … 957 962 */ 958 963 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 ); 960 965 if ( ! $options ) { 961 966 return $raw; … … 963 968 $out = array(); 964 969 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 ) ); 972 979 } 973 980 … … 1351 1358 } 1352 1359 $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() ) ); 1354 1361 PremiumPress_Admin_UI::crumb(); 1355 1362 echo '<div class="ppd-porting">'; … … 1368 1375 echo '<div class="notice notice-info inline"><p>'; 1369 1376 /* 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() ) ) ); 1371 1378 echo '</p><form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_PHOTOS ) . '">'; 1372 1379 wp_nonce_field( self::A_PHOTOS ); … … 1395 1402 echo '<div class="ppd-a-twocards"><section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">'; 1396 1403 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>'; 1398 1405 /* 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>'; 1401 1408 echo '<form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_EXPORT ) . '">'; 1402 1409 wp_nonce_field( self::A_EXPORT ); … … 1407 1414 echo '<section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">'; 1408 1415 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>'; 1411 1418 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>'; 1414 1421 echo '<form method="post" action="' . esc_url( $post_url ) . '" enctype="multipart/form-data"><input type="hidden" name="action" value="' . esc_attr( self::A_IMPORT ) . '">'; 1415 1422 wp_nonce_field( self::A_IMPORT ); … … 1417 1424 echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">'; 1418 1425 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>'; 1420 1427 echo '</div>'; 1421 1428 PremiumPress_Admin_UI::close(); -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-profiles.php
r3838627 r3848540 37 37 } 38 38 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' ); 125 41 126 42 return self::$defs; … … 129 45 /** @return array<int, string> Keys of released profiles, in registry order. */ 130 46 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 ) ); 132 48 return array_values( array_intersect( array_keys( self::all() ), $on ) ); 133 49 } … … 155 71 if ( '' === $key ) { 156 72 $enabled = self::enabled(); 157 $key = $enabled ? $enabled[0] : 'directory';73 $key = $enabled ? $enabled[0] : PREMIUMPRESS_PROFILE; 158 74 } 159 75 $all = self::all(); … … 176 92 177 93 /** 178 * Record the profile in the shared option when it is still empty, so a later179 * the me upgrade opens in the same niche. Never overwrites a value the site180 * 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. 181 97 */ 182 98 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; 186 131 } 187 132 … … 215 160 } 216 161 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. */ 218 163 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 ); 220 173 return '' !== $anchor ? $url . '#' . $anchor : $url; 221 174 } … … 234 187 235 188 /** 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 /** 236 262 * A field's value ready for display: comma-lists spaced, money prefixed. 237 263 * … … 254 280 return implode( ', ', array_filter( array_map( 'trim', explode( ',', $value ) ) ) ); 255 281 } 282 if ( 'select' === ( $field['type'] ?? '' ) ) { 283 $labels = self::options( $field ); 284 return $labels[ $value ] ?? $value; 285 } 256 286 return $value; 257 287 } -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-sample.php
r3837691 r3848540 1 1 <?php 2 2 /** 3 * Sample content: a handful of realistic example items (with photos, real map4 * 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. 5 5 * Everything created is tagged, so "Remove sample content" takes it all away 6 6 * 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 10 8 * 11 9 * @package PremiumPress … … 24 22 */ 25 23 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'; 153 25 return (array) apply_filters( 'premiumpress_sample_items', $items, PremiumPress_Profiles::current()['key'] ); 154 26 } … … 190 62 foreach ( (array) $item['meta'] as $key => $value ) { 191 63 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 } 192 69 } 193 70 if ( ! empty( $item['hours'] ) ) { -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-search.php
r3838627 r3848540 77 77 'lng' => $lng, 78 78 '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'] : '', 80 80 'page' => isset( $get[ self::PAGE_VAR ] ) ? max( 1, absint( $get[ self::PAGE_VAR ] ) ) : 1, 81 81 'tag' => '', 82 'f' => array(), 82 83 ); 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 } 83 96 // phpcs:enable 84 97 $term = self::archive_term(); … … 102 115 $t = get_queried_object(); 103 116 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; 104 160 } 105 161 … … 171 227 $args['orderby'] = 'relevance'; 172 228 } 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 } 174 283 if ( '' !== $r['cat'] ) { 175 284 $tax[] = array( … … 259 368 $uid = wp_unique_id( 'ppd-s-' ); 260 369 $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 ); 262 375 // On a category or location page, a new search goes to the main directory 263 376 // page (the term is already picked in the form), so filters never clash. … … 266 379 $action = $dir; 267 380 } 381 $filtered = (bool) array_filter( $r['f'], 'strlen' ); 268 382 $units = 'mi' === PremiumPress_Geo::units() ? __( 'miles', 'premiumpress-directory' ) : __( 'km', 'premiumpress-directory' ); 269 383 $has_geo = null !== $r['lat']; … … 286 400 287 401 <?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; ?> 288 425 289 426 <?php if ( $places ) : ?> … … 317 454 <div class="ppd-search__actions"> 318 455 <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 ) ) : ?> 320 457 <a class="ppd-search__reset" href="<?php echo esc_url( $action ); ?>"><?php esc_html_e( 'Clear', 'premiumpress-directory' ); ?></a> 321 458 <?php endif; ?> … … 334 471 */ 335 472 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' ); 344 474 $id = wp_unique_id( 'ppd-sort-' ); 345 475 $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 102 102 'geocode' => ! empty( $in['geocode'] ), 103 103 'maps' => ! empty( $in['maps'] ), 104 'units' => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi',104 'units' => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi', 105 105 'emails' => ! empty( $in['emails'] ), 106 106 'duration' => isset( $in['duration'] ) ? min( 3650, max( 0, absint( $in['duration'] ) ) ) : 0, … … 172 172 $out = array( 173 173 '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 ) ), 175 175 'desc' => __( 'Approval before going live, how long items stay up, and the terms people agree to', 'premiumpress-directory' ), 176 176 'icon' => 'shield', 177 177 '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' ) ), 179 179 ), 180 180 'email' => array( … … 253 253 if ( isset( $sections[ $section ] ) ) { 254 254 // 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() ) ); 256 256 echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::base_url() ) . '">'; 257 257 PremiumPress_Admin_UI::e_icon( 'back', 16 ); … … 265 265 } 266 266 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() ) ); 268 268 if ( $saved ) { 269 269 echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Settings saved.', 'premiumpress-directory' ) . '</div>'; 270 270 } 271 271 $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() ) ), 273 273 'maps' => array( __( 'Maps', 'premiumpress-directory' ), __( 'Where things are, and how far away.', 'premiumpress-directory' ) ), 274 274 'content' => array( __( 'Pages & content', 'premiumpress-directory' ), __( 'The pages visitors use and the sample items.', 'premiumpress-directory' ) ), … … 420 420 echo '<span class="ppd-a-pill ppd-a-pill--blue">' . esc_html( (string) $p['label'] ) . '</span></div></div>'; 421 421 } 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' ); 424 424 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' ) ); 425 425 self::stack_row( __( 'Terms page', 'premiumpress-directory' ), __( 'When set, people must agree to this page before submitting.', 'premiumpress-directory' ), 'ppd-terms' ); … … 440 440 } elseif ( 'maps' === $section ) { 441 441 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' ) ); 443 443 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' ) ); 444 444 self::stack_row( __( 'Distances in', 'premiumpress-directory' ), __( 'Used for "near me" searches and the distance on each result.', 'premiumpress-directory' ), 'ppd-units' ); … … 490 490 491 491 // 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>'; 495 495 echo '<div class="ppd-a-card ppd-pg-list">'; 496 496 $missing = false; … … 540 540 ); 541 541 $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>'; 544 544 echo '<div class="ppd-a-card ppd-a-pad ppd-pg-sample">'; 545 545 if ( $n ) { 546 546 /* 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>'; 548 548 echo '<ul class="ppd-pg-names">'; 549 549 foreach ( $samples as $sp ) { 550 550 echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>'; 551 551 } 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>'; 553 553 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">'; 554 554 wp_nonce_field( self::SAMPLE_ACTION ); 555 555 /* 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>'; 557 557 } 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>'; 559 559 $items = count( PremiumPress_Sample::items() ); 560 560 if ( $items ) { … … 564 564 wp_nonce_field( self::SAMPLE_ACTION ); 565 565 /* 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>'; 567 567 } 568 568 } … … 571 571 // Start again. 572 572 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>'; 574 574 echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Wizard::url() ) . '">' . esc_html__( 'Open the setup wizard', 'premiumpress-directory' ) . '</a></div></section>'; 575 575 } … … 625 625 $no = '<span class="ppd-up-no" role="img" aria-label="' . esc_attr__( 'Not included', 'premiumpress-directory' ) . '">–</span>'; 626 626 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() ); 638 629 639 630 echo '<div class="ppd-up">'; … … 642 633 $title = sprintf( esc_html__( 'See what the %s adds', 'premiumpress-directory' ), '<span>' . esc_html( $theme ) . '</span>' ); 643 634 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>'; 645 636 /* translators: %s: theme name, e.g. Directory theme */ 646 637 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 ) ) . ' '; … … 660 651 PremiumPress_Admin_UI::e_icon( 'layers', 22 ); 661 652 /* 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>'; 663 654 /* translators: %s: theme name, e.g. Directory theme */ 664 655 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 141 141 'required' => array( 'error', __( 'Please fill in every field marked with *.', 'premiumpress-directory' ) ), 142 142 ); 143 /** Niche code adds its own notices (e.g. "Marked as sold"). */ 144 $map = (array) apply_filters( 'premiumpress_flash_messages', $map, $one ); 143 145 if ( ! isset( $map[ $code ] ) ) { 144 146 return ''; … … 332 334 } 333 335 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 ] ?? '' ) ); 340 337 } 341 338 if ( PremiumPress_Profiles::has_section( 'hours' ) && isset( $in['ppd_hours'] ) && is_array( $in['ppd_hours'] ) ) { … … 480 477 self::back( $back, 'renewed' ); 481 478 } 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 } 482 484 self::back( $back, 'failed' ); 483 485 } -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-switch.php
r3838627 r3848540 24 24 } 25 25 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 26 40 /** @return array<string, string> source => name */ 27 41 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; 33 47 } 34 48 35 49 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'] ?? '' ); 42 51 } 43 52 … … 74 83 $wpdb->prepare( 75 84 "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') 77 86 AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) ) 78 87 ORDER BY p.ID ASC LIMIT %d", … … 91 100 $type = self::post_type( $source ); 92 101 // 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 ) ); 94 103 // Same rule as pending_ids(): not copied yet, whatever has happened to earlier copies. 95 104 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- as above. … … 97 106 $wpdb->prepare( 98 107 "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') 100 109 AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) )", 101 110 $type, … … 141 150 } 142 151 $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 } 144 159 ++$copied; 145 160 } else { … … 186 201 'copy_images' => true, 187 202 ); 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 524 214 525 215 /* ===== Shared ===== */ 526 216 527 217 /** Does one of the other plugin's tables exist? (Older or partial installs may lack some.) */ 528 p rivatestatic function table_exists( string $table ): bool {218 public static function table_exists( string $table ): bool { 529 219 global $wpdb; 530 220 static $seen = array(); … … 542 232 * @return array<int, array<int, string>> 543 233 */ 544 p rivatestatic function term_paths( int $sid, string $tax ): array {234 public static function term_paths( int $sid, string $tax ): array { 545 235 global $wpdb; 546 236 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the taxonomy may not be registered while its plugin is off. … … 580 270 * @return array<int, array<string, mixed>> 581 271 */ 582 p rivatestatic function comment_reviews( int $sid, string $source, callable $rating ): array {272 public static function comment_reviews( int $sid, string $source, callable $rating ): array { 583 273 $out = array(); 584 274 foreach ( get_comments( array( 'post_id' => $sid, 'status' => 'all', 'parent' => 0 ) ) as $c ) { … … 619 309 return; 620 310 } 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>'; 623 313 echo '<table class="widefat striped ppd-switch"><tbody>'; 624 314 foreach ( $rows as $key => $c ) { 625 315 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() ) ) ) . ', '; 628 318 /* translators: %d: number of listings still to copy */ 629 319 echo esc_html( sprintf( _n( '%d still to copy', '%d still to copy', $c['left'], 'premiumpress-directory' ), $c['left'] ) ); 630 320 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>'; 633 323 } 634 324 echo '</td><td>'; -
premiumpress-directory/tags/1.1.1/includes/class-premiumpress-wizard.php
r3838627 r3848540 31 31 */ 32 32 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; 95 43 } 96 44 97 45 /** True when the niche step applies (the business directory site type). */ 98 46 private static function has_niches(): bool { 99 return 'directory' === PremiumPress_Profiles::current_key();47 return (bool) self::niches(); 100 48 } 101 49 … … 229 177 private static function samples_fit(): bool { 230 178 $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 ); 232 180 } 233 181 … … 250 198 $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>'; 251 199 } 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>'; 253 201 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>'; 255 203 } 256 204 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>'; … … 334 282 $p = PremiumPress_Profiles::current(); 335 283 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() ) ); 337 285 echo '<div class="ppd-wizard">'; 338 286 /* translators: 1: step number, 2: number of steps */ … … 377 325 } elseif ( 'niche' === $step ) { 378 326 $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>'; 380 328 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">'; 381 329 foreach ( self::niches() as $key => $n ) { 382 330 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>', 384 332 esc_attr( $key ), 385 333 esc_html( $n['label'] ), … … 387 335 $now === $key ? ' is-current' : '', 388 336 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">' : '' 390 338 ); 391 339 } … … 394 342 $place = self::home_place(); 395 343 $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>'; 398 346 printf( 399 347 '<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>', … … 467 415 ); 468 416 /* 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>'; 471 419 echo '<ul class="ppd-wizard__names">'; 472 420 foreach ( $have as $sp ) { 473 421 echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>'; 474 422 } 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>'; 476 424 } elseif ( $n && self::samples_fit() ) { 477 425 /* translators: %s: plural item name, lowercase */ 478 426 echo '<h1>' . esc_html( sprintf( __( 'Add some sample %s?', 'premiumpress-directory' ), $many ) ) . '</h1>'; 479 427 /* 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>'; 482 430 } else { 483 431 /* translators: %s: plural item name, lowercase */ 484 432 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>'; 486 434 } 487 435 } 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>'; 490 438 PremiumPress_Design::cards( 'design' ); 491 439 } elseif ( 'home' === $step ) { 492 440 $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>'; 494 442 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>'; 496 444 } 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>'; 498 446 } else { 499 447 $front = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 500 448 $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>'; 502 450 echo '<p>' . esc_html__( 'You can change this any time in WordPress under Settings, Reading.', 'premiumpress-directory' ) . '</p>'; 503 451 } 504 452 } else { 505 453 $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">'; 508 456 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> '; 510 459 } 511 460 /* translators: %s: singular item name */ … … 514 463 self::next_steps(); 515 464 /* 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>'; 517 466 } 518 467 … … 529 478 } elseif ( 'content' === $step && count( PremiumPress_Sample::items() ) && self::samples_fit() ) { 530 479 /* 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> '; 532 481 echo '<button type="submit" name="skip" value="1" class="button-link">' . esc_html__( 'No thanks', 'premiumpress-directory' ) . '</button>'; 533 482 } elseif ( 'content' === $step ) { -
premiumpress-directory/tags/1.1.1/premiumpress-directory.php
r3838748 r3848540 4 4 * Plugin URI: https://www.premiumpress.com/plugin/premiumpress-directory/ 5 5 * 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. 06 * Version: 1.1.1 7 7 * Requires at least: 6.5 8 8 * Requires PHP: 7.4 … … 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 define( 'PREMIUMPRESS_VERSION', '1.1.0' ); 20 define( 'PREMIUMPRESS_VERSION', '1.1.1' ); 21 define( 'PREMIUMPRESS_NAME', 'PremiumPress Directory' ); 22 define( 'PREMIUMPRESS_PROFILE', 'directory' ); 23 define( 'PREMIUMPRESS_UTM', 'directory-plugin' ); 24 define( 'PREMIUMPRESS_MODULES', array( 'PremiumPress_Switch_Directory' ) ); 21 25 define( 'PREMIUMPRESS_FILE', __FILE__ ); 22 26 define( 'PREMIUMPRESS_DIR', plugin_dir_path( __FILE__ ) ); … … 50 54 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-porting.php'; 51 55 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch.php'; 56 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch-directory.php'; 52 57 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-plugin.php'; 53 58 -
premiumpress-directory/tags/1.1.1/readme.txt
r3838748 r3848540 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.1. 07 Stable tag: 1.1.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 15 15 PremiumPress 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. 16 16 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) 18 18 19 19 It 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. … … 70 70 = Need more? = 71 71 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/ ).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/?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 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/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org). 75 75 76 76 == Installation == … … 167 167 == Changelog == 168 168 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 169 173 = 1.1.0 = 170 174 * 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. … … 189 193 == Upgrade Notice == 190 194 195 = 1.1.1 = 196 Small improvements. 197 191 198 = 1.1.0 = 192 199 A 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 23 23 foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) { 24 24 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 ); 26 26 if ( '' !== $premiumpress_value ) { 27 27 $premiumpress_facts[] = $premiumpress_value; … … 86 86 </span> 87 87 <?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 ) ) : ?> 89 94 <span class="ppd-badge ppd-badge--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span> 90 95 <?php elseif ( null !== $premiumpress_open ) : ?> -
premiumpress-directory/tags/1.1.1/templates/listing-forms.php
r3837691 r3848540 16 16 $premiumpress_user = wp_get_current_user(); 17 17 $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 ); 19 20 ?> 20 21 <?php if ( $premiumpress_contact ) : ?> -
premiumpress-directory/tags/1.1.1/templates/my-listings.php
r3837691 r3848540 32 32 <?php if ( '' !== $premiumpress_submit ) : ?> 33 33 <?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> 35 35 <?php endif; ?> 36 36 </div> … … 53 53 $premiumpress_state = array( 'draft', __( 'Draft', 'premiumpress-directory' ) ); 54 54 } else { 55 $premiumpress_state = (array) apply_filters( 'premiumpress_account_state', array(), $premiumpress_id ); 56 } 57 if ( ! $premiumpress_state ) { 55 58 $premiumpress_state = array( 'live', __( 'Live', 'premiumpress-directory' ) ); 56 59 } … … 76 79 <a href="<?php echo esc_url( add_query_arg( 'edit', $premiumpress_id, $premiumpress_submit ) ); ?>"><?php esc_html_e( 'Edit', 'premiumpress-directory' ); ?></a> 77 80 <?php endif; ?> 81 <?php do_action( 'premiumpress_account_item_actions', $premiumpress_id, $premiumpress_item ); ?> 78 82 <?php if ( $premiumpress_expired ) : ?> 79 83 <a href="<?php echo esc_url( PremiumPress_Submit::item_url( $premiumpress_id, 'renew' ) ); ?>"><?php esc_html_e( 'Renew', 'premiumpress-directory' ); ?></a> … … 86 90 </ul> 87 91 <?php endif; ?> 92 93 <?php do_action( 'premiumpress_account_after_items', (int) $args['user_id'] ); ?> 88 94 89 95 <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 37 37 continue; 38 38 } 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 ); 40 40 if ( '' !== $premiumpress_value ) { 41 41 $premiumpress_details[ (string) $premiumpress_field['label'] ] = $premiumpress_value; … … 131 131 <div class="ppd-actions"> 132 132 <?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; ?> 134 136 <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> 135 137 <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> … … 157 159 <h1 class="ppd-single__title"><?php echo esc_html( get_the_title( $premiumpress_id ) ); ?></h1> 158 160 <?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; ?> 159 174 <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; ?> 160 179 <?php if ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?> 161 180 <li><span class="ppd-chip ppd-chip--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span></li> … … 264 283 <?php echo PremiumPress_Engage::reviews_html( $premiumpress_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?> 265 284 285 <?php do_action( 'premiumpress_single_after_content', $premiumpress_id ); ?> 286 266 287 <?php echo PremiumPress_Frontend::template( 'listing-forms', array( 'post_id' => $premiumpress_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?> 267 288 </div> -
premiumpress-directory/tags/1.1.1/templates/submit-form.php
r3838627 r3848540 99 99 <?php 100 100 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 ) : ''; 102 102 $premiumpress_fid = $premiumpress_uid . '-f-' . $premiumpress_key; 103 103 $premiumpress_type = (string) ( $premiumpress_field['type'] ?? 'text' ); … … 128 128 <legend><?php echo esc_html( $premiumpress_label ); ?><?php echo $premiumpress_req ? ' <span class="ppd-req" aria-hidden="true">*</span>' : ''; ?></legend> 129 129 <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> 132 132 <?php endforeach; ?> 133 133 </div> … … 138 138 <select id="<?php echo esc_attr( $premiumpress_fid ); ?>" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>]"<?php echo $premiumpress_req ? ' required' : ''; ?>> 139 139 <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> 142 142 <?php endforeach; ?> 143 143 </select> -
premiumpress-directory/trunk/assets/css/frontend.css
r3838627 r3848540 331 331 .ppd-card__facts { 332 332 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; 333 335 font-weight: 700; 334 336 } … … 370 372 371 373 .ppd-search__field label, 374 .ppd-search__field legend, 372 375 .ppd-sort label { 373 376 font-size: 0.8rem; … … 377 380 .ppd-search__form input[type="search"], 378 381 .ppd-search__form input[type="text"], 382 .ppd-search__form input[type="number"], 379 383 .ppd-search__form select, 380 384 .ppd-sort select { … … 1248 1252 } 1249 1253 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 1250 1261 .ppd-single__meta { 1251 1262 display: flex; … … 1451 1462 font-size: 1.35rem; 1452 1463 } 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 7 7 "icon": "location-alt", 8 8 "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 ], 10 14 "textdomain": "premiumpress-directory", 11 15 "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 } 20 54 }, 21 55 "supports": { 22 56 "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 } 25 65 }, 26 66 "editorScript": "file:./index.js", -
premiumpress-directory/trunk/blocks/my-listings/block.json
r3837691 r3848540 7 7 "icon": "id", 8 8 "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 ], 10 15 "textdomain": "premiumpress-directory", 11 "supports": { "html": false, "multiple": false }, 16 "supports": { 17 "html": false, 18 "multiple": false 19 }, 12 20 "editorScript": "file:./index.js", 13 21 "style": "premiumpress-frontend" -
premiumpress-directory/trunk/blocks/search/block.json
r3837691 r3848540 7 7 "icon": "search", 8 8 "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 ], 10 15 "textdomain": "premiumpress-directory", 11 16 "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 } 15 29 }, 16 30 "supports": { 17 31 "html": false, 18 32 "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 } 21 41 }, 22 42 "editorScript": "file:./index.js", -
premiumpress-directory/trunk/blocks/submit/block.json
r3837691 r3848540 7 7 "icon": "plus-alt", 8 8 "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 ], 10 15 "textdomain": "premiumpress-directory", 11 "supports": { "html": false, "multiple": false }, 16 "supports": { 17 "html": false, 18 "multiple": false 19 }, 12 20 "editorScript": "file:./index.js", 13 21 "style": "premiumpress-frontend" -
premiumpress-directory/trunk/includes/class-premiumpress-admin-editor.php
r3838627 r3848540 49 49 50 50 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' ) ); 52 52 // Hidden from the menu only after WordPress has checked access (admin_head). 53 53 add_action( … … 62 62 static function () { 63 63 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. 65 65 } 66 66 ); … … 113 113 'max' => self::MAX_IMAGES, 114 114 '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() ), 116 116 'main' => __( 'Main photo', 'premiumpress-directory' ), 117 117 'remove' => __( 'Remove photo', 'premiumpress-directory' ), … … 167 167 if ( $skip ) { 168 168 /* 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>'; 170 170 } 171 171 if ( 'title' === $err ) { … … 217 217 218 218 // 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' ) ); 220 220 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">'; 221 221 echo '<label class="ppd-ed-label" for="ppd_content">' . esc_html__( 'Description', 'premiumpress-directory' ) . '</label><div class="ppd-ed-editor" data-ppd-check="content">'; … … 341 341 echo '</div><p class="ppd-ed-tip">'; 342 342 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>'; 344 344 self::panel_close( 5, $order ); 345 345 } … … 461 461 $id = (int) $post->ID; 462 462 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>'; 464 464 echo '<ul class="ppd-ed-checks">'; 465 465 $checks = array( -
premiumpress-directory/trunk/includes/class-premiumpress-admin-listings.php
r3838627 r3848540 339 339 echo '</select><button type="submit" class="ppd-a-btn">' . esc_html__( 'Apply', 'premiumpress-directory' ) . '</button></div>'; 340 340 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>'; 342 342 $pills = array( 343 343 'publish' => array( __( 'Published', 'premiumpress-directory' ), 'green' ), … … 369 369 PremiumPress_Admin_UI::e_icon( 'image', 15 ); 370 370 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 } 372 374 echo '<td>' . wp_kses_post( PremiumPress_Admin_UI::pill( $pill[0], $pill[1] ) ) . '</td>'; 373 375 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>'; … … 513 515 if ( current_user_can( $obj->cap->delete_terms ) && (int) get_option( 'default_' . $tax ) !== (int) $t->term_id ) { 514 516 /* 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>'; 516 518 } 517 519 echo '</td></tr>'; … … 571 573 wp_nonce_field( self::A_TERM . '_edit_' . $tax . '_' . $id ); 572 574 /* 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>'; 574 576 $link = get_term_link( $t ); 575 577 if ( ! is_wp_error( $link ) ) { -
premiumpress-directory/trunk/includes/class-premiumpress-admin-reviews.php
r3838627 r3848540 42 42 43 43 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 } 45 47 add_submenu_page( PremiumPress_Admin_UI::parent(), __( 'Members', 'premiumpress-directory' ), '', 'list_users', self::MEMBERS, array( $this, 'render_members' ) ); 46 48 add_action( … … 255 257 $total = (int) get_comments( array_merge( $args, array( 'count' => true, 'number' => 0, 'offset' => 0 ) ) ); 256 258 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() ) ); 258 260 if ( $done >= 0 && isset( self::actions()[ $did ] ) ) { 259 261 /* translators: 1: number, 2: action, e.g. Approve */ … … 286 288 echo '<div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">'; 287 289 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>'; 289 291 PremiumPress_Admin_UI::close(); 290 292 return; … … 328 330 echo '<a href="' . esc_url( self::edit_url( $id ) ) . '">' . esc_html__( 'Edit', 'premiumpress-directory' ) . '</a>'; 329 331 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>'; 331 333 } 332 334 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 64 64 /** The screens that wear this look, by their `page` value. */ 65 65 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 ) ); 67 68 } 68 69 … … 215 216 $out = array( 216 217 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 ) ), 218 219 /* translators: %s: singular item name, e.g. Listing */ 219 220 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 ) ) ), 220 221 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() ), 222 223 array( 't' => __( 'Members', 'premiumpress-directory' ), 'd' => __( 'Everyone with an account', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Admin_Reviews::MEMBERS ) ), 223 224 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 ) ), 225 226 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 ) ), 227 228 array( 't' => __( 'Setup wizard', 'premiumpress-directory' ), 'd' => __( 'Answer a few questions to set up the basics', 'premiumpress-directory' ), 'u' => PremiumPress_Wizard::url() ), 228 229 array( 't' => __( 'Upgrade', 'premiumpress-directory' ), 'd' => __( 'What the PremiumPress theme adds', 'premiumpress-directory' ), 'u' => self::url( PremiumPress_Settings::PAGE, array( 'tab' => 'upgrade' ) ) ), … … 376 377 unset( $rows['reviews'], $rows['reports'] ); 377 378 } 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 ); 379 384 } 380 385 … … 397 402 398 403 // 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">'; 400 405 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>'; 401 406 /* translators: %s: profile menu name, e.g. Directory */ … … 515 520 /* translators: %s: plural item name, lowercase */ 516 521 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() ), 518 523 ), 519 524 ), … … 528 533 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' ), 529 534 /* 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' ), 531 536 ), 532 537 ), … … 737 742 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 ), 738 743 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() ), 740 745 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() ), 741 746 ); … … 781 786 self::moderation_card(); 782 787 self::status_card(); 783 self::recent_reviews_card(); 788 if ( PremiumPress_Engage::reviews_on() ) { 789 self::recent_reviews_card(); 790 } 784 791 echo '</div></div>'; 785 792 … … 789 796 private static function moderation_card(): void { 790 797 $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; 792 799 $reports = PremiumPress_Engage::open_reports(); 793 800 $p = PremiumPress_Profiles::current(); … … 801 808 $rows = array( 802 809 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() ), 804 811 array( __( 'Reports', 'premiumpress-directory' ), $reports, self::url( PremiumPress_Engage::REPORTS_PAGE ) ), 805 812 ); … … 846 853 array( 'ring', __( 'Expiring within 30 days', 'premiumpress-directory' ), $expiring, 'publish' ), 847 854 ); 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">'; 849 856 foreach ( $rows as $r ) { 850 857 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>'; … … 1001 1008 'members' => __( 'Members', 'premiumpress-directory' ), 1002 1009 ); 1010 if ( ! PremiumPress_Engage::reviews_on() ) { 1011 unset( $labels['reviews'] ); 1012 } 1003 1013 foreach ( $labels as $k => $label ) { 1004 1014 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>'; … … 1072 1082 array( 'blue', (string) $p['plural'], self::daily_listings( $days ) ), 1073 1083 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() ), 1075 1085 ); 1076 1086 $max = 1; … … 1124 1134 $p = PremiumPress_Profiles::current(); 1125 1135 $n = array(); 1126 if ( 'directory' === PremiumPress_Profiles::current_key() ) {1136 if ( PremiumPress_Wizard::niches() ) { 1127 1137 $n[] = __( 'What it is about', 'premiumpress-directory' ); 1128 1138 } … … 1142 1152 self::e_icon( 'sparkle', 16 ); 1143 1153 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>'; 1146 1156 echo '<ol class="ppd-a-cta-steps">'; 1147 1157 foreach ( self::setup_names() as $i => $name ) { … … 1162 1172 self::e_icon( 'sparkle', 20 ); 1163 1173 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>'; 1165 1175 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>'; 1166 1176 } -
premiumpress-directory/trunk/includes/class-premiumpress-compat.php
r3837691 r3848540 31 31 } 32 32 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 ) ); 34 77 echo '</p></div>'; 35 78 } -
premiumpress-directory/trunk/includes/class-premiumpress-design.php
r3838627 r3848540 208 208 */ 209 209 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'; 224 211 } 225 212 … … 256 243 } 257 244 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() ) ); 259 246 echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">'; 260 247 PremiumPress_Admin_UI::e_icon( 'back', 16 ); … … 269 256 return; 270 257 } 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() ) ); 272 259 $groups = array( 273 260 array( 274 261 __( '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() ), 276 263 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' ) ) ), 278 265 ), 279 266 ), … … 283 270 array( 284 271 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' ) ), 286 273 array( 'edit', __( 'Brand & logo', 'premiumpress-directory' ), __( 'Your logo, site title, brand colours and fonts.', 'premiumpress-directory' ), self::url( array( 'view' => 'identity' ) ) ), 287 274 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 ), … … 331 318 'designs' => array( __( 'Ready-made designs', 'premiumpress-directory' ), self::url( array( 'view' => 'designs' ) ), false ), 332 319 '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 ), 334 321 'header' => array( __( 'Header & footer', 'premiumpress-directory' ), self::wp_tool( 'header' ), true ), 335 322 ); … … 395 382 396 383 // 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>'; 398 385 self::colour_row( 'primary', __( 'Primary', 'premiumpress-directory' ), $b['primary'], $def['primary'] ); 399 386 self::colour_row( 'secondary', __( 'Secondary', 'premiumpress-directory' ), $b['secondary'], $def['secondary'] ); … … 403 390 404 391 // 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>'; 406 393 foreach ( array( 'head_font' => __( 'Headline font', 'premiumpress-directory' ), 'body_font' => __( 'Body text font', 'premiumpress-directory' ) ) as $k => $l ) { 407 394 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 ) . '">'; … … 424 411 // Live preview. 425 412 $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>'; 429 416 echo '<div class="ppd-bp-tokens">'; 430 417 foreach ( array( 'primary' => __( 'Primary', 'premiumpress-directory' ), 'secondary' => __( 'Secondary', 'premiumpress-directory' ), 'background' => __( 'Background', 'premiumpress-directory' ), 'cards' => __( 'Cards', 'premiumpress-directory' ) ) as $k => $l ) { … … 481 468 /** Custom code: WordPress's own "Additional CSS", edited here. */ 482 469 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() ) ); 484 471 self::crumbs( __( 'Custom code', 'premiumpress-directory' ), $msg ); 485 472 self::tabs( 'code' ); … … 511 498 $p = PremiumPress_Profiles::current(); 512 499 $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() ) ); 514 501 echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::url() ) . '">'; 515 502 PremiumPress_Admin_UI::e_icon( 'back', 16 ); … … 518 505 if ( $saved ) { 519 506 $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>'; 521 508 } 522 509 echo '<div class="ppd-a-card ppd-a-pad ppd-dz">'; … … 546 533 $lead = sprintf( __( 'This design comes with the PremiumPress %s. It isn\'t part of the free plugin.', 'premiumpress-directory' ), $theme ); 547 534 /* 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() ); 549 536 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">'; 550 537 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>'; … … 563 550 $now = self::current(); 564 551 $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() ) ), 567 554 ); 568 555 echo '<div class="ppd-design-cards">'; … … 582 569 } 583 570 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>'; 585 572 } 586 573 } -
premiumpress-directory/trunk/includes/class-premiumpress-engage.php
r3838627 r3848540 206 206 public function maybe_sync_deleted( $id, $comment ): void { 207 207 $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 ); 208 213 } 209 214 … … 324 329 } 325 330 $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() ); 328 333 $out .= '</p><p class="ppd-form__help">' . esc_html( $help ) . '</p></form></details>'; 329 334 return $out; … … 384 389 /** The reviews section for a listing page. */ 385 390 public static function reviews_html( int $post_id ): string { 391 if ( ! self::reviews_on() ) { 392 return ''; 393 } 386 394 $s = self::stats( $post_id ); 387 395 $reviews = get_comments( … … 433 441 } 434 442 435 if ( self::A_REVIEW === $action ) {443 if ( self::A_REVIEW === $action && self::reviews_on() ) { 436 444 $this->save_review( $id, $in, $back ); 437 445 } elseif ( self::A_REPORT === $action ) { … … 635 643 'review_pending' => array( 'success', __( 'Thanks! Your review will appear once it has been approved.', 'premiumpress-directory' ) ), 636 644 '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() ) ), 638 646 'rating' => array( 'error', __( 'Please choose a star rating.', 'premiumpress-directory' ) ), 639 647 'replied' => array( 'success', __( 'Your reply has been posted.', 'premiumpress-directory' ) ), … … 754 762 ); 755 763 $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 ) ) ); 757 765 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. 758 766 $msg = isset( $_GET['ppd_msg'] ) ? sanitize_key( wp_unslash( $_GET['ppd_msg'] ) ) : ''; 759 767 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>'; 761 769 } 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>'; 763 771 } 764 772 if ( ! $reports ) { 765 773 echo '<section class="ppd-a-card"><div class="ppd-a-empty ppd-a-empty--big"><span class="ppd-a-empty-ic">'; 766 774 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>'; 768 776 PremiumPress_Admin_UI::close(); 769 777 return; 770 778 } 771 779 /* 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>'; 773 781 774 782 $tones = array( … … 811 819 echo '<div class="ppd-rp-actions">'; 812 820 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>'; 814 822 } 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>'; 816 824 if ( $live && current_user_can( 'edit_post', $pid ) ) { 817 825 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 44 44 array( 45 45 '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() ), 48 48 ) 49 49 ); … … 72 72 } 73 73 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 74 92 /** Keys the plugin itself uses; a custom field may not take them over. */ 75 93 public static function reserved(): array { … … 126 144 $f = is_array( $f ) ? $f : array(); 127 145 $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' ) ); 128 151 return array_merge( 129 152 $f, … … 132 155 'label' => (string) ( $f['label'] ?? '' ), 133 156 '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(), 135 158 'help' => (string) ( $f['help'] ?? '' ), 136 159 'required' => ! empty( $f['required'] ) && 'title' !== $type, … … 179 202 $key = 'field'; 180 203 } 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 } 189 216 } 190 217 $used[] = $key; 191 218 $type = isset( $row['type'] ) && isset( self::types()[ $row['type'] ] ) ? (string) $row['type'] : 'text'; 219 if ( $locked ) { 220 $type = (string) ( $builtin[ $key ]['type'] ?? $type ); 221 } 192 222 $opts = array(); 193 223 if ( self::has_options( $type ) ) { … … 207 237 } 208 238 } 239 if ( $locked && self::has_options( $type ) ) { 240 $opts = (array) ( $builtin[ $key ]['options'] ?? array() ); 241 } 209 242 // 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() ); 211 244 $list[] = self::normalise( 212 245 array_merge( … … 298 331 ); 299 332 $name = 'fields[' . $uid . ']'; 333 $lock = self::locked( $f ); 300 334 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">'; 301 335 PremiumPress_Admin_UI::e_icon( 'grip', 16 ); … … 316 350 317 351 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' : '' ) . '>'; 320 354 foreach ( $types as $k => $label ) { 321 355 echo '<option value="' . esc_attr( $k ) . '"' . selected( $f['type'], $k, false ) . '>' . esc_html( $label ) . '</option>'; … … 324 358 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>'; 325 359 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 } 327 364 328 365 $cats = get_terms( … … 340 377 echo '</div></fieldset>'; 341 378 } 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>'; 344 381 echo '</div></details>'; 345 382 } … … 354 391 $defs = self::defaults(); 355 392 $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() ) ); 357 394 PremiumPress_Admin_UI::crumb(); 358 395 if ( 'saved' === $msg ) { … … 403 440 echo '</section><section class="ppd-a-card ppd-a-pad"><h2 class="ppd-a-h2">' . esc_html__( 'Reset to defaults', 'premiumpress-directory' ) . '</h2>'; 404 441 /* 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>'; 406 443 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 ) . '">'; 407 444 wp_nonce_field( self::A_RESET ); -
premiumpress-directory/trunk/includes/class-premiumpress-frontend.php
r3838627 r3848540 64 64 /* translators: %s: singular item name, e.g. Listing */ 65 65 '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' ), 67 67 '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. 68 68 'post_types' => array( PremiumPress_Post_Types::TYPE ), … … 72 72 $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. 73 73 $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 ) ), 77 77 ); 78 78 foreach ( $names as $tax => $title ) { … … 81 81 array( 82 82 '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() ), 84 84 'content' => $archive, 85 85 ) -
premiumpress-directory/trunk/includes/class-premiumpress-lifecycle.php
r3838627 r3848540 182 182 183 183 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' ); 185 185 } 186 186 -
premiumpress-directory/trunk/includes/class-premiumpress-listings-grid.php
r3837691 r3848540 133 133 134 134 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>'; 136 136 } 137 137 … … 175 175 'current' => $current, 176 176 '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' ), 179 179 ) 180 180 ); 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>' : ''; 182 182 } 183 183 } -
premiumpress-directory/trunk/includes/class-premiumpress-meta.php
r3838627 r3848540 98 98 99 99 foreach ( PremiumPress_Profiles::all_fields() as $key => $field ) { 100 if ( ! empty( $field['tax'] ) ) { 101 continue; // Stored as a term, not post meta. 102 } 100 103 register_post_meta( 101 104 PremiumPress_Post_Types::TYPE, … … 163 166 echo '<div class="ppd-grid">'; 164 167 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 ); 166 169 $id = 'ppd-f-' . $key; 167 170 $name = 'ppd_f[' . $key . ']'; … … 191 194 $on = array_map( 'trim', explode( ',', $value ) ); 192 195 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 ) { 194 197 printf( 195 198 '<label class="ppd-check"><input type="checkbox" name="%1$s[]" value="%2$s" %3$s> %4$s</label>', 196 199 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 ) 200 203 ); 201 204 } … … 203 206 } elseif ( 'select' === $type ) { 204 207 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 ) ); 207 210 } 208 211 echo '</select>'; … … 250 253 } 251 254 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>'; 253 256 } 254 257 … … 320 323 321 324 // 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. 323 326 // Each value is sanitised by the callback registered in register_meta(). 324 327 $in = isset( $_POST['ppd'] ) && is_array( $_POST['ppd'] ) ? wp_unslash( $_POST['ppd'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized … … 336 339 $custom = isset( $_POST['ppd_f'] ) && is_array( $_POST['ppd_f'] ) ? wp_unslash( $_POST['ppd_f'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 337 340 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 ] ?? '' ) ); 339 342 } 340 343 … … 367 370 public static function sanitize_field( array $field, $value ): string { 368 371 $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 ) ) ); 370 373 371 374 switch ( $type ) { -
premiumpress-directory/trunk/includes/class-premiumpress-pages.php
r3837691 r3848540 27 27 'submit' => array( 28 28 /* 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'] ) ), 30 30 'slug' => 'add-' . sanitize_title( (string) $p['singular'] ), 31 31 'block' => '<!-- wp:premiumpress/submit /-->', -
premiumpress-directory/trunk/includes/class-premiumpress-plugin.php
r3838627 r3848540 16 16 /** @var PremiumPress_Plugin|null */ 17 17 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 } 18 25 19 26 public static function instance(): PremiumPress_Plugin { … … 35 42 return; 36 43 } 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; 37 51 38 52 ( new PremiumPress_Post_Types() )->register(); … … 59 73 ( new PremiumPress_Porting() )->register(); 60 74 ( 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 } 61 79 62 80 add_action( 'init', array( $this, 'maybe_flush' ), 999 ); … … 65 83 // Coming back from a PremiumPress theme: our rules need rebuilding. 66 84 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' ) ); 67 90 } 68 91 … … 81 104 public static function activate(): void { 82 105 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 } 85 114 PremiumPress_Profiles::remember_single(); 86 115 PremiumPress_Pages::ensure(); -
premiumpress-directory/trunk/includes/class-premiumpress-porting.php
r3838627 r3848540 938 938 } elseif ( isset( $fields[ $key ] ) ) { 939 939 $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; 940 945 } else { 941 946 continue; … … 957 962 */ 958 963 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 ); 960 965 if ( ! $options ) { 961 966 return $raw; … … 963 968 $out = array(); 964 969 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 ) ); 972 979 } 973 980 … … 1351 1358 } 1352 1359 $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() ) ); 1354 1361 PremiumPress_Admin_UI::crumb(); 1355 1362 echo '<div class="ppd-porting">'; … … 1368 1375 echo '<div class="notice notice-info inline"><p>'; 1369 1376 /* 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() ) ) ); 1371 1378 echo '</p><form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_PHOTOS ) . '">'; 1372 1379 wp_nonce_field( self::A_PHOTOS ); … … 1395 1402 echo '<div class="ppd-a-twocards"><section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">'; 1396 1403 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>'; 1398 1405 /* 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>'; 1401 1408 echo '<form method="post" action="' . esc_url( $post_url ) . '"><input type="hidden" name="action" value="' . esc_attr( self::A_EXPORT ) . '">'; 1402 1409 wp_nonce_field( self::A_EXPORT ); … … 1407 1414 echo '<section class="ppd-a-card ppd-a-pad ppd-port-card"><span class="ppd-port-ic">'; 1408 1415 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>'; 1411 1418 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>'; 1414 1421 echo '<form method="post" action="' . esc_url( $post_url ) . '" enctype="multipart/form-data"><input type="hidden" name="action" value="' . esc_attr( self::A_IMPORT ) . '">'; 1415 1422 wp_nonce_field( self::A_IMPORT ); … … 1417 1424 echo '<button type="submit" class="ppd-a-btn ppd-a-btn--primary">'; 1418 1425 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>'; 1420 1427 echo '</div>'; 1421 1428 PremiumPress_Admin_UI::close(); -
premiumpress-directory/trunk/includes/class-premiumpress-profiles.php
r3838627 r3848540 37 37 } 38 38 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' ); 125 41 126 42 return self::$defs; … … 129 45 /** @return array<int, string> Keys of released profiles, in registry order. */ 130 46 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 ) ); 132 48 return array_values( array_intersect( array_keys( self::all() ), $on ) ); 133 49 } … … 155 71 if ( '' === $key ) { 156 72 $enabled = self::enabled(); 157 $key = $enabled ? $enabled[0] : 'directory';73 $key = $enabled ? $enabled[0] : PREMIUMPRESS_PROFILE; 158 74 } 159 75 $all = self::all(); … … 176 92 177 93 /** 178 * Record the profile in the shared option when it is still empty, so a later179 * the me upgrade opens in the same niche. Never overwrites a value the site180 * 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. 181 97 */ 182 98 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; 186 131 } 187 132 … … 215 160 } 216 161 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. */ 218 163 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 ); 220 173 return '' !== $anchor ? $url . '#' . $anchor : $url; 221 174 } … … 234 187 235 188 /** 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 /** 236 262 * A field's value ready for display: comma-lists spaced, money prefixed. 237 263 * … … 254 280 return implode( ', ', array_filter( array_map( 'trim', explode( ',', $value ) ) ) ); 255 281 } 282 if ( 'select' === ( $field['type'] ?? '' ) ) { 283 $labels = self::options( $field ); 284 return $labels[ $value ] ?? $value; 285 } 256 286 return $value; 257 287 } -
premiumpress-directory/trunk/includes/class-premiumpress-sample.php
r3837691 r3848540 1 1 <?php 2 2 /** 3 * Sample content: a handful of realistic example items (with photos, real map4 * 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. 5 5 * Everything created is tagged, so "Remove sample content" takes it all away 6 6 * 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 10 8 * 11 9 * @package PremiumPress … … 24 22 */ 25 23 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'; 153 25 return (array) apply_filters( 'premiumpress_sample_items', $items, PremiumPress_Profiles::current()['key'] ); 154 26 } … … 190 62 foreach ( (array) $item['meta'] as $key => $value ) { 191 63 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 } 192 69 } 193 70 if ( ! empty( $item['hours'] ) ) { -
premiumpress-directory/trunk/includes/class-premiumpress-search.php
r3838627 r3848540 77 77 'lng' => $lng, 78 78 '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'] : '', 80 80 'page' => isset( $get[ self::PAGE_VAR ] ) ? max( 1, absint( $get[ self::PAGE_VAR ] ) ) : 1, 81 81 'tag' => '', 82 'f' => array(), 82 83 ); 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 } 83 96 // phpcs:enable 84 97 $term = self::archive_term(); … … 102 115 $t = get_queried_object(); 103 116 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; 104 160 } 105 161 … … 171 227 $args['orderby'] = 'relevance'; 172 228 } 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 } 174 283 if ( '' !== $r['cat'] ) { 175 284 $tax[] = array( … … 259 368 $uid = wp_unique_id( 'ppd-s-' ); 260 369 $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 ); 262 375 // On a category or location page, a new search goes to the main directory 263 376 // page (the term is already picked in the form), so filters never clash. … … 266 379 $action = $dir; 267 380 } 381 $filtered = (bool) array_filter( $r['f'], 'strlen' ); 268 382 $units = 'mi' === PremiumPress_Geo::units() ? __( 'miles', 'premiumpress-directory' ) : __( 'km', 'premiumpress-directory' ); 269 383 $has_geo = null !== $r['lat']; … … 286 400 287 401 <?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; ?> 288 425 289 426 <?php if ( $places ) : ?> … … 317 454 <div class="ppd-search__actions"> 318 455 <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 ) ) : ?> 320 457 <a class="ppd-search__reset" href="<?php echo esc_url( $action ); ?>"><?php esc_html_e( 'Clear', 'premiumpress-directory' ); ?></a> 321 458 <?php endif; ?> … … 334 471 */ 335 472 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' ); 344 474 $id = wp_unique_id( 'ppd-sort-' ); 345 475 $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 102 102 'geocode' => ! empty( $in['geocode'] ), 103 103 'maps' => ! empty( $in['maps'] ), 104 'units' => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi',104 'units' => isset( $in['units'] ) && 'km' === $in['units'] ? 'km' : 'mi', 105 105 'emails' => ! empty( $in['emails'] ), 106 106 'duration' => isset( $in['duration'] ) ? min( 3650, max( 0, absint( $in['duration'] ) ) ) : 0, … … 172 172 $out = array( 173 173 '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 ) ), 175 175 'desc' => __( 'Approval before going live, how long items stay up, and the terms people agree to', 'premiumpress-directory' ), 176 176 'icon' => 'shield', 177 177 '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' ) ), 179 179 ), 180 180 'email' => array( … … 253 253 if ( isset( $sections[ $section ] ) ) { 254 254 // 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() ) ); 256 256 echo '<nav class="ppd-a-crumbs"><a href="' . esc_url( self::base_url() ) . '">'; 257 257 PremiumPress_Admin_UI::e_icon( 'back', 16 ); … … 265 265 } 266 266 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() ) ); 268 268 if ( $saved ) { 269 269 echo '<div class="ppd-a-note ppd-a-note--ok">' . esc_html__( 'Settings saved.', 'premiumpress-directory' ) . '</div>'; 270 270 } 271 271 $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() ) ), 273 273 'maps' => array( __( 'Maps', 'premiumpress-directory' ), __( 'Where things are, and how far away.', 'premiumpress-directory' ) ), 274 274 'content' => array( __( 'Pages & content', 'premiumpress-directory' ), __( 'The pages visitors use and the sample items.', 'premiumpress-directory' ) ), … … 420 420 echo '<span class="ppd-a-pill ppd-a-pill--blue">' . esc_html( (string) $p['label'] ) . '</span></div></div>'; 421 421 } 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' ); 424 424 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' ) ); 425 425 self::stack_row( __( 'Terms page', 'premiumpress-directory' ), __( 'When set, people must agree to this page before submitting.', 'premiumpress-directory' ), 'ppd-terms' ); … … 440 440 } elseif ( 'maps' === $section ) { 441 441 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' ) ); 443 443 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' ) ); 444 444 self::stack_row( __( 'Distances in', 'premiumpress-directory' ), __( 'Used for "near me" searches and the distance on each result.', 'premiumpress-directory' ), 'ppd-units' ); … … 490 490 491 491 // 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>'; 495 495 echo '<div class="ppd-a-card ppd-pg-list">'; 496 496 $missing = false; … … 540 540 ); 541 541 $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>'; 544 544 echo '<div class="ppd-a-card ppd-a-pad ppd-pg-sample">'; 545 545 if ( $n ) { 546 546 /* 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>'; 548 548 echo '<ul class="ppd-pg-names">'; 549 549 foreach ( $samples as $sp ) { 550 550 echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>'; 551 551 } 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>'; 553 553 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">'; 554 554 wp_nonce_field( self::SAMPLE_ACTION ); 555 555 /* 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>'; 557 557 } 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>'; 559 559 $items = count( PremiumPress_Sample::items() ); 560 560 if ( $items ) { … … 564 564 wp_nonce_field( self::SAMPLE_ACTION ); 565 565 /* 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>'; 567 567 } 568 568 } … … 571 571 // Start again. 572 572 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>'; 574 574 echo '<a class="ppd-a-btn" href="' . esc_url( PremiumPress_Wizard::url() ) . '">' . esc_html__( 'Open the setup wizard', 'premiumpress-directory' ) . '</a></div></section>'; 575 575 } … … 625 625 $no = '<span class="ppd-up-no" role="img" aria-label="' . esc_attr__( 'Not included', 'premiumpress-directory' ) . '">–</span>'; 626 626 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() ); 638 629 639 630 echo '<div class="ppd-up">'; … … 642 633 $title = sprintf( esc_html__( 'See what the %s adds', 'premiumpress-directory' ), '<span>' . esc_html( $theme ) . '</span>' ); 643 634 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>'; 645 636 /* translators: %s: theme name, e.g. Directory theme */ 646 637 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 ) ) . ' '; … … 660 651 PremiumPress_Admin_UI::e_icon( 'layers', 22 ); 661 652 /* 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>'; 663 654 /* translators: %s: theme name, e.g. Directory theme */ 664 655 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 141 141 'required' => array( 'error', __( 'Please fill in every field marked with *.', 'premiumpress-directory' ) ), 142 142 ); 143 /** Niche code adds its own notices (e.g. "Marked as sold"). */ 144 $map = (array) apply_filters( 'premiumpress_flash_messages', $map, $one ); 143 145 if ( ! isset( $map[ $code ] ) ) { 144 146 return ''; … … 332 334 } 333 335 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 ] ?? '' ) ); 340 337 } 341 338 if ( PremiumPress_Profiles::has_section( 'hours' ) && isset( $in['ppd_hours'] ) && is_array( $in['ppd_hours'] ) ) { … … 480 477 self::back( $back, 'renewed' ); 481 478 } 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 } 482 484 self::back( $back, 'failed' ); 483 485 } -
premiumpress-directory/trunk/includes/class-premiumpress-switch.php
r3838627 r3848540 24 24 } 25 25 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 26 40 /** @return array<string, string> source => name */ 27 41 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; 33 47 } 34 48 35 49 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'] ?? '' ); 42 51 } 43 52 … … 74 83 $wpdb->prepare( 75 84 "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') 77 86 AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) ) 78 87 ORDER BY p.ID ASC LIMIT %d", … … 91 100 $type = self::post_type( $source ); 92 101 // 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 ) ); 94 103 // Same rule as pending_ids(): not copied yet, whatever has happened to earlier copies. 95 104 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- as above. … … 97 106 $wpdb->prepare( 98 107 "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') 100 109 AND NOT EXISTS ( SELECT 1 FROM {$wpdb->postmeta} m WHERE m.meta_key = %s AND m.meta_value = CONCAT( %s, p.ID ) )", 101 110 $type, … … 141 150 } 142 151 $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 } 144 159 ++$copied; 145 160 } else { … … 186 201 'copy_images' => true, 187 202 ); 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 524 214 525 215 /* ===== Shared ===== */ 526 216 527 217 /** Does one of the other plugin's tables exist? (Older or partial installs may lack some.) */ 528 p rivatestatic function table_exists( string $table ): bool {218 public static function table_exists( string $table ): bool { 529 219 global $wpdb; 530 220 static $seen = array(); … … 542 232 * @return array<int, array<int, string>> 543 233 */ 544 p rivatestatic function term_paths( int $sid, string $tax ): array {234 public static function term_paths( int $sid, string $tax ): array { 545 235 global $wpdb; 546 236 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the taxonomy may not be registered while its plugin is off. … … 580 270 * @return array<int, array<string, mixed>> 581 271 */ 582 p rivatestatic function comment_reviews( int $sid, string $source, callable $rating ): array {272 public static function comment_reviews( int $sid, string $source, callable $rating ): array { 583 273 $out = array(); 584 274 foreach ( get_comments( array( 'post_id' => $sid, 'status' => 'all', 'parent' => 0 ) ) as $c ) { … … 619 309 return; 620 310 } 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>'; 623 313 echo '<table class="widefat striped ppd-switch"><tbody>'; 624 314 foreach ( $rows as $key => $c ) { 625 315 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() ) ) ) . ', '; 628 318 /* translators: %d: number of listings still to copy */ 629 319 echo esc_html( sprintf( _n( '%d still to copy', '%d still to copy', $c['left'], 'premiumpress-directory' ), $c['left'] ) ); 630 320 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>'; 633 323 } 634 324 echo '</td><td>'; -
premiumpress-directory/trunk/includes/class-premiumpress-wizard.php
r3838627 r3848540 31 31 */ 32 32 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; 95 43 } 96 44 97 45 /** True when the niche step applies (the business directory site type). */ 98 46 private static function has_niches(): bool { 99 return 'directory' === PremiumPress_Profiles::current_key();47 return (bool) self::niches(); 100 48 } 101 49 … … 229 177 private static function samples_fit(): bool { 230 178 $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 ); 232 180 } 233 181 … … 250 198 $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>'; 251 199 } 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>'; 253 201 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>'; 255 203 } 256 204 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>'; … … 334 282 $p = PremiumPress_Profiles::current(); 335 283 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() ) ); 337 285 echo '<div class="ppd-wizard">'; 338 286 /* translators: 1: step number, 2: number of steps */ … … 377 325 } elseif ( 'niche' === $step ) { 378 326 $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>'; 380 328 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">'; 381 329 foreach ( self::niches() as $key => $n ) { 382 330 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>', 384 332 esc_attr( $key ), 385 333 esc_html( $n['label'] ), … … 387 335 $now === $key ? ' is-current' : '', 388 336 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">' : '' 390 338 ); 391 339 } … … 394 342 $place = self::home_place(); 395 343 $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>'; 398 346 printf( 399 347 '<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>', … … 467 415 ); 468 416 /* 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>'; 471 419 echo '<ul class="ppd-wizard__names">'; 472 420 foreach ( $have as $sp ) { 473 421 echo '<li>' . esc_html( get_the_title( $sp ) ) . '</li>'; 474 422 } 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>'; 476 424 } elseif ( $n && self::samples_fit() ) { 477 425 /* translators: %s: plural item name, lowercase */ 478 426 echo '<h1>' . esc_html( sprintf( __( 'Add some sample %s?', 'premiumpress-directory' ), $many ) ) . '</h1>'; 479 427 /* 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>'; 482 430 } else { 483 431 /* translators: %s: plural item name, lowercase */ 484 432 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>'; 486 434 } 487 435 } 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>'; 490 438 PremiumPress_Design::cards( 'design' ); 491 439 } elseif ( 'home' === $step ) { 492 440 $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>'; 494 442 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>'; 496 444 } 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>'; 498 446 } else { 499 447 $front = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; 500 448 $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>'; 502 450 echo '<p>' . esc_html__( 'You can change this any time in WordPress under Settings, Reading.', 'premiumpress-directory' ) . '</p>'; 503 451 } 504 452 } else { 505 453 $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">'; 508 456 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> '; 510 459 } 511 460 /* translators: %s: singular item name */ … … 514 463 self::next_steps(); 515 464 /* 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>'; 517 466 } 518 467 … … 529 478 } elseif ( 'content' === $step && count( PremiumPress_Sample::items() ) && self::samples_fit() ) { 530 479 /* 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> '; 532 481 echo '<button type="submit" name="skip" value="1" class="button-link">' . esc_html__( 'No thanks', 'premiumpress-directory' ) . '</button>'; 533 482 } elseif ( 'content' === $step ) { -
premiumpress-directory/trunk/premiumpress-directory.php
r3838748 r3848540 4 4 * Plugin URI: https://www.premiumpress.com/plugin/premiumpress-directory/ 5 5 * 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. 06 * Version: 1.1.1 7 7 * Requires at least: 6.5 8 8 * Requires PHP: 7.4 … … 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 define( 'PREMIUMPRESS_VERSION', '1.1.0' ); 20 define( 'PREMIUMPRESS_VERSION', '1.1.1' ); 21 define( 'PREMIUMPRESS_NAME', 'PremiumPress Directory' ); 22 define( 'PREMIUMPRESS_PROFILE', 'directory' ); 23 define( 'PREMIUMPRESS_UTM', 'directory-plugin' ); 24 define( 'PREMIUMPRESS_MODULES', array( 'PremiumPress_Switch_Directory' ) ); 21 25 define( 'PREMIUMPRESS_FILE', __FILE__ ); 22 26 define( 'PREMIUMPRESS_DIR', plugin_dir_path( __FILE__ ) ); … … 50 54 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-porting.php'; 51 55 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch.php'; 56 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-switch-directory.php'; 52 57 require_once PREMIUMPRESS_DIR . 'includes/class-premiumpress-plugin.php'; 53 58 -
premiumpress-directory/trunk/readme.txt
r3838748 r3848540 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.1. 07 Stable tag: 1.1.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 15 15 PremiumPress 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. 16 16 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) 18 18 19 19 It 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. … … 70 70 = Need more? = 71 71 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/ ).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/?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 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/?utm_source=directory-plugin&utm_medium=wordpress.org&utm_campaign=directory-plugin&utm_term=wordpress.org). 75 75 76 76 == Installation == … … 167 167 == Changelog == 168 168 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 169 173 = 1.1.0 = 170 174 * 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. … … 189 193 == Upgrade Notice == 190 194 195 = 1.1.1 = 196 Small improvements. 197 191 198 = 1.1.0 = 192 199 A 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 23 23 foreach ( PremiumPress_Profiles::fields() as $premiumpress_key => $premiumpress_field ) { 24 24 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 ); 26 26 if ( '' !== $premiumpress_value ) { 27 27 $premiumpress_facts[] = $premiumpress_value; … … 86 86 </span> 87 87 <?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 ) ) : ?> 89 94 <span class="ppd-badge ppd-badge--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span> 90 95 <?php elseif ( null !== $premiumpress_open ) : ?> -
premiumpress-directory/trunk/templates/listing-forms.php
r3837691 r3848540 16 16 $premiumpress_user = wp_get_current_user(); 17 17 $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 ); 19 20 ?> 20 21 <?php if ( $premiumpress_contact ) : ?> -
premiumpress-directory/trunk/templates/my-listings.php
r3837691 r3848540 32 32 <?php if ( '' !== $premiumpress_submit ) : ?> 33 33 <?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> 35 35 <?php endif; ?> 36 36 </div> … … 53 53 $premiumpress_state = array( 'draft', __( 'Draft', 'premiumpress-directory' ) ); 54 54 } else { 55 $premiumpress_state = (array) apply_filters( 'premiumpress_account_state', array(), $premiumpress_id ); 56 } 57 if ( ! $premiumpress_state ) { 55 58 $premiumpress_state = array( 'live', __( 'Live', 'premiumpress-directory' ) ); 56 59 } … … 76 79 <a href="<?php echo esc_url( add_query_arg( 'edit', $premiumpress_id, $premiumpress_submit ) ); ?>"><?php esc_html_e( 'Edit', 'premiumpress-directory' ); ?></a> 77 80 <?php endif; ?> 81 <?php do_action( 'premiumpress_account_item_actions', $premiumpress_id, $premiumpress_item ); ?> 78 82 <?php if ( $premiumpress_expired ) : ?> 79 83 <a href="<?php echo esc_url( PremiumPress_Submit::item_url( $premiumpress_id, 'renew' ) ); ?>"><?php esc_html_e( 'Renew', 'premiumpress-directory' ); ?></a> … … 86 90 </ul> 87 91 <?php endif; ?> 92 93 <?php do_action( 'premiumpress_account_after_items', (int) $args['user_id'] ); ?> 88 94 89 95 <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 37 37 continue; 38 38 } 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 ); 40 40 if ( '' !== $premiumpress_value ) { 41 41 $premiumpress_details[ (string) $premiumpress_field['label'] ] = $premiumpress_value; … … 131 131 <div class="ppd-actions"> 132 132 <?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; ?> 134 136 <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> 135 137 <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> … … 157 159 <h1 class="ppd-single__title"><?php echo esc_html( get_the_title( $premiumpress_id ) ); ?></h1> 158 160 <?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; ?> 159 174 <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; ?> 160 179 <?php if ( PremiumPress_Lifecycle::is_featured( $premiumpress_id ) ) : ?> 161 180 <li><span class="ppd-chip ppd-chip--featured"><?php esc_html_e( 'Featured', 'premiumpress-directory' ); ?></span></li> … … 264 283 <?php echo PremiumPress_Engage::reviews_html( $premiumpress_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?> 265 284 285 <?php do_action( 'premiumpress_single_after_content', $premiumpress_id ); ?> 286 266 287 <?php echo PremiumPress_Frontend::template( 'listing-forms', array( 'post_id' => $premiumpress_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- template escapes. ?> 267 288 </div> -
premiumpress-directory/trunk/templates/submit-form.php
r3838627 r3848540 99 99 <?php 100 100 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 ) : ''; 102 102 $premiumpress_fid = $premiumpress_uid . '-f-' . $premiumpress_key; 103 103 $premiumpress_type = (string) ( $premiumpress_field['type'] ?? 'text' ); … … 128 128 <legend><?php echo esc_html( $premiumpress_label ); ?><?php echo $premiumpress_req ? ' <span class="ppd-req" aria-hidden="true">*</span>' : ''; ?></legend> 129 129 <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> 132 132 <?php endforeach; ?> 133 133 </div> … … 138 138 <select id="<?php echo esc_attr( $premiumpress_fid ); ?>" name="ppd_f[<?php echo esc_attr( $premiumpress_key ); ?>]"<?php echo $premiumpress_req ? ' required' : ''; ?>> 139 139 <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> 142 142 <?php endforeach; ?> 143 143 </select>
Note:
See TracChangeset
for help on using the changeset viewer.