-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
386 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
..._html/wp-content/themes/wporg-pattern-directory-2024/src/blocks/report-pattern/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "wporg/report-pattern", | ||
"version": "0.1.0", | ||
"title": "Report Pattern", | ||
"category": "design", | ||
"icon": "", | ||
"description": "A button to trigger the report flow, including report modal.", | ||
"textdomain": "wporg", | ||
"attributes": {}, | ||
"supports": { | ||
"html": false | ||
}, | ||
"usesContext": [ "postId", "postType" ], | ||
"editorScript": "file:./index.js", | ||
"style": "file:./style-index.css", | ||
"viewScript": "file:./view.js", | ||
"render": "file:./render.php" | ||
} |
16 changes: 16 additions & 0 deletions
16
...ic_html/wp-content/themes/wporg-pattern-directory-2024/src/blocks/report-pattern/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Edit from '../../utils/dynamic-edit'; | ||
import metadata from './block.json'; | ||
import './style.scss'; | ||
|
||
registerBlockType( metadata.name, { | ||
edit: Edit, | ||
save: () => null, | ||
} ); |
15 changes: 15 additions & 0 deletions
15
...c_html/wp-content/themes/wporg-pattern-directory-2024/src/blocks/report-pattern/index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* Block Name: Report Pattern | ||
* Description: A button to trigger the report flow, including report modal. | ||
* | ||
* @package wporg | ||
*/ | ||
|
||
namespace WordPressdotorg\Theme\Pattern_Directory_2024\Report_Pattern_Block; | ||
|
||
add_action( 'init', __NAMESPACE__ . '\init' ); | ||
|
||
function init() { | ||
register_block_type( __DIR__ . '/../../../build/blocks/report-pattern' ); | ||
} |
110 changes: 110 additions & 0 deletions
110
..._html/wp-content/themes/wporg-pattern-directory-2024/src/blocks/report-pattern/render.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
use function WordPressdotorg\Theme\Pattern_Directory_2024\user_has_flagged_pattern; | ||
use const WordPressdotorg\Pattern_Directory\Pattern_Flag_Post_Type\TAX_TYPE as FLAG_REASON; | ||
|
||
// Move to footer so that HTML exists on page already. | ||
if ( ! empty( $block->block_type->view_script ) ) { | ||
wp_enqueue_script( $block->block_type->view_script ); | ||
// Move to footer. | ||
wp_script_add_data( $block->block_type->view_script, 'group', 1 ); | ||
} | ||
|
||
$post_id = $block->context['postId']; | ||
if ( ! $post_id ) { | ||
return; | ||
} | ||
|
||
if ( ! current_user_can( 'read' ) ) { | ||
return; | ||
} | ||
|
||
// If this pattern has been reported by this user, it can't be reported again. | ||
if ( user_has_flagged_pattern() ) { | ||
printf( | ||
'<div %s>%s</div>', | ||
get_block_wrapper_attributes(), | ||
__( 'You’ve reported this pattern.', 'wporg-patterns' ) | ||
); | ||
return; | ||
} | ||
|
||
$reasons = get_terms( [ 'taxonomy' => FLAG_REASON, 'hide_empty' => false, 'orderby' => 'slug' ] ); | ||
|
||
?> | ||
<div <?php echo get_block_wrapper_attributes(); // phpcs:ignore ?>> | ||
<div class="wp-block-button is-small is-style-text"> | ||
<button | ||
class="wp-block-button__link wp-element-button" | ||
disabled="disabled" | ||
data-a11y-dialog-show="report-dialog" | ||
> | ||
<?php echo esc_html_e( 'Report this pattern', 'wporg-patterns' ); ?> | ||
</button> | ||
</div> | ||
<div | ||
id="report-dialog" | ||
data-a11y-dialog="report-dialog" | ||
aria-labelledby="report-pattern-dialog-title" | ||
aria-hidden="true" | ||
class="wporg-report-pattern__dialog-container" | ||
> | ||
<div data-a11y-dialog-hide class="wporg-report-pattern__dialog-overlay"></div> | ||
<div role="document" class="wporg-report-pattern__dialog-content"> | ||
<div class="wporg-report-pattern__dialog-header"> | ||
<h1 id="report-pattern-dialog-title"> | ||
<?php echo esc_html_e( 'Report this pattern', 'wporg-patterns' ); ?> | ||
</h1> | ||
<button type="button" data-a11y-dialog-hide aria-label="<?php echo esc_attr_e( 'Close dialog', 'wporg-patterns' ); ?>"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button> | ||
</div> | ||
<form method="POST" action="<?php echo esc_url( get_the_permalink( $post_id ) ); ?>"> | ||
<div class="wporg-report-pattern__dialog-body"> | ||
<fieldset class="wporg-report-pattern__dialog-field"> | ||
<legend><?php echo esc_html_e( 'Please choose a reason:', 'wporg-patterns' ); ?></legend> | ||
<?php foreach ( $reasons as $reason ) : ?> | ||
<div> | ||
<input | ||
type="radio" | ||
name="report-reason" | ||
id="report-reason-<?php echo esc_attr( $reason->term_id ); ?>" | ||
value="<?php echo esc_attr( $reason->term_id ); ?>" | ||
required | ||
/> | ||
<label | ||
for="report-reason-<?php echo esc_attr( $reason->term_id ); ?>" | ||
> | ||
<?php echo esc_attr( $reason->name ); ?> | ||
</label> | ||
<div> | ||
<?php endforeach; ?> | ||
</fieldset> | ||
<div class="wporg-report-pattern__dialog-field"> | ||
<label | ||
for="report-details" | ||
><?php echo esc_html_e( 'Please provide details (required)', 'wporg-patterns' ); ?></label> | ||
<textarea | ||
id="report-details" | ||
rows="4" | ||
required | ||
name="report-details" | ||
></textarea> | ||
</div> | ||
<input type="hidden" name="action" value="report" /> | ||
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'report-' . $post_id ) ); ?>" /> | ||
</div> | ||
<div class="wp-block-buttons wporg-report-pattern__dialog-footer"> | ||
<div class="wp-block-button is-small is-style-outline"> | ||
<button type="button" data-a11y-dialog-hide class="wp-block-button__link wp-element-button"> | ||
<?php echo esc_html_e( 'Cancel', 'wporg-patterns' ); ?> | ||
</button> | ||
</div> | ||
<div class="wp-block-button is-small"> | ||
<button type="submit" class="wp-block-button__link wp-element-button"> | ||
<?php echo esc_html_e( 'Report', 'wporg-patterns' ); ?> | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.