Skip to content
This repository was archived by the owner on Sep 18, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 95 additions & 51 deletions select/taxonomy-dropdown-custom-control.php
Original file line number Diff line number Diff line change
@@ -1,69 +1,113 @@
<?php
/**
* Customize for taxonomy with dropdown, extend the WP customizer
*/

if ( ! class_exists( 'WP_Customize_Control' ) )
return NULL;
return NULL;

class Taxonomy_Dropdown_Custom_Control extends WP_Customize_Control
{
private $options = false;
/**
* A class to create a dropdown for all google fonts
*/
class Google_Font_Dropdown_Custom_Control extends WP_Customize_Control
{
private $fonts = false;

public function __construct($manager, $id, $args = array(), $options = array())
{
$this->options = $options;

$this->fonts = $this->get_fonts();
parent::__construct( $manager, $id, $args );
}

/**
* Render the control's content.
*
* Allows the content to be overriden without having to rewrite the wrapper.
*
* @since 11/14/2012
* @return void
*/
public function render_content()
/**
* Render the content of the category dropdown
*
* @return HTML
*/
public function render_content()
{
// call wp_dropdown_cats to get data and add to select field
add_action( 'wp_dropdown_cats', array( $this, 'wp_dropdown_cats' ) );

// Set defaults
$this->defaults = array(
'show_option_none' => __( 'None' ),
'orderby' => 'name',
'hide_empty' => 0,
'id' => $this->id,
'selected' => $this->value()
);

// parse defaults and user data
$cats = wp_parse_args(
$this->options,
$this->defaults
);

?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php wp_dropdown_categories( $cats ); ?>
</label>
<?php
}
if(!empty($this->fonts))
{
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<select <?php $this->link(); ?>>
<?php
foreach ( $this->fonts as $k => $v )
{
printf('<option value="%s" %s>%s</option>', $v->family, selected($this->value(), $v->family, false), $v->family);
}
?>
</select>
</label>
<?php
} else {
?>
<p>The font list is empty.</p>
<?php
}
}

/**
* Replace WP default dropdown
* Get the google fonts from the API or in the cache
*
* @param integer $amount
*
* @since 11/14/2012
* @return String $output
* @return String
*/
public function wp_dropdown_cats( $output )
public function get_fonts( $amount = 600 )
{
$output = str_replace( '<select', '<select ' . $this->get_link(), $output );
global $wp_filesystem;
// Initialize the WP filesystem, no more using 'file-put-contents' function
if (empty($wp_filesystem)) {
require_once (ABSPATH . '/wp-admin/includes/file.php');
WP_Filesystem();
}

$selectDirectory = get_stylesheet_directory().'/tbnframework/admin/options/customizer-custon-controls/select/';
$selectDirectoryInc = get_template_directory().'/tbnframework/admin/options/customizer-custon-controls/select/';

$finalselectDirectory = '';

if(is_dir($selectDirectory))
{
$finalselectDirectory = $selectDirectory;
}

if(is_dir($selectDirectoryInc))
{
$finalselectDirectory = $selectDirectoryInc;
}

$fontFile = $finalselectDirectory . '/cache/google-web-fonts.txt';

//Total time the file will be cached in seconds, set to 180 days
$cachetime = 86400 * 180;
if(file_exists($fontFile) && time() - $cachetime < filemtime($fontFile))
{
$content = json_decode($wp_filesystem->get_contents($fontFile));
} else {
$Api = 'AIzaSyCWMkc4xnpZZVE5HUG3CAAq8X8lrs5HhKQ';
$googleApi = 'https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key='.$Api;

$fontContent = wp_remote_get( $googleApi, array('sslverify' => false) );

if( $wp_filesystem ) {
$wp_filesystem->put_contents(
$fontFile,
$fontContent['body'],
FS_CHMOD_FILE // predefined mode settings for WP files
);
}

return $output;
$content = json_decode($fontContent['body']);
}
if( !empty($content->items) ) {
if($amount == 'all') {
return $content->items;
} else {
return array_slice($content->items, 0, $amount);
}
} else {
return false;
}
}
}
?>
}
?>