nfmohit

Untitled

Aug 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit;
  5. }
  6.  
  7.  
  8.  
  9. add_filter( 'manage_edit-mfmchurchactivity_columns', 'my_edit_mfmchurchactivity_columns' ) ;
  10.  
  11. function my_edit_mfmchurchactivity_columns( $columns ) {
  12.  
  13.     $columns = array(
  14.         'cb' => '<input type="checkbox" />',
  15.         'title' => __( 'Week' ),
  16.         'attendance' => __( 'Attendance' ),
  17.         'punctuality' => __( 'Punctuality' ),
  18.         'meeting_location' => __( 'Meeting Location' ),
  19.         'member_group' => __( 'Member Group' ),
  20.         'donations' => __( 'Donations' ),
  21.         'payments' => __( 'Payments' ),
  22.         'branch' => __( 'Branch' ),
  23.         'region' => __( 'Region' ),
  24.         'month' => __('Month'),
  25.         'year' => __( 'Year' ),
  26.         'country' => __('Country')
  27.     );
  28.  
  29.     return $columns;
  30. }
  31.  
  32. add_action( 'manage_mfmchurchactivity_posts_custom_column', 'my_manage_mfmchurchactivity_columns', 10, 2 );
  33.  
  34. function my_manage_mfmchurchactivity_columns( $column, $post_id ) {
  35.     global $post;
  36.  
  37.     switch( $column ) {
  38.  
  39.         /* If displaying the 'attendance' column. */
  40.         case 'attendance' :
  41.  
  42.             /* Get the post meta. */
  43.             $attendance = get_post_meta( $post_id, '_mfm_churchactivity_s_school_one', true );
  44.  
  45.             /* If no duration is found, output a default message. */
  46.             if ( empty( $attendance ) )
  47.                 echo __( 'Unknown' );
  48.  
  49.             /* If there is a duration, append 'minutes' to the text string. */
  50.             else
  51.                 printf ( __( '%s' ), $attendance );
  52.  
  53.             break;
  54.  
  55.         /* If displaying the 'punctuality' column. */
  56.         case 'punctuality' :
  57.  
  58.             /* Get the post meta. */
  59.             $punctuality = get_post_meta( $post_id, '_mfm_churchactivity_s_service_one', true );
  60.  
  61.             /* If no duration is found, output a default message. */
  62.             if ( empty( $punctuality ) )
  63.                 echo __( 'Unknown' );
  64.  
  65.             /* If there is a duration, append 'minutes' to the text string. */
  66.             else
  67.                 printf( __( '%s' ), $punctuality );
  68.  
  69.             break;
  70.            
  71.             /* If displaying the 'meeting_location' column. */                 
  72.             case 'meeting_location' :
  73.  
  74.             /* Get the post meta. */
  75.             $meeting_location = get_post_meta( $post_id, '_mfm_churchactivity_m_service_one', true );
  76.  
  77.             /* If no duration is found, output a default message. */
  78.             if ( empty( $meeting_location ) )
  79.                 echo __( 'Unknown' );
  80.  
  81.             /* If there is a duration, append 'minutes' to the text string. */
  82.             else
  83.                 printf( __( '%s' ), $meeting_location );
  84.  
  85.             break;
  86.            
  87.             /* If displaying the 'member_group' column. */                 
  88.             case 'member_group' :
  89.  
  90.             /* Get the post meta. */
  91.             $member_group = get_post_meta( $post_id, '_mfm_churchactivity_h_service_one', true );
  92.  
  93.             /* If no duration is found, output a default message. */
  94.             if ( empty( $member_group ) )
  95.                 echo __( 'Unknown' );
  96.  
  97.             /* If there is a duration, append 'minutes' to the text string. */
  98.             else
  99.                 printf( __( '%s' ), $member_group );
  100.  
  101.             break;
  102.            
  103.             case 'donations' :
  104.  
  105.             /* Get the post meta. */
  106.             $donations = get_post_meta( $post_id, '_mfm_churchactivity_off_one', true );
  107.  
  108.             /* If no duration is found, output a default message. */
  109.             if ( empty( $donations ) )
  110.                 echo __( 'Unknown' );
  111.  
  112.             /* If there is a duration, append 'minutes' to the text string. */
  113.             else
  114.                 printf( __( '%s' ), $donations );
  115.  
  116.             break;
  117.            
  118.             case 'payments' :
  119.  
  120.             /* Get the post meta. */
  121.             $payments = get_post_meta( $post_id, '_mfm_churchactivity_tit_one', true );
  122.  
  123.             /* If no duration is found, output a default message. */
  124.             if ( empty( $payments ) )
  125.                 echo __( 'Unknown' );
  126.  
  127.             /* If there is a duration, append 'minutes' to the text string. */
  128.             else
  129.                 printf( __( '%s' ), $payments );
  130.  
  131.             break;
  132.            
  133.             case 'branch' :
  134.  
  135.             /* Get the post meta. */
  136.             $branch = get_post_meta( $post_id, '_mfm_churchactivity_wk_branch', true );
  137.  
  138.             /* If no duration is found, output a default message. */
  139.             if ( empty( $branch ) )
  140.                 echo __( 'Unknown' );
  141.  
  142.             /* If there is a duration, append 'minutes' to the text string. */
  143.             else
  144.                 printf( __( '%s' ), $branch );
  145.  
  146.             break;
  147.            
  148.             case 'region' :
  149.  
  150.             /* Get the post meta. */
  151.             $region = get_post_meta( $post_id, '_mfm_churchactivity_wk_region', true );
  152.  
  153.             /* If no duration is found, output a default message. */
  154.             if ( empty( $region ) )
  155.                 echo __( 'Unknown' );
  156.  
  157.             /* If there is a duration, append 'minutes' to the text string. */
  158.             else
  159.                 printf( __( '%s' ), $region );
  160.  
  161.             break;
  162.            
  163.             case 'month' :
  164.  
  165.             /* Get the post meta. */
  166.             $month = get_post_meta( $post_id, '_mfm_churchactivity_wk_month', true );
  167.  
  168.             /* If no duration is found, output a default message. */
  169.             if ( empty( $month ) )
  170.                 echo __( 'Unknown' );
  171.  
  172.             /* If there is a duration, append 'minutes' to the text string. */
  173.             else
  174.                 printf( __( '%s' ), $month );
  175.  
  176.             break;
  177.            
  178.             case 'year' :
  179.            
  180.             /* Get the post meta. */
  181.             $year = get_post_meta( $post_id, '_mfm_churchactivity_wk_year', true );
  182.  
  183.             /* If no duration is found, output a default message. */
  184.             if ( empty( $year ) )
  185.                 echo __( 'Unknown' );
  186.  
  187.             /* If there is a duration, append 'minutes' to the text string. */
  188.             else
  189.                 printf( __( '%s' ), $year );
  190.  
  191.             break;
  192.            
  193.             case 'country' :
  194.  
  195.             /* Get the post meta. */
  196.             $country = get_post_meta( $post_id, '_mfm_churchactivity_wk_country', true );
  197.  
  198.             /* If no duration is found, output a default message. */
  199.             if ( empty( $country ) )
  200.                 echo __( 'Unknown' );
  201.  
  202.             /* If there is a duration, append 'minutes' to the text string. */
  203.             else
  204.                 printf( __( '%s' ), $country );
  205.  
  206.             break;
  207.            
  208.             case 'year' :
  209.  
  210.            
  211.  
  212.         /* Just break out of the switch statement for everything else. */
  213.         default :
  214.             break;
  215.     }
  216. }
  217.  
  218. add_filter( 'manage_edit-mfmchurchactivity_sortable_columns', 'my_mfmchurchactivity_sortable_columns' );
  219.  
  220. function my_mfmchurchactivity_sortable_columns( $columns ) {
  221.  
  222.     $columns['attendance'] = 'attendance';
  223.  
  224.     return $columns;
  225. }
  226.  
  227.  /*Only run our customization on the 'edit.php' page in the admin. */
  228. add_action( 'load-edit.php', 'my_edit_mfmchurchactivity_load' );
  229.  
  230. function my_edit_mfmchurchactivity_load() {
  231.     add_filter( 'request', 'my_sort_mfmchurchactivity' );
  232. }
  233.  
  234. /* Sorts the movies. */
  235. function my_sort_mfmchurchactivity( $vars ) {
  236.  
  237.     /* Check if we're viewing the 'movie' post type. */
  238.     if ( isset( $vars['post_type'] ) && 'mfmchurchactivity' == $vars['post_type'] ) {
  239.  
  240.         /* Check if 'orderby' is set to 'duration'. */
  241.         if ( isset( $vars['orderby'] ) && 'attendance' == $vars['orderby'] ) {
  242.  
  243.             /* Merge the query vars with our custom variables. */
  244.             $vars = array_merge(
  245.                 $vars,
  246.                 array(
  247.                     'meta_key' => '_mfm_churchactivity_s_school_one',
  248.                     'orderby' => 'meta_value_num'
  249.                 )
  250.             );
  251.         }
  252.     }
  253.  
  254.     return $vars;
  255. }
  256.  
  257. add_filter( 'views_edit-mfmchurchactivity', 'meta_views_wpse_94630', 10, 1 );
  258.  
  259. function meta_views_wpse_94630( $views )
  260. {
  261.     //$views['separator'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  262.     $views['metakey'] = '<a href="edit.php?post_type=mfmchurchactivity&_mfm_churchactivity_wk_branch=Ajao">Meta Key</a>';
  263.     return $views;
  264. }
Add Comment
Please, Sign In to add comment