Advertisement
Guest User

Untitled

a guest
Aug 8th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. <?php
  2. //Since the avid framework uses some functions that are very different to the default use of wordpress (for example post thumbnails) the functions here are provided for better compatibility with external plugins
  3.  
  4.  
  5.  
  6. if(!function_exists('avia_backend_compatibility_featured_image'))
  7. {
  8. /*
  9. * This function saves the first slideshow image as featured image so plugins that make use of that feature image are able to retrieve it
  10. */
  11.  
  12. function avia_backend_compatibility_featured_image($post_id, $result)
  13. {
  14. if(isset($result['slideshow'][0]['slideshow_image']))
  15. {
  16. $attachmend_id = $result['slideshow'][0]['slideshow_image'];
  17.  
  18. if($attachmend_id == "" || ($attachmend_id != "" && ! is_numeric($attachmend_id)))
  19. {
  20. delete_post_meta($post_id, '_thumbnail_id');
  21. }
  22.  
  23. if(is_numeric($attachmend_id))
  24. {
  25. update_post_meta($post_id, '_thumbnail_id', $attachmend_id);
  26. }
  27. }
  28. else if( in_array(get_post_type($post_id), array('post','page','portfolio')) )
  29. {
  30. delete_post_meta($post_id, '_thumbnail_id');
  31. }
  32. }
  33.  
  34. add_action('avia_meta_box_save_post','avia_backend_compatibility_featured_image',10,2);
  35. }
  36.  
  37.  
  38. if(!function_exists('avia_backend_compatibility_custom_field_filter'))
  39. {
  40. /*
  41. * This function checks if the current custom field is the slideshow custom field and overwrites the first element, in case it is empty and a feature image is set
  42. */
  43.  
  44. function avia_backend_compatibility_custom_field_filter($custom_fields, $post_id)
  45. {
  46. if(!is_array($custom_fields)) $custom_fields = array();
  47.  
  48. if(empty($custom_fields))
  49. {
  50. $custom_fields = array(
  51. 'slideshow' => array(
  52. 0 => array( 'slideshow_image' => '')
  53. )
  54. );
  55. }
  56.  
  57. if(isset($custom_fields['slideshow']) && is_array($custom_fields['slideshow']) && isset($custom_fields['slideshow'][0]['slideshow_image']))
  58. {
  59. $post_thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
  60.  
  61. if($custom_fields['slideshow'][0]['slideshow_image'] == "" && $post_thumbnail_id)
  62. {
  63. $custom_fields['slideshow'][0]['slideshow_image'] = $post_thumbnail_id;
  64. }
  65. }
  66. return $custom_fields;
  67. }
  68.  
  69. add_filter('avia_meta_box_filter_custom_fields','avia_backend_compatibility_custom_field_filter',10,2);
  70. add_filter('avia_post_meta_filter','avia_backend_compatibility_custom_field_filter',10,2);
  71. }
  72.  
  73. if(!function_exists('avia_get_post_by_title'))
  74. {
  75. function avia_get_post_by_title($post_title)
  76. {
  77.  
  78. global $wpdb;
  79. $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='avia_framework_post'", $post_title ));
  80.  
  81. if ( $post )
  82. {
  83. $return = get_post($post, 'ARRAY_A');
  84. return $return;
  85. }
  86.  
  87. return null;
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement