Our Locations
';
foreach($data['areasweserve'] as $key=>$value){
$parentTitle = $value;
if (!empty($value)) {
if(!empty(trim($data['address'][$key]))){
$contactPageContent = $contactPageContent . '
'.$parentTitle.'
'.$data['address'][$key].'
';
}
$post_data = [
'post_title' => $parentTitle,
'post_content' => '',
'post_status' => 'draft',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'page',
'post_parent' => 0
];
$parentID = wp_insert_post($post_data);
$totalPagesCreated++;
wp_update_post(
array(
'ID' => $parentID,
'post_parent' => $awsID
)
);
// Inserting page data to extension table as parent page
$awsPagecontent = $awsPagecontent . '
'.$parentTitle.'';
array_push($areasNameAndLink , [
'title' => $parentTitle,
'permalink' => get_permalink($parentID)
]);
$wpdb->insert($table_name,
[
'page_id' => $parentID,
'page_title' => $parentTitle,
'page_parent' => (int)$awsID,
'author' => get_current_user_id(),
'created_at' => date("Y-m-d H:i:s")
]
);
$practiceAreaContent = '';
if(!empty($data['practiceArea'.$key])){
$awsPagecontent = $awsPagecontent . '';
$practiceAreaContent = 'Here are the practice areas we have in ' . $parentTitle . '
';
}
foreach($data['practiceArea'.$key] as $paKey => $paValue){
if(!empty($paValue)){
$pageTitle = ucwords($parentTitle . ' ' . $paValue . ' Lawyer');
$post_data = [
'post_title' => $pageTitle,
'post_content' => '',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'page'
];
$childID = wp_insert_post($post_data);
$totalPagesCreated++;
wp_update_post(
array(
'ID' => $childID,
'post_parent' => $parentID
)
);
$awsPagecontent = $awsPagecontent . '- '.$pageTitle.'';
$practiceAreaContent = $practiceAreaContent . '
- '.$pageTitle.'
';
// if($key == 0){
array_push($paNameAndLink , [
'title' => $pageTitle,
'permalink' => get_permalink($childID)
]);
// }
// Inserting page data to extension table as parent page
$wpdb->insert($table_name,
[
'page_id' => $childID,
'page_title' => $pageTitle,
'page_parent' => (int)$parentID,
'author' => get_current_user_id(),
'created_at' => date("Y-m-d H:i:s")
]
);
}
}
if(!empty($data['practiceArea'.$key])){
$practiceAreaContent = $practiceAreaContent . '
';
wp_update_post(
array(
'ID' => $parentID,
'post_content' => $practiceAreaContent,
)
);
$awsPagecontent = $awsPagecontent . '
';
}
$awsPagecontent = $awsPagecontent . '';
}
}
$awsPagecontent = $awsPagecontent . '';
wp_update_post(
array(
'ID' => $awsID,
'post_content' => $awsPagecontent,
)
);
// Create a manu or populate the current menu with the new created pages
$menuname = 'Attorney Header Menu';
$hdAttorneyTheme = 'primary';
// Does the menu exist already?
$menu_exists = wp_get_nav_menu_object( $menuname );
// If it doesn't exist, let's create it.
if( !$menu_exists){
$menu_id = wp_create_nav_menu($menuname);
// Set up default BuddyPress links and add them to the menu.
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Home' , 'attorney'),
'menu-item-classes' => 'home',
'menu-item-url' => home_url( '/' ),
'menu-item-status' => 'publish'));
$awsMenuId = wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Areas We Serve' , 'attorney'),
'menu-item-classes' => 'aws',
'menu-item-url' => home_url( '/areas-we-serve/' ),
'menu-item-status' => 'publish')
);
// Foreach Practice Area page as Practice Area
foreach($areasNameAndLink as $awsPage){
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __($awsPage['title'] , 'attorney'),
'menu-item-url' => $awsPage['permalink'],
'menu-item-status' => 'publish',
'menu-item-parent-id' => $awsMenuId)
);
}
$practiceAreasMenuID = wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Practice Areas' , 'attorney'),
'menu-item-classes' => 'pa',
'menu-item-url' => '#',
'menu-item-status' => 'publish')
);
foreach($paNameAndLink as $paPage){
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __($paPage['title'] , 'attorney'),
'menu-item-url' => $paPage['permalink'],
'menu-item-status' => 'publish',
'menu-item-parent-id' => $practiceAreasMenuID)
);
}
$practiceAreasMenuID = wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Contact' , 'attorney'),
'menu-item-classes' => 'contact',
'menu-item-url' => home_url('/contact-us/'),
'menu-item-status' => 'publish')
);
if( !has_nav_menu( $hdAttorneyTheme ) ){
$locations = get_theme_mod('nav_menu_locations');
$locations[$hdAttorneyTheme] = $menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
}
}
// Create contact page
if(shortcode_exists( 'contact-form-7' )){
$contactPageContent = '
Tell us about your case
[contact-form-7 title="HD Attorney Theme Lead Form"]
'.$contactPageContent.'
';
}else{
$contactPageContent = $contactPageContent.'';
}
$post_data = [
'post_title' => 'Contact Us',
'post_content' => $contactPageContent,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'page',
'post_parent' => 0
];
$totalPagesCreated++;
$contactID = wp_insert_post($post_data);
// Inserting page data to extension table as parent page
$wpdb->insert($table_name,
[
'page_id' => $contactID,
'page_title' => 'Contact Us',
'page_parent' => 0,
'author' => get_current_user_id(),
'created_at' => date("Y-m-d H:i:s")
]
);
wp_redirect(site_url().'/wp-admin/admin.php?page=hennessey-theme-settings&pagesCreated='.$totalPagesCreated);