Skip to content

Commit ec5261b

Browse files
committed
Added loading Font Awesome based on plugin settings (as example)
1 parent 6f901eb commit ec5261b

4 files changed

Lines changed: 48 additions & 24 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ It may also be used as the means of [separating custom code](http://www.billeric
1111
### Clone Repository
1212

1313
1. At command prompt, change to your `wp-content/plugins` directory.
14-
2. Clone the repository: `git clone https://github.com/dmhendricks/wordpress-base-plugin.git`
15-
3. `cd wordpress-base-plugin`
16-
4. `composer install`
14+
1. Close the repository: `git clone https://github.com/dmhendricks/wordpress-base-plugin.git`
15+
16+
### Composer
17+
18+
1. Modify `composer.json` to suit your needs
19+
1. Run `composer install` to install dependencies and autoload namespace
1720

1821
## Planned Features
1922

@@ -34,6 +37,7 @@ It may also be used as the means of [separating custom code](http://www.billeric
3437
#### 0.2.0
3538

3639
* Added experimental Cache class
40+
* Added example of loading Font Awesome if enabled in plugin settings
3741
* Removed `./vendor` from repo
3842
* Renamed Helpers Class to Utils
3943
* Tested PHP 5.3 - 7.1 compatibility

app/Core.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ function __construct() {
99
add_filter( 'body_class', array(&$this, 'add_body_classes') );
1010

1111
// Remove Emoji code from header
12-
if(!$this->is_ajax()) add_filter( 'init', array(&$this, 'disable_wp_emojicons') );
12+
if( carbon_get_theme_option( self::$prefix.'remove_header_emojicons') ) {
13+
if(!$this->is_ajax()) add_filter( 'init', array( $this, 'disable_wp_emojicons' ) );
14+
}
1315

1416
}
1517

app/EnqueueScripts.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@ class EnqueueScripts extends Plugin {
55

66
function __construct() {
77

8-
add_action( 'wp_loaded', function() {
9-
$this->enqueue_frontend_scripts();
10-
$this->enqueue_admin_scripts();
11-
});
8+
// Enqueue frontend and backend scripts
9+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts') );
10+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts') );
11+
12+
// Load Font Awesome from CDN, if enabled
13+
$enqueue_font_awesome = carbon_get_theme_option( self::$prefix.'enqueue_font_awesome' );
14+
if( $enqueue_font_awesome ) {
15+
if( in_array( 'frontend', $enqueue_font_awesome) )
16+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_font_awesome') );
17+
if( in_array( 'backend', $enqueue_font_awesome) )
18+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_font_awesome') );
19+
}
1220

1321
}
1422

1523
/**
1624
* Enqueue scripts used on frontend of site
1725
*/
18-
private function enqueue_frontend_scripts() {
26+
public function enqueue_frontend_scripts() {
1927

2028
// Example enqueuing remote scripts (http://select2.github.io/)
2129
wp_enqueue_style( 'select2', '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css', null, '4.0.3' );
@@ -32,15 +40,18 @@ private function enqueue_frontend_scripts() {
3240
/**
3341
* Enqueue scripts used in WP admin interface
3442
*/
35-
private function enqueue_admin_scripts() {
36-
37-
// Only load script(s) on edit pages
38-
// if( strstr($_SERVER['REQUEST_URI'], '/post-new.php') || strstr($_SERVER['REQUEST_URI'], '/post.php') ) {
39-
add_action( 'admin_enqueue_scripts', function() {
40-
// Load custom JavaScript in admin
41-
wp_enqueue_script( 'wordpress-base-plugin', plugins_url('/assets/js/wordpress-base-admin.js', dirname(__FILE__)) );
42-
});
43-
//}
43+
public function enqueue_admin_scripts() {
44+
45+
wp_enqueue_script( 'wordpress-base-plugin', $this->get_script_url('assets/js/wordpress-base-admin.js'), array('jquery'), $this->get_script_version('assets/js/wordpress-base-admin.js') );
46+
47+
}
48+
49+
/**
50+
* Enqueue Font Awesome
51+
*/
52+
public function enqueue_font_awesome() {
53+
54+
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', null, '4.7.0' );
4455

4556
}
4657

app/Settings.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@ function __construct() {
1414
Container::make('theme_options', self::$settings['data']['Name'])
1515
->set_page_parent('options-general.php')
1616
->add_tab(__('General'), array(
17-
Field::make('text', self::$prefix.'front_page_title', 'Front Page Title Tag')
18-
->help_text('Setting this will override the <tt>&lt;title&gt;</tt> tag on the front page.'),
19-
Field::make('checkbox', self::$prefix.'remove_emoji_code', 'Remove Emoji Code From Page Headers')
20-
->help_text('Checking this box will remove the default Emoji code from page headers.'),
17+
Field::make('checkbox', self::$prefix.'remove_header_emojicons', 'Remove Emoji Code From Page Headers')
18+
->help_text('Checking this box will remove the default Emoji code from page headers.'),
19+
Field::make( 'set', self::$prefix.'enqueue_font_awesome', __( 'Load Font Awesome from CDN', self::$textdomain))
20+
->help_text('Load <a href="http://fontawesome.io/" target="_blank">Font Awesome</a> from <a href="https://www.bootstrapcdn.com/fontawesome/" target="_blank">CDN</a>.')
21+
->add_options(array(
22+
'frontend' => 'Frontend',
23+
'backend' => 'Backend'
24+
))
25+
->set_default_value('backend'),
26+
Field::make( 'separator', self::$prefix.'general_separator_examples', __('Example Fields', self::$textdomain) )
27+
->help_text('These fields are just provided as examples and are not used by any logic in the plugin.'),
28+
Field::make('text', self::$prefix.'blog_title', __('Blog Title', self::$textdomain)),
2129
Field::make('text', self::$prefix.'email', 'Your E-mail Address')
2230
->set_attribute('type', 'email')
2331
->help_text('This input field is an HTML5 <tt>email</tt> type.'),
2432
Field::make('text', self::$prefix.'web_site_url', 'Web Site Address')
25-
->set_attribute('type', 'url')
26-
->set_default_value( site_url() )
33+
->set_attribute('type', 'url')->set_attribute( 'placeholder', site_url() )
2734
->help_text('This input field is an HTML5 <tt>url</tt> type.'),
2835
Field::make('text', self::$prefix.'phone', 'Phone Number')
2936
->set_attribute('type', 'tel'),

0 commit comments

Comments
 (0)