Skip to content

Commit 9aec53a

Browse files
committed
Sanitize args
1 parent fdb887f commit 9aec53a

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

includes/frontend/class-breadcrumbs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace WebberZone\Knowledge_Base\Frontend;
99

10+
use WebberZone\Knowledge_Base\Util\Helpers;
11+
1012
if ( ! defined( 'WPINC' ) ) {
1113
die;
1214
}
@@ -88,6 +90,7 @@ public static function get_breadcrumb( $args = array() ) {
8890
);
8991

9092
$args = wp_parse_args( $args, $defaults );
93+
$args = Helpers::sanitize_args( $args );
9194

9295
if ( strpos( $args['separator'], '\\' ) === 0 ) {
9396
$args['separator'] = self::unicode_to_char( $args['separator'] );

includes/frontend/class-display.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace WebberZone\Knowledge_Base\Frontend;
99

1010
use WebberZone\Knowledge_Base\Util\Cache;
11+
use WebberZone\Knowledge_Base\Util\Helpers;
1112

1213
if ( ! defined( 'WPINC' ) ) {
1314
die;
@@ -66,6 +67,7 @@ public static function get_knowledge_base( $args = array() ) {
6667
);
6768

6869
$args = wp_parse_args( $args, $defaults );
70+
$args = Helpers::sanitize_args( $args );
6971

7072
// Set defaults if variables are empty.
7173
$args['limit'] = ( ! empty( absint( $args['limit'] ) ) ) ? absint( $args['limit'] ) : \wzkb_get_option( 'limit' );

includes/frontend/class-related.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace WebberZone\Knowledge_Base\Frontend;
99

10+
use WebberZone\Knowledge_Base\Util\Helpers;
11+
1012
// If this file is called directly, abort.
1113
if ( ! defined( 'WPINC' ) ) {
1214
die;
@@ -59,6 +61,7 @@ public static function get_related_articles( $args = array() ) {
5961

6062
// Parse incomming $args into an array and merge it with $defaults.
6163
$args = wp_parse_args( $args, $defaults );
64+
$args = Helpers::sanitize_args( $args );
6265

6366
// Assign post to a separate variable for easy processing.
6467
$post = $args['post'];

includes/functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use WebberZone\Knowledge_Base\Frontend\Media_Handler;
99
use WebberZone\Knowledge_Base\Frontend\Related;
10+
use WebberZone\Knowledge_Base\Util\Helpers;
1011

1112
// If this file is called directly, abort.
1213
if ( ! defined( 'WPINC' ) ) {
@@ -102,6 +103,7 @@ function wzkb_get_alert( $args = array(), $content = '' ) {
102103

103104
// Parse incomming $args into an array and merge it with $defaults.
104105
$args = wp_parse_args( $args, $defaults );
106+
$args = Helpers::sanitize_args( $args );
105107

106108
$type = 'wzkb-alert-' . $args['type'];
107109

includes/util/class-helpers.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,21 @@ public static function get_credit_link() {
4444

4545
return $output;
4646
}
47+
48+
/**
49+
* Sanitize args.
50+
*
51+
* @since 3.0.0
52+
*
53+
* @param array $args Array of arguments.
54+
* @return array Sanitized array of arguments.
55+
*/
56+
public static function sanitize_args( $args ): array {
57+
foreach ( $args as $key => $value ) {
58+
if ( is_string( $value ) ) {
59+
$args[ $key ] = wp_kses_post( $value );
60+
}
61+
}
62+
return $args;
63+
}
4764
}

0 commit comments

Comments
 (0)