Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Mar 26, 2024
1 parent 92cf4d1 commit 439bce0
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 96 deletions.
43 changes: 4 additions & 39 deletions .github/workflows/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,14 @@ on:
- master

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.2', '7.4' ] # PHP versions to check.
wp: [ 'latest', '5.9' ] # WordPress version to check.
services:
mysql:
image: mysql:5.7
options: --health-cmd "mysqladmin ping --host 127.0.0.1 --port 3306" --health-interval 20s --health-timeout 10s --health-retries 10
ports:
- 3306/tcp
env:
MYSQL_ROOT_PASSWORD: root
name: WordPress ${{ matrix.wp }} in PHP ${{ matrix.php }} UnitTest
steps:
- uses: actions/checkout@main

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist

- name: Start MySQL
run: sudo systemctl start mysql

- name: Check PHP syntax
run: composer lint

phpcs:
uses: tarosky/workflows/.github/workflows/phpcs.yml@main
with:
version: 8.0

phplint:
uses: tarosky/workflows/.github/workflows/phplint.yml@main

assets:
name: Assets Test
runs-on: ubuntu-latest
Expand All @@ -73,7 +38,7 @@ jobs:

release:
name: Deploy WordPress.org
needs: [ test, assets ]
needs: [ phpcs, phplint, assets ]
if: contains(github.ref, 'tags/')
runs-on: ubuntu-latest
steps:
Expand Down
37 changes: 25 additions & 12 deletions app/Admin/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function admin_menu() {
$page .= '?post_type=' . $post_type;
}
$object = get_post_type_object( $post_type );
// translators: %s is post type name.
add_submenu_page( $page, sprintf( __( 'Feedback Statistic of %s', 'anyway-feedback' ), $object->labels->name ), __( 'Feedback Statistic', 'anyway-feedback' ), 'edit_posts', 'anyway-feedback-static-' . $post_type, array( $this, 'render_static' ) );
}
}
Expand Down Expand Up @@ -149,20 +150,32 @@ public function admin_init() {
}, 'anyway-feedback' );
$settings = [
'post_types' => [ __( 'Post Types', 'anyway-feedback' ), 'default', [] ],
'comment' => [ __( 'Comment', 'anyway-feedback' ), 'default', [
'' => __( 'Not supported', 'anyway-feedback' ),
1 => __( 'Allow feedback for comments', 'anyway-feedback' ),
] ],
'style' => [ __( 'Controller Appearance', 'anyway-feedback' ), 'appearance', [
'' => __( 'No style', 'anyway-feedback' ),
1 => __( 'Plugin Default', 'anyway-feedback' ),
] ],
'comment' => [
__( 'Comment', 'anyway-feedback' ),
'default',
[
'' => __( 'Not supported', 'anyway-feedback' ),
1 => __( 'Allow feedback for comments', 'anyway-feedback' ),
],
],
'style' => [
__( 'Controller Appearance', 'anyway-feedback' ),
'appearance',
[
'' => __( 'No style', 'anyway-feedback' ),
1 => __( 'Plugin Default', 'anyway-feedback' ),
],
],
'hide_default_controller' => [ __( 'Hide default feedback controller', 'anyway-feedback' ), 'appearance', [] ],
'controller' => [ __( 'Custom markup', 'anyway-feedback' ), 'appearance', [] ],
'ga' => [ __( 'Google Analytics Integration', 'anyway-feedback' ), 'option', [
'' => __( 'Not Active', 'anyway-feedback' ),
1 => __( 'Track Event', 'anyway-feedback' ),
] ],
'ga' => [
__( 'Google Analytics Integration', 'anyway-feedback' ),
'option',
[
'' => __( 'Not Active', 'anyway-feedback' ),
1 => __( 'Track Event', 'anyway-feedback' ),
],
],
];
foreach ( $settings as $key => list( $label, $section, $options ) ) {
add_settings_field( 'afb_' . $key, $label, function() use ( $key, $options ) {
Expand Down
5 changes: 3 additions & 2 deletions app/Api/ApiFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function register_rest_api() {
'callback' => [ $this, 'post_feedback' ],
'permission_callback' => [ $this, 'permission_callback' ],
'args' => [
'post_type' => [
'post_type' => [
'required' => true,
'type' => 'string',
'validate_callback' => function ( $post_type ) {
return ( 'comment' === $post_type ) || post_type_exists( $post_type );
},
],
'object_id' => [
'object_id' => [
'required' => true,
'type' => 'integer',
'validate_callback' => function ( $object_id ) {
Expand Down Expand Up @@ -101,6 +101,7 @@ public function post_feedback( \WP_REST_Request $request ) {
'success' => true,
'message' => __( 'Thank you for your feedback.', 'anyway-feedback' ),
'status' => sprintf(
// translators: %1$d is number of positive feedbacks, %2$d is total number, %3$s is post type name.
__( '%1$d of %2$d people say this %3$s is useful.', 'anyway-feedback' ),
afb_affirmative( false, $object_id, $post_type ),
afb_total( false, $object_id, $post_type ),
Expand Down
16 changes: 9 additions & 7 deletions app/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ public function default_controller_html( $message, $link, $useful, $useless, $st
*/
public function get_controller_tag( $object_id, $post_type ) {
$post_type_name = ( 'comment' === $post_type ) ? __( 'Comment', 'anyway-feedback' ) : get_post_type_object( $post_type )->labels->singular_name;
$message = sprintf( __( 'Is this %s useful?', 'anyway-feedback' ), $post_type_name );
$status = sprintf( __( '%1$d of %2$d people say this %3$s is useful.', 'anyway-feedback' ), afb_affirmative( false, $object_id, $post_type ), afb_total( false, $object_id, $post_type ), $post_type_name );
$useful = __( 'Useful', 'anyway-feedback' );
$useless = __( 'Useless', 'anyway-feedback' );
$url = "#afb-{$post_type}-{$object_id}";
$id =esc_attr( "afb-container-{$post_type}-{$object_id}" );
$before = <<<HTML
// translators: %s is post type name.
$message = sprintf( __( 'Is this %s useful?', 'anyway-feedback' ), $post_type_name );
// translators: %1$d is number of positive feedback, %2$d is number of total feedback.
$status = sprintf( __( '%1$d of %2$d people say this %3$s is useful.', 'anyway-feedback' ), afb_affirmative( false, $object_id, $post_type ), afb_total( false, $object_id, $post_type ), $post_type_name );
$useful = __( 'Useful', 'anyway-feedback' );
$useless = __( 'Useless', 'anyway-feedback' );
$url = "#afb-{$post_type}-{$object_id}";
$id = esc_attr( "afb-container-{$post_type}-{$object_id}" );
$before = <<<HTML
<!-- Anyway Feedback Container //-->
<div class="afb_container" id="{$id}">
HTML;
Expand Down
2 changes: 1 addition & 1 deletion app/Pattern/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function is_allowed( $post_type ) {
* @return void
*/
protected function refresh_option() {
$option = get_option( 'afb_setting', [] );
$option = get_option( 'afb_setting', [] );
if ( ! empty( $option ) ) {
foreach ( [
'style' => 'bool',
Expand Down
15 changes: 12 additions & 3 deletions app/Widget/Popular.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public function widget( $args, $instance ) {
?>
<li>
<a href="<?php echo get_permalink( $post ); ?>"><?php echo get_the_title( $post ); ?></a>
<span class="count">(<?php printf( __( '%d says useful', 'anyway-feedback' ), $post->positive ); ?>)</span>
<span class="count">(
<?php
// translators: %d is number of positive feedback.
printf( __( '%d says useful', 'anyway-feedback' ), $post->positive );
?>
)</span>
</li>
<?php
endforeach;
Expand Down Expand Up @@ -96,8 +101,12 @@ public function form( $instance ) {
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
<?php _e( 'Title:' ); ?>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( isset( $instance['title'] ) ? $instance['title'] : sprintf( __( 'Popular %s', 'anyway-feedback' ), get_post_type_object( $current_post_type )->labels->name ) ); ?>" />
<?php
esc_html_e( 'Title:', 'anyway-feedback' );
// translators: %s is post type name.
$title = isset( $instance['title'] ) ? $instance['title'] : sprintf( __( 'Popular %s', 'anyway-feedback' ), get_post_type_object( $current_post_type )->labels->name );
?>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</label>
<label for="<?php echo $this->get_field_id( 'post_type' ); ?>">
<?php _e( 'Post Type:', 'anyway-feedback' ); ?> <br />
Expand Down
14 changes: 8 additions & 6 deletions templates/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@
<?php echo get_avatar( '[email protected]', 60 ); ?>
<?php
printf(
// translators: %s is link to WordPress.org profile.
esc_html__( 'Takahashi Fumiki did. I am a WordPress developer and novelist. See detail at %s', 'anyway-feedback' ),
'<a href="https://profiles.wordpress.org/takahashi_fumiki/" target="_blank">WordPrss.org</a>'
'<a href="https://profiles.wordpress.org/takahashi_fumiki/" target="_blank" rel="noopener noreferrer">WordPrss.org</a>'
);
?>
</p>
</div><!-- //.div_4 -->

<div class="div_4">
<h3><i class="dashicons dashicons-email-alt"></i> <?php _e( 'Contact', 'anyway-feedback' ); ?></h3>
<h3><i class="dashicons dashicons-email-alt"></i> <?php esc_html_e( 'Contact', 'anyway-feedback' ); ?></h3>
<p>
<?php _e( 'If you have some request, please feel free to contact via:', 'anyway-feedback' ); ?>
<?php esc_html_e( 'If you have some request, please feel free to contact via:', 'anyway-feedback' ); ?>
</p>
<p class="contact">
<?php
foreach ( array(
'wordpress' => 'https://wordpress.org/support/plugin/anyway-feedback',
'twitter' => 'https://twitter.com/takahashifumiki',
'facebook' => 'https://www.facebook.com/TakahashiFumiki.Page',
'wordpress' => 'https://wordpress.org/support/plugin/anyway-feedback',
'twitter' => 'https://twitter.com/takahashifumiki',
'facebook' => 'https://www.facebook.com/TakahashiFumiki.Page',
) as $icon => $url ) :
?>
<a href="<?php echo esc_html( $url ); ?>" target="_blank"><i class="dashicons dashicons-<?php echo $icon; ?>"></i></a>
Expand All @@ -44,6 +45,7 @@
<p>
<?php
printf(
// translators: %s is link to GitHub.
esc_html__( 'Japanese, English and French are welcomed. Of course, you can send pull request via %s.', 'anyway-feedback' ),
'<a href="https://github.com/hametuha/anyway-feedback" target="_blank" rel="noopener noreferrer">GitHub</a>'
);
Expand Down
51 changes: 35 additions & 16 deletions templates/page/advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@
?>
<div id="tabs-4">

<h3><?php _e( 'Template Tags', 'anyway-feedback' ); ?></h3>
<h3><?php esc_html_e( 'Template Tags', 'anyway-feedback' ); ?></h3>

<p>
<?php _e( 'If you are experienced developper, you may need customazation. Ofcourse, you can edit your theme and get your own appearance.', 'anyway-feedback' ); ?>
<?php esc_html_e( 'If you are experienced developer, you may need customisation. Of course, you can edit your theme and get your own appearance.', 'anyway-feedback' ); ?>
</p>
<dl class="code-format">
<dt><span class="blue">afb_display</span>()</dt>
<dd>
<p>
<?php _e( 'Display controller of post feedback. Use inside loop.', 'anyway-feedback' ); ?>
<?php esc_html_e( 'Display controller of post feedback. Use inside loop.', 'anyway-feedback' ); ?>
</p>
</dd>
<dt><span class="blue">afb_comment_display</span>( (int) <span class="yellow">$comment_id</span> )</dt>
<dd>
<p>
<?php _e( 'Display controller of comment feedback. You must pass comment_ID as 1st argument.', 'anyway-feedback' ); ?>
<?php esc_html_e( 'Display controller of comment feedback. You must pass comment_ID as 1st argument.', 'anyway-feedback' ); ?>
</p>
</dd>
<dt><span class="blue">afb_affirmative</span>( (boolean) <span class="yellow">$echo</span> = <span class="red">true</span>, (int) <span class="yellow">$object_id</span> = <sapn class="red">null</sapn>, (string) <span class="yellow">$post_type</span> = <sapn class="red">null</sapn>)</dt>
<dd>
<p>
<?php _e( "Display number of affirmative feedbacks of specified post. In loop, you don't have to specify \$object_id and \$post_type. \$echo set true, value won't displayed and just return.", 'anyway-feedback' ); ?>
<?php esc_html_e( "Display number of affirmative feedbacks of specified post. In loop, you don't have to specify \$object_id and \$post_type. \$echo set true, value won't displayed and just return.", 'anyway-feedback' ); ?>
</p>
</dd>
<dt><span class="blue">afb_negative</span>( (boolean) <span class="yellow">$echo</span> = <span class="red">true</span>, (int) <span class="yellow">$object_id</span> = <sapn class="red">null</sapn>, (string) <span class="yellow">$post_type</span> = <sapn class="red">null</sapn>)</dt>
<dd>
<p>
<?php _e( 'Display number of negative feedbacks of specified post. Same as afb_affirmative.', 'anyway-feedback' ); ?>
<?php esc_html_e( 'Display number of negative feedbacks of specified post. Same as afb_affirmative.', 'anyway-feedback' ); ?>
</p>
</dd>
<dt><span class="blue">afb_total</span>( (boolean) <span class="yellow">$echo</span> = <span class="red">true</span>, (int) <span class="yellow">$object_id</span> = <sapn class="red">null</sapn>, (string) <span class="yellow">$post_type</span> = <sapn class="red">null</sapn>)</dt>
<dd>
<p>
<?php _e( 'Display number of total feedbacks of specified post. Same as afb_affirmative.', 'anyway-feedback' ); ?>
<?php esc_html_e( 'Display number of total feedbacks of specified post. Same as afb_affirmative.', 'anyway-feedback' ); ?>
</p>
</dd>
</dl>
<p class="description">
<?php _e( "All these template tags above should be wrapped inside if declaration for compatibility. If not, stopping this plugin will break your theme's display.", 'anyway-feedback' ); ?>
<?php esc_html_e( "All these template tags above should be wrapped inside if declaration for compatibility. If not, stopping this plugin will break your theme's display.", 'anyway-feedback' ); ?>
</p>
<pre class="afb-code-exam">
<?php
Expand All @@ -53,20 +53,34 @@
?>
</pre>
<p class="description">
<?php printf( __( 'See function detail at <code>%s</code>', 'anyway-feedback' ), dirname( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'functions.php' ); ?>
<?php
printf(
// translators: %s is path to functions.php.
__( 'See function detail at <code>%s</code>', 'anyway-feedback' ),
dirname( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'functions.php'
);
?>
</p>

<hr />

<h3><?php _e( 'Google Analytics', 'anyway-feedback' ); ?></h3>
<h3><?php esc_html_e( 'Google Analytics', 'anyway-feedback' ); ?></h3>

<p><?php echo wp_kses_post( sprintf( __( 'You can save all data as <a href="%s" target="_blank">event tracking</a> and analize report chronologically. Data format is like below:', 'anyway-feedback' ), 'https://developers.google.com/analytics/devguides/collection/analyticsjs/events' ) ); ?></p>
<p>
<?php
echo wp_kses_post( sprintf(
// translators: %s is url to advanced usage.
__( 'You can save all data as <a href="%s" target="_blank">event tracking</a> and analize report chronologically. Data format is like below:', 'anyway-feedback' ),
'https://developers.google.com/analytics/devguides/collection/analyticsjs/events'
) );
?>
</p>

<table class="afb-speck">
<thead>
<tr>
<th scope="col"><?php _e( 'Name', 'anyway-feedback' ); ?></th>
<th scope="col"><?php _e( 'Value', 'anyway-feedback' ); ?></th>
<th scope="col"><?php esc_html_e( 'Name', 'anyway-feedback' ); ?></th>
<th scope="col"><?php esc_html_e( 'Value', 'anyway-feedback' ); ?></th>
</tr>
</thead>
<tbody>
Expand All @@ -80,17 +94,22 @@
</tr>
<tr>
<th>Label</th>
<td><?php _e( '<code>Post ID</code> or <code>comment ID</code>', 'anyway-feedback' ); ?></td>
<td><?php wp_kses_post( __( '<code>Post ID</code> or <code>comment ID</code>', 'anyway-feedback' ) ); ?></td>
</tr>
<tr>
<th>Value</th>
<td><?php _e( 'Always 1', 'anyway-feedback' ); ?></td>
<td><?php esc_html_e( 'Always 1', 'anyway-feedback' ); ?></td>
</tr>
</tbody>
</table>

<p class="description">
<?php printf( __( 'This feature is premised on <a href="%s">Google Analytics 4</a>. If you use other services or Google Tag Manager, grab the event and record it by yourself.', 'anyway-feedback' ), 'https://developers.google.com/analytics/devguides/collection/ga4/events?client_type=gtag&sjid=8607412637313615612-AP' ); ?>
<?php
printf(
// translators: %s is url to Google Analytics 4.
__( 'This feature is premised on <a href="%s">Google Analytics 4</a>. If you use other services or Google Tag Manager, grab the event and record it by yourself.', 'anyway-feedback' ),
'https://developers.google.com/analytics/devguides/collection/ga4/events?client_type=gtag&sjid=8607412637313615612-AP' );
?>
</p>

<pre class="afb-code-exam">
Expand Down
Loading

0 comments on commit 439bce0

Please sign in to comment.