Conditions | 5 |
Paths | 7 |
Total Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | function enqueue_block_editor_assets() { |
||
34 | |||
35 | if ( !apply_filters( 'foogallery_gutenberg_enabled', true ) ) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | //enqueue foogallery dependencies |
||
40 | wp_enqueue_script( 'masonry' ); |
||
41 | foogallery_enqueue_core_gallery_template_script(); |
||
42 | foogallery_enqueue_core_gallery_template_style(); |
||
43 | |||
44 | $deps = array( |
||
45 | 'wp-blocks', |
||
46 | 'wp-i18n', |
||
47 | 'wp-element', |
||
48 | 'foogallery-core', |
||
49 | 'wp-components', |
||
50 | 'wp-editor', |
||
51 | 'underscore' |
||
52 | ); |
||
53 | |||
54 | $js_url = plugins_url( 'gutenberg/dist/blocks.build.js', dirname( __FILE__ ) ); |
||
55 | |||
56 | // Scripts. |
||
57 | wp_enqueue_script( |
||
58 | 'foogallery-block-js', // Handle. |
||
59 | $js_url, // Block.build.js: We register the block here. Built with Webpack. |
||
60 | $deps, // Dependencies, defined above. |
||
61 | // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: filemtime — Gets file modification time. |
||
62 | true // Enqueue the script in the footer. |
||
63 | ); |
||
64 | |||
65 | // Styles. |
||
66 | wp_enqueue_style( |
||
67 | 'foogallery-block-editor-css', // Handle. |
||
68 | plugins_url( 'gutenberg/dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS. |
||
69 | array( 'wp-edit-blocks', 'foogallery-core' ) // Dependency to include the CSS after it. |
||
70 | // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: filemtime — Gets file modification time. |
||
71 | ); |
||
72 | |||
73 | $local_data = false; |
||
74 | |||
75 | if ( function_exists( 'wp_get_jed_locale_data' ) ) { |
||
76 | $local_data = wp_get_jed_locale_data( 'foogallery' ); |
||
77 | } else if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) { |
||
78 | $local_data = gutenberg_get_jed_locale_data( 'foogallery' ); |
||
79 | } |
||
80 | |||
81 | if ( false !== $local_data ) { |
||
82 | |||
83 | /* |
||
84 | * Pass already loaded translations to our JavaScript. |
||
85 | * |
||
86 | * This happens _before_ our JavaScript runs, afterwards it's too late. |
||
87 | */ |
||
88 | wp_add_inline_script( |
||
89 | 'foogallery-block-js', |
||
90 | 'wp.i18n.setLocaleData( ' . json_encode( $local_data ) . ', "foogallery" );', |
||
91 | 'before' |
||
92 | ); |
||
93 | } |
||
94 | } |
||
95 | |||
160 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.