AsteriskHero

my-original

May 20th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.35 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Custom edd
  4.  *
  5.  * Learn more: http://docs.easydigitaldownloads.com/
  6.  *
  7.  */
  8.  
  9. if ( class_exists( 'Easy_Digital_Downloads' ) ) :
  10.  
  11.     define('EDD_SLUG', 'musics');
  12.  
  13.     // Change edd labels
  14.     function edd_labels( $labels ) {
  15.         $labels = array(
  16.            'singular' => esc_html__('Music', 'musik'),
  17.            'plural'   => esc_html__('Musics', 'musik')
  18.         );
  19.         return $labels;
  20.     }
  21.     add_filter('edd_default_downloads_name', 'edd_labels');
  22.  
  23.     // Change icon
  24.     remove_action( 'admin_head', 'edd_admin_downloads_icon' );
  25.     function edd_menu_icon( $args ){
  26.         $args['menu_icon'] = 'dashicons-format-audio';
  27.         return $args;
  28.     }
  29.     add_filter( 'edd_download_post_type_args', 'edd_menu_icon');
  30.  
  31.     // Change category labels
  32.     function edd_cat_labels( $labels ) {
  33.         $singular  = 'Genre';
  34.         $plural    = 'Genres';
  35.         $labels = get_labels($singular, $plural);
  36.         return $labels;
  37.     }
  38.     add_filter( 'edd_download_category_labels', 'edd_cat_labels' );
  39.  
  40.     // change the category slug
  41.     function edd_cat_args( $args ){
  42.         $args['rewrite'] = array( 'slug' => 'genre', 'with_front' => false, 'hierarchical' => true);
  43.         return $args;
  44.     }
  45.     add_filter( 'edd_download_category_args', 'edd_cat_args');
  46.  
  47.     // add artist taxomomy
  48.     function artist_taxonomies($taxonomies){
  49.         $singular  = 'Artist';
  50.         $plural    = 'Artists';
  51.         $taxonomies[] = array(
  52.           'post_type' => 'download'
  53.           ,'name' => 'download_artist'
  54.           ,'show_admin_column' => true
  55.           ,'configuration' => array(
  56.             'hierarchical' => false
  57.             ,'labels' => get_labels($singular, $plural)
  58.             ,'hide_meta_box' => false
  59.             ,'show_ui' => true
  60.             ,'query_var' => true
  61.             ,'rewrite' => array(
  62.               'slug' => 'artists'
  63.             )
  64.           )
  65.         );
  66.         return $taxonomies;
  67.     }
  68.     add_filter('piklist_taxonomies', 'artist_taxonomies');
  69.  
  70.     // Get labels
  71.     function get_labels( $singular, $plural ){
  72.         $labels =  array(
  73.             'name'               => _x( '%2$s', 'taxonomy general name', 'musik' ),
  74.             'singular_name'      => _x( '%1$s', 'taxonomy singular name', 'musik' ),
  75.             'add_new'            => __( 'Add New', 'musik' ),
  76.             'add_new_item'       => __( 'Add New %1$s', 'musik' ),
  77.             'new_item_name'      => __( 'New %1$s Name', 'musik' ),
  78.             'edit_item'          => __( 'Edit %1$s', 'musik' ),
  79.             'new_item'           => __( 'New %1$s', 'musik' ),
  80.             'all_items'          => __( 'All %2$s', 'musik' ),
  81.             'view_item'          => __( 'View %1$s', 'musik' ),
  82.             'update_item'        => __( 'Update %1$s', 'musik' ),
  83.             'search_items'       => __( 'Search %2$s', 'musik' ),
  84.             'popular_items'      => __( 'Popular %2$s', 'musik' ),
  85.             'not_found'          => __( 'No %2$s found', 'musik' ),
  86.             'not_found_in_trash' => __( 'No %2$s found in Trash', 'musik' ),
  87.             'parent_item'        => __( 'Parent %1$s', 'musik' ),
  88.             'parent_item_colon'  => __( 'Parent %1$s :', 'musik' ),
  89.             'separate_items_with_commas'    => __( 'Separate %2$s with commas', 'musik' ),
  90.             'add_or_remove_items'           => __( 'Add or remove %2$s', 'musik' ),
  91.             'choose_from_most_used'         => __( 'Choose from most used %2$s', 'musik' ),
  92.             'menu_name'          => _x( '%2$s', 'taxonomy menu name', 'musik' )
  93.         );
  94.         foreach ( $labels as $key => $value ) {
  95.            $labels[ $key ] = sprintf( $value, $singular, $plural );
  96.         }
  97.         return $labels;
  98.     }
  99.  
  100.     // disable the microdata for layout
  101.     add_filter( 'edd_add_schema_microdata', '__return_false' );
  102.  
  103.     // allow comments
  104.     function edd_supports($supports){
  105.         $supports[] = 'comments';
  106.         return $supports;
  107.     }
  108.     add_filter( 'edd_download_supports', 'edd_supports' );
  109.  
  110.     // change avatar on profile page
  111.     function edd_profile_avatar(){
  112.         echo do_shortcode('[basic-user-avatars]');
  113.     }
  114.     add_filter( 'edd_profile_editor_before', 'edd_profile_avatar' );
  115.  
  116.     // remove the auto purchase btton after the content.
  117.     remove_action( 'edd_after_download_content', 'edd_append_purchase_link' );
  118.  
  119.     // add register link after the login form
  120.     function _edd_login_after(){
  121.         echo '<a href="'.esc_url( get_permalink( get_theme_mod( 'register-page') ) ).'" class="text-info">'. __( 'Register New Account', 'musik' ) .'</a>';
  122.     }
  123.     add_action('edd_login_fields_after', '_edd_login_after');
  124.  
  125.     // ajax to get the media
  126.     function edd_media(){
  127.         if( !isset($_REQUEST['id']) ){
  128.             die(0);
  129.         }
  130.         $post_id = intval($_REQUEST['id']);
  131.         $list = edd_get_bundled_products( $post_id );
  132.         if(empty($list)){
  133.             $list = array($post_id);
  134.         };
  135.         $args = array(
  136.             'posts_per_page'   => -1,
  137.             'orderby'          => 'date',
  138.             'order'            => 'DESC',
  139.             'post_type'        => 'download',
  140.             'post_mime_type'   => '',
  141.             'post_parent'      => '',
  142.             'author'           => '',
  143.             'post_status'      => 'publish',
  144.             'suppress_filters' => true,
  145.             'post__in'         => $list
  146.         );
  147.         $objs = array();
  148.         $posts = get_posts($args);
  149.         foreach ( $posts as $post ){
  150.             $obj = array();
  151.             $obj['id'] = $post->ID;
  152.             $obj['ids'] = $post_id;
  153.             $obj['title'] = $post->post_title;
  154.             $preview_type = get_post_meta($post->ID, 'preview_type', true);
  155.             if($preview_type == 'remote'){
  156.                 $group = get_post_meta($post->ID, 'preview_url', true);
  157.                 foreach($group['preview_media_type'] as $key=>$value){
  158.                     $obj[$value] = $group['preview_media_url'][$key];
  159.                 }
  160.             }else{
  161.                 // local files
  162.                 $ids  = get_post_meta($post->ID, 'preview');
  163.                 foreach($ids as $id){
  164.                     $preview = wp_get_attachment_url( $id );
  165.                     $metadata = wp_get_attachment_metadata($id);
  166.                     if(!empty($metadata) && isset($metadata['fileformat'])){
  167.                         switch($metadata['fileformat']){
  168.                             case 'mp3':
  169.                                 $obj['mp3'] = $preview;
  170.                                 break;
  171.                             case 'mp4':
  172.                                 $obj['m4a'] = $preview;
  173.                                 break;
  174.                             case 'ogg':
  175.                                 $obj['oga'] = $preview;
  176.                                 break;
  177.                             case 'webm':
  178.                                 $obj['webma'] = $preview;
  179.                                 break;
  180.                         }
  181.                     }
  182.                 }
  183.             }
  184.             $terms = get_the_terms( $post->ID, 'download_artist', '', ', ', '' );
  185.             if ( $terms && ! is_wp_error( $terms ) ) {
  186.                 $artist = array();
  187.                 foreach ( $terms as $term ) {
  188.                     $artist[] = $term->name;
  189.                 }
  190.                 $obj['artist'] = join( ", ", $artist );
  191.             }
  192.             $obj['poster'] = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
  193.             $objs[] = $obj;
  194.         }
  195.        
  196.         echo json_encode($objs);
  197.         die();
  198.     }
  199.  
  200.     add_action( 'wp_ajax_nopriv_get_media', 'edd_media' );
  201.     add_action( 'wp_ajax_get_media', 'edd_media' );
  202.  
  203. endif;
Add Comment
Please, Sign In to add comment