post_type)
{
case "song":
require_once themeRootDir()."objects/song.class.php";
$CustomPost = Song::Get()->ByPost($post); break;
case "album":
require_once themeRootDir()."objects/album.class.php";
$CustomPost = Album::Get()->ByPost($post);
break;
case "bandmember":
require_once themeRootDir()."objects/bandmember.class.php";
$CustomPost = BandMember::Get()->ByPost($post);
break;
case "gig":
require_once themeRootDir()."objects/gig.class.php";
$CustomPost = Gig::Get()->ByPost($post);
break;
case "gear":
require_once themeRootDir()."objects/gear.class.php";
$CustomPost = Gear::Get()->ByPost($post);
break;
default:
require_once themeRootDir()."objects/coreobject.class.php";
$CustomPost = CoreObject::Get()->ByPost($post);
break;
}
return $CustomPost;
}
function seoUrl($string)
{
$string = strtolower($string);
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
$string = preg_replace("/[\s-]+/", " ", $string);
$string = preg_replace("/[\s_]/", "-", $string);
return $string;
}
function getBaseUrl()
{
return "/wp-content/themes/banddemo/bandmanager/";
}
function getRelativePluginUrl()
{
return plugins_url()."/dx2bands/";
}
function getPostBySlug($slug, $posttype = "post")
{
$post = null;
try{
$args = array(
'post_type' => $posttype,
'numberposts' => 1,
'posts_per_page' => 1,
'post_status' => 'publish',
'name' => $slug
);
$post = new WP_Query($args);
}
catch(Exception $e)
{
}
return $post;
}
function getMultiplePosts($limit, $posttype="post")
{
$posts = null;
try{
$args=array('post_type' => $posttype,
'post_status' => 'publish',
'posts_per_page' => $limit);
$posts = new WP_Query($args);
}
catch(Exception $e)
{
}
return $posts;
}
function validateMetaSave()
{
// Check if our nonce is set.
if (!isset($_POST['customNBFieldsSaveMetaBoxNonce'])) return false;
// Verify that the nonce is valid.
if (!wp_verify_nonce($_POST['customNBFieldsSaveMetaBoxNonce'], 'customNBFieldsSaveMetaBoxData')) return;
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if (defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false;
// Check the user's permissions.
if (isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'])
{
if (!current_user_can( 'edit_page', $post_id )) return false;
}
else
{
if (!current_user_can( 'edit_post', $post_id ))return false;
}
//submission is valid and can continue
return true;
}
function saveMetaField($post_id, $fieldname)
{
if(isset($_POST[$fieldname]))
{
update_post_meta($post_id, $fieldname, sanitize_text_field($_POST[$fieldname]));
//echo "added $fieldname
";
}
}
function isLandscape($image)
{
list($width, $height) = getimagesize($image);
//echo "Width : ".$width." - Height : ".$height;
if ($width > $height) {
return true;
} else {
return false;
}
}
function getBMImageDir()
{
return "/wp-content/themes/banddemo/bandmanager/images/";
}
function youtubeUrlToEmbed($string) {
// return preg_replace(
// "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
// "",
// $url
// );
$search = '/youtube\.com\/watch\?v=([a-zA-Z0-9]+)/smi';
$replace = "youtube.com/embed/$1";
$url = preg_replace($search,$replace,$string);
return "