File: //wordpress/plugins/wp-cloud-client/1.0.3/src/BusinessProfile/ProfileHelperPage.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\BusinessProfile;
/**
* Renders the Business Profile settings tab content — either the missing-profile
* notice (when no data has been synced) or the shortcode reference table.
*/
final class ProfileHelperPage {
/**
* Constructor.
*
* @param ProfileRepository $repository The profile data repository.
* @param FieldRenderer $renderer The field renderer.
* @param ProfileAdminNotice $notice The missing-profile notice renderer.
*/
public function __construct(
private readonly ProfileRepository $repository,
private readonly FieldRenderer $renderer,
private readonly ProfileAdminNotice $notice,
) {}
/**
* Render the Business Profile tab content.
*
* If no profile data exists, delegates to {@see ProfileAdminNotice::render()};
* otherwise renders the shortcode reference table.
*
* @return void
*/
public function render(): void {
$profile = $this->repository->get();
if ( null === $profile ) {
$this->notice->render();
return;
}
// Add full_address as a virtual key so it appears in the shortcode reference table.
// The actual rendering is handled by FieldRenderer::renderField() which detects this key.
if ( ! isset( $profile['full_address'] ) ) {
$profile['full_address'] = null;
}
?>
<table class="widefat striped" style="max-width: 900px;">
<thead>
<tr>
<th style="width: 50%;"><?php esc_html_e( 'Shortcode', 'wp-cloud-client' ); ?></th>
<th style="width: 50%;"><?php esc_html_e( 'Preview', 'wp-cloud-client' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $profile as $key => $value ) : ?>
<tr class="wpcc-bpr-copy-row" style="vertical-align: middle;">
<td style="vertical-align: middle;">
<div style="display: flex; align-items: center; gap: 6px;">
<input
type="text"
readonly
class="regular-text wpcc-bpr-shortcode"
value="<?php echo esc_attr( "[business_profile attr='{$key}']" ); ?>"
style="flex: 1; font-family: monospace; font-size: 12px;"
/>
<button type="button" class="button button-small wpcc-bpr-copy-btn" title="<?php esc_attr_e( 'Copy shortcode', 'wp-cloud-client' ); ?>">
<span class="dashicons dashicons-clipboard" style="vertical-align: middle;"></span>
</button>
</div>
</td>
<td style="vertical-align: middle;">
<?php
echo wp_kses_post( $this->renderer->renderField( $profile, $key ) );
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
/**
* Enqueue helper page assets on the WP Cloud Client settings page.
*
* @param string $hook The current admin page hook suffix.
* @return void
*/
public function enqueueAssets( string $hook ): void {
if ( 'settings_page_wpcc-settings' !== $hook ) {
return;
}
$cssPath = VPLUGINS_WPCC_PATH . 'assets/business-profile/css/helper-page.css';
$jsPath = VPLUGINS_WPCC_PATH . 'assets/business-profile/js/helper-page.js';
wp_enqueue_style(
'wpcc-bpr-helper',
plugins_url( 'assets/business-profile/css/helper-page.css', VPLUGINS_WPCC_FILE ),
[],
file_exists( $cssPath ) ? (string) filemtime( $cssPath ) : VPLUGINS_WPCC_VERSION,
);
wp_enqueue_script(
'wpcc-bpr-helper',
plugins_url( 'assets/business-profile/js/helper-page.js', VPLUGINS_WPCC_FILE ),
[],
file_exists( $jsPath ) ? (string) filemtime( $jsPath ) : VPLUGINS_WPCC_VERSION,
true,
);
}
}