| 1 |
<?php |
| 2 |
/** |
| 3 |
* Gutenify Helper file. |
| 4 |
* |
| 5 |
* @package Gutenify |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
class Gutenify_Helpers{ |
| 13 |
public static function is_gutenberg_page() { |
| 14 |
if ( function_exists( 'is_gutenberg_page' ) && |
| 15 |
is_gutenberg_page() |
| 16 |
) { |
| 17 |
// The Gutenberg plugin is on. |
| 18 |
return true; |
| 19 |
} |
| 20 |
$current_screen = get_current_screen(); |
| 21 |
if ( method_exists( $current_screen, 'is_block_editor' ) && |
| 22 |
$current_screen->is_block_editor() |
| 23 |
) { |
| 24 |
// Gutenberg page on 5+. |
| 25 |
return true; |
| 26 |
} |
| 27 |
return false; |
| 28 |
} |
| 29 |
public static function get_google_fonts(){ |
| 30 |
if ( false === ( $gutenify_google_fonts = get_transient( 'gutenify_google_fonts' ) ) ) { |
| 31 |
$response = wp_remote_get( 'https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyBwIX97bVWr3-6AIUvGkcNnmFgirefZ6Sw', |
| 32 |
array( |
| 33 |
'timeout' => 120, |
| 34 |
'httpversion' => '1.1', |
| 35 |
) |
| 36 |
); |
| 37 |
$gutenify_google_fonts = self::load_request( $response); |
| 38 |
set_transient( 'gutenify_google_fonts', $gutenify_google_fonts, 12 * HOUR_IN_SECONDS ); |
| 39 |
} |
| 40 |
|
| 41 |
return $gutenify_google_fonts; |
| 42 |
} |
| 43 |
|
| 44 |
public static function load_request($response) { |
| 45 |
try { |
| 46 |
$json = json_decode( $response['body'] ); |
| 47 |
} catch ( Exception $ex ) { |
| 48 |
$json = null; |
| 49 |
} |
| 50 |
return $json; |
| 51 |
} |
| 52 |
|
| 53 |
public static function typography_style($typography, $screen='desktop'){ |
| 54 |
$style = ''; |
| 55 |
$style .= ! empty( $typography['fontFamily'] ) ? 'font-family:' . $typography['fontFamily'] . ', sans-serif;' : ''; |
| 56 |
$style .= ! empty( $typography['weight'] ) ? 'font-weight:' . $typography['weight'] . ';' : ''; |
| 57 |
$style .= ! empty( $typography['transform'] ) ? 'text-transform:' . $typography['transform'] . ';' : ''; |
| 58 |
$style .= ! empty( $typography['style'] ) ? 'font-style:' . $typography['style'] . ';' : ''; |
| 59 |
$style .= ! empty( $typography['decoration'] ) ? 'text-decoration:' . $typography['decoration'] . ';' : ''; |
| 60 |
$style .= ! empty( $typography['size'][$screen]['value'] ) ? 'font-size:' . $typography['size'][$screen]['value'].$typography['size'][$screen]['unit'] . ';' : ''; |
| 61 |
$style .= ! empty( $typography['lineHeight'][$screen]['value'] ) ? 'line-height:' . $typography['lineHeight'][$screen]['value'].$typography['lineHeight'][$screen]['unit'] . ';' : ''; |
| 62 |
$style .= ! empty( $typography['letterSpacing'][$screen]['value'] ) ? 'letter-spacing:' . $typography['letterSpacing'][$screen]['value'] . 'px;' : ''; |
| 63 |
return $style; |
| 64 |
} |
| 65 |
} |