Skip to content

Commit

Permalink
Merge pull request #37 from AyeCode/master
Browse files Browse the repository at this point in the history
pull
  • Loading branch information
kprajapatii authored Apr 11, 2024
2 parents 9329805 + 544927f commit bfb038f
Show file tree
Hide file tree
Showing 15 changed files with 468 additions and 1,971 deletions.
46 changes: 45 additions & 1 deletion includes/admin/class-geodir-admin-dummy-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public static function add_dummy_address($post_info = array()){
*/
public static function create_dummy_posts( $request ) {

global $city_bound_lat1, $city_bound_lng1, $city_bound_lat2, $city_bound_lng2,$dummy_post_index,$dummy_image_url,$plugin_prefix, $dummy_categories, $dummy_custom_fields, $dummy_posts,$dummy_sort_fields,$dummy_page_templates;
global $city_bound_lat1, $city_bound_lng1, $city_bound_lat2, $city_bound_lng2,$dummy_post_index,$dummy_image_url,$plugin_prefix, $dummy_categories, $dummy_custom_fields, $dummy_posts,$dummy_sort_fields,$dummy_page_templates,$dummy_advanced_search_fields,$cpt_changes;

$city_bound_lat1 = $request['city_bound_lat1'];
$city_bound_lng1 = $request['city_bound_lng1'];
Expand All @@ -348,7 +348,9 @@ public static function create_dummy_posts( $request ) {
$dummy_sort_fields = array();
$dummy_posts = array();
$dummy_page_templates = array();
$dummy_advanced_search_fields = array();
$dummy_image_url = '';
$cpt_changes = array();
foreach ( $data_types as $key => $val ) {
if ( $key == $data_type ) {
$total_count = $val['count'];
Expand Down Expand Up @@ -466,6 +468,23 @@ public static function create_dummy_posts( $request ) {
self::set_page_templates($post_type,$dummy_page_templates);
}

// Maybe insert advanced search filters
if ( class_exists( 'GeoDir_Adv_Search_Settings_Cpt_Search' ) && ! empty( $dummy_advanced_search_fields ) ) {
$as = new GeoDir_Adv_Search_Settings_Cpt_Search();
foreach ( $dummy_advanced_search_fields as $advanced_search_field ) {
$exists = $as::field_exists( $advanced_search_field['htmlvar_name'], $post_type );
if ( ! $exists ) {
$as::save_field( $advanced_search_field );
}
}
}


// maybe update CPT names
if ( $update_templates && !empty($cpt_changes)) {
self::update_cpt( $post_type, $cpt_changes );
}

return true;

} else { // if index is not 0 then we are starting on posts.
Expand Down Expand Up @@ -493,6 +512,31 @@ public static function create_dummy_posts( $request ) {
}
}

/**
* @param $post_type
* @param $cpt_changes
*
* @return void
*/
public static function update_cpt( $post_type, $cpt_changes ) {
$post_types = geodir_get_option('post_types', array());

// bail if not a GD CPT
if(empty($post_types[$post_type])){
return;
}

$cpt_changes_escaped[$post_type] = map_deep( $cpt_changes, 'sanitize_text_field' );

if ( ! empty( $cpt_changes_escaped ) ) {
$post_types = array_replace_recursive($post_types,$cpt_changes_escaped);
// print_r($post_types);exit;
//Update custom post types
geodir_update_option( 'post_types', $post_types );
}

}

/**
* Update the template content if set to do so.
*
Expand Down
3 changes: 3 additions & 0 deletions includes/admin/dummy-data/car_sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,3 +835,6 @@ function geodir_extra_custom_fields_classifieds( $fields, $post_type, $package_i
[gd_output_location location='listing']
[gd_post_content key='post_content' limit='60' max_height='120']
[gd_archive_item_section type='close' position='right']";



Loading

0 comments on commit bfb038f

Please sign in to comment.