wp-bootstrap/wp-bootstrap-loader

View on GitHub
wp-bootstrap-loader.php

Summary

Maintainability
A
0 mins
Test Coverage
Class file names should be based on the class name with "class-" prepended. Expected class-wp-bootstrap-loader.php, but found wp-bootstrap-loader.php.
<?php
/**
* WP Bootstrap Loader
*
* @package wp-bootstrap-loader
*/
 
Found precision alignment of 1 spaces.
/*
* Plugin Name: WP Bootstrap Loader
* Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-loader
* Version: 2.0.5
* Description: A WordPress class to load Bootstrap and FontAwesome stylesheets and scripts.
* Author: WP-Bootstrap
* Author URI: https://github.com/wp-bootstrap
* GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-loader
* GitHub Branch: master
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*/
 
// Exit if accessed directly.
Newline required after opening brace
if ( ! defined( 'ABSPATH' ) ) { exit; }
 
if ( ! class_exists( 'WP_Bootstrap_Loader' ) ) {
 
/**
* WP_Bootstrap_Loader class.
*/
The class WP_Bootstrap_Loader is not named in CamelCase.
class WP_Bootstrap_Loader {
 
/**
* Construct
*
* @access public
* @return void
*/
Visibility must be declared on method "__construct"
function __construct() {
 
// Load Bootstrap Scripts.
add_action( 'wp_enqueue_scripts', array( $this, 'bootstrap_scripts' ) );
 
// Async & Defer.
Expected 1 spaces before closing bracket; 0 found
add_filter( 'script_loader_tag', array( $this, 'bootstrap_async' ), 10, 2);
Expected 1 spaces before closing bracket; 0 found
add_filter( 'script_loader_tag', array( $this, 'jquery_migrate_async' ), 10, 3);
 
// Load Bootstrap for WordPress Editor.
add_action( 'admin_init', array( $this, 'bootstrap_editor_css' ) );
}
/**
* Bootstrap Async and Defer.
*
* @access public
* @param mixed $tag Tag.
* @param mixed $handle Handle.
Function return type is void, but function contains return statement
* @return void
*/
Expected 1 spaces between opening bracket and argument "$tag"; 0 found
No space before closing parenthesis is prohibited
No space after opening parenthesis is prohibited
Visibility must be declared on method "bootstrap_async"
function bootstrap_async($tag, $handle) {
Inline control structures are not allowed
if ( 'bootstrap' !== $handle )
return $tag;
return str_replace( ' src', ' async="async" src', $tag );
}
 
/**
Doc comment short description must start with a capital letter
* jquery_migrate_async function.
*
* @access public
* @param mixed $tag Tag.
* @param mixed $handle Handle.
Function return type is void, but function contains return statement
* @return void
*/
Visibility must be declared on method "jquery_migrate_async"
function jquery_migrate_async( $tag, $handle ) {
Inline control structures are not allowed
if ( 'jquery-migrate' !== $handle )
return $tag;
return str_replace( ' src', ' defer="defer" src', $tag );
}
 
/**
* Loads Bootstrap & Font Awesome Stylesheet & Scripts.
*
* @access public
* @return void
*/
Visibility must be declared on method "bootstrap_scripts"
function bootstrap_scripts() {
if ( ! is_admin() ) {
// Twitter Bootstrap CSS.
Resource version not set in call to wp_register_style(). This means new versions of the style will not always be loaded due to browser caching.
wp_register_style( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', '', null, 'all' );
wp_enqueue_style( 'bootstrap' );
// Load jQuery.
wp_enqueue_script( 'jquery' );
// Twitter Bootstrap Javascript.
Resource version not set in call to wp_register_script(). This means new versions of the script will not always be loaded due to browser caching.
wp_register_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', 'jquery', null, true );
wp_enqueue_script( 'bootstrap' );
// Google Webfont.
Resource version not set in call to wp_register_script(). This means new versions of the script will not always be loaded due to browser caching.
wp_register_script( 'webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', null, null, true );
wp_enqueue_script( 'webfont' );
// Load Font Awesome via Google Webfont.
wp_add_inline_script( 'webfont', 'WebFont.load({custom:{families:["font-awesome"],urls:["https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"]}});' );
}
}
/**
* Loads Bootstrap & Font-Awesome CSS in WordPress editor.
*
* @access public
* @return void
*/
Visibility must be declared on method "bootstrap_editor_css"
function bootstrap_editor_css() {
// Support Custom Editor CSS.
add_editor_style( array(
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
));
}
}
}
Parenthesis should always be used when instantiating a new object.
new WP_Bootstrap_Loader;