First, make sure you have Composer installed in your system.
In order to use the WPCS you'll need the PHP_CodeSniffer (PHPCS) and the WPCS rules (sniffs) installed.
You can install PHP_CodeSniffer globally using Composer by running this command:
| <?php | |
| use PhpCsFixer\Config; | |
| use PhpCsFixer\Finder; | |
| $rules = [ | |
| 'array_indentation' => true, | |
| 'array_syntax' => ['syntax' => 'short'], | |
| 'binary_operator_spaces' => [ | |
| 'default' => 'single_space', |
First, make sure you have Composer installed in your system.
In order to use the WPCS you'll need the PHP_CodeSniffer (PHPCS) and the WPCS rules (sniffs) installed.
You can install PHP_CodeSniffer globally using Composer by running this command:
| <?php | |
| /** | |
| * Plugin Name: Block — Hi Test | |
| * Description: The shortest possible example PHP-rendered WordPress block. | |
| * Author: Paul Clark | |
| * Author URI: https://pdclark.com | |
| * | |
| * @package hi | |
| */ |
| <?php | |
| /** | |
| * Plugin Name: Pods — Block | |
| * Description: Gutenberg block to wrap the `[pods]` shortcode. | |
| * Author: Paul Clark | |
| * Author URI: https://pdclark.com | |
| * Plugin URI: https://pd.cm/pods-block | |
| * Version: 28 | |
| * | |
| * @package pd |
| <?php | |
| /** | |
| * Plugin Name: PD Blocks — Example OOP with attributes | |
| * Description: Single-file OOP PHP-rendered WordPress blocks with 5 example blocks. | |
| * Author: Paul David Clark | |
| * Author URI: https://pd.cm | |
| * Plugin URI: https://pd.cm/oop-blocks | |
| * Version: 30 | |
| * | |
| * @package pd |
| // color customizations for Nord | |
| "editor.tokenColorCustomizations": { | |
| "textMateRules": [ | |
| { | |
| "settings": { | |
| "foreground": "#d1d5dc", | |
| "background": "#2f343f" | |
| } | |
| }, | |
| { |
| <?php | |
| add_filter( 'the_content', 'crd_append_post_links' ); | |
| function crd_append_post_links( $content ) { | |
| if ( is_page() ) { | |
| $post_links_data = get_post_meta( get_the_ID() ); | |
| if ( isset( $post_links_data[ 'blog_group' ][ 0 ] ) ) { | |
| $blog_list = maybe_unserialize( $post_links_data[ 'blog_group' ][ 0 ] ); | |
| $posts_list = '<ul>'; | |
| foreach ( $blog_list as $post_info ) { |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.