/** * Install * * Runs on plugin install by setting up the post types, custom taxonomies, * flushing rewrite rules to initiate the new 'sell_media_item' slug and also * creates the plugin and populates the settings fields for those plugin * pages. * * @since 1.8.5 * @global $wpdb * @global $wp_version * @return void */ function sell_media_install() { $version = get_option('sell_media_version'); if ($version && $version > SELL_MEDIA_VERSION) { return; } // Register Custom Post Types sell_media_register_post_types(); // Register Taxonomies sell_media_register_taxonomies(); // Flush the permalinks flush_rewrite_rules(); // Don't forget registration hook is called // BEFORE! taxonomies are registered! therefore // these terms and taxonomies are NOT derived from our object! $settings = sell_media_get_plugin_options(); $admin_columns = empty($settings->admin_columns) ? null : $settings->admin_columns; // Install new table for term meta $taxonomy_metadata = new SellMediaTaxonomyMetadata(); $taxonomy_metadata->activate(); $taxonomy = 'licenses'; // Add Personal and Commerical default license terms $r_personal = wp_insert_term('Personal', $taxonomy, array('slug' => 'personal')); $r_commercial = wp_insert_term('Commercial', $taxonomy, array('slug' => 'commercial')); // Install protected folder for uploading files and prevent hotlinking $downloads_url = sell_media_get_upload_dir(); if (wp_mkdir_p($downloads_url) && !file_exists($downloads_url . '/.htaccess')) { if ($file_handle = @fopen($downloads_url . '/.htaccess', 'w')) { fwrite($file_handle, 'deny from all'); fclose($file_handle); } } // Add a new Customer role add_role('sell_media_customer', 'Customer', array('read' => true)); // This is a new install so add the defaults to the options table if (empty($version)) { $defaults = sell_media_get_plugin_option_defaults(); update_option(sell_media_get_current_plugin_id() . "_options", $defaults); // A version number exists, so run upgrades } else { require_once SELL_MEDIA_PLUGIN_DIR . '/inc/admin-upgrade.php'; } // Update the version number update_option('sell_media_version', SELL_MEDIA_VERSION); }
/** * Update term meta field based on term ID. * * Use the $prev_value parameter to differentiate between meta fields with the * same key and term ID. * * If the meta field for the term does not exist, it will be added. * * @param int $term_id Term ID. * @param string $key Metadata key. * @param mixed $value Metadata value. * @param mixed $prev_value Optional. Previous value to check before removing. * @return bool False on failure, true if success. */ function sell_media_update_term_meta($term_id, $meta_key, $meta_value, $prev_value = '') { SellMediaTaxonomyMetadata::wpdbfix(); return update_metadata('taxonomy', $term_id, $meta_key, $meta_value, $prev_value); }