function wp_all_export_rand_char($length) { $random = ''; do { $random .= str_replace(array('-', '_'), '', wp_all_export_url_title(chr(mt_rand(33, 126)))); } while (strlen($random) < $length); return $random; }
/** * Class constructor containing dispatching logic * @param string $rootDir Plugin root dir * @param string $pluginFilePath Plugin main file */ protected function __construct() { // regirster autoloading method if (function_exists('__autoload') and !in_array('__autoload', spl_autoload_functions())) { // make sure old way of autoloading classes is not broken spl_autoload_register('__autoload'); } spl_autoload_register(array($this, '__autoload')); // register helpers if (is_dir(self::ROOT_DIR . '/helpers')) { foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/helpers/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) { require_once $filePath; } } // init plugin options $option_name = get_class($this) . '_Options'; $options_default = PMXE_Config::createFromFile(self::ROOT_DIR . '/config/options.php')->toArray(); $this->options = array_intersect_key(get_option($option_name, array()), $options_default) + $options_default; $this->options = array_intersect_key($options_default, array_flip(array('info_api_url'))) + $this->options; // make sure hidden options apply upon plugin reactivation if ('' == $this->options['cron_job_key']) { $this->options['cron_job_key'] = wp_all_export_url_title(wp_all_export_rand_char(12)); } update_option($option_name, $this->options); $this->options = get_option(get_class($this) . '_Options'); register_activation_hook(self::FILE, array($this, '__activation')); // register action handlers if (is_dir(self::ROOT_DIR . '/actions')) { if (is_dir(self::ROOT_DIR . '/actions')) { foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/actions/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) { require_once $filePath; $function = $actionName = basename($filePath, '.php'); if (preg_match('%^(.+?)[_-](\\d+)$%', $actionName, $m)) { $actionName = $m[1]; $priority = intval($m[2]); } else { $priority = 10; } add_action($actionName, self::PREFIX . str_replace('-', '_', $function), $priority, 99); // since we don't know at this point how many parameters each plugin expects, we make sure they will be provided with all of them (it's unlikely any developer will specify more than 99 parameters in a function) } } } // register filter handlers if (is_dir(self::ROOT_DIR . '/filters')) { foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/filters/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) { require_once $filePath; $function = $actionName = basename($filePath, '.php'); if (preg_match('%^(.+?)[_-](\\d+)$%', $actionName, $m)) { $actionName = $m[1]; $priority = intval($m[2]); } else { $priority = 10; } add_filter($actionName, self::PREFIX . str_replace('-', '_', $function), $priority, 99); // since we don't know at this point how many parameters each plugin expects, we make sure they will be provided with all of them (it's unlikely any developer will specify more than 99 parameters in a function) } } // register shortcodes handlers if (is_dir(self::ROOT_DIR . '/shortcodes')) { foreach (PMXE_Helper::safe_glob(self::ROOT_DIR . '/shortcodes/*.php', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH) as $filePath) { $tag = strtolower(str_replace('/', '_', preg_replace('%^' . preg_quote(self::ROOT_DIR . '/shortcodes/', '%') . '|\\.php$%', '', $filePath))); add_shortcode($tag, array($this, 'shortcodeDispatcher')); } } // register admin page pre-dispatcher add_action('admin_init', array($this, '__adminInit')); add_action('admin_init', array($this, '__fix_db_schema')); add_action('init', array($this, 'init')); }
<?php /** * List of plugin optins, contains only default values, actual values are stored in database * and can be changed by corresponding wordpress function calls */ $config = array("info_api_url" => "http://www.wpallimport.com", "dismiss" => 0, "dismiss_manage_top" => 0, "dismiss_manage_bottom" => 0, "cron_job_key" => wp_all_export_url_title(wp_all_export_rand_char(12)), "max_input_time" => -1, "max_execution_time" => -1, "secure" => 1, "zapier_api_key" => wp_all_export_rand_char(32), "zapier_invitation_url" => "", "zapier_invitation_url_received" => "");