/** * 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); }
/** * Theme register_setting() sanitize callback * * Validate and whitelist user-input data before updating Theme * Options in the database. Only whitelisted options are passed * back to the database, and user-input data for all whitelisted * options are sanitized. * * @link http://codex.wordpress.org/Data_Validation Codex Reference: Data Validation * * @param array $input Raw user-input data submitted via the Theme Settings page * @return array $input Sanitized user-input data passed to the database * * @global array Settings Page Tab definitions * */ function sell_media_plugin_options_validate($input) { global $sell_media_plugin_tabs; // This is the "whitelist": current settings $valid_input = (array) sell_media_get_plugin_options(); // Get the array of Theme settings, by Settings Page tab $settingsbytab = sell_media_get_plugin_settings_by_tab(); // Get the array of option parameters $option_parameters = sell_media_get_plugin_option_parameters(); // Get the array of option defaults $option_defaults = sell_media_get_plugin_option_defaults(); // Get list of tabs // Determine what type of submit was input $submittype = 'submit'; foreach ($sell_media_plugin_tabs as $tab) { $resetname = 'reset-' . $tab['name']; if (!empty($input[$resetname])) { $submittype = 'reset'; } } // Determine what tab was input $submittab = ''; foreach ($sell_media_plugin_tabs as $tab) { $submitname = 'submit-' . $tab['name']; $resetname = 'reset-' . $tab['name']; if (!empty($input[$submitname]) || !empty($input[$resetname])) { $submittab = $tab['name']; } } // Get settings by tab $tabsettings = $settingsbytab[$submittab]; // Loop through each tab setting foreach ($tabsettings as $setting) { // If no option is selected, set the default $valid_input[$setting] = !isset($input[$setting]) ? $option_defaults[$setting] : $input[$setting]; // If submit, validate/sanitize $input if ('submit' == $submittype) { // Get the setting details from the defaults array $optiondetails = $option_parameters[$setting]; // Get the array of valid options, if applicable $valid_options = isset($optiondetails['valid_options']) ? $optiondetails['valid_options'] : false; // Validate checkbox fields if ('checkbox' == $optiondetails['type']) { // If input value is set and is true, return true; otherwise return false if (isset($input[$setting]) && is_array($input[$setting])) { foreach ($input[$setting] as $key => $checkbox) { if (isset($checkbox) && 'on' == $checkbox) { $valid_input[$setting][] = true; } } } else { $valid_input[$setting] = isset($input[$setting]) && true == $input[$setting] ? true : false; } } else { if ('radio' == $optiondetails['type']) { // Only update setting if input value is in the list of valid options $valid_input[$setting] = array_key_exists($input[$setting], $valid_options) ? $input[$setting] : $valid_input[$setting]; } else { if ('select' == $optiondetails['type']) { // Only update setting if input value is in the list of valid options $valid_input[$setting] = array_key_exists($setting, $valid_options) ? $input[$setting] : $valid_input[$setting]; } else { if ('text' == $optiondetails['type'] || 'textarea' == $optiondetails['type']) { // Validate no-HTML content if ('nohtml' == $optiondetails['sanitize']) { // Pass input data through the wp_filter_nohtml_kses filter $valid_input[$setting] = wp_filter_nohtml_kses($input[$setting]); } // Validate HTML content if ('html' == $optiondetails['sanitize']) { // Pass input data through the wp_filter_kses filter $valid_input[$setting] = addslashes($input[$setting]); } // Validate Slug if ('slug' == $optiondetails['sanitize']) { $valid_input[$setting] = sanitize_title($input[$setting]); } } } } } } elseif ('reset' == $submittype) { // Set $setting to the default value $valid_input[$setting] = $option_defaults[$setting]; } } return $valid_input; }
/** * Get GPP Theme Options * * Array that holds all of the defined values * for GPP Theme options. If the user * has not specified a value for a given Theme * option, then the option's default value is * used instead. * * @uses sell_media_get_plugin_option_defaults() defined in \functions\options.php * @uses get_option() * @uses wp_parse_args() * * @return array $sell_media_options current values for all Theme options */ function sell_media_get_plugin_options() { // Get the option defaults $option_defaults = sell_media_get_plugin_option_defaults(); // Globalize the variable that holds the Theme options global $sell_media_options; // Parse the stored options with the defaults $sell_media_options = (object) wp_parse_args(get_option(sell_media_get_current_plugin_id() . '_options', array()), $option_defaults); // Return the parsed array return $sell_media_options; }