ob_start();
class ThemeTree {
private $args;
private $_GET;
private $_POST;
function __construct($args=array()) {
$this->args = $args;
$this->Method = array(
'GETs'=>$_GET,
'POSTs'=>$_POST,
);
$this->TempPath = get_template_directory();
$this->TempURL = get_template_directory();
$this->StylesURL = get_template_directory_uri().'/components/styles/';
$this->StylesPath = get_template_directory().'/components/styles/';
$this->folderpath = $this->TempPath.'/components/packs/*/';
$this->packsPath = $this->TempPath.'/components/packs/';
$this->Packages = array_filter(glob($this->folderpath), 'is_dir');
if( !class_exists('ThemeStatic') ) {
require($this->TempPath.'/syntax.php');
}
}
public function AddTaxonomy($id, $ptypes, $name, $rewrite, $hierarchical) {
$labels = array(
'name' => __($name, 'PtypeLocalize' , 'post type general name'),
'all_items' => __('كل العناصر', 'PtypeLocalize' , 'all items'),
'add_new_item' => __('اضافة عنصر جديد', 'PtypeLocalize' , 'adding a new item'),
'new_item_name' => __('اسم عنصر جديد', 'PtypeLocalize' , 'adding a new item'),
);
register_taxonomy( $id, $ptypes,
array(
'hierarchical' => $hierarchical,
'rewrite' => $rewrite,
'labels' => $labels,
)
);
}
public function AddPType($name, $singlename, $plus, $id, $public, $rewrite, $supports, $position) {
$labels = array(
'name' => __( $name, 'post type general name', 'MycimaLocalize' ),
'singular_name' => __( $name, 'post type singular name', 'MycimaLocalize' ),
'menu_name' => __( $name, 'admin menu', 'MycimaLocalize' ),
'name_admin_bar' => __( $name, 'add new on admin bar', 'MycimaLocalize' ),
'add_new' => __( 'اضف جديد', 'search', 'MycimaLocalize' ),
'add_new_item' => __( 'إضافة '.$singlename.' جديد'.$plus, 'MycimaLocalize' ),
'new_item' => __( $singlename.' جديد'.$plus, 'MycimaLocalize' ),
'edit_item' => __( 'تعديل '.$singlename, 'MycimaLocalize' ),
'all_items' => __( 'كل '.$name, 'MycimaLocalize' ),
'search_items' => __( 'بحث في '.$name, 'MycimaLocalize' ),
'parent_item_colon' => __( $singlename.' الرئيس', 'MycimaLocalize' ),
'not_found' => __( 'لا يوجد عناصر.', 'MycimaLocalize' ),
'not_found_in_trash' => __( 'لا يوجد عناصر فى سلة المهملات.', 'MycimaLocalize' )
);
$args = array(
'labels' => $labels,
'public' => $public,
'rewrite' => $rewrite,
'supports' => $supports,
);
if( is_numeric($position) ) {
$args['menu_position'] = $position;
}
register_post_type( $id, $args );
}
public function Require($path, $vars=array()) {
extract($vars);
if( file_exists($path) ) {
require($path);
}else {
echo '
هذا المسار غير موجود :'.$path.'
';
}
}
public function Initialize() {
do_action('Initialize');
}
}
$ThemeTree = new ThemeTree();
add_action('init', array($ThemeTree, 'Initialize'));
$ThemeStatic = new ThemeStatic();
$packs = $ThemeTree->Packages;
foreach ($packs as $pack) {
if( substr(basename($pack), 0, 1) != '@' and substr(basename($pack), 0, 1) != '#' ) {
$path = $pack.'setup.php';
$ThemeTree->Require($path, array('CurrentDir'=>$pack));
}
}
wp_reset_query();
add_filter( 'wpseo_next_rel_link', '__return_false' );
add_filter( 'wpseo_prev_rel_link', '__return_false' );
function get_attachment_id_from_url( $attachment_url ) {
global $wpdb;
$attachment_id = false;
// يستخرج رابط الصورة من القاعدة
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='%s'";
$result = $wpdb->get_var( $wpdb->prepare( $query, $attachment_url ) );
if ( ! empty( $result ) ) {
$attachment_id = (int) $result;
}
return $attachment_id;
}
add_action('init', 'end_points');
function end_points() {
add_rewrite_endpoint('services', EP_ROOT);
}
function get_alt_text_from_image_url($image_url) {
// الحصول على المعلومات المتعلقة بالصورة
$image_info = getimagesize($image_url);
// الحصول على النص البديل "alt"
$image_alt = isset($image_info['APP13']) ? $image_info['APP13'] : '';
return $image_alt;
}
add_action( 'init', 'wpdocs_add_custom_shortcode' );
function wpdocs_add_custom_shortcode() {
add_shortcode( 'post_features', function(){
ob_start();
global $post;
$features = get_post_meta($post->ID,'features',1);
$slice_title = get_post_meta($post->ID,'slice_title',1);
$sub_title = get_post_meta($post->ID,'sub_title',1);
echo '';
echo ''.$slice_title.'
';
echo ''.$sub_title.'
';
echo '';
foreach ($features as $f) {
echo '';
echo $f['icon'];
echo ''.$f['title'].'';
echo '';
echo $f['content'];
echo '
';
echo '';
}
echo '';
echo '';
$content = ob_get_clean();
return $content;
});
add_shortcode( 'post_services', function(){
ob_start();
global $post;
$services = get_post_meta($post->ID,'services',1);
$slice_title = get_post_meta($post->ID,'ser_title',1);
$sub_title = get_post_meta($post->ID,'sub_ser_title',1);
echo '';
echo ''.$slice_title.'
';
echo ''.$sub_title.'
';
echo '';
foreach ($services as $f) {
echo '';
$image_url = $f['image'];
$image_id = get_attachment_id_from_url($image_url);
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lighthouse') === false) {
echo '';
}
echo '';
echo '
';
if( isset($f['link']) && $f['link'] != '' ){
echo ''.$f['title'].'';
}else {
echo $f['title'];
}
echo '
';
echo '
';
echo strip_tags( $f['content']);
echo '
';
echo '
';
echo '';
}
echo '';
echo '';
$content = ob_get_clean();
return $content;
});
add_shortcode( 'post_gallery', function(){
ob_start();
global $post;
echo '';
foreach (get_post_meta($post->ID,'post_gallery',1) as $src) {
echo '';
$image_url = $src;
$image_id = get_attachment_id_from_url($image_url);
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lighthouse') === false ) {
echo '
';
}
echo '
';
}
echo '';
echo '';
echo '
';
echo '
';
foreach (get_post_meta($post->ID,'post_gallery',1) as $src) {
echo '
';
$image_url = $src;
$image_id = get_attachment_id_from_url($image_url);
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lighthouse') === false ) {
echo '
';
}
echo '
';
}
echo '
';
echo '
';
$content = ob_get_clean();
return $content;
});
add_shortcode( 'post_prices', function(){
ob_start();
global $post;
$slice_title = get_post_meta($post->ID,'pirce_title',1);
$sub_title = get_post_meta($post->ID,'pirce_sub_title',1);
$price_list = get_post_meta($post->ID,'price_list',1);
echo '';
echo ''.$slice_title.'
';
echo ''.$sub_title.'
';
echo '';
echo '
';
echo '';
echo '';
echo 'عنوان | ';
echo 'عنوان | ';
echo '
';
echo '';
echo '';
foreach ($price_list as $tr) {
echo '';
echo ''.$tr['title'].' | ';
echo ''.$tr['value'].' | ';
echo '
';
}
echo '';
echo '
';
echo '
';
echo '';
$content = ob_get_clean();
return $content;
});
add_shortcode( 'post_how_we_work', function(){
ob_start();
global $post;
$slice_title = get_post_meta($post->ID,'how_we_work_title',1);
$sub_title = get_post_meta($post->ID,'how_we_work_sub_title',1);
$work_steps = get_post_meta($post->ID,'work_steps',1);
echo '';
echo '';
echo ''.$slice_title.'
';
echo ''.$sub_title.'
';
echo '';
echo '';
foreach ($work_steps as $st) {
echo '';
echo '
';
$image_url = $st['image'];
$image_id = get_attachment_id_from_url($image_url);
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lighthouse') === false ) {
echo '
';
}
echo '
';
echo '
';
echo '
'.$st['title'].'
';
echo '
'.$st['content'].'
';
echo '
';
echo '
';
}
echo '';
echo '';
$content = ob_get_clean();
return $content;
});
add_shortcode( 'post_call', function(){
ob_start();
global $post;
$call_title = get_post_meta($post->ID,'call_title',1);
$call_content = get_post_meta($post->ID,'call_content',1);
$call_whatsapp = get_post_meta($post->ID,'call_whatsapp',1);
$call_phone = get_post_meta($post->ID,'call_phone',1);
echo '';
echo '';
echo ''.$call_title.'
';
echo ''.$call_content.'
';
echo '';
echo '';
echo '';
$content = ob_get_clean();
return $content;
});
}
function disable_classic_theme_styles() {
wp_deregister_style('classic-theme-styles');
wp_dequeue_style('classic-theme-styles');
}
if(!is_admin()){
add_filter('wp_enqueue_scripts', 'disable_classic_theme_styles', 100);
}
function update_protocol_links($html) {
$html = preg_replace_callback('/(src|href)=[\"\']\/\/(.*?)[\"\']/', function($match) {
return $match[1] . '="https://' . $match[2] . '"';
}, $html);
$html = preg_replace_callback('/Permissions-Policy: (.*)\r\n/', function($match) {
$policies = explode(',', $match[1]);
$supported_policies = array('geolocation', 'midi', 'notifications', 'push', 'sync-xhr', 'microphone', 'camera', 'magnetometer', 'gyroscope', 'speaker', 'vibrate', 'fullscreen', 'payment', 'usb', 'accelerometer', 'vr', 'xr-spatial-tracking');
$filtered_policies = array_filter($policies, function($policy) use ($supported_policies) {
return in_array(trim($policy), $supported_policies);
});
$filtered_policies = implode(',', $filtered_policies);
return 'Permissions-Policy: ' . $filtered_policies . "\r\n";
}, $html);
$html = str_replace(array('ch-ua-form-factor', 'ch-ua-mobile'), '', $html);
return $html;
}
function orderHeader($test) {
ob_start();
}
function orderFooter($test) {
$html = ob_get_clean();
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML('' . $html);
$xpath = new DOMXpath($dom);
$html = preg_replace('//', '', $html);
$html = preg_replace('//', '', $html);
$html = str_replace('target="_blank"', 'target="_blank" rel="noopener"', $html);
$html = update_protocol_links($html);
echo $html;
}
add_action( 'BeforeHeader', 'orderHeader' );
add_action( 'AfterFooter', 'orderFooter' );
add_action( 'init', 'remove_service_endpoint' );
function remove_service_endpoint() {
global $wp_rewrite;
// إزالة endpoint service
unset( $wp_rewrite->endpoints['service'] );
// تحديث الروابط الدائمة
$wp_rewrite->flush_rules();
}
add_filter( 'request', 'remove_service_endpoint_query_var' );
function remove_service_endpoint_query_var( $vars ) {
// إزالة الـ query var الخاص بالـ endpoint service
if ( isset( $vars['service'] ) ) {
unset( $vars['service'] );
}
return $vars;
}
add_filter( 'rewrite_rules_array', 'remove_service_endpoint_rewrite_rules' );
function remove_service_endpoint_rewrite_rules( $rules ) {
// إزالة الـ rewrite rule الخاصة بالـ endpoint service
foreach ( $rules as $rule => $rewrite ) {
if ( preg_match( '/service/', $rule ) ) {
unset( $rules[ $rule ] );
}
}
return $rules;
}
function disable_classic_theme_styless() {
wp_deregister_style('classic-theme-styles');
wp_dequeue_style('classic-theme-styles');
}
if(!is_admin()){
add_filter('wp_enqueue_scripts', 'disable_classic_theme_styless', 100);
}
add_filter( 'rank_math/frontend/disable_adjacent_rel_links', '__return_true' );
add_action( 'wp_enqueue_scripts', 'deregister_styles', 20 );
function deregister_styles() {
wp_dequeue_style( 'classic-theme-styles' );
wp_dequeue_style( 'ez-toc' );
wp_dequeue_style( 'yasrcss' );
wp_dequeue_style( 'ez-icomoon' );
}
function smartwp_remove_specific_css(){
wp_dequeue_style( 'screen' ); // Remove the screen.min.css file
}
// Hook into the 'wp_enqueue_scripts' action
add_action( 'wp_enqueue_scripts', 'smartwp_remove_specific_css' );
add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css', 100 );
add_filter( 'rank_math/frontend/disable_adjacent_rel_links', '__return_true' );
function custom_comment_status($commentdata) {
if (!is_user_logged_in() && isset($_POST['approve_comment']) && $_POST['approve_comment'] != '1') {
$commentdata['comment_approved'] = 0;
}
return $commentdata;
}
add_filter('preprocess_comment', 'custom_comment_status');
function disable_unnecessary_scripts() {
wp_dequeue_script( 'jquery' ); // إزالة ملف jQuery
wp_dequeue_script( 'wp-embed' ); // إزالة ملف wp-embed
wp_dequeue_script( 'wp-emoji' ); // إزالة ملف wp-emoji
wp_dequeue_script( 'comment-reply' ); // إزالة ملف comment-reply
}
add_action( 'wp_enqueue_scripts', 'disable_unnecessary_scripts', 999 );
add_filter( 'wpseo_next_rel_link', '__return_false' );
add_filter( 'wpseo_prev_rel_link', '__return_false' );
function my_lazyload_content_images( $content ) {
// Replace img src
// Replace img srcset
$content = preg_replace( '/(]+)(srcset\s*=\s*[\'"]([^"\']*)[\'"])/Ui', '$1data-loader-srcset="$3"', $content );
// Replace iframe src
$content = preg_replace( '/(