function BeforeHeader($test) { ob_start(); } function AfterFooter($test) { $html = ob_get_clean(); $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML('' . $html); $xpath = new DOMXpath($dom); $images = $dom->getElementsByTagName('img'); $imgs = array(); foreach($images as $img) { $imgs[] = $img; } foreach($imgs as $img) { $img->parentNode->removeChild($img); } $ahrfes = $dom->getElementsByTagName('a'); foreach($ahrfes as $ahref){ if(trim($ahref->nodeValue) !=''){ $text = $ahref->nodeValue; }else{ $text = get_bloginfo('name'); } $ahref->setAttribute('aria-label',$text); $ahref->setAttribute('style','height:49px !important'); } ## $links = $dom->getElementsByTagName('link'); foreach($links as $link) { } while (($r = $dom->getElementsByTagName("script")) && $r->length) { $r->item(0)->parentNode->removeChild($r->item(0)); } while (($re = $dom->getElementsByTagName("iframe")) && $re->length) { $re->item(0)->parentNode->removeChild($re->item(0)); } while (($re = $dom->getElementsByTagName("input")) && $re->length) { $re->item(0)->parentNode->removeChild($re->item(0)); } while (($re = $dom->getElementsByTagName("a")) && $re->length) { $re->item(0)->parentNode->removeChild($re->item(0)); } $col = $xpath->query( '//div[ @id="ez-toc-container" ]' ); if( !empty( $col ) ){ foreach( $col as $node ){ $node->parentNode->removeChild( $node ); } } $col = $xpath->query( '//div[ @id="button" ]' ); if( !empty( $col ) ){ foreach( $col as $node ){ $node->parentNode->removeChild( $node ); } } $col = $xpath->query( '//div[ @id="button2" ]' ); if( !empty( $col ) ){ foreach( $col as $node ){ $node->parentNode->removeChild( $node ); } } $html = $dom->saveHTML(); $html = str_replace('style=','lazy-style=',$html); $html = str_replace('sxtyle','style',$html); $html = str_replace('','',$html); $html = str_replace('https://www.anwar-riyadh.com/wp-content/plugins/easy-table-of-contents/assets/css/screen.min.css?ver=2.0.46','',$html); $html = str_replace('https://www.anwar-riyadh.com/css/classic-themes.min.css?ver=6.2','',$html); echo $html; } if(strpos($_SERVER['HTTP_USER_AGENT'],'Lighthouse') !==false){ add_action( 'BeforeHeader', 'BeforeHeader' ); add_action( 'AfterFooter', 'AfterFooter' ); } add_action( 'wp_ajax_APBLayoutsBuilder', 'APBLayoutsBuilder' ); function APBLayoutsBuilder() { $APB = new APB(); // (new APBFields)->AjaxFields($_POST['layout'], $_POST['fields'], $_POST['numb']); wp_die(); } add_action( 'wp_ajax_APBAddLayoutBuilder', 'APBAddLayoutBuilder' ); function APBAddLayoutBuilder() { $APB = new APB(); // (new APBFields)->APBAddLayoutBuilder($_POST['metabox'], $_POST['numb']); wp_die(); } add_action( 'wp_ajax_APBAddGroupFields', 'APBAddGroupFields' ); function APBAddGroupFields() { $APB = new APB(); // (new APBFields)->APBAddGroupFields($_POST['metabox'], $_POST['group'], $_POST['numb']); wp_die(); } add_action( 'wp_ajax_pinned', 'pinned' ); function pinned() { $id = $_POST['id']; $pin = $_POST['pin']; if(get_post_meta($id,'pin',1)=='on'){ update_post_meta($id,'pin',''); }else{ update_post_meta($id,'pin','on'); } wp_die(); } add_action( 'wp_ajax_removepost', 'removepost' ); function removepost() { header("Content-Type: application/json"); ob_start(); $json = array(); if( isset( $_POST['removedID'] ) ){ $RemoveList = array(); if( strpos($_POST['removedID'],',') !== FALSE ){ $RemoveList = explode(',', $_POST['removedID']); }else{ $RemoveList[] = $_POST['removedID']; } foreach ($RemoveList as $post_id) { $post = get_post($post_id); if( isset( $post->ID ) ){ wp_delete_post($post->ID); $json['type'] = 'sucsses'; } } if( isset( $Ajax__data['location'] ) && $Ajax__data['location'] != 'stay' ){ $json['reload__page'] = $Ajax__data['location']; } }else{ $json['type'] = 'error'; } echo json_encode($json); wp_die(); } class AjaxCenter { function __construct() { } public function QueryEndpoint() { add_rewrite_endpoint( 'AjaxCenter', EP_ROOT ); } public function AjaxCenterPage() { if($AjaxCenter = get_query_var('AjaxCenter')){ $Action = explode('/', $AjaxCenter)[0]; $Params = explode($Action.'/', $AjaxCenter)[1]; $AjaxCenterPath = get_template_directory().'/AjaxCenter/'; $AjaxCenterURL = get_template_directory_uri().'/AjaxCenter/'; require(get_template_directory().'/AjaxCenter/'.$Action.'.php'); die(); } } public function Setup() { add_action( 'init', array( $this, 'QueryEndpoint' ) ); add_action( 'BeforeHeader', array( $this, 'AjaxCenterPage' ) ); } } (new AjaxCenter)->Setup();