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

Various tweaks #118

Merged
merged 20 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 0 additions & 2 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
/.cache
/node_modules
/tests
/grunt

.phpcs.xml.dist
.distignore
.gitignore
.removeable-files
Gruntfile.js
package.json
phpmd.xml
phpunit.xml.dist
Expand Down
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
.gitignore export-ignore
.phpcs.xml.dist export-ignore
.removable-files export-ignore
Gruntfile.js export-ignore
package.json export-ignore
phpmd.xml export-ignore
phpunit.xml.dist export-ignore
readme.md export-ignore
yarn.lock export-ignore
/.cache export-ignore
/.github export-ignore
/grunt export-ignore
/.wordpress-org export-ignore
/tests export-ignore

Expand Down
56 changes: 0 additions & 56 deletions .github/workflows/js.yml

This file was deleted.

18 changes: 15 additions & 3 deletions .phpcs.xml.dist
aristath marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

<file>.</file>

<!-- Check for cross-version support for PHP 7.4 and higher. -->
<config name="testVersion" value="7.4-"/>
<rule ref="PHPCompatibilityWP">
<include-pattern>*\.php$</include-pattern>
</rule>

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>

Expand All @@ -36,8 +42,8 @@
-->

<rule ref="Yoast">
<exclude name="Yoast.Commenting.FileComment"/>
<exclude name="Squiz.Commenting.VariableComment.MissingVar"/>
<exclude name="Yoast.Commenting.FileComment"/>
<exclude name="Squiz.Commenting.VariableComment.MissingVar"/>
<properties>
<!-- Set the custom test class whitelist for all sniffs which use it in one go.
Ref: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#custom-unit-test-classes
Expand Down Expand Up @@ -97,6 +103,12 @@
<exclude-pattern>/tests/bootstrap\.php</exclude-pattern>
</rule>

<!-- These only apply to PHP versions lower than 7.4, so we can exclude them. -->
<rule ref="PHPCompatibility">
<exclude name="PHPCompatibility.Classes.NewTypedProperties.Found"/>
<exclude name="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations"/>
aristath marked this conversation as resolved.
Show resolved Hide resolved
<exclude name="PHPCompatibility.FunctionDeclarations.NewParamTypeDeclarations"/>
</rule>

<!--
#############################################################################
Expand All @@ -109,7 +121,7 @@
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array" extend="true">
<element value="yst_comment"/>
<element value="epch_comment"/>
<element value="EMILIA_COMMENT_HACKS"/>
</property>
</properties>
Expand Down
87 changes: 0 additions & 87 deletions Gruntfile.js

This file was deleted.

