/** * Autoloads files with CMB2 classes when needed * @since 1.0.0 * @param string $class_name Name of the class being requested */ function cmb2_autoload_classes($class_name) { if (0 !== strpos($class_name, 'CMB2')) { return; } include_once cmb2_dir("includes/{$class_name}.php"); }
/** * Autoloads files with CMB2 classes when needed * @since 1.0.0 * @param string $class_name Name of the class being requested */ function cmb2_autoload_classes($class_name) { if (class_exists($class_name, false) || false === strpos($class_name, 'CMB2_')) { return; } $file = cmb2_dir("includes/{$class_name}.php"); if (file_exists($file)) { @(include_once $file); } }
/** * Autoloads files with CMB2 classes when needed * @since 1.0.0 * @param string $class_name Name of the class being requested */ function cmb2_autoload_classes($class_name) { if (0 !== strpos($class_name, 'CMB2')) { return; } $path = 'includes'; if ('CMB2_Type' === $class_name || 0 === strpos($class_name, 'CMB2_Type_')) { $path .= '/types'; } include_once cmb2_dir("{$path}/{$class_name}.php"); }
/** * Defines the url which is used to load local resources. * This may need to be filtered for local Window installations. * If resources do not load, please check the wiki for details. * @since 1.0.1 * @return string URL to CMB resources */ public function url($path = '') { if ($this->url) { return $this->url . $path; } if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) { // Windows $content_dir = str_replace('/', DIRECTORY_SEPARATOR, WP_CONTENT_DIR); $content_url = str_replace($content_dir, WP_CONTENT_URL, cmb2_dir()); $cmb2_url = str_replace(DIRECTORY_SEPARATOR, '/', $content_url); } else { $cmb2_url = str_replace(array(WP_CONTENT_DIR, WP_PLUGIN_DIR), array(WP_CONTENT_URL, WP_PLUGIN_URL), cmb2_dir()); } /** * Filter the CMB location url * * @param string $cmb2_url Currently registered url */ $this->url = trailingslashit(apply_filters('cmb2_meta_box_url', set_url_scheme($cmb2_url), CMB2_VERSION)); return $this->url . $path; }
public function test_url_set() { $cmb2_url = str_replace(array(WP_CONTENT_DIR, WP_PLUGIN_DIR), array(WP_CONTENT_URL, WP_PLUGIN_URL), cmb2_dir()); $this->assertEquals(cmb2_utils()->url(), $cmb2_url); }
<?php /** * Helper function to provide directory path to CMB * @since 2.0.0 * @param string $path Path to append * @return string Directory with optional path appended */ function cmb2_dir($path = '') { return trailingslashit(dirname(__FILE__)) . $path; } require_once cmb2_dir('includes/helper-functions.php'); $meta_boxes_config = apply_filters('cmb2_meta_boxes', array()); foreach ((array) $meta_boxes_config as $meta_box) { $cmb = new CMB2($meta_box); if ($cmb->prop('hookup')) { $hookup = new CMB2_hookup($cmb); } } /** * Create meta boxes */ class CMB2 { /** * Current field's ID * @var string * @since 2.0.0 */ protected $cmb_id = '';
/** * Defines the url which is used to load local resources. * This may need to be filtered for local Window installations. * If resources do not load, please check the wiki for details. * @since 1.0.1 * @return string URL to CMB2 resources */ public function url($path = '') { if ($this->url) { return $this->url . $path; } $cmb2_url = self::get_url_from_dir(cmb2_dir()); /** * Filter the CMB location url * * @param string $cmb2_url Currently registered url */ $this->url = trailingslashit(apply_filters('cmb2_meta_box_url', $cmb2_url, CMB2_VERSION)); return $this->url . $path; }