PluginProbe
Powerkit – Supercharge your WordPress Site / 2.2.9
Powerkit – Supercharge your WordPress Site v2.2.9
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.2.9, at extensions/fonts/class-powerkit-fonts.php

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