global $dg_options; define('DG_OPTION_NAME', 'document_gallery'); $dg_options = get_option(DG_OPTION_NAME, null); // core functionality include_once DG_PATH . 'inc/class-document-gallery.php'; include_once DG_PATH . 'inc/class-thumb.php'; include_once DG_PATH . 'inc/class-util.php'; // logging functionality include_once DG_PATH . 'inc/class-logger.php'; add_action(DG_Logger::PurgeLogsAction, array('DG_Logger', 'purgeExpiredEntries')); // handle activation, updates, and uninstallation include_once DG_PATH . 'inc/class-setup.php'; register_activation_hook(__FILE__, array('DG_Setup', 'activate')); add_action('wpmu_new_blog', array('DG_Setup', 'activateNewBlog')); register_uninstall_hook(__FILE__, array('DG_Setup', 'uninstall')); DG_Setup::maybeUpdate(); // ensure we don't allow invalid option structure add_action('init', array('DocumentGallery', 'addValidation')); // I18n add_action('plugins_loaded', array('DocumentGallery', 'loadTextDomain')); // cleanup cached data when thumbed attachment deleted include_once DG_PATH . 'inc/class-thumber.php'; add_action('delete_attachment', array('DG_Thumb', 'cleanupAttachmentMeta')); if (is_admin()) { // admin house keeping include_once DG_PATH . 'admin/class-admin.php'; // AJAX handling include_once DG_PATH . 'admin/class-ajax-handler.php'; // add links to plugin index add_filter('plugin_action_links_' . DG_BASENAME, array('DG_Admin', 'addSettingsLink')); add_filter('plugin_row_meta', array('DG_Admin', 'addDonateLink'), 10, 2);
/** * @param mixed[]|mixed $o The options structure to validate. * @param mixed[] $schema The schema to validate against (note that only keys matter -- non-array values are ignored). * * @return bool Whether the given options structure matches the schema. */ public static function isValidOptionsStructure($o, $schema = null) { if (is_null($schema)) { $schema = DG_Setup::getDefaultOptions(true); } // simple checks first $valid = is_array($o) && count($schema) === count($o); if ($valid) { foreach ($schema as $sk => $sv) { $valid = array_key_exists($sk, $o); if (is_array($sv) && !empty($sv)) { $valid = $valid && self::isValidOptionsStructure($o[$sk], $sv); } if (!$valid) { break; } } } return $valid; }