예제 #1
0
 /**
  * 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__));
 }
예제 #2
0
 /**
  * initializes the static class
  * 
  * sets up the class autoloading, configuration values, hooks, filters and shortcodes
  * 
  * @global object $wpdb
  */
 public static function initialize()
 {
     // set the table names
     global $wpdb;
     self::$participants_table = $wpdb->prefix . str_replace('-', '_', self::PLUGIN_NAME);
     self::$fields_table = self::$participants_table . '_fields';
     self::$groups_table = self::$participants_table . '_groups';
     // set the plugin version
     self::$plugin_version = self::_get_plugin_data('Version');
     // define some locations
     self::$participants_db_options = self::PLUGIN_NAME . '_options';
     self::$default_options = self::$prefix . 'default_options';
     self::$plugin_page = self::PLUGIN_NAME;
     self::$plugin_path = dirname(__FILE__);
     self::$plugin_url = WP_PLUGIN_URL . '/' . self::PLUGIN_NAME;
     // this is relative to the WP install
     self::$uploads_path = 'wp-content/uploads/' . self::PLUGIN_NAME . '/';
     self::$last_record = self::$prefix . 'last_record';
     self::$css_prefix = self::$prefix;
     self::$session = new PDb_Session();
     // install/deactivate and uninstall methods are handled by the PDB_Init class
     register_activation_hook(__FILE__, array('PDb_Init', 'on_activate'));
     register_deactivation_hook(__FILE__, array('PDb_Init', 'on_deactivate'));
     register_uninstall_hook(__FILE__, array('PDb_Init', 'on_uninstall'));
     add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(__CLASS__, 'add_plugin_action_links'));
     add_filter('plugin_row_meta', array(__CLASS__, 'add_plugin_meta_links'), 10, 2);
     // set the WP hooks to finish setting up the plugin
     add_action('init', array(__CLASS__, 'init'));
     add_action('wp', array(__CLASS__, 'post_check_shortcode'));
     add_action('template_include', array(__CLASS__, 'template_check_shortcode'));
     add_filter('admin_body_class', array(__CLASS__, 'add_admin_body_class'));
     add_filter('body_class', array(__CLASS__, 'add_body_class'));
     add_action('admin_menu', array(__CLASS__, 'plugin_menu'));
     add_action('admin_init', array(__CLASS__, 'admin_init'));
     add_action('wp_enqueue_scripts', array(__CLASS__, 'include_scripts'));
     add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_includes'));
     add_action('wp_footer', array(__CLASS__, 'add_scripts'));
     // handles ajax request from list filter
     add_action('wp_ajax_pdb_list_filter', array(__CLASS__, 'pdb_list_filter'));
     add_action('wp_ajax_nopriv_pdb_list_filter', array(__CLASS__, 'pdb_list_filter'));
     // define our shortcodes
     add_shortcode('pdb_record', array(__CLASS__, 'print_record_edit_form'));
     add_shortcode('pdb_signup', array(__CLASS__, 'print_signup_form'));
     add_shortcode('pdb_signup_thanks', array(__CLASS__, 'print_signup_thanks_form'));
     add_shortcode('pdb_request_link', array(__CLASS__, 'print_retrieval_form'));
     add_shortcode('pdb_list', array(__CLASS__, 'print_list'));
     add_shortcode('pdb_single', array(__CLASS__, 'print_single_record'));
     add_shortcode('pdb_search', array(__CLASS__, 'print_search_form'));
     add_shortcode('pdb_total', array(__CLASS__, 'print_total'));
     /*
      * sets up the update notification
      * 
      * in this case, we use this to simulate a new releaase for testing.
      * 
      * uncomment to enable
      */
     //add_filter('pre_set_site_transient_update_plugins', array(__CLASS__, 'check_for_plugin_update'));// for plugin update test
     /*
      * uncomment this to enable custom upgrade details window
      */
     //add_filter('plugins_api', array(__CLASS__, 'plugin_update_info'), 10, 3);
     /*
      * this adds a custom update message to the plugin list 
      */
     global $pagenow;
     if ('plugins.php' === $pagenow) {
         $plugin_path = plugin_basename(__FILE__);
         $hook = "in_plugin_update_message-" . $plugin_path;
         //add_action( $hook, array(__CLASS__, 'plugin_update_message'), 20, 2 );
     }
 }