' . "\n";
return $output;
}
}
/**
* Uses "silent" posts in the database to store relationships for images.
* This also creates the facility to collect galleries of, for example, logo images.
*
* Return: $_postid.
*
* If no "silent" post is present, one will be created with the type "evolve"
* and the post_name of "of-$_token".
*
* Example Usage:
* evolve_mlu_get_silentpost ( 'evl_logo' );
*/
if ( ! function_exists( 'evolve_mlu_get_silentpost' ) ) {
function evolve_mlu_get_silentpost ( $_token ) {
global $wpdb;
$_id = 0;
// Check if the token is valid against a whitelist.
// $_whitelist = array( 'evl_logo', 'evl_custom_favicon', 'evl_ad_top_image' );
// Sanitise the token.
$_token = strtolower( str_replace( ' ', '_', $_token ) );
// if ( in_array( $_token, $_whitelist ) ) {
if ( $_token ) {
// Tell the function what to look for in a post.
$_args = array( 'post_type' => 'evolve', 'post_name' => 'of-' . $_token, 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed' );
// Look in the database for a "silent" post that meets our criteria.
$query = 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_parent = 0';
foreach ( $_args as $k => $v ) {
$query .= ' AND ' . $k . ' = "' . $v . '"';
} // End FOREACH Loop
$query .= ' LIMIT 1';
$_posts = $wpdb->get_row( $query );
// If we've got a post, loop through and get it's ID.
if ( count( $_posts ) ) {
$_id = $_posts->ID;
} else {
// If no post is present, insert one.
// Prepare some additional data to go with the post insertion.
$_words = explode( '_', $_token );
$_title = join( ' ', $_words );
$_title = ucwords( $_title );
$_post_data = array( 'post_title' => $_title );
$_post_data = array_merge( $_post_data, $_args );
$_id = wp_insert_post( $_post_data );
}
}
return $_id;
}
}
/**
* Trigger code inside the Media Library popup.
*/
if ( ! function_exists( 'evolve_mlu_insidepopup' ) ) {
function evolve_mlu_insidepopup () {
if ( isset( $_REQUEST['is_evolve'] ) && $_REQUEST['is_evolve'] == 'yes' ) {
add_action( 'admin_head', 'evolve_mlu_js_popup' );
add_filter( 'media_upload_tabs', 'evolve_mlu_modify_tabs' );
}
}
}
if ( ! function_exists( 'evolve_mlu_js_popup' ) ) {
function evolve_mlu_js_popup () {
$_evl_title = $_REQUEST['evl_title'];
if ( ! $_evl_title ) { $_evl_title = 'file'; } // End IF Statement
?>