| Server IP : 38.190.208.107 / Your IP : 216.73.217.1 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.5/wp-content/themes/woodmart/inc/integrations/gutenberg/ |
Upload File : |
<?php
/**
* Gutenberg google fonts class.
*
* @package woodmart
*/
namespace XTS\Gutenberg;
use XTS\Singleton;
use XTS\Admin\Modules\Options\Google_Fonts\Google_Fonts as Global_Google_Fonts;
/**
* Google Fonts module.
*
* @package woodmart
*/
class Google_Fonts extends Singleton {
/**
* Init.
*
* @return void
*/
public function init() {
add_action( 'wp', array( $this, 'enqueue_google_fonts' ), 130 );
add_action( 'init', array( $this, 'enqueue_google_fonts' ), 130 );
add_action( 'save_post', array( $this, 'remove_post_meta' ), 5 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_google_fonts_on_editor' ), 10 );
}
/**
* Enqueue google fonts on editor.
*
* @return void
*/
public function enqueue_google_fonts_on_editor() {
if ( ! is_admin() ) {
return;
}
$this->enqueue_google_fonts();
}
/**
* Remove post meta.
*
* @param int $post_id Post ID.
* @return void
*/
public function remove_post_meta( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
delete_post_meta( $post_id, 'xts_blocks_google_fonts' );
}
/**
* Add google font at block.
*
* @param array $font_data Font data.
* @return void
*/
public function add_google_font( $font_data ) {
$font_data = wp_parse_args(
$font_data,
array(
'font-family' => '',
'font-weight' => '',
'font-style' => '',
'font-subset' => '',
)
);
$post_id = $this->get_post_id();
if ( ! $post_id ) {
return;
}
$fonts = (array) get_post_meta( $post_id, 'xts_blocks_google_fonts', true );
$fonts[] = $font_data;
update_post_meta( $post_id, 'xts_blocks_google_fonts', $fonts );
}
/**
* Enqueue google fonts in frontend.
*
* @return void
*/
public function enqueue_google_fonts() {
$post_id = $this->get_post_id();
if ( ! $post_id ) {
return;
}
$fonts = get_post_meta( $post_id, 'xts_blocks_google_fonts', true );
if ( empty( $fonts ) ) {
return;
}
foreach ( $fonts as $font ) {
Global_Google_Fonts::add_google_font( $font );
}
}
/**
* Enqueue inline google fonts.
*
* @param int $post_id Post ID.
* @return void
*/
public function enqueue_inline_google_fonts( $post_id ) {
$fonts = get_post_meta( $post_id, 'xts_blocks_google_fonts', true );
if ( empty( $fonts ) ) {
return;
}
Global_Google_Fonts::get_instance()->enqueue_inline_fonts( $fonts, $post_id );
}
/**
* Get post ID.
*
* @return int
*/
protected function get_post_id() {
global $post;
$post_id = '';
if ( is_admin() && isset( $_GET['post'] ) ) { // phpcs:ignore
$post_id = $_GET['post']; // phpcs:ignore
} elseif ( ! empty( $post ) && ! empty( $post->ID ) ) {
$post_id = $post->ID;
}
return $post_id;
}
}
Google_Fonts::get_instance();