/** * @param string $generator_slug * @param string $namespace * * @return boolean */ function get_generator_class($generator_slug, $namespace) { $generator_slug = implode('_', array_map('ucfirst', explode('_', Util::underscorify($generator_slug)))); $generator_class = Util::get_qualified_class_name("{$generator_slug}_Generator", $namespace); if (!class_exists($generator_class)) { Util::log_error("The generator class {$generator_class} is not a valid class or it's filename" . " is malformed for the autoloader; should be /generators/{$generator_slug}-generator.php"); } return $generator_class; }
/** * Strip a prefix from a string seperated by an $seperator (typically dash or underscore). * * @example * * self::strip_prefix( 'aa_foobar', 'aa' ) => 'foobar' * self::strip_prefix( 'aa_foobar', 'aa', '_' ) => 'foobar' * * @param string $identifier * @param string $prefix * @param string $seperators * * @return string */ static function strip_prefix($identifier, $prefix, $seperators = '-_') { /** * Convert all identifiers to using lowercase and underscores */ $identifier = Util::underscorify(strtolower($identifier)); $regex = '#^' . preg_quote($prefix) . "[{$seperators}](.*)\$#"; if (preg_match($regex, $identifier, $match)) { /** * If the post type was prefixed with short prefix, strip it. */ $identifier = $match[1]; } return $identifier; }