paging = $paging; $this->base_url = $base_url ?: \AfroIT\Messaging\WorkflowAutomations\Admin\Hub\HubPage::url( array( 'tab' => 'templates' ) ); parent::__construct( array( 'singular' => 'template', 'plural' => 'templates', 'ajax' => false, ) ); } /** * Column definitions. * * @return array */ public function get_columns() { return array( 'name' => _x( 'Name', 'column name', 'afroit-messaging-workflows' ), 'language' => _x( 'Language', 'column name', 'afroit-messaging-workflows' ), 'status' => _x( 'Status', 'column name', 'afroit-messaging-workflows' ), 'actions' => _x( 'Actions', 'column name', 'afroit-messaging-workflows' ), ); } /** * Primary column. * * @return string */ protected function get_primary_column_name() { return 'name'; } /** * Override to ensure columns are set (bypass screen filter which may not fire). * * @return array */ protected function get_column_info() { if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) && 4 === count( $this->_column_headers ) ) { return $this->_column_headers; } $columns = $this->get_columns(); $hidden = $this->screen ? get_hidden_columns( $this->screen ) : array(); $sortable = array(); $primary = $this->get_primary_column_name(); $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); return $this->_column_headers; } /** * Prepare items (data is passed in, not fetched here). * * @param array $items Template items. * @return void */ public function prepare_items_with_data( $items ) { $this->items = is_array( $items ) ? $items : array(); $per_page = 20; $this->set_pagination_args( array( 'total_items' => count( $this->items ), 'per_page' => $per_page, 'total_pages' => 1, ) ); } /** * Required by parent but we use prepare_items_with_data. */ public function prepare_items() { $this->items = array(); } /** * Message when no templates found. */ public function no_items() { echo esc_html__( 'No message templates found.', 'afroit-messaging-workflows' ); } /** * Column: name. * * @param array $item Template row. * @return string */ protected function column_name( $item ) { $name = isset( $item['name'] ) ? $item['name'] : ''; return '' . esc_html( $name ) . ''; } /** * Column: language. * * @param array $item Template row. * @return string */ protected function column_language( $item ) { $lang = isset( $item['language'] ) ? $item['language'] : ''; if ( is_array( $lang ) && isset( $lang['code'] ) ) { $lang = $lang['code']; } return esc_html( (string) $lang ); } /** * Column: status. * * @param array $item Template row. * @return string */ protected function column_status( $item ) { $status = isset( $item['status'] ) ? (string) $item['status'] : ''; $labels = array( 'APPROVED' => __( 'Approved', 'afroit-messaging-workflows' ), 'PENDING' => __( 'Pending', 'afroit-messaging-workflows' ), 'REJECTED' => __( 'Rejected', 'afroit-messaging-workflows' ), 'DISABLED' => __( 'Disabled', 'afroit-messaging-workflows' ), 'PAUSED' => __( 'Paused', 'afroit-messaging-workflows' ), ); $label = isset( $labels[ $status ] ) ? $labels[ $status ] : $status; $class = strtolower( $status ); return '' . esc_html( $label ) . ''; } /** * Column: actions (Edit, Test). * * @param array $item Template row. * @return string */ protected function column_actions( $item ) { $id = isset( $item['id'] ) ? $item['id'] : ''; $name = isset( $item['name'] ) ? $item['name'] : ''; $lang = isset( $item['language'] ) ? $item['language'] : 'en_US'; if ( is_array( $lang ) && isset( $lang['code'] ) ) { $lang = $lang['code']; } $lang = (string) $lang; $business_id = (new SecureOptions())->get_selected_business()['business_id']; $edit_url = 'https://business.facebook.com/latest/whatsapp_manager/template_details?business_id=' . $business_id . '&tab=template-details&id=' . $id; $view_url = add_query_arg( array( 'page' => \AFROMEWO_PLUGIN_SLUG, 'tab' => 'templates', 'id' => rawurlencode( $id ), 'name' => rawurlencode( $name ), 'language' => rawurlencode( $lang ), ), admin_url( 'admin.php' ) ); $delete_url = add_query_arg( array( 'action' => 'wp_wacc_delete_template', 'id' => rawurlencode( $id ), 'name' => rawurlencode( $name ), '_wpnonce' => wp_create_nonce( 'delete_template_' . $id ), ), admin_url( 'admin-post.php' ) ); $out = '' . esc_html__( 'Edit on Meta', 'afroit-messaging-workflows' ) . ' '; $out .= '' . esc_html__( 'Template JSON', 'afroit-messaging-workflows' ) . ' '; $out .= '' . esc_html__( 'Delete', 'afroit-messaging-workflows' ) . ''; return $out; } /** * Default column. * * @param array $item Template row. * @param string $column_name Column key. * @return string */ protected function column_default( $item, $column_name ) { return ''; } /** * Cursor-based pagination (override default page-number pagination). * * @param string $which 'top' or 'bottom'. */ protected function pagination( $which ) { $cursors = isset( $this->paging['cursors'] ) ? $this->paging['cursors'] : array(); $before = isset( $cursors['before'] ) ? $cursors['before'] : ''; $after = isset( $cursors['after'] ) ? $cursors['after'] : ''; $prev_url = $before ? add_query_arg( 'cursor_before', $before, $this->base_url ) : ''; $next_url = $after ? add_query_arg( 'cursor_after', $after, $this->base_url ) : ''; $item_count = count( $this->items ); echo ''; echo esc_html( sprintf( /* translators: %s: Number of items. */ _n( '%s item', '%s items', $item_count, 'afroit-messaging-workflows' ), number_format_i18n( $item_count ) ) ); echo ''; echo ''; if ( empty( $prev_url ) ) { echo ''; } else { echo '' . esc_html__( 'Previous page', 'afroit-messaging-workflows' ) . ''; } if ( empty( $next_url ) ) { echo ''; } else { echo '' . esc_html__( 'Next page', 'afroit-messaging-workflows' ) . ''; } echo ''; } /** * Hide bulk actions (no checkboxes). * * @return array */ protected function get_bulk_actions() { return array(); } /** * Hide bulk actions dropdown. * * @param string $which 'top' or 'bottom'. */ protected function bulk_actions( $which = '' ) { // No bulk actions. } }