generator-chisel 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/commands/create/creators/app/chisel-starter-theme/404.php +1 -1
  3. package/lib/commands/create/creators/app/chisel-starter-theme/archive.php +1 -1
  4. package/lib/commands/create/creators/app/chisel-starter-theme/author.php +1 -1
  5. package/lib/commands/create/creators/app/chisel-starter-theme/composer.json +7 -6
  6. package/lib/commands/create/creators/app/chisel-starter-theme/footer.php +1 -1
  7. package/lib/commands/create/creators/app/chisel-starter-theme/functions.php +3 -3
  8. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Controllers/AjaxController.php +20 -15
  9. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Enums/AcfOptionsPageType.php +8 -0
  10. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Enums/BlocksType.php +17 -0
  11. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factories/RegisterAcfOptionsPage.php +78 -0
  12. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Factory → Factories}/RegisterBlocks.php +41 -30
  13. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Factory → Factories}/RegisterCustomPostType.php +44 -32
  14. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Factory → Factories}/RegisterCustomTaxonomy.php +39 -27
  15. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/AcfHelpers.php +12 -12
  16. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helpers/AjaxHelpers.php +36 -0
  17. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/AssetsHelpers.php +3 -3
  18. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/BlocksHelpers.php +22 -18
  19. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helpers/CacheHelpers.php +43 -0
  20. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/CommentsHelpers.php +8 -6
  21. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/DataHelpers.php +5 -5
  22. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/GravityFormsHelpers.php +13 -13
  23. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/ImageHelpers.php +30 -15
  24. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/ThemeHelpers.php +29 -25
  25. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/WoocommerceHelpers.php +15 -9
  26. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Helper → Helpers}/YoastHelpers.php +6 -6
  27. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Interfaces/HooksInterface.php +3 -3
  28. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Interfaces/InstanceInterface.php +1 -1
  29. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Plugin → Plugins}/GravityForms.php +13 -15
  30. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Plugin → Plugins}/Woocommerce.php +14 -14
  31. package/lib/commands/create/creators/app/chisel-starter-theme/inc/{Plugin → Plugins}/Yoast.php +6 -6
  32. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/PageBlocks.php +14 -14
  33. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Traits/Singleton.php +28 -7
  34. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Acf.php +16 -15
  35. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/AcfBlocks.php +19 -19
  36. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/{AjaxEnpoints.php → AjaxEndpoints.php} +13 -13
  37. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Assets.php +42 -68
  38. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Blocks.php +23 -23
  39. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Cache.php +10 -11
  40. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselImage.php +3 -2
  41. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselPost.php +13 -7
  42. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselProduct.php +11 -10
  43. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/ChiselProductCategory.php +10 -10
  44. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Comments.php +27 -35
  45. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Components.php +44 -61
  46. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomPostTypes.php +12 -13
  47. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/CustomTaxonomies.php +12 -13
  48. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Sidebars.php +6 -6
  49. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Site.php +7 -8
  50. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Theme.php +22 -22
  51. package/lib/commands/create/creators/app/chisel-starter-theme/inc/WP/Twig.php +53 -48
  52. package/lib/commands/create/creators/app/chisel-starter-theme/index.php +1 -1
  53. package/lib/commands/create/creators/app/chisel-starter-theme/page.php +1 -1
  54. package/lib/commands/create/creators/app/chisel-starter-theme/search.php +1 -1
  55. package/lib/commands/create/creators/app/chisel-starter-theme/single.php +1 -1
  56. package/lib/commands/create/creators/app/chisel-starter-theme/src/scripts/editor/blocks-styles.js +3 -2
  57. package/lib/commands/create/creators/app/chisel-starter-theme/src/styles/vendor/_breadcrumbs.scss +6 -3
  58. package/lib/commands/create/creators/app/chisel-starter-theme/style.chisel-tpl.css +1 -1
  59. package/lib/commands/create/creators/app/chisel-starter-theme/woocommerce.php +3 -3
  60. package/lib/commands/create/packages-versions.js +1 -1
  61. package/package.json +2 -2
  62. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Factory/RegisterAcfOptionsPage.php +0 -62
  63. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/AjaxHelpers.php +0 -33
  64. package/lib/commands/create/creators/app/chisel-starter-theme/inc/Helper/CacheHelpers.php +0 -41
