*/
class CustomHeaderFooter extends CustomHeaderFooterModel
{
public $url ;
public function __construct()
{
$this->url = WP_ADMINIFY_URL . 'Inc/Modules/CustomHeaderFooter';
$this->options = ( new CustomHeaderFooterSettings() )->get();
$this->options = ( !empty($this->options['custom_scripts']) ? $this->options['custom_scripts'] : '' );
if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
add_action( 'wp_head', [ $this, 'adminify_header_scripts' ], 9999 );
add_action( 'wp_footer', [ $this, 'adminify_footer_scripts' ], 9999 );
add_action( 'the_content', [ $this, 'adminify_content_scripts' ] );
}
// Add Header Scripts
public function adminify_header_scripts()
{
$this->adminify_custom_css_js_script( 'header' );
}
// Add Footer Scripts
public function adminify_footer_scripts()
{
$this->adminify_custom_css_js_script( 'footer' );
}
// Add Footer Scripts
public function adminify_content_scripts( $content )
{
return $this->adminify_custom_css_js_script( false, $content );
}
/**
* Render Snippet
*
* @param [since] 1.0.0
*
* @return void
*/
public function render_snippet( $value )
{
// $device_display = wp_is_mobile() ? 'desktop' : 'mobile';
if ( $value['script_type'] == 'css' ) {
echo "\n\n" ;
echo '' ;
echo "\n\n" ;
} elseif ( $value['script_type'] === 'js' ) {
echo "\n\n" ;
echo '' ;
echo "\n\n" ;
}
}
/**
* Add Snippet
*
* @return void
*/
public function adminify_custom_css_js_script( $location = '', $content = '' )
{
$options = $this->options;
$before_content = '';
$after_content = '';
if ( !empty($options) ) {
foreach ( $options as $key => $value ) {
$output = '';
if ( $value['location'] === $location ) {
switch ( $value['display_on'] ) {
case 'full_site':
$output = $this->render_snippet( $value );
break;
case 's_posts':
break;
case 's_pages':
break;
case 's_categories':
break;
case 's_custom_posts':
break;
case 's_tags':
break;
}
}
}
}
return $before_content . $content . $after_content;
}
/**
* Scripts/Styles
*/
public function enqueue_scripts()
{
global $pagenow ;
// Load Scripts/Styles only WP Adminify Custom CSS/JS Page
if ( 'admin.php' === $pagenow && 'adminify-custom-css-js' === $_GET['page'] ) {
$this->header_footer_admin_script();
}
}
// WP Adminify Custom CSS/JS Page Style
public function header_footer_admin_script()
{
echo '' ;
}
}