Function Reference: geodir_default_taxonomies

Summary

Default taxonomies

Description

Adds the default terms for taxonomies – placecategory. Modify at your own risk.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$dummy_image_path
(string) (required) The dummy image path.

Default: None

Package

GeoDirectory

Change Log

Since: 1.0.0

Filters

‘place_dummy_cat_image_url’ [Line: 677]

Source File

geodir_default_taxonomies() is located in geodirectory-admin/admin_functions.php [Line: 648]

Source Code

function geodir_default_taxonomies() {
    global $wpdb, $dummy_image_path;

    $category_array = array('Attractions', 'Hotels', 'Restaurants', 'Food Nightlife', 'Festival', 'Videos', 'Feature');

    $last_catid = '';

    $uploads = wp_upload_dir(); // Array of key => value pairs

    for ($i = 0; $i < count($category_array); $i++) {
        $parent_catid = 0;
        if (is_array($category_array[$i])) {
            $cat_name_arr = $category_array[$i];
            for ($j = 0; $j < count($cat_name_arr); $j++) {
                $catname = $cat_name_arr[$j];

                if (!term_exists($catname, 'gd_placecategory')) {
                    $last_catid = wp_insert_term($catname, 'gd_placecategory', $args = array('parent' => $parent_catid));

                    if ($j == 0) {
                        $parent_catid = $last_catid;
                    }


                    if (geodir_dummy_folder_exists())
                        $dummy_image_url = geodir_plugin_url() . "/geodirectory-admin/dummy/cat_icon";
                    else
                        $dummy_image_url = 'http://www.wpgeodirectory.com/dummy/cat_icon';

                    $dummy_image_url = apply_filters('place_dummy_cat_image_url', $dummy_image_url);

                    $catname = str_replace(' ', '_', $catname);
                    $uploaded = (array)fetch_remote_file("$dummy_image_url/" . $catname . ".png");

                    if (empty($uploaded['error'])) {
                        $new_path = $uploaded['file'];
                        $new_url = $uploaded['url'];
                    }

                    $wp_filetype = wp_check_filetype(basename($new_path), null);

                    $attachment = array(
                        'guid' => $uploads['baseurl'] . '/' . basename($new_path),
                        'post_mime_type' => $wp_filetype['type'],
                        'post_title' => preg_replace('/\.[^.]+$/', '', basename($new_path)),
                        'post_content' => '',
                        'post_status' => 'inherit'
                    );
                    $attach_id = wp_insert_attachment($attachment, $new_path);

                    // you must first include the image.php file
                    // for the function wp_generate_attachment_metadata() to work
                    require_once(ABSPATH . 'wp-admin/includes/image.php');
                    $attach_data = wp_generate_attachment_metadata($attach_id, $new_path);
                    wp_update_attachment_metadata($attach_id, $attach_data);

                    if (!get_tax_meta($last_catid['term_id'], 'ct_cat_icon', false, 'gd_place')) {
                        update_tax_meta($last_catid['term_id'], 'ct_cat_icon', array('id' => 'icon', 'src' => $new_url), 'gd_place');
                    }
                }
            }

        } else {
            $catname = $category_array[$i];

            if (!term_exists($catname, 'gd_placecategory')) {
                $last_catid = wp_insert_term($catname, 'gd_placecategory');

                if (geodir_dummy_folder_exists())
                    $dummy_image_url = geodir_plugin_url() . "/geodirectory-admin/dummy/cat_icon";
                else
                    $dummy_image_url = 'http://www.wpgeodirectory.com/dummy/cat_icon';

                $dummy_image_url = apply_filters('place_dummy_cat_image_url', $dummy_image_url);

                $catname = str_replace(' ', '_', $catname);
                $uploaded = (array)fetch_remote_file("$dummy_image_url/" . $catname . ".png");

                if (empty($uploaded['error'])) {
                    $new_path = $uploaded['file'];
                    $new_url = $uploaded['url'];
                }

                $wp_filetype = wp_check_filetype(basename($new_path), null);

                $attachment = array(
                    'guid' => $uploads['baseurl'] . '/' . basename($new_path),
                    'post_mime_type' => $wp_filetype['type'],
                    'post_title' => preg_replace('/\.[^.]+$/', '', basename($new_path)),
                    'post_content' => '',
                    'post_status' => 'inherit'
                );

                $attach_id = wp_insert_attachment($attachment, $new_path);


                // you must first include the image.php file
                // for the function wp_generate_attachment_metadata() to work
                require_once(ABSPATH . 'wp-admin/includes/image.php');
                $attach_data = wp_generate_attachment_metadata($attach_id, $new_path);
                wp_update_attachment_metadata($attach_id, $attach_data);

                if (!get_tax_meta($last_catid['term_id'], 'ct_cat_icon', false, 'gd_place')) {
                    update_tax_meta($last_catid['term_id'], 'ct_cat_icon', array('id' => $attach_id, 'src' => $new_url), 'gd_place');
                }
            }
        }

    }
}