150 | | $docs_link = ''; |
151 | | if ( 'check' === substr( $item->check_name, 0, 5 ) ) { |
152 | | $docs_link = "<a href='help#{$item->check_name}'>" . __( 'More about this.', 'wporg-plugins' ) . '</a>'; |
| 157 | // Only get details if this is a warning or error. |
| 158 | $details = ( 'info' === $type ) ? false : self::get_detailed_help( $item->check_name ); |
| 159 | if ( $details ) { |
| 160 | $details = '<p>' . implode( '</p><p>', (array) $details ) . '</p>'; |
| 161 | $output .= "<details class='{$item->check_name}'><summary>{$item->message}</summary>{$details}</details>"; |
| 162 | } else { |
| 163 | $output .= "<p>{$item->message}</p>"; |
156 | | $output .= "</ul>\n"; |
| 166 | // Collapse block.json warnings into one details at the end of warnings list. |
| 167 | if ( 'warning' === $type && ! empty( $block_json_issues ) ) { |
| 168 | $messages = wp_list_pluck( $block_json_issues, 'message' ); |
| 169 | $details = '<p>' . implode( '</p><p>', (array) $messages ) . '</p>'; |
| 170 | $output .= sprintf( |
| 171 | '<details class="check_block_json_is_valid"><summary>%1$s</summary>%2$s</details>', |
| 172 | __( 'Issues found in block.json file.', 'wporg-plugins' ), |
| 173 | $details |
| 174 | ); |
| 175 | } |
| 187 | |
| 188 | /** |
| 189 | * Get a more detailed help message for a given check. |
| 190 | * |
| 191 | * @param string $method The name of the check method. |
| 192 | * |
| 193 | * @return string|array More details for a given block issue. Array of strings if there should be a linebreak. |
| 194 | */ |
| 195 | public static function get_detailed_help( $method ) { |
| 196 | switch ( $method ) { |
| 197 | // These don't need more details. |
| 198 | case 'check_readme_exists': |
| 199 | case 'check_license': |
| 200 | case 'check_plugin_headers': |
| 201 | return false; |
| 202 | // This is a special case, since multiple values may be collapsed. |
| 203 | case 'check_block_json_is_valid': |
| 204 | return false; |
| 205 | case 'check_block_tag': |
| 206 | return __( 'The readme.txt file must contain the tag "block" for this to be added to the block directory.', 'wporg-plugins' ); |
| 207 | case 'check_for_duplicate_block_name': |
| 208 | return [ |
| 209 | __( "Block names must be unique, otherwise it can cause problems when using the block. It is recommended to use your plugin's name as the namespace.", 'wporg-plugins' ), |
| 210 | '<em>' . __( 'If this is a different version of your own plugin, you can ignore this warning.', 'wporg-plugins' ) . '</em>', |
| 211 | ]; |
| 212 | case 'check_for_blocks': |
| 213 | return [ |
| 214 | __( 'In order to work in the Block Directory, a plugin must register a block. Generally one per plugin (multiple blocks may be permitted if those blocks are interdependent, such as a list block that contains list item blocks).', 'wporg-plugins' ), |
| 215 | __( 'If your plugin doesn’t register a block, it probably belongs in the main Plugin Directory rather than the Block Directory.', 'wporg-plugins' ), |
| 216 | sprintf( '<a href="TUTORIAL">%s</a>', __( 'Learn how to create a block.' ) ), |
| 217 | ]; |
| 218 | case 'check_for_block_json': |
| 219 | return __( 'Your plugin should contain at least one <code>block.json</code> file. This file contains metadata describing the block and its JavaScript and CSS assets. Make sure you include at least one <code>script</code> or <code>editorScript</code> item.', 'wporg-plugins' ); |
| 220 | case 'check_for_block_scripts': |
| 221 | return 'TODO'; |
| 222 | case 'check_for_block_script_files': |
| 223 | return 'TODO'; |
| 224 | case 'check_for_register_block_type': |
| 225 | return __( 'At least one of your JavaScript files must explicitly call registerBlockType(). Without that call, your block will not work in the editor.', 'wporg-plugins' ); |
| 226 | case 'check_block_json_is_valid_json': |
| 227 | return __( 'This block.json file is invalid. The Block Directory needs to be able to read this file.', 'wporg-plugins' ); |
| 228 | case 'check_asset_php_file': |
| 229 | return 'TODO'; // Is this really an issue? |
| 230 | case 'check_php_size': |
| 231 | return __( 'Block plugins should keep the PHP code to a mimmum. If you need a lot of PHP code, your plugin probably belongs in the main Plugin Directory rather than the Block Directory.', 'wporg-plugins' ); |
| 232 | } |
| 233 | } |