96 changes: 57 additions & 39 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,21 @@ public function forward_comment(): void {
$comment_id = (int) $_GET['comment_id'];
$comment = \get_comment( $comment_id );

/* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the blogpost. */
echo '<div class="msg updated"><p>' . \sprintf( \esc_html__( 'Forwarding comment from %1$s to %2$s.', 'comment-hacks' ), '<strong>' . \esc_html( $comment->comment_author ) . '</strong>', \esc_html( $this->options['forward_name'] ) ) . '</div></div>';
echo '<div class="msg updated"><p>';
\printf(
/* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the blogpost. */
\esc_html__( 'Forwarding comment from %1$s to %2$s.', 'comment-hacks' ),
'<strong>' . \esc_html( $comment->comment_author ) . '</strong>',
\esc_html( $this->options['forward_name'] )
);
echo '</div></div>';

$intro = \sprintf( 'This comment was forwarded from %s where it was left on: %s.', '<a href=" ' . \get_site_url() . ' ">' . \esc_html( \get_bloginfo( 'name' ) ) . '</a>', '<a href="' . \get_permalink( $comment->comment_post_ID ) . '">' . \get_the_title( $comment->comment_post_ID ) . '</a>' ) . "\n\n";
$intro = \sprintf(
/* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the post. */
\esc_html__( 'This comment was forwarded from %1$s where it was left on: %2$s.', 'comment-hacks' ),
'<a href=" ' . \get_site_url() . ' ">' . \esc_html( \get_bloginfo( 'name' ) ) . '</a>',
aristath marked this conversation as resolved.
Show resolved Hide resolved
'<a href="' . \get_permalink( $comment->comment_post_ID ) . '">' . \get_the_title( $comment->comment_post_ID ) . '</a>'
aristath marked this conversation as resolved.
Show resolved Hide resolved
) . "\n\n";

if ( ! empty( $this->options['forward_extra'] ) ) {
$intro .= $this->options['forward_extra'] . "\n\n";
Expand Down Expand Up @@ -176,8 +187,17 @@ public function register_meta_boxes(): void {
* @param WP_Post $post Current post object.
*/
public function meta_box_callback( $post ): void {
echo '<input type="hidden" name="comment_notification_recipient_nonce" value="' . \esc_attr( \wp_create_nonce( 'comment_notification_recipient_nonce' ) ) . '" />';
echo '<label for="comment_notification_recipient">' . \esc_html__( 'Comment notification recipients:', 'comment-hacks' ) . '</label><br/>';
?>
<input
type="hidden"
name="comment_notification_recipient_nonce"
value="<?php echo \esc_attr( \wp_create_nonce( 'comment_notification_recipient_nonce' ) ); ?>"
/>
<label for="comment_notification_recipient">
<?php \esc_html_e( 'Comment notification recipients:', 'comment-hacks' ); ?>
</label>
<br/>
<?php

/**
* This filter allows filtering which roles should be shown in the dropdown for notifications.
Expand All @@ -187,7 +207,10 @@ public function meta_box_callback( $post ): void {
*
* @since 1.6.0
*/
$roles = \apply_filters( 'EmiliaProjects\WP\Comment\notification_roles', $roles );
$roles = \apply_filters(
'EmiliaProjects\WP\Comment\notification_roles',
[ 'contributor', 'author', 'editor', 'administrator', 'super-admin' ]
);
Comment on lines -190 to +215
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$roles was undefined here. The doc for this filter was saying "Defaults to contributor and up", so the array used here contains these roles.


\wp_dropdown_users(
[
Expand Down Expand Up @@ -223,21 +246,16 @@ public function enqueue(): void {
$page = \filter_input( \INPUT_GET, 'page' );

if ( $page === 'comment-hacks' ) {
$min = '.min';
if ( \defined( 'SCRIPT_DEBUG' ) && \SCRIPT_DEBUG ) {
$min = '';
}

\wp_enqueue_style(
'emiliaprojects-comment-hacks-admin-css',
\plugins_url( 'admin/assets/css/dist/comment-hacks.css', \EMILIA_COMMENT_HACKS_FILE ),
\plugins_url( 'admin/assets/css/comment-hacks.css', \EMILIA_COMMENT_HACKS_FILE ),
[],
\EMILIA_COMMENT_HACKS_VERSION
);

\wp_enqueue_script(
'emiliaprojects-comment-hacks-admin-js',
\plugins_url( 'admin/assets/js/comment-hacks' . $min . '.js', \EMILIA_COMMENT_HACKS_FILE ),
\plugins_url( 'admin/assets/js/comment-hacks.js', \EMILIA_COMMENT_HACKS_FILE ),
[],
\EMILIA_COMMENT_HACKS_VERSION,
true
Expand Down Expand Up @@ -302,8 +320,15 @@ public function options_validate( array $input ): array {
}

if ( ( $this->absolute_min + 1 ) > $input['mincomlength'] || empty( $input['mincomlength'] ) ) {
/* translators: %d is replaced with the minimum number of characters */
\add_settings_error( $this->hook, 'min_length_invalid', \sprintf( \__( 'The minimum length you entered is invalid, please enter a minimum length above %d.', 'comment-hacks' ), $this->absolute_min ) );
\add_settings_error(
$this->hook,
'min_length_invalid',
\sprintf(
/* translators: %d is replaced with the minimum number of characters */
\__( 'The minimum length you entered is invalid, please enter a minimum length above %d.', 'comment-hacks' ),
$this->absolute_min
)
);
$input['mincomlength'] = 15;
}

Expand All @@ -316,14 +341,7 @@ public function options_validate( array $input ): array {
* @param mixed $value The input value to cast to boolean.
*/
private function sanitize_bool( $value ): bool {
if ( $value ) {
$value = true;
}
if ( empty( $value ) ) {
$value = false;
}

return $value;
return ( $value || ! empty( $value ) );
}

/**
Expand All @@ -335,11 +353,7 @@ private function sanitize_bool( $value ): bool {
* @return array $input The array with sanitized input values.
*/
private function sanitize_string( $value, $default ) {
if ( $value === '' ) {
$value = $default;
}

return $value;
return ( $value === '' ) ? $default : $value;
}

/**
Expand Down Expand Up @@ -388,17 +402,21 @@ public function config_page(): void {

// Show the content of the options array when debug is enabled.
if ( \defined( 'WP_DEBUG' ) && \WP_DEBUG ) {
echo '<h4>', \esc_html__( 'Options debug', 'comment-hacks' ), '</h4>';
echo '<div style="border: 1px solid #aaa; padding: 20px;">';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Debug output.
echo \str_replace(
'<code>',
'<code style="background-color: #eee; margin: 0; padding: 0;">',
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode.
\highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true ),
$num
);
echo '</div>';
?>
<h4><?php \esc_html_e( 'Options debug', 'comment-hacks' ); ?></h4>
<div style="border: 1px solid #aaa; padding: 20px;">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Debug output.
echo \str_replace(
'<code>',
'<code style="background-color: #eee; margin: 0; padding: 0;">',
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode.
\highlight_string( "<?php\n\$this->options = " . \var_export( $this->options, true ) . ';', true ),
$num
);
?>
</div>
<?php
}
}
}
16 changes: 16 additions & 0 deletions admin/assets/css/comment-hacks.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.emiliaprojectstab {
display: none;
margin-top :15px
}

.emiliaprojectstab.active {
display: block
}

.emiliaprojectstab strong {
font-size: 115%
}

.emiliaprojectstab .dashicons-email-alt {
color:#00f
}
Loading