/** * defines arrays containg a starting set of fields, groups, etc. * * @return void */ private function _define_init_arrays() { // define the default field groups self::$field_groups = array('main' => __('Participant Info', 'participants-database'), 'personal' => __('Personal Info', 'participants-database'), 'admin' => __('Administrative Info', 'participants-database'), 'internal' => __('Record Info', 'participants-database')); // fields for keeping track of records; not manually edited, but they can be displayed self::$internal_fields = array('id' => array('title' => 'Record ID', 'signup' => 1, 'form_element' => 'text-line', 'CSV' => 1, 'readonly' => 1), 'private_id' => array('title' => 'Private ID', 'signup' => 1, 'form_element' => 'text', 'admin_column' => 90, 'default' => 'RPNE2', 'readonly' => 1), 'date_recorded' => array('title' => 'Date Recorded', 'form_element' => 'timestamp', 'admin_column' => 100, 'sortable' => 1, 'readonly' => 1), 'date_updated' => array('title' => 'Date Updated', 'form_element' => 'timestamp', 'sortable' => 1, 'readonly' => 1), 'last_accessed' => array('title' => 'Last Accessed', 'form_element' => 'timestamp', 'sortable' => 1, 'readonly' => 1)); /* * these are some fields just to get things started * in the released plugin, these will be defined by the user * * the key is the id slug of the field * the fields in the array are: * title - a display title * help_text - help text to appear on the form * default - a default value * sortable - a listing can be sorted by this value if set * column - column in the list view and order (missing or 0 for not used) * persistent - is the field persistent from one entry to the next (for * convenience while entering multiple records) * CSV - is the field one to be imported or exported * validation - if the field needs to be validated, use this regex or just * yes for a value that must be filled in * form_element - the element to use in the form--defaults to * input, Could be text-line (input), text-field (textarea), * radio, dropdown (option) or checkbox, also select-other * multi-checkbox and asmselect.(http: *www.ryancramer.com/journal/entries/select_multiple/) * The mysql data type is determined by this. * values array title=>value pairs for checkboxes, radio buttons, dropdowns * for checkbox, first item is visible option, if value * matches 'default' value then it defaults checked */ self::$main_fields = array('first_name' => array('title' => 'First Name', 'form_element' => 'text-line', 'validation' => 'yes', 'sortable' => 1, 'admin_column' => 2, 'display_column' => 1, 'signup' => 1, 'CSV' => 1), 'last_name' => array('title' => 'Last Name', 'form_element' => 'text-line', 'validation' => 'yes', 'sortable' => 1, 'admin_column' => 3, 'display_column' => 2, 'signup' => 1, 'CSV' => 1), 'address' => array('title' => 'Address', 'form_element' => 'text-line', 'CSV' => 1), 'city' => array('title' => 'City', 'sortable' => 1, 'persistent' => 1, 'form_element' => 'text-line', 'admin_column' => 0, 'display_column' => 3, 'CSV' => 1), 'state' => array('title' => 'State', 'sortable' => 1, 'persistent' => 1, 'form_element' => 'text-line', 'display_column' => 4, 'CSV' => 1), 'country' => array('title' => 'Country', 'sortable' => 1, 'persistent' => 1, 'form_element' => 'text-line', 'CSV' => 1), 'zip' => array('title' => 'Zip Code', 'sortable' => 1, 'persistent' => 1, 'form_element' => 'text-line', 'CSV' => 1), 'phone' => array('title' => 'Phone', 'help_text' => 'Your primary contact number', 'form_element' => 'text-line', 'CSV' => 1), 'email' => array('title' => 'Email', 'form_element' => 'text-line', 'admin_column' => 4, 'validation' => '#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$#i', 'signup' => 1, 'CSV' => 1), 'mailing_list' => array('title' => 'Mailing List', 'help_text' => 'do you want to receive our newsletter and occasional announcements?', 'sortable' => 1, 'signup' => 1, 'form_element' => 'checkbox', 'CSV' => 1, 'default' => 'Yes', 'values' => array('Yes', 'No'))); self::$personal_fields = array('photo' => array('title' => 'Photo', 'help_text' => 'Upload a photo of yourself. 300 pixels maximum width or height.', 'form_element' => 'image-upload'), 'website' => array('title' => 'Website, Blog or Social Media Link', 'form_element' => 'link', 'help_text' => 'Put the URL in the left box and the link text that will be shown on the right'), 'interests' => array('title' => 'Interests or Hobbies', 'form_element' => 'multi-select-other', 'values' => array('Sports' => 'sports', 'Photography' => 'photography', 'Art/Crafts' => 'crafts', 'Outdoors' => 'outdoors', 'Yoga' => 'yoga', 'Music' => 'music', 'Cuisine' => 'cuisine'))); self::$admin_fields = array('approved' => array('title' => 'Approved', 'sortable' => 1, 'form_element' => 'checkbox', 'default' => 'no', 'values' => array('yes', 'no'))); }
/** * initializes the plugin in the WP environment, fired on the 'init' hook * * @return null */ public static function init() { // set the table names global $wpdb; /* * this filter allows a plugin to determine which db tables to use * * this allows things like multilingual field definitions or possibly even multiple databases */ self::$participants_table = self::set_filter('select_database_table', self::$participants_table); self::$fields_table = self::set_filter('select_database_table', self::$fields_table); self::$groups_table = self::set_filter('select_database_table', self::$groups_table); // also filter the name of the settings to use self::$participants_db_options = self::set_filter('select_database_table', self::$participants_db_options); /* * set up the base reference object arrays * * this is to reduce the number of db queries */ self::_setup_columns(); self::load_plugin_textdomain(__FILE__); self::$plugin_title = __('Participants Database', 'participants-database'); self::_set_i18n(); /** * @version 1.6 filter pdb-private_id_length */ self::$private_id_length = self::set_filter('private_id_length', self::$private_id_length); /* * checks for the need to update the DB * * this is to allow for updates to occur in many different ways */ if (false === get_option(self::$db_version_option) || get_option(self::$db_version_option) != self::$db_version) { PDb_Init::on_update(); } /* * instantiate the settings class; this only sets up the settings definitions, * the WP Settings API may not be available at this point, so we register the * settings on the 'admin_menu' hook */ self::$Settings = new PDb_Settings(); // get the plugin options array if (!is_array(self::$plugin_options)) { $default_options = get_option(self::$default_options); if (!is_array($default_options)) { $default_options = self::$Settings->get_default_options(); add_option(self::$default_options, $default_options, '', false); } self::$plugin_options = array_merge($default_options, (array) get_option(self::$participants_db_options)); } /* * normally, the custom CSS is written to a static css file, but on some systems, * that doesn't work, so the fallback is to load the dynamic CSS file */ if (self::_set_custom_css()) { $custom_css_file = 'PDb-custom.css'; } else { $custom_css_file = 'custom_css.php'; } /* * set the plugin date display format; uses the blog setting, which is localized * * since version 1.5.5 we have not used the "strict date format" becuase that * is for input purposes only. This format is used to display dates. * * this property can be changed in a template if desired */ self::$date_format = get_option('date_format'); if (self::plugin_setting_is_true('html_email')) { $type = 'text/html; charset="' . get_option('blog_charset') . '"'; } else { $type = 'text/plain; charset=us-ascii'; } $email_headers = "From: " . self::$plugin_options['receipt_from_name'] . " <" . self::$plugin_options['receipt_from_address'] . ">\n" . "Content-Type: " . $type . "\n"; self::$email_headers = self::set_filter('email_headers', $email_headers); // this processes form submits before any output so that redirects can be used self::process_page_request(); // if (!is_object(self::$Settings)) { // self::$Settings = new PDb_Settings(); // } // self::$Settings->initialize(); $option_version = self::$Settings->option_version(); /* * register frontend scripts and stylesheets */ wp_register_style('pdb-frontend', plugins_url('/css/participants-database.css', __FILE__), array('dashicons')); wp_register_style('custom_plugin_css', plugins_url('/css/' . $custom_css_file, __FILE__), null, $option_version); wp_register_script(self::$prefix . 'shortcode', plugins_url('js/shortcodes.js', __FILE__), array('jquery')); wp_register_script(self::$prefix . 'list-filter', plugins_url('js/list-filter.js', __FILE__), array('jquery')); wp_register_script(self::$prefix . 'jq-placeholder', plugins_url('js/jquery.placeholder.min.js', __FILE__), array('jquery')); wp_register_script(self::$prefix . 'otherselect', plugins_url('js/otherselect.js', __FILE__), array('jquery')); /* * register admin scripts and stylesheets */ wp_register_script(self::$prefix . 'cookie', plugins_url('js/jquery_cookie.js', __FILE__)); wp_register_script(self::$prefix . 'manage_fields', plugins_url('js/manage_fields.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-tabs', 'jquery-ui-sortable', 'jquery-ui-dialog', self::$prefix . 'cookie'), false, true); wp_register_script(self::$prefix . 'settings_script', plugins_url('js/settings.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-tabs', self::$prefix . 'cookie'), false, true); wp_register_script(self::$prefix . 'record_edit_script', plugins_url('js/record_edit.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-tabs', self::$prefix . 'cookie'), false, true); wp_register_script(self::$prefix . 'jq-placeholder', plugins_url('js/jquery.placeholder.min.js', __FILE__), array('jquery')); wp_register_script('jq-doublescroll', plugins_url('js/jquery.doubleScroll.js', __FILE__), array('jquery', 'jquery-ui-widget')); wp_register_script(self::$prefix . 'admin', plugins_url('js/admin.js', __FILE__), array('jquery', 'jq-doublescroll')); wp_register_script(self::$prefix . 'otherselect', plugins_url('js/otherselect.js', __FILE__), array('jquery')); wp_register_script(self::$prefix . 'list-admin', plugins_url('js/list_admin.js', __FILE__), array('jquery')); wp_register_script(self::$prefix . 'debounce', plugins_url('js/jq_debounce.js', __FILE__), array('jquery')); //wp_register_script( 'datepicker', plugins_url( 'js/jquery.datepicker.js', __FILE__ ) ); //wp_register_script( 'edit_record', plugins_url( 'js/edit.js', __FILE__ ) ); wp_register_style('pdb-utility', plugins_url('/css/xnau-utility.css', __FILE__)); wp_register_style('pdb-global-admin', plugins_url('/css/PDb-admin-global.css', __FILE__), false, false); wp_register_style('pdb-frontend', plugins_url('/css/participants-database.css', __FILE__)); wp_register_style('pdb-admin', plugins_url('/css/PDb-admin.css', __FILE__)); }
/** * initializes the plugin in the WP environment * @return null */ public static function init() { load_plugin_textdomain('participants-database', false, dirname(plugin_basename(__FILE__)) . '/languages/'); self::$plugin_title = __('Participants Database', 'participants-database'); self::_set_i18n(); /* * checks for the need to update the DB * * this is to allow for updates to occur in many different ways */ if (false === get_option(self::$db_version_option) || get_option(self::$db_version_option) != self::$db_version) { PDb_Init::on_update(); } // get the plugin options array if (!is_array(self::$plugin_options)) { $default_options = get_option(self::$default_options); if (!is_array($default_options)) { /* * instantiate the settings class; this only sets up the settings definitions, * the WP Settings API may not be available at this point, so we register the * settings on the 'admin_menu' hook */ self::$Settings = new PDb_Settings(); $default_options = self::$Settings->get_default_options(); add_option(self::$default_options, $default_options, '', false); } self::$plugin_options = array_merge($default_options, (array) get_option(self::$participants_db_options)); } /* * set the plugin date display format: if "strict dates" is enabled, use the * input date format to display all dates, if not, use the blog date format */ self::$date_format = self::$plugin_options['strict_dates'] == 1 ? self::$plugin_options['input_date_format'] : get_option('date_format'); if (0 != self::$plugin_options['html_email']) { $type = 'text/html; charset="' . get_option('blog_charset') . '"'; //add_filter('wp_mail_content_type', array( __CLASS__, 'set_content_type')); } else { $type = 'text/plain; charset=us-ascii'; } self::$email_headers = "MIME-Version: 1.0\n" . "From: " . self::$plugin_options['receipt_from_name'] . " <" . self::$plugin_options['receipt_from_address'] . ">\n" . "Content-Type: " . $type . "\n"; // this processes form submits before any output so that redirects can be used self::process_page_request(); }