optionsframework_mlu_get_silentpost

The Evolved optionsframework mlu get silentpost function.

Description

optionsframework_mlu_get_silentpost( $_token ); 

Parameters (1)

0. $token
The token.

Usage

  1. if ( !function_exists( 'optionsframework_mlu_get_silentpost' ) ) { 
  2. require_once '/admin/options-framework/options-medialibrary-uploader.php'; 
  3.  
  4. // The token. 
  5. $token = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = optionsframework_mlu_get_silentpost($token); 
  9.  

Defined (1)

The function is defined in the following location(s).

/admin/options-framework/options-medialibrary-uploader.php  
  1. function optionsframework_mlu_get_silentpost ( $_token ) { 
  2.  
  3. global $wpdb; 
  4. $_id = 0; 
  5.  
  6. // Check if the token is valid against a whitelist. 
  7. // $_whitelist = array( 'of_logo', 'of_custom_favicon', 'of_ad_top_image' ); 
  8. // Sanitise the token. 
  9.  
  10. $_token = strtolower( str_replace( ' ', '_', $_token ) ); 
  11.  
  12. // if ( in_array( $_token, $_whitelist ) ) { 
  13. if ( $_token ) { 
  14.  
  15. // Tell the function what to look for in a post. 
  16.  
  17. $_args = array( 'post_type' => 'optionsframework', 'post_name' => 'of-' . $_token, 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed' ); 
  18.  
  19. // Look in the database for a "silent" post that meets our criteria. 
  20. $query = 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_parent = 0'; 
  21. foreach ( $_args as $k => $v ) { 
  22. $query .= ' AND ' . $k . ' = "' . $v . '"'; 
  23. } // End FOREACH Loop 
  24.  
  25. $query .= ' LIMIT 1'; 
  26. $_posts = $wpdb->get_row( $query ); 
  27.  
  28. // If we've got a post, loop through and get it's ID. 
  29. if ( count( $_posts ) ) { 
  30. $_id = $_posts->ID; 
  31. } else { 
  32.  
  33. // If no post is present, insert one. 
  34. // Prepare some additional data to go with the post insertion. 
  35. $_words = explode( '_', $_token ); 
  36. $_title = join( ' ', $_words ); 
  37. $_title = ucwords( $_title ); 
  38. $_post_data = array( 'post_title' => $_title ); 
  39. $_post_data = array_merge( $_post_data, $_args ); 
  40. $_id = wp_insert_post( $_post_data ); 
  41. }  
  42. return $_id;