current_action(); switch( $action ) { case 'approve_events' : check_admin_referer( 'bulk-posts' ); $post_ids = array_map( 'absint', array_filter( (array) $_GET['post'] ) ); $approved_events = array(); if ( ! empty( $post_ids ) ) foreach( $post_ids as $post_id ) { $event_data = array( 'ID' => $post_id, 'post_status' => 'publish' ); if ( in_array( get_post_status( $post_id ), array( 'pending', 'pending_payment' ) ) && current_user_can( 'publish_post', $post_id ) && wp_update_post( $event_data ) ) { $approved_events[] = $post_id; } } wp_redirect( add_query_arg( 'approved_events', $approved_events, remove_query_arg( array( 'approved_events', 'expired_events' ), admin_url( 'edit.php?post_type=event_listing' ) ) ) ); exit; break; case 'expire_events' : check_admin_referer( 'bulk-posts' ); $post_ids = array_map( 'absint', array_filter( (array) $_GET['post'] ) ); $expired_events = array(); if ( ! empty( $post_ids ) ) foreach( $post_ids as $post_id ) { $event_data = array( 'ID' => $post_id, 'post_status' => 'expired' ); if ( current_user_can( 'manage_event_listings' ) && wp_update_post( $event_data ) ) $expired_events[] = $post_id; } wp_redirect( add_query_arg( 'expired_events', $expired_events, remove_query_arg( array( 'approved_events', 'expired_events' ), admin_url( 'edit.php?post_type=event_listing' ) ) ) ); exit; break; } return; } /** * Approve a single event */ public function approve_event() { if ( ! empty( $_GET['approve_event'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'approve_event' ) && current_user_can( 'publish_post', $_GET['approve_event'] ) ) { $post_id = absint( $_GET['approve_event'] ); $event_data = array( 'ID' => $post_id, 'post_status' => 'publish' ); wp_update_post( $event_data ); wp_redirect( remove_query_arg( 'approve_event', add_query_arg( 'approved_events', $post_id, admin_url( 'edit.php?post_type=event_listing' ) ) ) ); exit; } } /** * Show a notice if we did a bulk action or approval */ public function approved_notice() { global $post_type, $pagenow; if ( $pagenow == 'edit.php' && $post_type == 'event_listing' && ! empty( $_REQUEST['approved_events'] ) ) { $approved_events = $_REQUEST['approved_events']; if ( is_array( $approved_events ) ) { $approved_events = array_map( 'absint', $approved_events ); $titles = array(); foreach ( $approved_events as $event_id ) $titles[] = get_the_title( $event_id ); echo '

' . sprintf( __( '%s approved', 'wp-event-manager' ), '"' . implode( '", "', $titles ) . '"' ) . '

'; } else { echo '

' . sprintf( __( '%s approved', 'wp-event-manager' ), '"' . get_the_title( $approved_events ) . '"' ) . '

'; } } } /** * Show a notice if we did a bulk action or approval */ public function expired_notice() { global $post_type, $pagenow; if ( $pagenow == 'edit.php' && $post_type == 'event_listing' && ! empty( $_REQUEST['expired_events'] ) ) { $expired_events = $_REQUEST['expired_events']; if ( is_array( $expired_events ) ) { $expired_events = array_map( 'absint', $expired_events ); $titles = array(); foreach ( $expired_events as $event_id ) $titles[] = get_the_title( $event_id ); echo '

' . sprintf( __( '%s expired', 'wp-event-manager' ), '"' . implode( '", "', $titles ) . '"' ) . '

'; } else { echo '

' . sprintf( __( '%s expired', 'wp-event-manager' ), '"' . get_the_title( $expired_events ) . '"' ) . '

'; } } } /** * Show category dropdown */ public function events_by_category() { global $typenow, $wp_query; if ( $typenow != 'event_listing' || ! taxonomy_exists( 'event_listing_category' ) ) { return; } include_once( EVENT_MANAGER_PLUGIN_DIR . '/core/wp-event-manager-category-walker.php' ); $r= array(); $r['pad_counts'] = 1; $r['hierarchical'] = 1; $r['hide_empty'] = 0; $r['show_count'] = 1; $r['selected'] = ( isset( $wp_query->query['event_listing_category'] ) ) ? $wp_query->query['event_listing_category'] : ''; $r['menu_order'] = false; $terms = get_terms( 'event_listing_category', $r ); $walker = new WP_Event_Manager_Category_Walker; if ( ! $terms ) { return; } $output = ""; echo $output; } /** * enter_title_here function. * * @access public * @return void */ public function enter_title_here( $text, $post ) { if ( $post->post_type == 'event_listing' ) return __( 'Event Title', 'wp-event-manager' ); return $text; } /** * post_updated_messages function. * * @access public * @param mixed $messages * @return void */ public function post_updated_messages( $messages ) { global $post, $post_ID, $wp_post_types; $messages['event_listing'] = array( 0 => '', 1 => sprintf( __( '%s updated. View', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name, esc_url( get_permalink( $post_ID ) ) ), 2 => __( 'Custom field updated.', 'wp-event-manager' ), 3 => __( 'Custom field deleted.', 'wp-event-manager' ), 4 => sprintf( __( '%s updated.', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name ), 5 => isset( $_GET['revision'] ) ? sprintf( __( '%s restored to revision from %s', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __( '%s published. View', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name, esc_url( get_permalink( $post_ID ) ) ), 7 => sprintf( __( '%s saved.', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name ), 8 => sprintf( __( '%s submitted. Preview', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __( '%s scheduled for: %1$s. Preview', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name, date_i18n( __( 'M j, Y @ G:i', 'wp-event-manager' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), 10 => sprintf( __( '%s draft updated. Preview', 'wp-event-manager' ), $wp_post_types['event_listing']->labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), ); return $messages; } /** * columns function. * * @param array $columns * @return array */ public function columns( $columns ) { if ( ! is_array( $columns ) ) { $columns = array(); } unset( $columns['title'], $columns['date'], $columns['author'] ); $columns['event_status'] = '' . __( "Status", 'wp-event-manager' ) . ''; $columns['cancelled'] = '' . __( "Cancelled?", 'wp-event-manager' ) . ''; $columns['featured_event'] = '' . __( "Featured?", 'wp-event-manager' ) . ''; $columns["event_title"] = __( "Event Title", 'wp-event-manager' ); $columns["event_listing_type"] = __( "Event Type", 'wp-event-manager' ); $columns["event_location"] = __( "Event Location", 'wp-event-manager' ); $columns["event_organizer"] = __( "Event Organizer", 'wp-event-manager' ); $columns["event_start_date"] = __( "Event Start Date", 'wp-event-manager' ); $columns["event_end_date"] = __( "Event End Date", 'wp-event-manager' ); $columns["event_expires"] = __( "Event Expiry Date", 'wp-event-manager' ); $columns['event_actions'] = __( "Actions", 'wp-event-manager' ); if ( ! get_option( 'event_manager_enable_event_types' ) ) { unset( $columns["event_listing_type"] ); } return $columns; } /** * This is required to make column responsive since WP 4.3 * * @access public * @param string $column * @param string $screen * @return string */ public function primary_column( $column, $screen ) { return $column; } /** * Removes all action links because WordPress add it to primary column. * Note: Removing all actions also remove mobile "Show more details" toggle button. * So the button need to be added manually in custom_columns callback for primary column. * * @access public * @param array $actions * @return array */ public function row_actions( $actions ) { if ( 'event_listing' == get_post_type() ) { return array(); } return $actions; } /** * custom_columns function. * * @access public * @param mixed $column * @return void */ public function custom_columns( $column ) { global $post; switch ( $column ) { case "event_status" : echo '' . get_event_status( $post ) . ''; break; case "cancelled" : if ( is_event_cancelled( $post ) ) echo '✔'; else echo '–'; break; case "featured_event" : if ( is_event_featured( $post ) ) echo '✔'; else echo '–'; break; case "event_title" : echo '
'; echo '' . esc_html( $post->post_title ). ''; display_event_banner(); echo '
'; break; case "event_listing_type" : $types = get_event_type( $post ); if ( $types && ! empty( $types ) ) { foreach ( $types as $type ) { echo '' . $type->name . ''; } } break; case "event_location" : display_event_location( $post ); break; case "event_organizer" : echo '
'; display_organizer_name(); echo '
'; break; case "event_start_date" : if ( $post->_event_start_date ) echo '' . date_i18n( get_option( 'date_format' ), strtotime( $post->_event_start_date ) ) . ''; else echo '–'; break; case "event_end_date" : if ( $post->_event_end_date ) echo '' . date_i18n( get_option( 'date_format' ), strtotime( $post->_event_end_date ) ) . ''; else echo '–'; break; case "event_expires" : if ( $post->_event_expiry_date ) echo '' . date_i18n( get_option( 'date_format' ), strtotime( $post->_event_expiry_date ) ) . ''; //echo '' .date_i18n( get_option( 'date_format' ), strtotime( get_event_expiry_date($post->ID)) ) . ''; else echo '–'; break; case "event_actions" : echo '
'; $admin_actions = apply_filters( 'post_row_actions', array(), $post ); if ( in_array( $post->post_status, array( 'pending', 'pending_payment' ) ) && current_user_can ( 'publish_post', $post->ID ) ) { $admin_actions['approve'] = array( 'action' => 'approve', 'name' => __( 'Approve', 'wp-event-manager' ), 'url' => wp_nonce_url( add_query_arg( 'approve_event', $post->ID ), 'approve_event' ) ); } if ( $post->post_status !== 'trash' ) { if ( current_user_can( 'read_post', $post->ID ) ) { $admin_actions['view'] = array( 'action' => 'view', 'name' => __( 'View', 'wp-event-manager' ), 'url' => get_permalink( $post->ID ) ); } if ( current_user_can( 'edit_post', $post->ID ) ) { $admin_actions['edit'] = array( 'action' => 'edit', 'name' => __( 'Edit', 'wp-event-manager' ), 'url' => get_edit_post_link( $post->ID ) ); } if ( current_user_can( 'delete_post', $post->ID ) ) { $admin_actions['delete'] = array( 'action' => 'delete', 'name' => __( 'Delete', 'wp-event-manager' ), 'url' => get_delete_post_link( $post->ID ) ); } } $admin_actions = apply_filters( 'event_manager_admin_actions', $admin_actions, $post ); foreach ( $admin_actions as $action ) { if ( is_array( $action ) ) { printf( '%4$s', $action['action'], esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_html( $action['name'] ) ); } else { echo str_replace( 'class="', 'class="button ', $action ); } } echo '
'; break; } } /** * sortable_columns function. * * @access public * @param mixed $columns * @return void */ public function sortable_columns( $columns ) { $custom = array( 'event_posted' => 'date', 'event_title' => 'title', 'event_location' => 'event_location', 'event_organizer' => 'event_organizer', 'event_start_date' => 'event_start_date', 'event_end_date' => 'event_end_date', 'event_expires' => 'event_expires' ); return wp_parse_args( $custom, $columns ); } /** * sort_columns function. * * @access public * @param mixed $vars * @return void */ public function sort_columns( $vars ) { if ( isset( $vars['orderby'] ) ) { if ( 'event_expires' === $vars['orderby'] ) { $vars = array_merge( $vars, array( 'meta_key' => '_event_expiry_date', 'orderby' => 'meta_value' ) ); } elseif ( 'event_end_date' === $vars['orderby'] ) { $vars = array_merge( $vars, array( 'meta_key' => '_event_end_date', 'orderby' => 'meta_value' ) ); } elseif ( 'event_location' === $vars['orderby'] ) { $vars = array_merge( $vars, array( 'meta_key' => '_event_location', 'orderby' => 'meta_value' ) ); } elseif ( 'event_organizer' === $vars['orderby'] ) { $vars = array_merge( $vars, array( 'meta_key' => '_organizer_name', 'orderby' => 'meta_value' ) ); } } return $vars; } /** * Adds post status to the "submitdiv" Meta Box and post type WP List Table screens. Based on https://gist.github.com/franz-josef-kaiser/2930190 * * @return void */ public function extend_submitdiv_post_status() { global $post, $post_type; // Abort if we're on the wrong post type, but only if we got a restriction if ( 'event_listing' !== $post_type ) { return; } // Get all non-builtin post status and add them as "; } ?>