@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | - * Registers a Meta Data object as defined REST field. |
|
| 133 | - * |
|
| 134 | - * @param \PinkCrab\Registerables\Meta_Data $meta |
|
| 135 | - * @return void |
|
| 136 | - */ |
|
| 132 | + * Registers a Meta Data object as defined REST field. |
|
| 133 | + * |
|
| 134 | + * @param \PinkCrab\Registerables\Meta_Data $meta |
|
| 135 | + * @return void |
|
| 136 | + */ |
|
| 137 | 137 | public function register_meta_rest_field( Meta_Data $meta ) { |
| 138 | 138 | // Skip if not sub type defined for post or term. |
| 139 | 139 | if ( null === $meta->get_subtype() ) { |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | switch ( $meta->get_meta_type() ) { |
| 206 | 206 | case 'post': |
| 207 | 207 | /** |
| 208 | - * @var \WP_Post $object_instance |
|
| 208 | + * @var \WP_Post $object_instance |
|
| 209 | 209 | */ |
| 210 | 210 | update_post_meta( $object_instance->ID, $meta->get_meta_key(), $value ); |
| 211 | 211 | break; |
| 212 | 212 | |
| 213 | 213 | case 'term': |
| 214 | 214 | /** |
| 215 | - * @var \WP_Term $object_instance |
|
| 215 | + * @var \WP_Term $object_instance |
|
| 216 | 216 | */ |
| 217 | 217 | update_term_meta( $object_instance->term_id, $meta->get_meta_key(), $value ); |
| 218 | 218 | break; |
| 219 | 219 | |
| 220 | 220 | case 'user': |
| 221 | 221 | /** |
| 222 | - * @var \WP_User $object_instance |
|
| 222 | + * @var \WP_User $object_instance |
|
| 223 | 223 | */ |
| 224 | 224 | update_user_meta( $object_instance->ID, $meta->get_meta_key(), $value ); |
| 225 | 225 | break; |
| 226 | 226 | |
| 227 | 227 | case 'comment': |
| 228 | 228 | /** |
| 229 | - * @var \WP_Comment $object_instance |
|
| 229 | + * @var \WP_Comment $object_instance |
|
| 230 | 230 | */ |
| 231 | 231 | update_comment_meta( (int) $object_instance->comment_ID, $meta->get_meta_key(), $value ); |
| 232 | 232 | break; |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * @return boolean |
| 38 | 38 | * @throws \Exception if fails to register meta data. |
| 39 | 39 | */ |
| 40 | - public function register_for_post_type( Meta_Data $meta, string $post_type ): bool { |
|
| 41 | - return $this->register_meta( $meta, 'post', $post_type ); |
|
| 40 | + public function register_for_post_type(Meta_Data $meta, string $post_type): bool { |
|
| 41 | + return $this->register_meta($meta, 'post', $post_type); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @return boolean |
| 50 | 50 | * @throws \Exception if fails to register meta data. |
| 51 | 51 | */ |
| 52 | - public function register_for_term( Meta_Data $meta, string $taxonomy ): bool { |
|
| 53 | - return $this->register_meta( $meta, 'term', $taxonomy ); |
|
| 52 | + public function register_for_term(Meta_Data $meta, string $taxonomy): bool { |
|
| 53 | + return $this->register_meta($meta, 'term', $taxonomy); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | * @return boolean |
| 61 | 61 | * @throws \Exception if fails to register meta data. |
| 62 | 62 | */ |
| 63 | - public function register_for_user( Meta_Data $meta ): bool { |
|
| 64 | - return $this->register_meta( $meta, 'user', '' ); |
|
| 63 | + public function register_for_user(Meta_Data $meta): bool { |
|
| 64 | + return $this->register_meta($meta, 'user', ''); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @return boolean |
| 72 | 72 | * @throws \Exception if fails to register meta data. |
| 73 | 73 | */ |
| 74 | - public function register_for_comment( Meta_Data $meta ): bool { |
|
| 75 | - return $this->register_meta( $meta, 'comment', '' ); |
|
| 74 | + public function register_for_comment(Meta_Data $meta): bool { |
|
| 75 | + return $this->register_meta($meta, 'comment', ''); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -86,25 +86,25 @@ discard block |
||
| 86 | 86 | * @return boolean |
| 87 | 87 | * @throws \Exception if fails to register meta data. |
| 88 | 88 | */ |
| 89 | - protected function register_meta( Meta_Data $meta, string $meta_type, string $sub_type ): bool { |
|
| 89 | + protected function register_meta(Meta_Data $meta, string $meta_type, string $sub_type): bool { |
|
| 90 | 90 | // Clone and set the post type, while enforcing it as a post meta. |
| 91 | 91 | $meta = clone $meta; |
| 92 | - $meta->object_subtype( $sub_type ); |
|
| 93 | - $meta->meta_type( $meta_type ); |
|
| 92 | + $meta->object_subtype($sub_type); |
|
| 93 | + $meta->meta_type($meta_type); |
|
| 94 | 94 | |
| 95 | 95 | // Normalise rest schema model to array. |
| 96 | - $meta = $this->normalise_rest_schema( $meta ); |
|
| 96 | + $meta = $this->normalise_rest_schema($meta); |
|
| 97 | 97 | |
| 98 | - $result = register_meta( $meta->get_meta_type(), $meta->get_meta_key(), $meta->parse_args() ); |
|
| 99 | - if ( ! $result ) { |
|
| 98 | + $result = register_meta($meta->get_meta_type(), $meta->get_meta_key(), $meta->parse_args()); |
|
| 99 | + if ( ! $result) { |
|
| 100 | 100 | throw new \Exception( |
| 101 | - esc_html( "Failed to register {$meta->get_meta_key()} (meta) for {$sub_type} of {$meta_type} type" ) |
|
| 101 | + esc_html("Failed to register {$meta->get_meta_key()} (meta) for {$sub_type} of {$meta_type} type") |
|
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Maybe register rest fields. |
| 106 | - if ( false !== $meta->get_rest_schema() ) { |
|
| 107 | - $this->register_meta_rest_field( $meta ); |
|
| 106 | + if (false !== $meta->get_rest_schema()) { |
|
| 107 | + $this->register_meta_rest_field($meta); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | return $result; |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | * @param \PinkCrab\Registerables\Meta_Data $meta |
| 120 | 120 | * @return \PinkCrab\Registerables\Meta_Data |
| 121 | 121 | */ |
| 122 | - protected function normalise_rest_schema( Meta_Data $meta ): Meta_Data { |
|
| 123 | - if ( \class_exists( 'PinkCrab\WP_Rest_Schema\Argument\Argument' ) |
|
| 122 | + protected function normalise_rest_schema(Meta_Data $meta): Meta_Data { |
|
| 123 | + if (\class_exists('PinkCrab\WP_Rest_Schema\Argument\Argument') |
|
| 124 | 124 | && $meta->get_rest_schema() instanceof \PinkCrab\WP_Rest_Schema\Argument\Argument |
| 125 | 125 | ) { |
| 126 | - $meta->rest_schema( \PinkCrab\WP_Rest_Schema\Parser\Argument_Parser::for_meta_data( $meta->get_rest_schema() ) ); |
|
| 126 | + $meta->rest_schema(\PinkCrab\WP_Rest_Schema\Parser\Argument_Parser::for_meta_data($meta->get_rest_schema())); |
|
| 127 | 127 | } |
| 128 | 128 | return $meta; |
| 129 | 129 | } |
@@ -134,22 +134,22 @@ discard block |
||
| 134 | 134 | * @param \PinkCrab\Registerables\Meta_Data $meta |
| 135 | 135 | * @return void |
| 136 | 136 | */ |
| 137 | - public function register_meta_rest_field( Meta_Data $meta ) { |
|
| 137 | + public function register_meta_rest_field(Meta_Data $meta) { |
|
| 138 | 138 | // Skip if not sub type defined for post or term. |
| 139 | - if ( null === $meta->get_subtype() ) { |
|
| 139 | + if (null === $meta->get_subtype()) { |
|
| 140 | 140 | return; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | add_action( |
| 144 | 144 | 'rest_api_init', |
| 145 | - function () use ( $meta ) { |
|
| 145 | + function() use ($meta) { |
|
| 146 | 146 | register_rest_field( |
| 147 | 147 | $meta->get_subtype(), |
| 148 | 148 | $meta->get_meta_key(), |
| 149 | 149 | array( // @phpstan-ignore-line WP Docblock doesn't give enough details of callable param types, so throws false positive |
| 150 | - 'get_callback' => $meta->get_rest_view() ?? $this->create_rest_get_method( $meta ), |
|
| 150 | + 'get_callback' => $meta->get_rest_view() ?? $this->create_rest_get_method($meta), |
|
| 151 | 151 | 'schema' => $meta->get_rest_schema(), |
| 152 | - 'update_callback' => $meta->get_rest_update() ?? $this->create_rest_update_method( $meta ), |
|
| 152 | + 'update_callback' => $meta->get_rest_update() ?? $this->create_rest_update_method($meta), |
|
| 153 | 153 | ) |
| 154 | 154 | ); |
| 155 | 155 | } |
@@ -162,23 +162,23 @@ discard block |
||
| 162 | 162 | * @param \PinkCrab\Registerables\Meta_Data $meta |
| 163 | 163 | * @return callable(array<mixed>):void |
| 164 | 164 | */ |
| 165 | - protected function create_rest_get_method( Meta_Data $meta ): callable { |
|
| 166 | - return function ( $model ) use ( $meta ) { |
|
| 167 | - switch ( $meta->get_meta_type() ) { |
|
| 165 | + protected function create_rest_get_method(Meta_Data $meta): callable { |
|
| 166 | + return function($model) use ($meta) { |
|
| 167 | + switch ($meta->get_meta_type()) { |
|
| 168 | 168 | case 'post': |
| 169 | - $value = get_post_meta( $model['id'], $meta->get_meta_key(), true ); |
|
| 169 | + $value = get_post_meta($model['id'], $meta->get_meta_key(), true); |
|
| 170 | 170 | break; |
| 171 | 171 | |
| 172 | 172 | case 'term': |
| 173 | - $value = get_term_meta( $model['id'], $meta->get_meta_key(), true ); |
|
| 173 | + $value = get_term_meta($model['id'], $meta->get_meta_key(), true); |
|
| 174 | 174 | break; |
| 175 | 175 | |
| 176 | 176 | case 'user': |
| 177 | - $value = get_user_meta( $model['id'], $meta->get_meta_key(), true ); |
|
| 177 | + $value = get_user_meta($model['id'], $meta->get_meta_key(), true); |
|
| 178 | 178 | break; |
| 179 | 179 | |
| 180 | 180 | case 'comment': |
| 181 | - $value = get_comment_meta( $model['id'], $meta->get_meta_key(), true ); |
|
| 181 | + $value = get_comment_meta($model['id'], $meta->get_meta_key(), true); |
|
| 182 | 182 | break; |
| 183 | 183 | |
| 184 | 184 | default: |
@@ -196,39 +196,39 @@ discard block |
||
| 196 | 196 | * @param Meta_Data $meta |
| 197 | 197 | * @return \Closure(mixed, \WP_Post|\WP_Term|\WP_User|\WP_Comment): mixed |
| 198 | 198 | */ |
| 199 | - protected function create_rest_update_method( Meta_Data $meta ): \Closure { |
|
| 199 | + protected function create_rest_update_method(Meta_Data $meta): \Closure { |
|
| 200 | 200 | /** |
| 201 | 201 | * @param mixed $value |
| 202 | 202 | * @param \WP_Post|\WP_Term|\WP_User|\WP_Comment $object_instance |
| 203 | 203 | */ |
| 204 | - return function ( $value, $object_instance ) use ( $meta ) { |
|
| 205 | - switch ( $meta->get_meta_type() ) { |
|
| 204 | + return function($value, $object_instance) use ($meta) { |
|
| 205 | + switch ($meta->get_meta_type()) { |
|
| 206 | 206 | case 'post': |
| 207 | 207 | /** |
| 208 | 208 | * @var \WP_Post $object_instance |
| 209 | 209 | */ |
| 210 | - update_post_meta( $object_instance->ID, $meta->get_meta_key(), $value ); |
|
| 210 | + update_post_meta($object_instance->ID, $meta->get_meta_key(), $value); |
|
| 211 | 211 | break; |
| 212 | 212 | |
| 213 | 213 | case 'term': |
| 214 | 214 | /** |
| 215 | 215 | * @var \WP_Term $object_instance |
| 216 | 216 | */ |
| 217 | - update_term_meta( $object_instance->term_id, $meta->get_meta_key(), $value ); |
|
| 217 | + update_term_meta($object_instance->term_id, $meta->get_meta_key(), $value); |
|
| 218 | 218 | break; |
| 219 | 219 | |
| 220 | 220 | case 'user': |
| 221 | 221 | /** |
| 222 | 222 | * @var \WP_User $object_instance |
| 223 | 223 | */ |
| 224 | - update_user_meta( $object_instance->ID, $meta->get_meta_key(), $value ); |
|
| 224 | + update_user_meta($object_instance->ID, $meta->get_meta_key(), $value); |
|
| 225 | 225 | break; |
| 226 | 226 | |
| 227 | 227 | case 'comment': |
| 228 | 228 | /** |
| 229 | 229 | * @var \WP_Comment $object_instance |
| 230 | 230 | */ |
| 231 | - update_comment_meta( (int) $object_instance->comment_ID, $meta->get_meta_key(), $value ); |
|
| 231 | + update_comment_meta((int) $object_instance->comment_ID, $meta->get_meta_key(), $value); |
|
| 232 | 232 | break; |
| 233 | 233 | |
| 234 | 234 | default: |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @return Registrar |
| 55 | 55 | * @throws Exception If not valid registerable type passed. |
| 56 | 56 | */ |
| 57 | - public function create_from_registerable( Registerable $registerable ): Registrar { |
|
| 58 | - switch ( true ) { |
|
| 59 | - case is_a( $registerable, Post_Type::class ): |
|
| 60 | - return new Post_Type_Registrar( new Post_Type_Validator(), new Meta_Data_Registrar() ); |
|
| 57 | + public function create_from_registerable(Registerable $registerable): Registrar { |
|
| 58 | + switch (true) { |
|
| 59 | + case is_a($registerable, Post_Type::class): |
|
| 60 | + return new Post_Type_Registrar(new Post_Type_Validator(), new Meta_Data_Registrar()); |
|
| 61 | 61 | |
| 62 | - case is_a( $registerable, Taxonomy::class ): |
|
| 63 | - return new Taxonomy_Registrar( new Taxonomy_Validator(), new Meta_Data_Registrar() ); |
|
| 62 | + case is_a($registerable, Taxonomy::class): |
|
| 63 | + return new Taxonomy_Registrar(new Taxonomy_Validator(), new Meta_Data_Registrar()); |
|
| 64 | 64 | |
| 65 | 65 | default: |
| 66 | - $type = get_class( $registerable ); |
|
| 67 | - throw new Exception( esc_html( 'Invalid registerable (' . $type . ')type (no dispatcher exists)' ) ); |
|
| 66 | + $type = get_class($registerable); |
|
| 67 | + throw new Exception(esc_html('Invalid registerable (' . $type . ')type (no dispatcher exists)')); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | * @param \PinkCrab\Loader\Hook_Loader $loader |
| 76 | 76 | * @return Meta_Box_Registrar |
| 77 | 77 | */ |
| 78 | - public function meta_box_registrar( DI_Container $container, Hook_Loader $loader ): Meta_Box_Registrar { |
|
| 79 | - return new Meta_Box_Registrar( new Meta_Box_Validator(), $container, $loader ); |
|
| 78 | + public function meta_box_registrar(DI_Container $container, Hook_Loader $loader): Meta_Box_Registrar { |
|
| 79 | + return new Meta_Box_Registrar(new Meta_Box_Validator(), $container, $loader); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | */ |
| 54 | 54 | public function register( Registerable $registerable ): void { |
| 55 | 55 | /** |
| 56 | - * @var Post_Type $registerable, Validation call below catches no Post_Type Registerables |
|
| 56 | + * @var Post_Type $registerable, Validation call below catches no Post_Type Registerables |
|
| 57 | 57 | */ |
| 58 | 58 | |
| 59 | 59 | if ( ! $this->validator->validate( $registerable ) ) { |
@@ -51,17 +51,17 @@ discard block |
||
| 51 | 51 | * @param \PinkCrab\Registerables\Module\Middleware\Registerable $registerable |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | - public function register( Registerable $registerable ): void { |
|
| 54 | + public function register(Registerable $registerable): void { |
|
| 55 | 55 | /** |
| 56 | 56 | * @var Post_Type $registerable, Validation call below catches no Post_Type Registerables |
| 57 | 57 | */ |
| 58 | 58 | |
| 59 | - if ( ! $this->validator->validate( $registerable ) ) { |
|
| 59 | + if ( ! $this->validator->validate($registerable)) { |
|
| 60 | 60 | throw new Exception( |
| 61 | 61 | sprintf( |
| 62 | 62 | 'Failed validating post type model(%s) with errors: %s', |
| 63 | - esc_html( get_class( $registerable ) ), |
|
| 64 | - esc_html( join( ', ', $this->validator->get_errors() ) ) |
|
| 63 | + esc_html(get_class($registerable)), |
|
| 64 | + esc_html(join(', ', $this->validator->get_errors())) |
|
| 65 | 65 | ) |
| 66 | 66 | ); |
| 67 | 67 | } |
@@ -69,16 +69,16 @@ discard block |
||
| 69 | 69 | // Attempt to register the post type. |
| 70 | 70 | try { |
| 71 | 71 | /* @phpstan-ignore-next-line */ |
| 72 | - $result = register_post_type( $registerable->key, $this->compile_args( $registerable ) ); |
|
| 73 | - if ( is_a( $result, \WP_Error::class ) ) { |
|
| 74 | - throw new Exception( join( $result->get_error_messages() ) ); |
|
| 72 | + $result = register_post_type($registerable->key, $this->compile_args($registerable)); |
|
| 73 | + if (is_a($result, \WP_Error::class)) { |
|
| 74 | + throw new Exception(join($result->get_error_messages())); |
|
| 75 | 75 | } |
| 76 | - } catch ( \Throwable $th ) { |
|
| 77 | - throw new Exception( esc_html( "Failed to register {$registerable->key} post type ({$th->getMessage()})" ) ); |
|
| 76 | + } catch (\Throwable $th) { |
|
| 77 | + throw new Exception(esc_html("Failed to register {$registerable->key} post type ({$th->getMessage()})")); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Register all meta data for post type. |
| 81 | - $this->register_meta_data( $registerable ); |
|
| 81 | + $this->register_meta_data($registerable); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -87,18 +87,18 @@ discard block |
||
| 87 | 87 | * @param \PinkCrab\Registerables\Post_Type $post_type |
| 88 | 88 | * @return void |
| 89 | 89 | */ |
| 90 | - protected function register_meta_data( Post_Type $post_type ): void { |
|
| 90 | + protected function register_meta_data(Post_Type $post_type): void { |
|
| 91 | 91 | |
| 92 | 92 | // Get all meta fields for post_type. |
| 93 | - $meta_fields = $post_type->meta_data( array() ); |
|
| 93 | + $meta_fields = $post_type->meta_data(array()); |
|
| 94 | 94 | // Attempt to register all Meta for post_type. |
| 95 | 95 | try { |
| 96 | - foreach ( $meta_fields as $meta_field ) { |
|
| 96 | + foreach ($meta_fields as $meta_field) { |
|
| 97 | 97 | $this->meta_data_registrar |
| 98 | - ->register_for_post_type( $meta_field, $post_type->key ); |
|
| 98 | + ->register_for_post_type($meta_field, $post_type->key); |
|
| 99 | 99 | } |
| 100 | - } catch ( \Throwable $th ) { |
|
| 101 | - throw new Exception( esc_html( $th->getMessage() ) ); |
|
| 100 | + } catch (\Throwable $th) { |
|
| 101 | + throw new Exception(esc_html($th->getMessage())); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -110,64 +110,64 @@ discard block |
||
| 110 | 110 | * @param \PinkCrab\Registerables\Post_Type $post_type |
| 111 | 111 | * @return array<string, string|int|array<string, string>> |
| 112 | 112 | */ |
| 113 | - protected function compile_args( Post_Type $post_type ): array { |
|
| 113 | + protected function compile_args(Post_Type $post_type): array { |
|
| 114 | 114 | // Create the labels. |
| 115 | 115 | $labels = array( |
| 116 | 116 | 'name' => $post_type->plural, |
| 117 | 117 | 'singular_name' => $post_type->singular, |
| 118 | - 'add_new' => _x( 'Add New', 'Add new post label of custom post type', 'pinkcrab' ), |
|
| 118 | + 'add_new' => _x('Add New', 'Add new post label of custom post type', 'pinkcrab'), |
|
| 119 | 119 | /* translators: %s: Post type singular name */ |
| 120 | - 'add_new_item' => wp_sprintf( _x( 'Add New %s', 'Label for adding a new singular item. Default is ‘Add New {post type singular name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 120 | + 'add_new_item' => wp_sprintf(_x('Add New %s', 'Label for adding a new singular item. Default is ‘Add New {post type singular name}’.', 'pinkcrab'), $post_type->singular), |
|
| 121 | 121 | /* translators: %s: Post type singular name */ |
| 122 | - 'edit_item' => wp_sprintf( _x( 'Edit %s', 'Label for editing a singular item. Default is ‘Edit {post type singular name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 122 | + 'edit_item' => wp_sprintf(_x('Edit %s', 'Label for editing a singular item. Default is ‘Edit {post type singular name}’.', 'pinkcrab'), $post_type->singular), |
|
| 123 | 123 | /* translators: %s: Post type singular name */ |
| 124 | - 'new_item' => wp_sprintf( _x( 'New %s', 'Label for the new item page title. Default is ‘New {post type singular name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 124 | + 'new_item' => wp_sprintf(_x('New %s', 'Label for the new item page title. Default is ‘New {post type singular name}’.', 'pinkcrab'), $post_type->singular), |
|
| 125 | 125 | /* translators: %s: Post type singular name */ |
| 126 | - 'view_item' => wp_sprintf( _x( 'View %s', 'Label for viewing a singular item. Default is ‘View {post type singular name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 126 | + 'view_item' => wp_sprintf(_x('View %s', 'Label for viewing a singular item. Default is ‘View {post type singular name}’.', 'pinkcrab'), $post_type->singular), |
|
| 127 | 127 | /* translators: %s: Post type plural name */ |
| 128 | - 'view_items' => wp_sprintf( _x( 'View %s', 'Label for viewing post type archives. Default is ‘View {post type plural name}’.', 'pinkcrab' ), $post_type->plural ), |
|
| 128 | + 'view_items' => wp_sprintf(_x('View %s', 'Label for viewing post type archives. Default is ‘View {post type plural name}’.', 'pinkcrab'), $post_type->plural), |
|
| 129 | 129 | /* translators: %s: Post type singular name */ |
| 130 | - 'search_items' => wp_sprintf( _x( 'Search %s', 'Label for searching plural items. Default is ‘Search {post type plural name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 130 | + 'search_items' => wp_sprintf(_x('Search %s', 'Label for searching plural items. Default is ‘Search {post type plural name}’.', 'pinkcrab'), $post_type->singular), |
|
| 131 | 131 | /* translators: %s: Post type plural name */ |
| 132 | - 'not_found' => wp_sprintf( _x( 'No %s found', 'Label used when no items are found. Default is ‘No {post type plural name} found’.', 'pinkcrab' ), $post_type->plural ), |
|
| 132 | + 'not_found' => wp_sprintf(_x('No %s found', 'Label used when no items are found. Default is ‘No {post type plural name} found’.', 'pinkcrab'), $post_type->plural), |
|
| 133 | 133 | /* translators: %s: Post type plural name */ |
| 134 | - 'not_found_in_trash' => wp_sprintf( _x( 'No %s found in Trash', 'Label used when no items are in the Trash. Default is ‘No {post type plural name} found in Trash’.', 'pinkcrab' ), $post_type->plural ), |
|
| 134 | + 'not_found_in_trash' => wp_sprintf(_x('No %s found in Trash', 'Label used when no items are in the Trash. Default is ‘No {post type plural name} found in Trash’.', 'pinkcrab'), $post_type->plural), |
|
| 135 | 135 | /* translators: %s: Post type singular name */ |
| 136 | - 'parent_item_colon' => wp_sprintf( _x( 'Parent %s:', 'Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is ‘Parent {post type plural name}:’.', 'pinkcrab' ), $post_type->singular ), |
|
| 136 | + 'parent_item_colon' => wp_sprintf(_x('Parent %s:', 'Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is ‘Parent {post type plural name}:’.', 'pinkcrab'), $post_type->singular), |
|
| 137 | 137 | /* translators: %s: Post type singular name */ |
| 138 | - 'all_items' => wp_sprintf( _x( 'All %s', 'Label to signify all items in a submenu link. Default is ‘All {post type plural name}’.', 'pinkcrab' ), $post_type->plural ), |
|
| 138 | + 'all_items' => wp_sprintf(_x('All %s', 'Label to signify all items in a submenu link. Default is ‘All {post type plural name}’.', 'pinkcrab'), $post_type->plural), |
|
| 139 | 139 | /* translators: %s: Post type plural name */ |
| 140 | - 'archives' => wp_sprintf( _x( '%s Archives', ' Label for archives in nav menus. Default is ‘Post Archives’.', 'pinkcrab' ), \ucfirst( $post_type->plural ) ), |
|
| 140 | + 'archives' => wp_sprintf(_x('%s Archives', ' Label for archives in nav menus. Default is ‘Post Archives’.', 'pinkcrab'), \ucfirst($post_type->plural)), |
|
| 141 | 141 | /* translators: %s: Post type plural name */ |
| 142 | - 'attributes' => wp_sprintf( _x( '%s Attributes', 'Label for the attributes meta box. Default is ‘{post type plural name} Attributes’.', 'pinkcrab' ), \ucfirst( $post_type->plural ) ), |
|
| 142 | + 'attributes' => wp_sprintf(_x('%s Attributes', 'Label for the attributes meta box. Default is ‘{post type plural name} Attributes’.', 'pinkcrab'), \ucfirst($post_type->plural)), |
|
| 143 | 143 | /* translators: %s: Post type singular name */ |
| 144 | - 'insert_into_item' => wp_sprintf( _x( 'Insert into %s', 'Label for the media frame button. Default is ‘Insert into {post type plural name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 144 | + 'insert_into_item' => wp_sprintf(_x('Insert into %s', 'Label for the media frame button. Default is ‘Insert into {post type plural name}’.', 'pinkcrab'), $post_type->singular), |
|
| 145 | 145 | /* translators: %s: Post type singular name */ |
| 146 | - 'uploaded_to_this_item' => wp_sprintf( _x( 'Uploaded to this %s', 'Label for the media frame filter. Default is ‘Uploaded to this {post type plural name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 147 | - 'featured_image' => _x( 'Featured image', 'Label for the featured image meta box title. Default is ‘Featured image’.', 'pinkcrab' ), |
|
| 148 | - 'set_featured_image' => _x( 'Set featured image', 'Label for setting the featured image. Default is ‘Set featured image’.', 'pinkcrab' ), |
|
| 149 | - 'remove_featured_image' => _x( 'Remove featured image', 'Label for removing the featured image. Default is ‘Remove featured image’.', 'pinkcrab' ), |
|
| 150 | - 'use_featured_image' => _x( 'Use as featured image', 'Label in the media frame for using a featured image. Default is ‘Use as featured image’.', 'pinkcrab' ), |
|
| 146 | + 'uploaded_to_this_item' => wp_sprintf(_x('Uploaded to this %s', 'Label for the media frame filter. Default is ‘Uploaded to this {post type plural name}’.', 'pinkcrab'), $post_type->singular), |
|
| 147 | + 'featured_image' => _x('Featured image', 'Label for the featured image meta box title. Default is ‘Featured image’.', 'pinkcrab'), |
|
| 148 | + 'set_featured_image' => _x('Set featured image', 'Label for setting the featured image. Default is ‘Set featured image’.', 'pinkcrab'), |
|
| 149 | + 'remove_featured_image' => _x('Remove featured image', 'Label for removing the featured image. Default is ‘Remove featured image’.', 'pinkcrab'), |
|
| 150 | + 'use_featured_image' => _x('Use as featured image', 'Label in the media frame for using a featured image. Default is ‘Use as featured image’.', 'pinkcrab'), |
|
| 151 | 151 | 'menu_name' => $post_type->plural, |
| 152 | 152 | /* translators: %s: Post type plural name */ |
| 153 | - 'filter_items_list' => wp_sprintf( _x( 'Filter %s list', 'Label for the table views hidden heading. Default is ‘Filter {post type plural name} list’.', 'pinkcrab' ), $post_type->plural ), |
|
| 154 | - 'filter_by_date' => _x( 'Filter by date', 'Label for the date filter in list tables. Default is ‘Filter by date’.', 'pinkcrab' ), |
|
| 153 | + 'filter_items_list' => wp_sprintf(_x('Filter %s list', 'Label for the table views hidden heading. Default is ‘Filter {post type plural name} list’.', 'pinkcrab'), $post_type->plural), |
|
| 154 | + 'filter_by_date' => _x('Filter by date', 'Label for the date filter in list tables. Default is ‘Filter by date’.', 'pinkcrab'), |
|
| 155 | 155 | /* translators: %s: Post type plural name */ |
| 156 | - 'items_list' => wp_sprintf( _x( '%s list', 'Label for the table hidden heading. Default is ‘{post type plural name} list’.', 'pinkcrab' ), \ucfirst( $post_type->plural ) ), |
|
| 156 | + 'items_list' => wp_sprintf(_x('%s list', 'Label for the table hidden heading. Default is ‘{post type plural name} list’.', 'pinkcrab'), \ucfirst($post_type->plural)), |
|
| 157 | 157 | /* translators: %s: Post type singular name */ |
| 158 | - 'item_published' => wp_sprintf( _x( '%s published', 'Label used when an item is published. Default is ‘{post type singular name} published’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ), |
|
| 158 | + 'item_published' => wp_sprintf(_x('%s published', 'Label used when an item is published. Default is ‘{post type singular name} published’.', 'pinkcrab'), \ucfirst($post_type->singular)), |
|
| 159 | 159 | /* translators: %s: Post type singular name */ |
| 160 | - 'item_published_privately' => wp_sprintf( _x( '%s published privately', 'Label used when an item is published with private visibility. Default is ‘{post type singular name} published privately.’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ), |
|
| 160 | + 'item_published_privately' => wp_sprintf(_x('%s published privately', 'Label used when an item is published with private visibility. Default is ‘{post type singular name} published privately.’.', 'pinkcrab'), \ucfirst($post_type->singular)), |
|
| 161 | 161 | /* translators: %s: Post type singular name */ |
| 162 | - 'item_reverted_to_draft' => wp_sprintf( _x( '%s reverted to draft', 'Label used when an item is switched to a draft. Default is ‘{post type singular name} reverted to draft’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ), |
|
| 162 | + 'item_reverted_to_draft' => wp_sprintf(_x('%s reverted to draft', 'Label used when an item is switched to a draft. Default is ‘{post type singular name} reverted to draft’.', 'pinkcrab'), \ucfirst($post_type->singular)), |
|
| 163 | 163 | /* translators: %s: Post type singular name */ |
| 164 | - 'item_scheduled' => wp_sprintf( _x( '%s scheduled', 'Label used when an item is scheduled for publishing. Default is ‘{post type singular name} scheduled.’ ', 'pinkcrab' ), \ucfirst( $post_type->singular ) ), |
|
| 164 | + 'item_scheduled' => wp_sprintf(_x('%s scheduled', 'Label used when an item is scheduled for publishing. Default is ‘{post type singular name} scheduled.’ ', 'pinkcrab'), \ucfirst($post_type->singular)), |
|
| 165 | 165 | /* translators: %s: Post type singular name */ |
| 166 | - 'item_updated' => wp_sprintf( _x( '%s updated', 'Label used when an item is updated. Default is ‘{post type singular name} updated.’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ), |
|
| 166 | + 'item_updated' => wp_sprintf(_x('%s updated', 'Label used when an item is updated. Default is ‘{post type singular name} updated.’.', 'pinkcrab'), \ucfirst($post_type->singular)), |
|
| 167 | 167 | /* translators: %s: Post type singular name */ |
| 168 | - 'item_link' => wp_sprintf( _x( '%s Link', 'Title for a navigation link block variation. Default is ‘{post type singular name} Link’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ), |
|
| 168 | + 'item_link' => wp_sprintf(_x('%s Link', 'Title for a navigation link block variation. Default is ‘{post type singular name} Link’.', 'pinkcrab'), \ucfirst($post_type->singular)), |
|
| 169 | 169 | /* translators: %s: Post type singular name */ |
| 170 | - 'item_link_description' => wp_sprintf( _x( 'A link to a %s', 'Description for a navigation link block variation. Default is ‘A link to a {post type singular name}’.', 'pinkcrab' ), $post_type->singular ), |
|
| 170 | + 'item_link_description' => wp_sprintf(_x('A link to a %s', 'Description for a navigation link block variation. Default is ‘A link to a {post type singular name}’.', 'pinkcrab'), $post_type->singular), |
|
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * @param Post_Type $cpt |
| 179 | 179 | * @return array<string, string> |
| 180 | 180 | */ |
| 181 | - $labels = apply_filters( Registerable_Hooks::POST_TYPE_LABELS, $post_type->filter_labels( $labels ), $post_type ); |
|
| 181 | + $labels = apply_filters(Registerable_Hooks::POST_TYPE_LABELS, $post_type->filter_labels($labels), $post_type); |
|
| 182 | 182 | |
| 183 | 183 | // Set the rewrite rules if not defined. |
| 184 | - if ( is_null( $post_type->rewrite ) ) { |
|
| 184 | + if (is_null($post_type->rewrite)) { |
|
| 185 | 185 | $post_type->rewrite = array( |
| 186 | 186 | 'slug' => $post_type->key, |
| 187 | 187 | 'with_front' => true, |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | // Set the meta cap based on its definition and if uses gutenberg. |
| 194 | 194 | // See https://github.com/Pink-Crab/Perique-Registerables/issues/66 |
| 195 | - if ( null === $post_type->map_meta_cap ) { |
|
| 195 | + if (null === $post_type->map_meta_cap) { |
|
| 196 | 196 | $meta_cap = $post_type->gutenberg ? true : false; |
| 197 | 197 | } else { |
| 198 | 198 | $meta_cap = $post_type->map_meta_cap ?? false; |
@@ -202,30 +202,30 @@ discard block |
||
| 202 | 202 | $args = array( |
| 203 | 203 | 'labels' => $labels, |
| 204 | 204 | 'description' => $post_type->description ?? $post_type->plural, |
| 205 | - 'hierarchical' => is_bool( $post_type->hierarchical ) ? $post_type->hierarchical : false, |
|
| 205 | + 'hierarchical' => is_bool($post_type->hierarchical) ? $post_type->hierarchical : false, |
|
| 206 | 206 | 'supports' => $post_type->supports, |
| 207 | - 'public' => is_bool( $post_type->public ) ? $post_type->public : true, |
|
| 208 | - 'show_ui' => is_bool( $post_type->show_ui ) ? $post_type->show_ui : true, |
|
| 209 | - 'show_in_menu' => is_bool( $post_type->show_in_menu ) ? $post_type->show_in_menu : true, |
|
| 210 | - 'show_in_admin_bar' => is_bool( $post_type->show_in_admin_bar ) ? $post_type->show_in_admin_bar : true, |
|
| 207 | + 'public' => is_bool($post_type->public) ? $post_type->public : true, |
|
| 208 | + 'show_ui' => is_bool($post_type->show_ui) ? $post_type->show_ui : true, |
|
| 209 | + 'show_in_menu' => is_bool($post_type->show_in_menu) ? $post_type->show_in_menu : true, |
|
| 210 | + 'show_in_admin_bar' => is_bool($post_type->show_in_admin_bar) ? $post_type->show_in_admin_bar : true, |
|
| 211 | 211 | 'menu_position' => $post_type->menu_position, |
| 212 | 212 | 'menu_icon' => $post_type->dashicon, |
| 213 | - 'show_in_nav_menus' => is_bool( $post_type->show_in_nav_menus ) ? $post_type->show_in_nav_menus : true, |
|
| 214 | - 'publicly_queryable' => is_bool( $post_type->publicly_queryable ) ? $post_type->publicly_queryable : true, |
|
| 215 | - 'exclude_from_search' => is_bool( $post_type->exclude_from_search ) ? $post_type->exclude_from_search : true, |
|
| 216 | - 'has_archive' => is_bool( $post_type->has_archive ) ? $post_type->has_archive : true, |
|
| 217 | - 'query_var' => is_bool( $post_type->query_var ) ? $post_type->query_var : false, |
|
| 218 | - 'can_export' => is_bool( $post_type->can_export ) ? $post_type->can_export : true, |
|
| 219 | - 'rewrite' => is_bool( $post_type->rewrite ) ? $post_type->rewrite : false, |
|
| 213 | + 'show_in_nav_menus' => is_bool($post_type->show_in_nav_menus) ? $post_type->show_in_nav_menus : true, |
|
| 214 | + 'publicly_queryable' => is_bool($post_type->publicly_queryable) ? $post_type->publicly_queryable : true, |
|
| 215 | + 'exclude_from_search' => is_bool($post_type->exclude_from_search) ? $post_type->exclude_from_search : true, |
|
| 216 | + 'has_archive' => is_bool($post_type->has_archive) ? $post_type->has_archive : true, |
|
| 217 | + 'query_var' => is_bool($post_type->query_var) ? $post_type->query_var : false, |
|
| 218 | + 'can_export' => is_bool($post_type->can_export) ? $post_type->can_export : true, |
|
| 219 | + 'rewrite' => is_bool($post_type->rewrite) ? $post_type->rewrite : false, |
|
| 220 | 220 | 'capability_type' => $post_type->capability_type, |
| 221 | 221 | 'capabilities' => $post_type->capabilities, |
| 222 | 222 | 'taxonomies' => $post_type->taxonomies, |
| 223 | - 'show_in_rest' => is_bool( $post_type->show_in_rest ) ? $post_type->show_in_rest : true, |
|
| 223 | + 'show_in_rest' => is_bool($post_type->show_in_rest) ? $post_type->show_in_rest : true, |
|
| 224 | 224 | 'rest_base' => $post_type->rest_base ?? $post_type->key, |
| 225 | - 'rest_controller_class' => \class_exists( $post_type->rest_controller_class ) ? $post_type->rest_controller_class : \WP_REST_Posts_Controller::class, |
|
| 226 | - 'delete_with_user' => \is_bool( $post_type->delete_with_user ) ? $post_type->delete_with_user : null, |
|
| 227 | - 'template' => \is_array( $post_type->template ) ? $post_type->template : array(), |
|
| 228 | - 'template_lock' => \is_string( $post_type->template_lock ) ? $post_type->template_lock : false, |
|
| 225 | + 'rest_controller_class' => \class_exists($post_type->rest_controller_class) ? $post_type->rest_controller_class : \WP_REST_Posts_Controller::class, |
|
| 226 | + 'delete_with_user' => \is_bool($post_type->delete_with_user) ? $post_type->delete_with_user : null, |
|
| 227 | + 'template' => \is_array($post_type->template) ? $post_type->template : array(), |
|
| 228 | + 'template_lock' => \is_string($post_type->template_lock) ? $post_type->template_lock : false, |
|
| 229 | 229 | 'map_meta_cap' => $meta_cap, |
| 230 | 230 | ); |
| 231 | 231 | |
@@ -239,6 +239,6 @@ discard block |
||
| 239 | 239 | * @return array<string, string|bool|int|null|array<string, string>> |
| 240 | 240 | */ |
| 241 | 241 | /* @phpstan-ignore-next-line, this is due to apply_filters type hints being wrong. */ |
| 242 | - return apply_filters( Registerable_Hooks::POST_TYPE_ARGS, $post_type->filter_args( $args ), $post_type ); |
|
| 242 | + return apply_filters(Registerable_Hooks::POST_TYPE_ARGS, $post_type->filter_args($args), $post_type); |
|
| 243 | 243 | } |
| 244 | 244 | } |
@@ -53,34 +53,34 @@ discard block |
||
| 53 | 53 | * @param Meta_Box $meta_box |
| 54 | 54 | * @return void |
| 55 | 55 | */ |
| 56 | - public function register( Meta_Box $meta_box ): void { |
|
| 56 | + public function register(Meta_Box $meta_box): void { |
|
| 57 | 57 | |
| 58 | - if ( ! $this->validator->verify_meta_box( $meta_box ) ) { |
|
| 58 | + if ( ! $this->validator->verify_meta_box($meta_box)) { |
|
| 59 | 59 | throw new Exception( |
| 60 | 60 | sprintf( |
| 61 | 61 | 'Failed validating meta box model(%s) with errors: %s', |
| 62 | - esc_html( get_class( $meta_box ) ), |
|
| 63 | - esc_html( join( ', ', $this->validator->get_errors() ) ) |
|
| 62 | + esc_html(get_class($meta_box)), |
|
| 63 | + esc_html(join(', ', $this->validator->get_errors())) |
|
| 64 | 64 | ) |
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Set the view using View, if not traditional callback supplied and a defined template. |
| 69 | - if ( ! \is_callable( $meta_box->view ) && is_string( $meta_box->view_template ) ) { |
|
| 70 | - $meta_box = $this->set_view_callback_from_renderable( $meta_box ); |
|
| 69 | + if ( ! \is_callable($meta_box->view) && is_string($meta_box->view_template)) { |
|
| 70 | + $meta_box = $this->set_view_callback_from_renderable($meta_box); |
|
| 71 | 71 | } |
| 72 | - if ( \is_callable( $meta_box->view ) ) { |
|
| 73 | - $meta_box = $this->set_view_callback_from_callable( $meta_box ); |
|
| 72 | + if (\is_callable($meta_box->view)) { |
|
| 73 | + $meta_box = $this->set_view_callback_from_callable($meta_box); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Add meta_box to loader. |
| 77 | 77 | $this->loader->action( |
| 78 | 78 | 'add_meta_boxes', |
| 79 | - function () use ( $meta_box ): void { |
|
| 79 | + function() use ($meta_box): void { |
|
| 80 | 80 | \add_meta_box( |
| 81 | 81 | $meta_box->key, |
| 82 | 82 | $meta_box->label, |
| 83 | - $meta_box->view ?? fn( $e ) => '', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
|
| 83 | + $meta_box->view ?? fn($e) => '', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
|
| 84 | 84 | /*** |
| 85 | 85 | * @phpstan-ignore-line, is validated above |
| 86 | 86 | */ |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | // Deffer adding meta box hooks until we can asses the current screen. |
| 96 | 96 | $this->loader->action( |
| 97 | 97 | 'current_screen', |
| 98 | - function () use ( $meta_box ) { |
|
| 98 | + function() use ($meta_box) { |
|
| 99 | 99 | // If we have any hook calls, add them to the loader. |
| 100 | - if ( $this->is_active( $meta_box ) && ! empty( $meta_box->actions ) ) { |
|
| 101 | - foreach ( $meta_box->actions as $handle => $hook ) { |
|
| 102 | - add_action( (string) $handle, $hook['callback'], $hook['priority'], $hook['params'] ); |
|
| 100 | + if ($this->is_active($meta_box) && ! empty($meta_box->actions)) { |
|
| 101 | + foreach ($meta_box->actions as $handle => $hook) { |
|
| 102 | + add_action((string) $handle, $hook['callback'], $hook['priority'], $hook['params']); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -112,21 +112,21 @@ discard block |
||
| 112 | 112 | * @param \PinkCrab\Registerables\Meta_Box $meta_box |
| 113 | 113 | * @return \PinkCrab\Registerables\Meta_Box |
| 114 | 114 | */ |
| 115 | - protected function set_view_callback_from_callable( Meta_Box $meta_box ): Meta_Box { |
|
| 115 | + protected function set_view_callback_from_callable(Meta_Box $meta_box): Meta_Box { |
|
| 116 | 116 | |
| 117 | 117 | // Get the current view callback. |
| 118 | 118 | $current_callback = $meta_box->view; |
| 119 | 119 | |
| 120 | 120 | $meta_box->view( |
| 121 | - function ( \WP_Post $post, array $args ) use ( $meta_box, $current_callback ) { |
|
| 121 | + function(\WP_Post $post, array $args) use ($meta_box, $current_callback) { |
|
| 122 | 122 | |
| 123 | 123 | // Set the view args |
| 124 | 124 | $args['args']['post'] = $post; |
| 125 | - $args['args'] = $this->filter_view_args( $meta_box, $post, $args['args'] ); |
|
| 125 | + $args['args'] = $this->filter_view_args($meta_box, $post, $args['args']); |
|
| 126 | 126 | |
| 127 | 127 | // Render the callback. |
| 128 | - if ( \is_callable( $current_callback ) ) { |
|
| 129 | - call_user_func( $current_callback, $post, $args ); |
|
| 128 | + if (\is_callable($current_callback)) { |
|
| 129 | + call_user_func($current_callback, $post, $args); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | ); |
@@ -140,22 +140,22 @@ discard block |
||
| 140 | 140 | * @param \PinkCrab\Registerables\Meta_Box $meta_box |
| 141 | 141 | * @return \PinkCrab\Registerables\Meta_Box |
| 142 | 142 | */ |
| 143 | - protected function set_view_callback_from_renderable( Meta_Box $meta_box ): Meta_Box { |
|
| 143 | + protected function set_view_callback_from_renderable(Meta_Box $meta_box): Meta_Box { |
|
| 144 | 144 | |
| 145 | 145 | // Create View(View) |
| 146 | - $view = $this->container->create( View::class ); |
|
| 147 | - if ( is_null( $view ) || ! is_a( $view, View::class ) ) { |
|
| 148 | - throw new Exception( 'View not defined' ); |
|
| 146 | + $view = $this->container->create(View::class); |
|
| 147 | + if (is_null($view) || ! is_a($view, View::class)) { |
|
| 148 | + throw new Exception('View not defined'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $meta_box->view( |
| 152 | - function ( \WP_Post $post, array $args ) use ( $meta_box, $view ) { |
|
| 152 | + function(\WP_Post $post, array $args) use ($meta_box, $view) { |
|
| 153 | 153 | |
| 154 | 154 | $args['args']['post'] = $post; |
| 155 | - $args['args'] = $this->filter_view_args( $meta_box, $post, $args['args'] ); |
|
| 155 | + $args['args'] = $this->filter_view_args($meta_box, $post, $args['args']); |
|
| 156 | 156 | |
| 157 | 157 | // @phpstan-ignore-next-line, template should already be checked for valid template path in register() method (which calls this) |
| 158 | - $view->render( $meta_box->view_template, $args['args'] ); |
|
| 158 | + $view->render($meta_box->view_template, $args['args']); |
|
| 159 | 159 | } |
| 160 | 160 | ); |
| 161 | 161 | |
@@ -167,12 +167,12 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @return boolean |
| 169 | 169 | */ |
| 170 | - protected function is_active( Meta_Box $meta_box ): bool { |
|
| 170 | + protected function is_active(Meta_Box $meta_box): bool { |
|
| 171 | 171 | global $current_screen; |
| 172 | 172 | |
| 173 | - return ! is_null( $current_screen ) |
|
| 174 | - && ! empty( $current_screen->post_type ) |
|
| 175 | - && in_array( $current_screen->post_type, $meta_box->screen, true ); |
|
| 173 | + return ! is_null($current_screen) |
|
| 174 | + && ! empty($current_screen->post_type) |
|
| 175 | + && in_array($current_screen->post_type, $meta_box->screen, true); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -183,9 +183,9 @@ discard block |
||
| 183 | 183 | * @param array<string, mixed> $view_args |
| 184 | 184 | * @return array<string, mixed> |
| 185 | 185 | */ |
| 186 | - public function filter_view_args( Meta_Box $meta_box, \WP_Post $post, array $view_args ): array { |
|
| 187 | - if ( is_callable( $meta_box->view_data_filter ) ) { |
|
| 188 | - $view_args = ( $meta_box->view_data_filter )( $post, $view_args ); |
|
| 186 | + public function filter_view_args(Meta_Box $meta_box, \WP_Post $post, array $view_args): array { |
|
| 187 | + if (is_callable($meta_box->view_data_filter)) { |
|
| 188 | + $view_args = ($meta_box->view_data_filter)($post, $view_args); |
|
| 189 | 189 | } |
| 190 | 190 | return $view_args; |
| 191 | 191 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * @param \PinkCrab\Registerables\Module\Middleware\Registerable $registerable |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | - public function register( Registerable $registerable ): void { |
|
| 55 | - if ( ! is_a( $registerable, Shared_Meta_Box_Controller::class ) ) { |
|
| 54 | + public function register(Registerable $registerable): void { |
|
| 55 | + if ( ! is_a($registerable, Shared_Meta_Box_Controller::class)) { |
|
| 56 | 56 | return; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // Get the meta box and meta data. |
| 62 | 62 | $meta_box = $registerable->meta_box(); |
| 63 | - $meta_data = $registerable->meta_data( array() ); |
|
| 63 | + $meta_data = $registerable->meta_data(array()); |
|
| 64 | 64 | |
| 65 | 65 | // Register the meta box. |
| 66 | - $this->meta_box_registrar->register( $meta_box ); |
|
| 66 | + $this->meta_box_registrar->register($meta_box); |
|
| 67 | 67 | |
| 68 | 68 | // Register all meta data. |
| 69 | - foreach ( $this->filter_meta_data( $meta_data ) as $meta_field ) { |
|
| 69 | + foreach ($this->filter_meta_data($meta_data) as $meta_field) { |
|
| 70 | 70 | // Register meta data for each post type. |
| 71 | - foreach ( $meta_box->screen as $post_type ) { |
|
| 72 | - $this->meta_data_registrar->register_for_post_type( $meta_field, $post_type ); |
|
| 71 | + foreach ($meta_box->screen as $post_type) { |
|
| 72 | + $this->meta_data_registrar->register_for_post_type($meta_field, $post_type); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @param mixed[] $meta_data |
| 81 | 81 | * @return Meta_Data[] |
| 82 | 82 | */ |
| 83 | - protected function filter_meta_data( array $meta_data ): array { |
|
| 83 | + protected function filter_meta_data(array $meta_data): array { |
|
| 84 | 84 | return array_filter( |
| 85 | 85 | $meta_data, |
| 86 | - function ( $e ) { |
|
| 87 | - return is_a( $e, Meta_Data::class ); |
|
| 86 | + function($e) { |
|
| 87 | + return is_a($e, Meta_Data::class); |
|
| 88 | 88 | } |
| 89 | 89 | ); |
| 90 | 90 | } |