| Server IP : 31.214.178.50 / Your IP : 216.73.217.58 Web Server : Apache System : Linux hostingsrv42.dondominio.com 6.12.107+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.107-1 (2026-08-29) x86_64 User : ( 1021069) PHP Version : 8.5.9 Disable Function : system,passthru,popen,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,exec,ini_alter,show_source,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,mail,eval MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /hosting/www/univolution.com/public/wp-content/plugins/code-snippets/php/ |
Upload File : |
<?php
namespace Code_Snippets;
/**
* Class for loading active snippets of various types.
*
* @package Code_Snippets
*/
class Active_Snippets {
/**
* Cached list of active snippets.
*
* @var Snippet[]
*/
private array $active_snippets = [];
/**
* Class constructor.
*/
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
/**
* Initialise class functions.
*/
public function init() {
add_action( 'wp_head', [ $this, 'load_head_content' ] );
add_action( 'wp_footer', [ $this, 'load_footer_content' ] );
}
/**
* Fetch active snippets for a given scope, and cache the data in this class.
*
* @param string|string[] $scope Snippet scope.
*
* @return array[][]
*/
protected function fetch_active_snippets( $scope ) {
$scope_key = is_array( $scope ) ? implode( '|', $scope ) : $scope;
if ( ! isset( $this->active_snippets[ $scope_key ] ) ) {
$this->active_snippets[ $scope_key ] = code_snippets()->db->fetch_active_snippets( $scope );
}
return $this->active_snippets[ $scope_key ];
}
/**
* Print snippet code fetched from the database from a certain scope.
*
* @param string $scope Name of scope to print.
*/
private function print_content_snippets( string $scope ) {
$snippets_list = $this->fetch_active_snippets( [ 'head-content', 'footer-content' ] );
foreach ( $snippets_list as $snippets ) {
foreach ( $snippets as $snippet ) {
if ( $scope === $snippet['scope'] ) {
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo "\n", $snippet['code'], "\n";
}
}
}
}
/**
* Print head content snippets.
*/
public function load_head_content() {
$this->print_content_snippets( 'head-content' );
}
/**
* Print footer content snippets.
*/
public function load_footer_content() {
$this->print_content_snippets( 'footer-content' );
}
}