Skip to content

Commit 750d31c

Browse files
committed
fix coding standards
1 parent 7806171 commit 750d31c

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

classes/monthly.php

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
class FacetWP_Facet_Monthly {
34

45
function __construct() {
@@ -18,17 +19,17 @@ function load_values( $params ) {
1819

1920
// Orderby
2021
$orderby = 'f.facet_display_value DESC';
21-
if( 'asc' === $facet['orderby'] ) {
22+
if ( 'asc' === $facet['orderby'] ) {
2223
$orderby = 'f.facet_display_value ASC';
2324
}
2425

2526
// Limit
2627
$limit = 10;
27-
if( absint( $facet['count'] ) > 0 ) {
28+
if ( absint( $facet['count'] ) > 0 ) {
2829
$limit = absint( $facet['count'] );
2930
}
3031

31-
$orderby = apply_filters( 'facetwp_facet_orderby', $orderby, $facet );
32+
$orderby = apply_filters( 'facetwp_facet_orderby', $orderby, $facet );
3233
$where_clause = apply_filters( 'facetwp_facet_where', $where_clause, $facet );
3334

3435
$sql = "
@@ -47,15 +48,16 @@ function load_values( $params ) {
4748
*/
4849
function render( $params ) {
4950

50-
$output = '';
51-
$facet = $params['facet'];
52-
$values = (array) $params['values'];
51+
$output = '';
52+
$facet = $params['facet'];
53+
$values = (array) $params['values'];
5354
$selected_values = (array) $params['selected_values'];
5455

55-
$label_any = empty( $facet['label_any'] ) ? __( 'Any', 'fwp' ) : sprintf( __( '%s', 'fwp' ), $facet['label_any'] );
56+
$label_any = empty( $facet['label_any'] ) ? __( 'Any', 'fwp' ) : sprintf( __( '%s', 'fwp' ),
57+
$facet['label_any'] );
5658

5759
$output .= '<select class="facetwp-monthly">';
58-
$output .= '<option value="">' . esc_attr( $label_any ) . '</option>';
60+
$output .= sprintf( '<option value="">%s</option>', esc_html( $label_any ) );
5961

6062
foreach ( $values as $result ) {
6163
$selected = in_array( $result['facet_value'], $selected_values ) ? ' selected' : '';
@@ -67,10 +69,14 @@ function render( $params ) {
6769
$display_value .= sprintf( ' (%s)', $result['counter'] );
6870
}
6971

70-
$output .= sprintf( '<option value="%s" %s>%s</option>', $result['facet_value'], $selected, $display_value );
72+
$output .= sprintf( '<option value="%s" %s>%s</option>',
73+
esc_attr( $result['facet_value'] ),
74+
$selected,
75+
esc_html( $display_value ) );
7176
}
7277

7378
$output .= '</select>';
79+
7480
return $output;
7581
}
7682

@@ -80,15 +86,15 @@ function render( $params ) {
8086
function filter_posts( $params ) {
8187
global $wpdb;
8288

83-
$output = array();
84-
$facet = $params['facet'];
89+
$output = array();
90+
$facet = $params['facet'];
8591
$selected_values = $params['selected_values'];
8692

8793
// Convert the selected value into an array
8894
// "0000-00" => array( year, month );
8995
$dates = explode( '-', reset( $selected_values ) );
9096

91-
if( count( $dates ) < 2 ) {
97+
if ( count( $dates ) < 2 ) {
9298
$dates = array( date( 'Y' ), date( 'm' ) );
9399
}
94100

@@ -123,7 +129,7 @@ function settings_html() { ?>
123129
</div>
124130
</td>
125131
<td>
126-
<input type="text" class="facet-label-any" value="<?php _e( 'Any', 'fwp' ); ?>" />
132+
<input type="text" class="facet-label-any" value="<?php _e( 'Any', 'fwp' ); ?>"/>
127133
</td>
128134
</tr>
129135
<tr class="facetwp-conditional type-monthly">
@@ -145,13 +151,14 @@ function settings_html() { ?>
145151
</tr>
146152
<tr class="facetwp-conditional type-monthly">
147153
<td>
148-
<?php _e('Count', 'fwp'); ?>:
154+
<?php _e( 'Count', 'fwp' ); ?>:
149155
<div class="facetwp-tooltip">
150156
<span class="icon-question">?</span>
151-
<div class="facetwp-tooltip-content"><?php _e( 'The maximum number of facet choices to show', 'fwp' ); ?></div>
157+
<div class="facetwp-tooltip-content"><?php _e( 'The maximum number of facet choices to show',
158+
'fwp' ); ?></div>
152159
</div>
153160
</td>
154-
<td><input type="text" class="facet-count" value="10" /></td>
161+
<td><input type="text" class="facet-count" value="10"/></td>
155162
</tr>
156163
<?php }
157164

@@ -160,19 +167,19 @@ function settings_html() { ?>
160167
*/
161168
function admin_scripts() { ?>
162169
<script>
163-
(function($) {
164-
wp.hooks.addAction('facetwp/load/monthly', function($this, obj) {
170+
(function ($) {
171+
wp.hooks.addAction('facetwp/load/monthly', function ($this, obj) {
165172
$this.find('.facet-source').val(obj['source']);
166173
$this.find('.type-monthly .facet-label-any').val(obj['label_any']);
167174
$this.find('.type-monthly .facet-orderby').val(obj['orderby']);
168175
$this.find('.type-monthly .facet-count').val(obj['count']);
169176
});
170177

171-
wp.hooks.addFilter('facetwp/save/monthly', function($this, obj) {
172-
obj['source'] = $this.find('.facet-source').val();
178+
wp.hooks.addFilter('facetwp/save/monthly', function ($this, obj) {
179+
obj['source'] = $this.find('.facet-source').val();
173180
obj['label_any'] = $this.find('.type-monthly .facet-label-any').val();
174-
obj['orderby'] = $this.find('.type-monthly .facet-orderby').val();
175-
obj['count'] = $this.find('.type-monthly .facet-count').val();
181+
obj['orderby'] = $this.find('.type-monthly .facet-orderby').val();
182+
obj['count'] = $this.find('.type-monthly .facet-count').val();
176183
return obj;
177184
});
178185
})(jQuery);
@@ -184,14 +191,14 @@ function admin_scripts() { ?>
184191
*/
185192
function front_scripts() { ?>
186193
<script>
187-
(function($) {
188-
wp.hooks.addAction('facetwp/refresh/monthly', function($this, facet_name) {
194+
(function ($) {
195+
wp.hooks.addAction('facetwp/refresh/monthly', function ($this, facet_name) {
189196
var val = $this.find('.facetwp-monthly').val();
190197
FWP.facets[facet_name] = val ? [val] : [];
191198
});
192199

193-
wp.hooks.addAction('facetwp/ready', function() {
194-
$(document).on('change', '.facetwp-facet .facetwp-monthly', function() {
200+
wp.hooks.addAction('facetwp/ready', function () {
201+
$(document).on('change', '.facetwp-facet .facetwp-monthly', function () {
195202
var $facet = $(this).closest('.facetwp-facet');
196203
if ('' != $facet.find(':selected').val()) {
197204
FWP.static_facet = $facet.attr('data-name');

facetwp-monthly.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
// don't load directly
12-
if ( !defined( 'ABSPATH' ) ) {
12+
if ( ! defined( 'ABSPATH' ) ) {
1313
die( '-1' );
1414
}
1515

@@ -20,7 +20,7 @@
2020
class FWP_MTLY {
2121

2222
function __construct() {
23-
add_action( 'init' , array( $this, 'init' ) );
23+
add_action( 'init', array( $this, 'init' ) );
2424
}
2525

2626

@@ -41,6 +41,7 @@ function init() {
4141
function register_facet_type( $facet_types ) {
4242
include( dirname( __FILE__ ) . '/classes/monthly.php' );
4343
$facet_types['monthly'] = new FacetWP_Facet_Monthly();
44+
4445
return $facet_types;
4546
}
4647
}

0 commit comments

Comments
 (0)