PluginProbe
Powerkit – Supercharge your WordPress Site / 2.9.0
Powerkit – Supercharge your WordPress Site v2.9.0
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / extensions / fonts / class-powerkit-fonts.php

class-powerkit-fonts.php in Powerkit – Supercharge your WordPress Site 2.9.0, at extensions/fonts/class-powerkit-fonts.php

160 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fonts
4 *
5 * @package Powerkit
6 * @subpackage Extensions
7 */
8
9 if ( class_exists( 'Powerkit_Module' ) ) {
10 /**
11 * Init module
12 */
13 class Powerkit_Fonts extends Powerkit_Module {
14
15 /**
16 * Register module
17 */
18 public function register() {
19 $this->name = 'fonts';
20 $this->slug = 'fonts';
21 $this->type = 'extension';
22 $this->category = 'basic';
23 $this->public = false;
24 $this->enabled = false;
25 }
26
27 /**
28 * Initialize module
29 */
30 public function initialize() {
31 add_action( 'admin_menu', array( $this, 'register_options_page' ) );
32 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
33 add_filter( 'powerkit_fonts_choices', array( $this, 'kirki_fonts_choices' ) );
34 }
35
36 /**
37 * Register admin page
38 *
39 * @since 1.0.0
40 */
41 public function register_options_page() {
42 add_theme_page( esc_html__( 'Fonts', 'powerkit' ), esc_html__( 'Fonts', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->slug ), array( $this, 'settings_page' ) );
43 }
44
45 /**
46 * Build admin page
47 *
48 * @since 1.0.0
49 */
50 public function settings_page() {
51
52 powerkit_uuid_hash();
53
54 // Check wpnonce.
55 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
56 return;
57 }
58
59 if ( ! current_user_can( 'manage_options' ) ) {
60 wp_die( esc_html__( 'You do not have sufficient rights to view this page.', 'powerkit' ) );
61 }
62 ?>
63 <div class="wrap">
64 <h1 class="wp-heading-inline"><?php esc_html_e( 'Fonts', 'powerkit' ); ?></h1>
65
66 <hr class="wp-header-end">
67
68 <div class="settings">
69 <?php $fonts_settings = apply_filters( 'powerkit_fonts_register_settings', array() ); ?>
70
71 <?php if ( $fonts_settings ) : ?>
72 <div class="tabs">
73 <?php
74 $first_settings = current( $fonts_settings );
75
76 $tab = sanitize_title( isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : $first_settings['id'] ); // Input var ok; sanitization ok.
77 ?>
78 <nav class="nav-tab-wrapper">
79 <?php
80 foreach ( $fonts_settings as $item ) {
81 $class = ( $item['id'] === $tab ) ? 'nav-tab-active' : '';
82
83 printf( '<a class="nav-tab %4$s" href="%1$s&tab=%2$s">%3$s</a>',
84 esc_url( powerkit_get_page_url( $this->slug, 'themes' ) ), esc_attr( $item['id'] ), esc_html( $item['name'] ), esc_attr( $class )
85 );
86 }
87 ?>
88 </nav>
89
90 <?php
91 foreach ( $fonts_settings as $item ) {
92 if ( $item['id'] === $tab ) {
93 ?>
94 <div id="tab-<?php echo esc_attr( $item['id'] ); ?>" class="tab-wrap">
95 <?php
96 if ( is_callable( $item['function'] ) ) {
97 call_user_func( $item['function'] );
98 }
99 ?>
100 </div>
101 <?php
102 }
103 }
104 ?>
105 </div>
106 <?php endif; ?>
107 </div>
108 </div>
109 <?php
110 }
111
112 /**
113 * Add support wp-custom-fonts in Kirki.
114 *
115 * @param array $settings Pre settings.
116 */
117 public function kirki_fonts_choices( $settings = array() ) {
118 $fonts_list = apply_filters( 'powerkit_fonts_list', array() );
119
120 if ( ! $fonts_list ) {
121 return $settings;
122 }
123
124 $fonts_settings = array(
125 'fonts' => array(
126 'google' => array(),
127 'families' => isset( $fonts_list['families'] ) ? $fonts_list['families'] : null,
128 'variants' => isset( $fonts_list['variants'] ) ? $fonts_list['variants'] : null,
129 ),
130 );
131
132 $fonts_settings = array_merge( (array) $fonts_settings, (array) $settings );
133
134 return $fonts_settings;
135 }
136
137 /**
138 * Register the stylesheets and JavaScript for the admin area.
139 *
140 * @param string $page Current page.
141 */
142 public function admin_enqueue_scripts( $page ) {
143 if ( 'appearance_page_' . powerkit_get_page_slug( $this->slug ) === $page ) {
144
145 wp_enqueue_media();
146
147 wp_enqueue_script( 'admin-powerkit-fonts', plugin_dir_url( __FILE__ ) . 'js/admin-powerkit-fonts.js', array( 'jquery' ), powerkit_get_setting( 'version' ), false );
148
149 wp_localize_script( 'admin-powerkit-fonts', 'powerkitFonts', array(
150 'delete' => esc_html__( 'Are you sure you want to delete this font and all the files downloaded from it?', 'powerkit' ),
151 'title' => esc_html__( 'Select or Upload Font', 'powerkit' ),
152 'button' => esc_html__( 'Use This File', 'powerkit' ),
153 ) );
154 }
155 }
156 }
157
158 new Powerkit_Fonts();
159 }
160