plugin_data = apply_filters('wie_plugin_data', $plugin_data); } /** * Define constants * * @since 0.1 * @access public */ public function defineConstants() { // Plugin version. define('WIE_VERSION', $this->plugin_data['Version']); // Plugin's main file path. define('WIE_FILE', __FILE__); // Plugin's directory. define('WIE_DIR', dirname(plugin_basename(WIE_FILE))); // Plugin's directory path. define('WIE_PATH', untrailingslashit(plugin_dir_path(WIE_FILE))); // Plugin's directory URL. define('WIE_URL', untrailingslashit(plugin_dir_url(WIE_FILE))); // Includes directory. define('WIE_INC_DIR', 'includes'); // Stylesheets directory. define('WIE_CSS_DIR', 'css'); // JavaScript directory. define('WIE_JS_DIR', 'js'); // Image directory. define('WIE_IMG_DIR', 'img'); // Languages directory. define('WIE_LANG_DIR', 'languages'); } /** * Load language file * * This will load the MO file for the current locale. * The translation file must be named widget-importer-exporter-$locale.mo. * * First it will check to see if the MO file exists in wp-content/languages/plugins. * If not, then the 'languages' directory inside the plugin will be used. * It is ideal to keep translation files outside of the plugin to avoid loss during updates.\ * * @since 0.1 * @access public */ public function loadTextdomain() { // Text-domain. $domain = 'widget-importer-exporter'; // WordPress core locale filter. $locale = apply_filters('plugin_locale', get_locale(), $domain); // WordPress 3.6 and earlier don't auto-load from wp-content/languages, so check and load manually // http://core.trac.wordpress.org/changeset/22346. $external_mofile = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo'; // External translation exists. if (get_bloginfo('version') <= 3.6 && file_exists($external_mofile)) { load_textdomain($domain, $external_mofile); } else { // Load normally. Either using WordPress 3.7+ or older version with external translation. $languages_dir = WIE_DIR . '/' . trailingslashit(WIE_LANG_DIR); // ensure trailing slash. load_plugin_textdomain($domain, false, $languages_dir); } } /** * Set includes * * @since 0.1 * @access public */ public function setIncludes() { $this->includes = apply_filters('wie_includes', array( // Admin only. 'admin' => array( WIE_INC_DIR . '/admin.php', WIE_INC_DIR . '/export.php', WIE_INC_DIR . '/import.php', WIE_INC_DIR . '/mime-types.php', WIE_INC_DIR . '/page.php', WIE_INC_DIR . '/widgets.php', ), )); } /** * Load includes * * Include files based on whether or not condition is met. * * @since 0.1 * @access public */ public function loadIncludes() { // Get includes. $includes = $this->includes; // Loop conditions. foreach ($includes as $condition => $files) { $do_includes = false; // Check condition. // Change this to for statement so can use new lines without warning from wpcs - more readable. switch ($condition) { // Admin Only. case 'admin': if (is_admin()) { $do_includes = true; } break; // Frontend Only. case 'frontend': if (! is_admin()) { $do_includes = true; } break; // Admin or Frontend (always). default: $do_includes = true; break; } // Loop files if condition met. if ($do_includes) { foreach ($files as $file) { require_once trailingslashit(WIE_PATH) . $file; } } } } } // Instantiate the main class. new Widget_Importer_Exporter();