Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLANET-7510 Investigate native lightbox implementation #2298

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions src/MasterSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ function ($block_content, $block) {
add_action('init', [$this, 'login_redirect'], 1);
add_filter('attachment_fields_to_edit', [$this, 'add_image_attachment_fields_to_edit'], 10, 2);
add_filter('attachment_fields_to_save', [$this, 'add_image_attachment_fields_to_save'], 10, 2);
version_compare(get_bloginfo('version'), '5.5', '<')
? add_action('init', [$this, 'p4_register_core_image_block'])
: add_filter('register_block_type_args', [$this, 'register_core_blocks_callback']);
add_action('admin_notices', [$this, 'show_dashboard_notice']);
add_action('wp_ajax_dismiss_dashboard_notice', [$this, 'dismiss_dashboard_notice']);

Expand Down Expand Up @@ -1457,78 +1454,6 @@ public function add_image_attachment_fields_to_save(array $post, array $attachme
return $post;
}

/**
* Override the Gutenberg core/image block render method output,
* to add credit field in it's caption text & image alt text as title.
*
* @param array $attributes Attributes of the Gutenberg core/image block.
* @param string $content The image element HTML.
*
* @return string HTML content of image element with credit field in caption and alt text in image title.
*/
public function p4_core_image_block_render(array $attributes, string $content): string
{
$image_id = isset($attributes['id']) ? trim(str_replace('attachment_', '', $attributes['id'])) : '';
$img_post_meta = $image_id ? get_post_meta($image_id) : [];
if (!$img_post_meta) {
return $content;
}

$credit = $img_post_meta[self::CREDIT_META_FIELD][0] ?? '';
$alt_text = $img_post_meta['_wp_attachment_image_alt'][0] ?? '';

if ($alt_text) {
$content = str_replace(' alt=', ' title="' . esc_attr($alt_text) . '" alt=', $content);
}

$image_credit = ' ' . $credit;
if (false === strpos($credit, '©')) {
$image_credit = ' ©' . $image_credit;
}

$caption = wp_get_attachment_caption($image_id) ?? '';

if (empty($credit) || (!empty($caption) && strpos($caption, $image_credit) !== false)) {
return $content;
}

return str_replace(
empty($caption) ? '</figure>' : $caption,
empty($caption) ?
'<figcaption>' . esc_attr($image_credit) . '</figcaption></figure>' :
$caption . esc_attr($image_credit),
$content
);
}

/**
* Add callback function to Gutenberg core/image block.
*/
public function p4_register_core_image_block(): void
{
unregister_block_type('core/image');
register_block_type(
'core/image',
['render_callback' => [$this, 'p4_core_image_block_render']]
);
}

/**
* Add callback function to Gutenberg core/image block.
*
* @param array $args Parameters given during block register.
*
* @return array Parameters of the block.
*/
public function register_core_blocks_callback(array $args): array
{
if ('core/image' === $args['name']) {
$args['render_callback'] = [$this, 'p4_core_image_block_render'];
}

return $args;
}

/**
* Show P4 team message on dashboard.
*/
Expand Down
6 changes: 5 additions & 1 deletion theme.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 2,
"version": 3,
"styles": {
"color": {
"background": "var(--body--background-color)",
Expand Down Expand Up @@ -48,6 +48,10 @@
}
},
"settings": {
"lightbox": {
"allowEditing": true,
"enabled": true
},
"color": {
"custom": false,
"duotone": [],
Expand Down