61 | "Ubuntu Condensed",
20 | "location" => "Ubuntu+Condensed",
21 | "cssDeclaration" => "'Ubuntu Condensed', sans-serif",
22 | "cssClass" => "ubuntuCondensed"
23 | );
24 | $customFontFamilies = new Google_Font_Collection($fonts);
25 | }
26 | ```
27 | * **title** - the title you wish the user to see.
28 | * **location** - the query string on the stylesheet for the google font. If the file name for the font is `http://fonts.googleapis.com/css?family=Ubuntu+Condensed` then the `location` should be `Ubuntu+Condensed`.
29 | * **cssDeclaration** - the code to be applied to the `font-family` css property. You can keep is the same as Google suggests or you can set up your own fallbacks.
30 | * **cssClass** - the CSS class for the theme cusomizer. You can create any CSS class you want.
31 |
32 | 5. Create the control
33 |
34 | ``` php
35 | if (class_exists('Google_Font_Picker_Custom_Control'))
36 | {
37 | // make sure we have the control included
38 | $wp_customize->add_control( new Google_Font_Picker_Custom_Control( $wp_customize, 'font_family_control', array(
39 | 'label' => __( 'Font Family', 'mytheme' ),
40 | 'section' => 'mytheme_new_section_fonts',
41 | 'settings' => 'font_family',
42 | 'choices' => $customFontFamilies->getFontFamilyNameArray(),
43 | 'fonts' => $customFontFamilies
44 | )));
45 | }
46 | ```
47 |
48 |
49 | ## Results
50 |
51 | 
52 |
53 | ## FAQ
54 |
55 | 1. **Can I only add one font to the $fonts array in step 4?**
56 |
57 | No, you can add as many as you like. IMO eight choices looks pretty and gives the user tons of options.
58 |
59 | 2. **What's up with the class_exists() functions?**
60 |
61 | Those are there so that if you were to ever deactivate or uninstall the plugin that your site wouldn't crash. If you do uninstall the plugin the control will simply not load. There shouldn't be any errors.
62 |
63 | ## Version
64 |
65 | **1.1**
66 |
67 | * Updated array select box to save font names instead of array indices. See issue #1.
68 |
69 | **1.0**
70 |
71 | * Initial release
72 |
--------------------------------------------------------------------------------
/google-font-collection.php:
--------------------------------------------------------------------------------
1 | $value)
25 | {
26 | $this->fonts[$value["title"]] = new Google_Font($value["title"], $value["location"], $value["cssDeclaration"], $value["cssClass"]);
27 | }
28 | }
29 |
30 | /**
31 | * getFontFamilyNameArray Function
32 | * this function returns an array containing all of the font family names
33 | **/
34 | function getFontFamilyNameArray()
35 | {
36 | $result;
37 | foreach ($this->fonts as $key => $value)
38 | {
39 | $result[] = $value->__get("title");
40 | }
41 | return $result;
42 | }
43 |
44 | /**
45 | * getTitle
46 | * this function returns the font title
47 | **/
48 | function getTitle($key)
49 | {
50 | return $this->fonts[$key]->__get("title");
51 | }
52 |
53 | /**
54 | * getLocation
55 | * this function returns the font location
56 | **/
57 | function getLocation($key)
58 | {
59 | return $this->fonts[$key]->__get("location");
60 | }
61 |
62 | /**
63 | * getCssDeclaration
64 | * this function returns the font css declaration
65 | **/
66 | function getCssDeclaration($key)
67 | {
68 | return $this->fonts[$key]->__get("cssDeclaration");
69 | }
70 |
71 |
72 | /**
73 | * getCssClassArray
74 | * this function returns an array of css classes
75 | * this function is used when displaying the fancy list of fonts in the theme customizer
76 | * this function is used to send a JS file an array for the postMessage transport option in the theme customizer
77 | **/
78 | function getCssClassArray()
79 | {
80 | $result;
81 | foreach ($this->fonts as $key => $value)
82 | {
83 | $result[$value->__get("title")] = $value->__get("cssClass");
84 | }
85 | return $result;
86 | }
87 |
88 | /**
89 | * getTotalNumberOfFonts
90 | * this function returns the total number of fonts
91 | **/
92 | function getTotalNumberOfFonts()
93 | {
94 | return count($this->fonts);
95 | }
96 |
97 | /**
98 | * printThemeCustomizerCssLocations
99 | * this function prints the links to the css files for the theme customizer
100 | **/
101 | function printThemeCustomizerCssLocations()
102 | {
103 | foreach ($this->fonts as $key => $value)
104 | {
105 | ?>
106 | " rel='stylesheet' type='text/css'>
107 |
118 |
130 |