esc_html( 'Thumbnail' ), 'title' => esc_html( 'Title' ), 'shortcode' => esc_html( 'Shortcode' ), 'privacy' => esc_html( 'Privacy' ), 'edit' => esc_html( 'Edit' ), ); return $columns; } /** * Bind table with columns, display data. */ public function prepare_items() { if ( isset( $_POST['s'] ) ) { $s_query = sanitize_text_field( wp_unslash( $_POST['s'] ) ); } if ( isset( $_POST['search_video'] ) ) { $search_video = sanitize_text_field( wp_unslash( $_POST['search_video'] ) ); } if ( ! empty( $s_query ) && current_user_can( 'manage_options' ) ) { if ( ! isset( $search_video ) || ! wp_verify_nonce( $search_video, '42videobricks_search' ) ) { add_settings_error( 'videobricks42_plugin_notice', 's', 'Request not verified' ); $videos = array(); } else { $videos = videobricks42_get_videos( null, 0, $s_query ); } } else { $videos = videobricks42_get_videos(); } $data = array(); $key = 0; if ( ! empty( $videos ) ) { foreach ( $videos as $video ) { $data[ $key ]['thumbnail'] = 'thumbnail'; $data[ $key ]['title'] = stripslashes( esc_attr( $video->getTitle() ) ); if ( $video->getPublic() ) { $data[ $key ]['privacy'] = esc_attr( 'Public' ); $svg = ''; $data[ $key ]['shortcode'] = $svg . ''; } else { $data[ $key ]['shortcode'] = esc_attr( 'Your video is private' ); $data[ $key ]['privacy'] = esc_attr( 'Private' ); } if ( $video->getStatus() !== 'AVAILABLE' ) { $data[ $key ]['shortcode'] = esc_attr( 'Your video will be ready soon. Please reload this page in a few minutes. In case of troubleshooting, please check 42videobricks administration page.' ); } $svg_edit = ''; $edit_video = sprintf( '' . $svg_edit . '', esc_attr( get_option( 'videobricks42_env' ) ), esc_attr( $video->getId() ) ); $data[ $key ]['edit'] = $edit_video; ++$key; } } $columns = $this->get_columns(); $this->_column_headers = array( $columns ); /* pagination */ $per_page = $this->get_items_per_page( 'elements_per_page', 10 ); $current_page = $this->get_pagenum(); $total_items = count( $data ); $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page ); $this->set_pagination_args( array( 'total_items' => $total_items, // total number of items. 'per_page' => $per_page, // items to show on a page. 'total_pages' => ceil( $total_items / $per_page ), // use ceil to round up. ) ); $this->items = $data; } /** * Set default column. * * @param array $item Video item. * @param string $column_name Column name. * @return mixed */ protected function column_default( $item, $column_name ) { switch ( $column_name ) { case 'thumbnail': case 'title': case 'shortcode': case 'privacy': case 'edit': default: return $item[ $column_name ]; } } /** * Adding action links to column. * * @param array $item Video item. * @return mixed Row action. */ public function actions( $item ) { $actions = array( 'Edit' => sprintf( '' . esc_html( 'Edit' ) . '', esc_html( get_option( 'videobricks42_env' ) ), esc_attr( $item['id'] ) ), ); return $this->row_actions( $actions ); } /** * Display table. */ public function display() { $this->display_tablenav( esc_attr( 'top' ) ); $this->screen->render_screen_reader_content( esc_attr( 'heading_list' ) ); ?> print_table_description(); ?> print_column_headers(); ?> display_rows_or_placeholder(); ?>
has_items() ) { return; } if ( isset( $_POST['search_video'] ) && isset( $search ) ) { if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['search_video'] ) ), '42videobricks_search' ) ) { return; } } $input_id = $input_id . '-search-input'; ?>