Function Reference: geodir_cp_from_submit_handler
Summary
This function has not been documented yet.
Actions
‘geodir_after_custom_detail_table_create’ [Line: 472]
Filters
‘geodir_cpt_img_width’ [Line: 547]
‘geodir_cpt_img_height’ [Line: 548]
Source File
geodir_cp_from_submit_handler() is located in geodir_custom_posts/geodir_cp_functions.php [Line: 105]
Source Code
function geodir_cp_from_submit_handler(){ global $plugin_prefix, $wpdb; if(isset($_REQUEST['geodir_save_post_type'])) { $custom_post_type = (trim($_REQUEST['geodir_custom_post_type'])); $listing_slug = (trim($_REQUEST['geodir_listing_slug'])); $listing_order = trim($_REQUEST['geodir_listing_order']); $categories = $_REQUEST['geodir_categories']; $tags = isset($_REQUEST['geodir_tags']) ? $_REQUEST['geodir_tags'] : ''; $name = ($_REQUEST['geodir_name']);//htmlentities(trim($_REQUEST['geodir_name'])); $singular_name = (trim($_REQUEST['geodir_singular_name'])); $add_new = (trim($_REQUEST['geodir_add_new'])); $add_new_item = (trim($_REQUEST['geodir_add_new_item'])); $edit_item = (trim($_REQUEST['geodir_edit_item'])); $new_item = (trim($_REQUEST['geodir_new_item'])); $view_item = (trim($_REQUEST['geodir_view_item'])); $search_item = (trim($_REQUEST['geodir_search_item'])); $not_found = (trim($_REQUEST['geodir_not_found'])); $not_found_trash = (trim($_REQUEST['geodir_not_found_trash'])); $support = $_REQUEST['geodir_support']; $description = (trim($_REQUEST['geodir_description'])); $menu_icon = (trim($_REQUEST['geodir_menu_icon'])); $can_export = $_REQUEST['geodir_can_export']; $geodir_cp_meta_keyword = $_REQUEST['geodir_cp_meta_keyword']; $geodir_cp_meta_description = $_REQUEST['geodir_cp_meta_description']; $label_post_profile = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_profile'])); $label_post_info = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_info'])); $label_post_images = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_images'])); $label_post_map = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_map'])); $label_reviews = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_reviews'])); $label_related_listing = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_related_listing'])); $cpt_image = isset($_FILES['geodir_cpt_img']) && !empty($_FILES['geodir_cpt_img']) ? $_FILES['geodir_cpt_img'] : NULL; $cpt_image_remove = isset($_POST['geodir_cpt_img_remove']) ? $_POST['geodir_cpt_img_remove'] : false; if($can_export == 'true') { $can_export = true; } else { $can_export = false; } $custom_post_type = geodir_clean( $custom_post_type ); // erase special characters from string $listing_slug = geodir_clean( $listing_slug ); // erase special characters from string if(isset($_REQUEST['posttype']) && $_REQUEST['posttype'] != '') { $geodir_post_types = get_option( 'geodir_post_types' ); $post_type_array = $geodir_post_types[$_REQUEST['posttype']]; } if($custom_post_type != '' && $listing_slug != '') { if(empty($post_type_array)) { $is_custom = 1; //check post type create by custom or any other add-once $posttypes_array = get_option( 'geodir_post_types' ); $post_type = $custom_post_type; $custom_post_type = 'gd_'.$custom_post_type; if (array_key_exists($custom_post_type, $posttypes_array)) { $error[] = __( 'Post Type already exists.', GEODIR_CP_TEXTDOMAIN ); } foreach($posttypes_array as $key=>$value) { if($value['has_archive'] == $listing_slug) { $error[] = __( 'Listing Slug already exists.', GEODIR_CP_TEXTDOMAIN ); break; } } } else { $post_type = preg_replace('/gd_/', '', $_REQUEST['posttype'], 1); $custom_post_type = $_REQUEST['posttype']; $is_custom = isset($post_type_array['is_custom']) ? $post_type_array['is_custom'] : ''; /*check post type create by custom or any other add-once */ //Edit case check duplicate listing slug if($post_type_array['has_archive'] != $listing_slug) { $posttypes_array = get_option( 'geodir_post_types' ); foreach($posttypes_array as $key=>$value) { if($value['has_archive'] == $listing_slug) { $error[] = __( 'Listing Slug already exists.', GEODIR_CP_TEXTDOMAIN ); break; } } } } if(empty($error)) { /** * Include any functions needed for upgrades. * * @since 1.1.7 */ require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); if(!empty($post_type_array)) { if(!$categories) { $geodir_taxonomies = get_option('geodir_taxonomies'); if(array_key_exists($custom_post_type.'category', $geodir_taxonomies)) { unset($geodir_taxonomies[$custom_post_type.'category']); update_option( 'geodir_taxonomies', $geodir_taxonomies ); } } if(!$tags) { $geodir_taxonomies = get_option('geodir_taxonomies'); if (array_key_exists($custom_post_type.'_tags', $geodir_taxonomies)) { unset($geodir_taxonomies[$custom_post_type.'_tags']); update_option( 'geodir_taxonomies', $geodir_taxonomies ); } } } $taxonomies = array(); if ( $categories ) { $taxonomies[] = $custom_post_type.'category'; $categories = $custom_post_type.'category'; } if ( $tags ) { $taxonomies[] = $custom_post_type.'_tags'; $tags = $custom_post_type.'_tags'; } if ( $categories ) { $gd_placecategory = array(); $gd_placecategory['object_type']= $custom_post_type; $gd_placecategory['listing_slug']= $listing_slug; $gd_placecategory['args'] = array ( 'public' => true, 'hierarchical' => true, 'rewrite' => array ( 'slug' => $listing_slug, 'with_front' => false, 'hierarchical' => true ), 'query_var' => true, 'labels' => array ( 'name' => __( ucfirst($post_type).' Categories', GEODIR_CP_TEXTDOMAIN ), 'singular_name' => __( ucfirst($post_type).' Category', GEODIR_CP_TEXTDOMAIN ), 'search_items' => __( 'Search '.ucfirst($post_type).' Categories', GEODIR_CP_TEXTDOMAIN ), 'popular_items' => __( 'Popular '.ucfirst($post_type).' Categories', GEODIR_CP_TEXTDOMAIN ), 'all_items' => __( 'All '.ucfirst($post_type).' Categories', GEODIR_CP_TEXTDOMAIN ), 'edit_item' => __( 'Edit '.ucfirst($post_type).' Category', GEODIR_CP_TEXTDOMAIN ), 'update_item' => __( 'Update '.ucfirst($post_type).' Category', GEODIR_CP_TEXTDOMAIN ), 'add_new_item' => __( 'Add New '.ucfirst($post_type).' Category', GEODIR_CP_TEXTDOMAIN ), 'new_item_name' => __( 'New '.ucfirst($post_type).' Category', GEODIR_CP_TEXTDOMAIN ), 'add_or_remove_items' => __( 'Add or remove '.ucfirst($post_type).' categories', GEODIR_CP_TEXTDOMAIN ), ), 'show_in_nav_menus' => ( !empty( $_REQUEST['geodir_disable_nav_menus']['cats'] ) ? 0 : 1 ), ); $geodir_taxonomies = get_option( 'geodir_taxonomies' ); $geodir_taxonomies[$categories] = $gd_placecategory; update_option( 'geodir_taxonomies', $geodir_taxonomies ); } if ( $tags ) { $gd_placetags = array(); $gd_placetags['object_type'] = $custom_post_type; $gd_placetags['listing_slug'] = $listing_slug.'/tags'; $gd_placetags['args'] = array ( 'public' => true, 'hierarchical' => false, 'rewrite' => array ( 'slug' => $listing_slug.'/tags', 'with_front' => false, 'hierarchical' => false ), 'query_var' => true, 'labels' => array ( 'name' => __( ucfirst($post_type).' Tags', GEODIR_CP_TEXTDOMAIN ), 'singular_name' => __( ucfirst($post_type).' Tag', GEODIR_CP_TEXTDOMAIN ), 'search_items' => __( 'Search '.ucfirst($post_type).' Tags', GEODIR_CP_TEXTDOMAIN ), 'popular_items' => __( 'Popular '.ucfirst($post_type).' Tags', GEODIR_CP_TEXTDOMAIN ), 'all_items' => __( 'All '.ucfirst($post_type).' Tags', GEODIR_CP_TEXTDOMAIN ), 'edit_item' => __( 'Edit '.ucfirst($post_type).' Tag', GEODIR_CP_TEXTDOMAIN ), 'update_item' => __( 'Update '.ucfirst($post_type).' Tag', GEODIR_CP_TEXTDOMAIN ), 'add_new_item' => __( 'Add New '.ucfirst($post_type).' Tag', GEODIR_CP_TEXTDOMAIN ), 'new_item_name' => __( 'New '.ucfirst($post_type).' Tag Name', GEODIR_CP_TEXTDOMAIN ), 'add_or_remove_items' => __( 'Add or remove '.ucfirst($post_type).' tags', GEODIR_CP_TEXTDOMAIN ), 'choose_from_most_used' => __( 'Choose from the most used '.ucfirst($post_type).' tags', GEODIR_CP_TEXTDOMAIN ), 'separate_items_with_commas' => __( 'Separate '.ucfirst($post_type).' tags with commas', GEODIR_CP_TEXTDOMAIN ), ), 'show_in_nav_menus' => ( !empty( $_REQUEST['geodir_disable_nav_menus']['tags'] ) ? 0 : 1 ), ); $geodir_taxonomies = get_option( 'geodir_taxonomies' ); $geodir_taxonomies[$tags] = $gd_placetags; update_option( 'geodir_taxonomies', $geodir_taxonomies ); } if(empty($name)) $name = __( ucfirst($post_type), GEODIR_CP_TEXTDOMAIN ); if(empty($singular_name)) $singular_name = __( ucfirst($post_type), GEODIR_CP_TEXTDOMAIN ); if(empty($add_new)) $add_new = __( 'Add New '.ucfirst($post_type), GEODIR_CP_TEXTDOMAIN ); if(empty($add_new_item)) $add_new_item = __( 'Add New Item', GEODIR_CP_TEXTDOMAIN ); if(empty($edit_item)) $edit_item = __( 'Edit Item', GEODIR_CP_TEXTDOMAIN ); if(empty($new_item)) $new_item = __( 'New Item', GEODIR_CP_TEXTDOMAIN ); if(empty($view_item)) $view_item = __( 'View Item', GEODIR_CP_TEXTDOMAIN ); if(empty($search_item)) $search_item = __( 'Search Items', GEODIR_CP_TEXTDOMAIN ); if(empty($not_found)) $not_found = __( 'Not Found', GEODIR_CP_TEXTDOMAIN ); if(empty($not_found_trash)) $not_found_trash = __( 'Not Found In Trash', GEODIR_CP_TEXTDOMAIN ); $labels = array ( 'name' => ucfirst($name), 'singular_name' => ucfirst($singular_name), 'add_new' => ucfirst($add_new), 'add_new_item' => ucfirst($add_new_item), 'edit_item' => ucfirst($edit_item), 'new_item' => ucfirst($new_item), 'view_item' => ucfirst($view_item), 'search_items' => ucfirst($search_item), 'not_found' => ucfirst($not_found), 'not_found_in_trash' => ucfirst($not_found_trash), 'label_post_profile' => $label_post_profile, 'label_post_info' => $label_post_info, 'label_post_images' => $label_post_images, 'label_post_map' => $label_post_map, 'label_reviews' => $label_reviews, 'label_related_listing' => $label_related_listing ); $place_default = array ( 'labels' => $labels, 'can_export' => $can_export, 'capability_type' => 'post', 'description' => $description, 'has_archive' => $listing_slug, 'hierarchical' => false, 'map_meta_cap' => true, 'menu_icon' => apply_filters('geodir_custom_post_type_default_menu_icon', $menu_icon), 'public' => true, 'query_var' => true, 'rewrite' => array ( 'slug' => $listing_slug, 'with_front' => false, 'hierarchical' => true ), 'supports' => $support, 'taxonomies' => $taxonomies, 'is_custom' => $is_custom, 'listing_order' => $listing_order, 'seo' => array ( 'meta_keyword'=> $geodir_cp_meta_keyword, 'meta_description'=> $geodir_cp_meta_description ), 'show_in_nav_menus' => ( !empty( $_REQUEST['geodir_disable_nav_menus']['posts'] ) ? 0 : 1 ), ); update_option( 'temp_post_type' , $place_default ) ; $geodir_post_types = get_option( 'geodir_post_types' ); $geodir_post_types[$custom_post_type] = $place_default; update_option( 'geodir_post_types', $geodir_post_types ); //ADD NEW CUSTOM POST TYPE IN SHOW POST TYPE NAVIGATIONS if(!isset($_REQUEST['posttype'])){ $get_posttype_settings_options = array('geodir_add_posttype_in_listing_nav','geodir_allow_posttype_frontend','geodir_add_listing_link_add_listing_nav','geodir_add_listing_link_user_dashboard','geodir_listing_link_user_dashboard','geodir_favorite_link_user_dashboard'); foreach($get_posttype_settings_options as $get_posttype_settings_options_obj){ $geodir_post_types_listing = get_option( $get_posttype_settings_options_obj); if(empty($geodir_post_types_listing) || (is_array($geodir_post_types_listing) && !in_array($custom_post_type, $geodir_post_types_listing))){ $geodir_post_types_listing[] = $custom_post_type; update_option( $get_posttype_settings_options_obj, $geodir_post_types_listing ); } } } // Save post types in default table if(empty($post_type_array)) { $geodir_custom_post_types = get_option('geodir_custom_post_types'); if(!$geodir_custom_post_types) $geodir_custom_post_types = array(); if (!array_key_exists($custom_post_type, $geodir_custom_post_types)) { $geodir_custom_post_types[$custom_post_type] = $custom_post_type; update_option( 'geodir_custom_post_types', $geodir_custom_post_types ); } } // Table for storing custom post type attribute - these are user defined $collate = ''; if($wpdb->has_cap( 'collation' )) { if(!empty($wpdb->charset)) $collate = "DEFAULT CHARACTER SET $wpdb->charset"; if(!empty($wpdb->collate)) $collate .= " COLLATE $wpdb->collate"; } $newtable_name = $plugin_prefix.$custom_post_type.'_detail'; $newposttype_detail = "CREATE TABLE IF NOT EXISTS ".$newtable_name." ( `post_id` int(11) NOT NULL, `post_title` text NULL DEFAULT NULL, `post_status` varchar(20) NULL DEFAULT NULL, `default_category` INT NULL DEFAULT NULL, `post_tags` text NULL DEFAULT NULL, `post_location_id` int(11) NOT NULL, `marker_json` text NULL DEFAULT NULL, `claimed` ENUM( '1', '0' ) NULL DEFAULT '0', `businesses` ENUM( '1', '0' ) NULL DEFAULT '0', `is_featured` ENUM( '1', '0' ) NULL DEFAULT '0', `featured_image` VARCHAR( 254 ) NULL DEFAULT NULL, `paid_amount` DOUBLE NOT NULL DEFAULT '0', `package_id` INT(11) NOT NULL DEFAULT '0', `alive_days` INT(11) NOT NULL DEFAULT '0', `paymentmethod` varchar(30) NULL DEFAULT NULL, `expire_date` VARCHAR( 100 ) NULL DEFAULT NULL, `submit_time` varchar(25) NULL DEFAULT NULL, `submit_ip` varchar(15) NULL DEFAULT NULL, `overall_rating` float(11) DEFAULT NULL, `rating_count` INT(11) DEFAULT '0', `post_locations` VARCHAR( 254 ) NULL DEFAULT NULL, PRIMARY KEY (`post_id`)) $collate "; dbDelta($newposttype_detail); do_action('geodir_after_custom_detail_table_create', $custom_post_type, $newtable_name); $package_info = array() ; /*$package_info = apply_filters('geodir_post_package_info' , $package_info , '', $custom_post_type); $package_id = $package_info->pid;*/ $package_info = geodir_post_package_info($package_info , '', $custom_post_type); $package_id = $package_info->pid; if(!$wpdb->get_var($wpdb->prepare("SELECT id FROM ".GEODIR_CUSTOM_FIELDS_TABLE." WHERE FIND_IN_SET(%s, packages)",array($package_id)))) { $table = $plugin_prefix.$custom_post_type.'_detail'; $wpdb->query($wpdb->prepare("UPDATE ".$table." SET package_id=%d",array($package_id))); $wpdb->query($wpdb->prepare("UPDATE ".GEODIR_CUSTOM_FIELDS_TABLE." SET packages=%s WHERE post_type=%s",array($package_id,$custom_post_type))); } geodir_cp_create_default_fields($custom_post_type, $package_id); $msg = __( 'Post type created successfully.', GEODIR_CP_TEXTDOMAIN ); if(isset($_REQUEST['posttype']) && $_REQUEST['posttype'] != ''){ $msg = __( 'Post type updated successfully.', GEODIR_CP_TEXTDOMAIN ); } /// call the geodirectory core function to register all posttypes again. geodir_register_post_types(); // call the geodirectory core function to register all taxonomies again. geodir_register_taxonomies(); geodir_flush_rewrite_rules(); geodir_set_user_defined_order() ; // Save CPT image $uploads = wp_upload_dir(); // if remove is set then remove the file if ($cpt_image_remove) { if (get_option('geodir_cpt_img_' . $custom_post_type)) { $image_name_arr = explode('/', get_option('geodir_cpt_img_' . $custom_post_type)); $img_path = $uploads['path'] . '/' . end($image_name_arr); if (file_exists($img_path)) unlink($img_path); } update_option('geodir_cpt_img_' . $custom_post_type, ''); } if ($cpt_image) { $tmp_name = isset($cpt_image['tmp_name']) ? $cpt_image['tmp_name'] : ''; $filename = isset($cpt_image['name']) ? $cpt_image['name'] : ''; $ext = pathinfo($filename, PATHINFO_EXTENSION); $uplaods = array(); $uplaods[] = $tmp_name; $allowed_file_types = array('jpg' => 'image/jpg','jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png'); $upload_overrides = array('test_form' => false, 'mimes' => $allowed_file_types); $cpt_img = wp_handle_upload($cpt_image, $upload_overrides); if (!empty($cpt_img) && !empty($cpt_img['url'])) { if (get_option('geodir_cpt_img_' . $custom_post_type)) { $image_name_arr = explode('/', get_option('geodir_cpt_img_' . $custom_post_type)); $img_path = $uploads['path'] . '/' . end($image_name_arr); if (file_exists($img_path)) unlink($img_path); } // set width and height $w = apply_filters('geodir_cpt_img_width', 300); // get large size width $h = apply_filters('geodir_cpt_img_height', 300); // get large size width // get the uploaded image $cpt_img_file = wp_get_image_editor( $cpt_img['file'] ); // if no error if ( ! is_wp_error( $cpt_img_file ) ) { // get image width and height $size = getimagesize( $cpt_img['file'] ); // $size[0] = width, $size[1] = height if ( $size[0] > $w || $size[1] > $h ){ // if the width or height is larger than the large-size $cpt_img_file->resize( $w, $h, false ); // resize the image $final_image = $cpt_img_file->save( $cpt_img['file'] ); // save the resized image } } update_option('geodir_cpt_img_' . $custom_post_type, $cpt_img['url']); } } $msg = urlencode($msg); $redirect_to = admin_url().'admin.php?page=geodirectory&tab=geodir_manage_custom_posts&cp_success='.$msg; wp_redirect( $redirect_to ); exit; } else { global $cp_error; foreach($error as $err) { $cp_error .= ''; } } } } if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'cp_delete') { if($_REQUEST['posttype']) { $geodir_taxonomies = get_option('geodir_taxonomies'); if (array_key_exists($_REQUEST['posttype'].'category', $geodir_taxonomies)) { unset($geodir_taxonomies[$_REQUEST['posttype'].'category']); update_option( 'geodir_taxonomies', $geodir_taxonomies ); } if (array_key_exists($_REQUEST['posttype'].'_tags', $geodir_taxonomies)) { unset($geodir_taxonomies[$_REQUEST['posttype'].'_tags']); update_option( 'geodir_taxonomies', $geodir_taxonomies ); } $geodir_post_types = get_option( 'geodir_post_types' ); if (array_key_exists($_REQUEST['posttype'], $geodir_post_types)) { unset($geodir_post_types[$_REQUEST['posttype']]); update_option( 'geodir_post_types', $geodir_post_types ); } //UPDATE SHOW POST TYPES NAVIGATION OPTIONS $get_posttype_settings_options = array('geodir_add_posttype_in_listing_nav','geodir_allow_posttype_frontend','geodir_add_listing_link_add_listing_nav','geodir_add_listing_link_user_dashboard','geodir_listing_link_user_dashboard','geodir_favorite_link_user_dashboard'); foreach($get_posttype_settings_options as $get_posttype_settings_options_obj) { $geodir_post_types_listing = get_option( $get_posttype_settings_options_obj); if (in_array($_REQUEST['posttype'], $geodir_post_types_listing)) { $geodir_update_post_type_nav = array_diff($geodir_post_types_listing, array($_REQUEST['posttype'])); update_option( $get_posttype_settings_options_obj, $geodir_update_post_type_nav ); } } //END CODE OPTIONS geodir_flush_rewrite_rules() ; $msg = __( 'Post type deleted successfully.', GEODIR_CP_TEXTDOMAIN ); $msg = urlencode($msg); $redirect_to = admin_url().'admin.php?page=geodirectory&tab=geodir_manage_custom_posts&confirm=true&geodir_customposttype='.$_REQUEST['posttype'].'&cp_success='.$msg; wp_redirect( $redirect_to ); exit; } } }' . $err . '