Completed
Branch dev (0b2b90)
by Eric
01:41
created

functions.php ➔ bitsy_setup()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 88
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 33
nc 1
nop 0
dl 0
loc 88
rs 8.6012
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * bitsy functions and definitions.
4
 *
5
 * Set up the theme and provides some helper functions, which are used in the
6
 * theme as custom template tags. Others are attached to action and filter
7
 * hooks in WordPress to change core functionality.
8
 *
9
 * When using a child theme you can override certain functions (those wrapped
10
 * in a function_exists() call) by defining them first in your child theme's
11
 * functions.php file. The child theme's functions.php file is included before
12
 * the parent theme's file, so the child theme functions would be used.
13
 *
14
 * @link https://codex.wordpress.org/Theme_Development
15
 * @link https://codex.wordpress.org/Child_Themes
16
 *
17
 * Functions that are not pluggable (not wrapped in function_exists()) are
18
 * instead attached to a filter or action hook.
19
 *
20
 * For more information on hooks, actions, and filters,
21
 * {@link https://codex.wordpress.org/Plugin_API}
22
 * 
23
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
24
 *
25
 * @package bitsy
26
 */
27
28
if ( ! function_exists( 'bitsy_setup' ) ) :
0 ignored issues
show
Coding Style introduced by
Please always use braces to surround the code block of IF statements.
Loading history...
29
/**
30
 * Sets up theme defaults and registers support for various WordPress features.
31
 *
32
 * Note that this function is hooked into the after_setup_theme hook, which
33
 * runs before the init hook. The init hook is too late for some features, such
34
 * as indicating support for post thumbnails.
35
 */
36
function bitsy_setup() {
37
	/*
38
	 * Make theme available for translation.
39
	 * Translations can be filed in the /languages/ directory.
40
	 * If you're building a theme based on bitsy, use a find and replace
41
	 * to change 'bitsy' to the name of your theme in all the template files.
42
	 */
43
	load_theme_textdomain( 'bitsy', get_template_directory() . '/languages' );
44
45
	// Add default posts and comments RSS feed links to head.
46
	add_theme_support( 'automatic-feed-links' );
47
48
	/*
49
	 * Let WordPress manage the document title.
50
	 * By adding theme support, we declare that this theme does not use a
51
	 * hard-coded <title> tag in the document head, and expect WordPress to
52
	 * provide it for us.
53
	 */
54
	add_theme_support( 'title-tag' );
55
56
	/*
57
	 * Enable support for Post Thumbnails on posts and pages.
58
	 *
59
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
60
	 */
61
	add_theme_support( 'post-thumbnails' );
62
63
	// This theme uses wp_nav_menu() in one location.
64
	register_nav_menus( array(
65
		'primary' => esc_html__( 'Primary', 'bitsy' ),
66
		'social'  => __( 'Social Links Menu', 'bitsy' )
67
	) );
68
69
	/*
70
	 * Switch default core markup for search form, comment form, and comments
71
	 * to output valid HTML5.
72
	 */
73
	add_theme_support( 'html5', array(
74
		'search-form',
75
		'comment-form',
76
		'comment-list',
77
		'gallery',
78
		'caption',
79
	) );
80
81
	// Set up the WordPress core custom background feature.
82
	add_theme_support( 'custom-background', apply_filters( 'bitsy_custom_background_args', array(
83
		'default-color' => 'ffffff',
84
		'default-image' => '',
85
	) ) );
86
87
	/*
88
	 * Enable support for Post Formats.
89
	 *
90
	 * See: https://codex.wordpress.org/Post_Formats
91
	 */
92
	add_theme_support( 'post-formats', array(
93
		'aside',
94
		'image',
95
		'video',
96
		'quote',
97
		'link',
98
		'gallery',
99
		'status',
100
		'audio',
101
		'chat',
102
	) );
103
	/*
104
	 * This theme styles the visual editor to resemble the theme style,
105
	 * specifically font, colors, icons, and column width.
106
	 */
107
	//add_editor_style( array( 'css/editor-style.css', bitsy_fonts_url() ) );
108
109
	// Add theme support for selective refresh for widgets.
110
	add_theme_support( 'customize-selective-refresh-widgets' );
111
112
	/**
113
	 * Add support for core custom logo.
114
	 *
115
	 * @link https://codex.wordpress.org/Theme_Logo
116
	 */
117
	add_theme_support( 'custom-logo', array(
118
		'height'      => 250,
119
		'width'       => 250,
120
		'flex-width'  => true,
121
		'flex-height' => true,
122
	) );
123
}
124
endif; // bitsy_setup
125
add_action( 'after_setup_theme', 'bitsy_setup' );
126
127
/**
128
 * Set the content width in pixels, based on the theme's design and stylesheet.
129
 *
130
 * Priority 0 to make it available to lower priority callbacks.
131
 *
132
 * @global int $content_width
133
 */
134
function bitsy_content_width() {
0 ignored issues
show
Coding Style introduced by
bitsy_content_width uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
135
	$GLOBALS['content_width'] = apply_filters( 'bitsy_content_width', 640 );
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
136
}
137
add_action( 'after_setup_theme', 'bitsy_content_width', 0 );
138
139
/**
140
 * Register widget area.
141
 *
142
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
143
 */
144
require get_template_directory() . '/inc/widgets.php';
145
146
/**
147
 * Enqueue scripts and styles.
148
 */
149
require get_template_directory() . '/inc/enqueue.php';
150
151
/**
152
 * Load the theme wrapper.
153
 */
154
require get_template_directory() . '/inc/theme-wrapper.php';
155
156
/**
157
 * Implement the Custom Header feature.
158
 */
159
require get_template_directory() . '/inc/custom-header.php';
160
161
/**
162
 * Custom template tags for this theme.
163
 */
164
require get_template_directory() . '/inc/template-tags.php';
165
166
/**
167
 * Custom functions that act independently of the theme templates.
168
 */
169
require get_template_directory() . '/inc/extras.php';
170
171
/**
172
 * Customizer additions.
173
 */
174
require get_template_directory() . '/inc/customizer.php';
175
176
/**
177
 * Load Jetpack compatibility file.
178
 */
179
if ( defined( 'JETPACK__VERSION' ) ) {
180
	require get_template_directory() . '/inc/jetpack.php';
181
}
182
183
/**
184
 * Load WooCommerce compatibility file.
185
 */
186
if ( class_exists( 'WooCommerce' ) ) {
187
	require get_template_directory() . '/inc/woocommerce.php';
188
}
189