@@ -1,18 +1,18 @@
1
1
  <?php
2
2
 
3
- namespace Chisel\Plugin;
3
+ namespace Chisel\Plugins;
4
4
 
5
5
  use Chisel\Interfaces\InstanceInterface;
6
6
  use Chisel\Interfaces\HooksInterface;
7
7
  use Chisel\Traits\Singleton;
8
- use Chisel\Helper\YoastHelpers;
8
+ use Chisel\Helpers\YoastHelpers;
9
9
 
10
10
  /**
11
11
  * Yoast SEO plugin related functionalities.
12
12
  *
13
13
  * @package Chisel
14
14
  */
15
- class Yoast implements InstanceInterface, HooksInterface {
15
+ final class Yoast implements InstanceInterface, HooksInterface {
16
16
 
17
17
  use Singleton;
18
18
 
@@ -32,15 +32,15 @@ class Yoast implements InstanceInterface, HooksInterface {
32
32
  /**
33
33
  * Set properties.
34
34
  */
35
- public function set_properties() {}
35
+ public function set_properties(): void {}
36
36
 
37
37
  /**
38
38
  * Register action hooks.
39
39
  */
40
- public function action_hooks() {}
40
+ public function action_hooks(): void {}
41
41
 
42
42
  /**
43
43
  * Register filter hooks.
44
44
  */
45
- public function filter_hooks() {}
45
+ public function filter_hooks(): void {}
46
46
  }
@@ -6,9 +6,9 @@ trait PageBlocks {
6
6
  /**
7
7
  * Content blocks from current page
8
8
  *
9
- * @var array|null
9
+ * @var ?array
10
10
  */
11
- private static $content_blocks_names = null;
11
+ private static ?array $content_blocks_names = null;
12
12
 
13
13
  /**
14
14
  * Get the instance of the class.
@@ -17,8 +17,8 @@ trait PageBlocks {
17
17
  *
18
18
  * @return array
19
19
  */
20
- public function get_content_blocks_names( $prefix = 'chisel' ) {
21
- if ( self::$content_blocks_names ) {
20
+ public function get_content_blocks_names( string $prefix = 'chisel' ): array {
21
+ if ( self::$content_blocks_names !== null ) {
22
22
  return self::$content_blocks_names;
23
23
  }
24
24
 
@@ -26,24 +26,24 @@ trait PageBlocks {
26
26
 
27
27
  $content_blocks_names = array();
28
28
 
29
- if ( is_a( $post, 'WP_Post' ) && $post->post_content && has_blocks( $post->post_content ) ) {
29
+ if ( $post instanceof \WP_Post && ! empty( $post->post_content ) && has_blocks( $post->post_content ) ) {
30
30
  $blocks = parse_blocks( $post->post_content );
31
31
 
32
- if ( $blocks ) {
32
+ if ( is_array( $blocks ) && ! empty( $blocks ) ) {
33
33
  $blocks_names = $this->get_blocks_names( $blocks );
34
34
 
35
- if ( $blocks_names ) {
35
+ if ( ! empty( $blocks_names ) ) {
36
36
  $blocks_names = array_filter(
37
37
  $blocks_names,
38
- function ( $block_name ) use ( $prefix ) {
39
- return strpos( $block_name, $prefix ) !== false;
38
+ function ( string $block_name ) use ( $prefix ): bool {
39
+ return (bool) strpos( $block_name, $prefix ) !== false;
40
40
  }
41
41
  );
42
42
 
43
- if ( $blocks_names ) {
43
+ if ( ! empty( $blocks_names ) ) {
44
44
  $blocks_names = array_values( array_unique( $blocks_names ) );
45
45
  $blocks_names = array_map(
46
- function ( $block_name ) use ( $prefix ) {
46
+ function ( string $block_name ) use ( $prefix ): string {
47
47
  return str_replace( $prefix . '/', '', $block_name );
48
48
  },
49
49
  $blocks_names
@@ -66,7 +66,7 @@ trait PageBlocks {
66
66
  *
67
67
  * @return array
68
68
  */
69
- private function get_blocks_names( $inner_blocks ) {
69
+ private function get_blocks_names( array $inner_blocks ): array {
70
70
  $blocks_names = array();
71
71
 
72
72
  foreach ( $inner_blocks as $block ) {
@@ -78,10 +78,10 @@ trait PageBlocks {
78
78
 
79
79
  $blocks_names[] = $block_name;
80
80
 
81
- if ( isset( $block['innerBlocks'] ) && $block['innerBlocks'] ) {
81
+ if ( isset( $block['innerBlocks'] ) && ! empty( $block['innerBlocks'] ) ) {
82
82
  $inner_blocks_names = $this->get_blocks_names( $block['innerBlocks'] );
83
83
 
84
- if ( $inner_blocks_names ) {
84
+ if ( ! empty( $inner_blocks_names ) ) {
85
85
  $blocks_names = array_merge( $blocks_names, $inner_blocks_names );
86
86
  }
87
87
  }
@@ -6,18 +6,39 @@ trait Singleton {
6
6
  /**
7
7
  * Instance of the class.
8
8
  *
9
- * @var self
9
+ * @var object
10
10
  */
11
- private static $instance;
11
+ private static ?object $instance = null;
12
12
 
13
13
  /**
14
- * Get the instance of the class.
14
+ * Get the instance of the class using the singleton.
15
+ *
16
+ * @return object
15
17
  */
16
- public static function get_instance() {
17
- if ( ! ( self::$instance instanceof self ) ) {
18
- self::$instance = new self();
18
+ public static function get_instance(): static {
19
+ if ( ! ( static::$instance instanceof static ) ) {
20
+ static::$instance = new static();
19
21
  }
20
22
 
21
- return self::$instance;
23
+ return static::$instance;
24
+ }
25
+
26
+ /**
27
+ * Prevent direct construction; let get_instance() control instantiation.
28
+ */
29
+ private function __construct() {}
30
+
31
+ /**
32
+ * Prevent cloning.
33
+ */
34
+ private function __clone() {}
35
+
36
+ /**
37
+ * Prevent unserialization.
38
+ *
39
+ * @throws \LogicException - Cannot unserialize singleton.
40
+ */
41
+ public function __wakeup(): void {
42
+ throw new \LogicException( 'Cannot unserialize singleton' );
22
43
  }
23
44
  }
@@ -5,14 +5,15 @@ namespace Chisel\WP;
5
5
  use Chisel\Interfaces\InstanceInterface;
6
6
  use Chisel\Interfaces\HooksInterface;
7
7
  use Chisel\Traits\Singleton;
8
- use Chisel\Factory\RegisterAcfOptionsPage;
8
+ use Chisel\Factories\RegisterAcfOptionsPage;
9
+ use Chisel\Enums\AcfOptionsPageType;
9
10
 
10
11
  /**
11
12
  * ACF related functionalities.
12
13
  *
13
14
  * @package Chisel
14
15
  */
15
- class Acf implements InstanceInterface, HooksInterface {
16
+ final class Acf implements InstanceInterface, HooksInterface {
16
17
 
17
18
  use Singleton;
18
19
 
@@ -21,14 +22,14 @@ class Acf implements InstanceInterface, HooksInterface {
21
22
  *
22
23
  * @var array
23
24
  */
24
- private $acf_options_pages = array();
25
+ private array $acf_options_pages = array();
25
26
 
26
27
  /**
27
28
  * ACF options sub pages.
28
29
  *
29
30
  * @var array
30
31
  */
31
- private $acf_options_sub_pages = array();
32
+ private array $acf_options_sub_pages = array();
32
33
 
33
34
  /**
34
35
  * Class constructor.
@@ -43,7 +44,7 @@ class Acf implements InstanceInterface, HooksInterface {
43
44
  /**
44
45
  * Set properties.
45
46
  */
46
- public function set_properties() {
47
+ public function set_properties(): void {
47
48
  $this->set_options_pages();
48
49
  $this->set_options_sub_pages();
49
50
  }
@@ -51,20 +52,20 @@ class Acf implements InstanceInterface, HooksInterface {
51
52
  /**
52
53
  * Register action hooks.
53
54
  */
54
- public function action_hooks() {
55
+ public function action_hooks(): void {
55
56
  add_action( 'acf/init', array( $this, 'options_pages' ) );
56
57
  }
57
58
 
58
59
  /**
59
60
  * Register filter hooks.
60
61
  */
61
- public function filter_hooks() {
62
+ public function filter_hooks(): void {
62
63
  }
63
64
 
64
65
  /**
65
66
  * Set ACF options pages.
66
67
  */
67
- private function set_options_pages() {
68
+ private function set_options_pages(): void {
68
69
  $this->acf_options_pages = array(
69
70
  // phpcs:disable
70
71
  // array(
@@ -78,7 +79,7 @@ class Acf implements InstanceInterface, HooksInterface {
78
79
  /**
79
80
  * Set ACF options sub pages.
80
81
  */
81
- private function set_options_sub_pages() {
82
+ private function set_options_sub_pages(): void {
82
83
  $this->acf_options_sub_pages = array(
83
84
  // phpcs:disable
84
85
  // array(
@@ -94,17 +95,17 @@ class Acf implements InstanceInterface, HooksInterface {
94
95
  /**
95
96
  * Register ACF options pages.
96
97
  */
97
- public function options_pages() {
98
+ public function options_pages(): void {
98
99
  $this->acf_options_pages = apply_filters( 'chisel_acf_options_pages', $this->acf_options_pages );
99
100
  $this->acf_options_sub_pages = apply_filters( 'chisel_acf_options_sub_pages', $this->acf_options_sub_pages );
100
101
 
101
- if ( $this->acf_options_pages && function_exists( 'acf_add_options_page' ) ) {
102
+ if ( is_array( $this->acf_options_pages ) && ! empty( $this->acf_options_pages ) && function_exists( 'acf_add_options_page' ) ) {
102
103
  foreach ( $this->acf_options_pages as $data ) {
103
104
  $this->register_options_page( $data, 'page' );
104
105
  }
105
106
  }
106
107
 
107
- if ( $this->acf_options_sub_pages && function_exists( 'acf_add_options_sub_page' ) ) {
108
+ if ( is_array( $this->acf_options_sub_pages ) && ! empty( $this->acf_options_sub_pages ) && function_exists( 'acf_add_options_sub_page' ) ) {
108
109
  foreach ( $this->acf_options_sub_pages as $data ) {
109
110
  $this->register_options_page( $data, 'subpage' );
110
111
  }
@@ -114,12 +115,12 @@ class Acf implements InstanceInterface, HooksInterface {
114
115
  /**
115
116
  * Register ACF options pages.
116
117
  *
117
- * @param array $data
118
- * @param string $type
118
+ * @param array $data
119
+ * @param AcfOptionsPageType|string $type
119
120
  *
120
121
  * @return void
121
122
  */
122
- private function register_options_page( $data, $type = 'page' ) {
123
+ private function register_options_page( array $data, AcfOptionsPageType|string $type = AcfOptionsPageType::Page ): void {
123
124
  ( new RegisterAcfOptionsPage( $data, $type ) )->register();
124
125
  }
125
126
  }
@@ -6,17 +6,17 @@ use Timber\Timber;
6
6
  use Chisel\Interfaces\InstanceInterface;
7
7
  use Chisel\Interfaces\HooksInterface;
8
8
  use Chisel\Traits\Singleton;
9
- use Chisel\Factory\RegisterBlocks;
9
+ use Chisel\Factories\RegisterBlocks;
10
10
  use Chisel\Traits\PageBlocks;
11
- use Chisel\Helper\BlocksHelpers;
12
- use Chisel\Helper\AssetsHelpers;
11
+ use Chisel\Helpers\BlocksHelpers;
12
+ use Chisel\Helpers\AssetsHelpers;
13
13
 
14
14
  /**
15
15
  * ACF blocks related functionalities.
16
16
  *
17
17
  * @package Chisel
18
18
  */
19
- class AcfBlocks implements InstanceInterface, HooksInterface {
19
+ final class AcfBlocks implements InstanceInterface, HooksInterface {
20
20
 
21
21
  use Singleton;
22
22
  use PageBlocks;
@@ -26,21 +26,21 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
26
26
  *
27
27
  * @var RegisterBlocks
28
28
  */
29
- private $register_blocks_factory;
29
+ private RegisterBlocks $register_blocks_factory;
30
30
 
31
31
  /**
32
32
  * Blocks.
33
33
  *
34
34
  * @var array
35
35
  */
36
- private $blocks = array();
36
+ private array $blocks = array();
37
37
 
38
38
  /**
39
39
  * Blocks twig file base path.
40
40
  *
41
41
  * @var string
42
42
  */
43
- public $blocks_twig_base_path;
43
+ public string $blocks_twig_base_path = '';
44
44
 
45
45
  /**
46
46
  * Class constructor.
@@ -59,21 +59,21 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
59
59
  /**
60
60
  * Set properties.
61
61
  */
62
- public function set_properties() {
62
+ public function set_properties(): void {
63
63
  $this->blocks_twig_base_path = 'build/blocks-acf/';
64
64
  }
65
65
 
66
66
  /**
67
67
  * Register action hooks.
68
68
  */
69
- public function action_hooks() {
69
+ public function action_hooks(): void {
70
70
  add_action( 'acf/init', array( $this, 'register_blocks' ) );
71
71
  }
72
72
 
73
73
  /**
74
74
  * Register filter hooks.
75
75
  */
76
- public function filter_hooks() {
76
+ public function filter_hooks(): void {
77
77
  add_filter( 'timber/locations', array( $this, 'tiwg_files_locations' ) );
78
78
  add_filter( 'acf/settings/load_json', array( $this, 'load_acf_field_group' ) );
79
79
  add_filter( 'acf/settings/save_json', array( $this, 'save_acf_field_group' ) );
@@ -82,7 +82,7 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
82
82
  /**
83
83
  * Register ACF blocks and their assets.
84
84
  */
85
- public function register_blocks() {
85
+ public function register_blocks(): void {
86
86
  $this->register_blocks_factory->register_custom_blocks();
87
87
  }
88
88
 
@@ -92,8 +92,8 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
92
92
  * @param array $locations The locations.
93
93
  * @return array
94
94
  */
95
- public function tiwg_files_locations( $locations ) {
96
- if ( ! is_array( $this->blocks ) || ! $this->blocks ) {
95
+ public function tiwg_files_locations( array $locations ): array {
96
+ if ( ! is_array( $this->blocks ) || empty( $this->blocks ) ) {
97
97
  return $locations;
98
98
  }
99
99
 
@@ -110,8 +110,8 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
110
110
  * @param array $paths The paths.
111
111
  * @return array
112
112
  */
113
- public function load_acf_field_group( $paths ) {
114
- if ( ! is_array( $this->blocks ) || ! $this->blocks ) {
113
+ public function load_acf_field_group( array $paths ): array {
114
+ if ( ! is_array( $this->blocks ) || empty( $this->blocks ) ) {
115
115
  return $paths;
116
116
  }
117
117
 
@@ -128,7 +128,7 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
128
128
  * @param string $path The path.
129
129
  * @return string
130
130
  */
131
- public function save_acf_field_group( $path ) {
131
+ public function save_acf_field_group( string $path ): string {
132
132
 
133
133
  $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : ''; // phpcs:ignore
134
134
  $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ) : ''; // phpcs:ignore
@@ -137,7 +137,7 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
137
137
  $location = isset( $_REQUEST['acf_field_group']['location'] ) ? $_REQUEST['acf_field_group']['location'] : array(); // phpcs:ignore
138
138
 
139
139
  foreach ( $location as $group ) {
140
- foreach ( $group as $rules ) {
140
+ foreach ( (array) $group as $rules ) {
141
141
  if ( sanitize_text_field( $rules['param'] ) === 'block' && sanitize_text_field( $rules['operator'] ) === '==' ) {
142
142
  $block_name = explode( '/', sanitize_text_field( $rules['value'] ) )[1];
143
143
 
@@ -159,7 +159,7 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
159
159
  *
160
160
  * @return void
161
161
  */
162
- public function dequeue_blocks_styles() {
162
+ public function dequeue_blocks_styles(): void {
163
163
  if ( is_admin() ) {
164
164
  return;
165
165
  }
@@ -167,7 +167,7 @@ class AcfBlocks implements InstanceInterface, HooksInterface {
167
167
  $blocks_used_on_page = $this->get_content_blocks_names();
168
168
  $blocks = $this->blocks;
169
169
 
170
- if ( $blocks ) {
170
+ if ( ! empty( $blocks ) ) {
171
171
  $blocks_path = $this->register_blocks_factory->get_blocks_path();
172
172
  $blocks_url = $this->register_blocks_factory->get_blocks_url();
173
173
 
@@ -3,32 +3,32 @@
3
3
  namespace Chisel\WP;
4
4
 
5
5
  use Timber\Timber;
6
- use Chisel\Helper\CacheHelpers;
6
+ use Chisel\Helpers\CacheHelpers;
7
7
 
8
8
  /**
9
9
  * Custom Ajax enpoints callbacks
10
10
  *
11
11
  * @package Chisel
12
12
  */
13
- class AjaxEndpoints {
13
+ final class AjaxEndpoints {
14
14
 
15
15
  /**
16
16
  * Ajax call for load more feature.
17
17
  *
18
18
  * @param \WP_REST_Request $request WP_REST_Request.
19
19
  *
20
- * @return json
20
+ * @return \WP_REST_Response
21
21
  */
22
- public function load_more( $request ) {
22
+ public function load_more( \WP_REST_Request $request ): \WP_REST_Response {
23
23
  if ( ! $request ) {
24
24
  return $this->error( 'No request data' );
25
25
  }
26
26
 
27
27
  $data = $this->get_data( $request );
28
28
 
29
- $post_type = sanitize_text_field( $data['post_type'] );
30
- $per_page = absint( $data['per_page'] );
31
- $page = absint( $data['page'] );
29
+ $post_type = isset( $data['post_type'] ) ? sanitize_text_field( $data['post_type'] ) : 'post';
30
+ $per_page = isset( $data['per_page'] ) ? absint( $data['per_page'] ) : 10;
31
+ $page = isset( $data['page'] ) ? absint( $data['page'] ) : 1;
32
32
 
33
33
  $response = '';
34
34
 
@@ -46,7 +46,7 @@ class AjaxEndpoints {
46
46
  array_unshift( $templates, 'woocommerce/content-product.twig' );
47
47
  }
48
48
 
49
- if ( $posts ) {
49
+ if ( ! empty( $posts ) ) {
50
50
  foreach ( $posts as $post ) {
51
51
  $response .= Timber::compile( $templates, array( 'post' => $post ), CacheHelpers::expiry() );
52
52
  }
@@ -62,18 +62,18 @@ class AjaxEndpoints {
62
62
  *
63
63
  * @return array
64
64
  */
65
- private function get_data( $request ) {
65
+ private function get_data( \WP_REST_Request $request ): array {
66
66
  return $request->get_body_params();
67
67
  }
68
68
 
69
69
  /**
70
70
  * This function will return a success response.
71
71
  *
72
- * @param array $data
72
+ * @param mixed $data
73
73
  *
74
74
  * @return \WP_REST_Response
75
75
  */
76
- private function success( $data = array() ) {
76
+ private function success( mixed $data = array() ): \WP_REST_Response {
77
77
  return new \WP_REST_Response(
78
78
  array(
79
79
  'error' => 0,
@@ -91,13 +91,13 @@ class AjaxEndpoints {
91
91
  *
92
92
  * @return \WP_REST_Response
93
93
  */
94
- private function error( $message ) {
94
+ private function error( string $message ): \WP_REST_Response {
95
95
  return new \WP_REST_Response(
96
96
  array(
97
97
  'error' => 1,
98
98
  'message' => $message,
99
99
  ),
100
- 400
100
+ 200
101
101
  );
102
102
  }
103
103
  }