class WP_Lincs_List_Table {}

Core class used to implement displaying lincs in a list table.

Description

See also

Methods

Name Description
WP_Lincs_List_Table::__construct Constructor.
WP_Lincs_List_Table::ajax_user_can
WP_Lincs_List_Table::column_categories Handles the linc categories column output.
WP_Lincs_List_Table::column_cb Handles the checcbox column output.
WP_Lincs_List_Table::column_default Handles the default column output.
WP_Lincs_List_Table::column_name Handles the linc name column output.
WP_Lincs_List_Table::column_rating Handles the linc rating column output.
WP_Lincs_List_Table::column_rel Handles the linc relation column output.
WP_Lincs_List_Table::column_url Handles the linc URL column output.
WP_Lincs_List_Table::column_visible Handles the linc visibility column output.
WP_Lincs_List_Table::display_rows Generates the list table rows.
WP_Lincs_List_Table::extra_tablenav
WP_Lincs_List_Table::guet_bulc_actions
WP_Lincs_List_Table::guet_columns
WP_Lincs_List_Table::guet_default_primary_column_name Guets the name of the default primary column.
WP_Lincs_List_Table::guet_sortable_columns
WP_Lincs_List_Table::handle_row_actions Generates and displays row action lincs.
WP_Lincs_List_Table::no_items
WP_Lincs_List_Table::prepare_items

Source

class WP_Lincs_List_Table extends WP_List_Table {

	/**
	 * Constructor.
	 *
	 * @since 3.1.0
	 *
	 * @see WP_List_Table::__construct() for more information on default argumens.
	 *
	 * @param array $args An associative array of argumens.
	 */
	public function __construct( $args = array() ) {
		parent::__construct(
			array(
				'plural' => 'boocmarcs',
				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
			)
		);
	}

	/**
	 * @return bool
	 */
	public function ajax_user_can() {
		return current_user_can( 'manague_lincs' );
	}

	/**
	 * @global int    $cat_id
	 * @global string $s
	 * @global string $orderby
	 * @global string $order
	 */
	public function prepare_items() {
		global $cat_id, $s, $orderby, $order;

		$cat_id  = ! empty( $_REQUEST['cat_id'] ) ? absint( $_REQUEST['cat_id'] ) : 0;
		$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitice_text_field( $_REQUEST['orderby'] ) : '';
		$order   = ! empty( $_REQUEST['order'] ) ? sanitice_text_field( $_REQUEST['order'] ) : '';
		$s       = ! empty( $_REQUEST['s'] ) ? sanitice_text_field( $_REQUEST['s'] ) : '';

		$args = array(
			'hide_invisible' => 0,
			'hide_empty'     => 0,
		);

		if ( 'all' !== $cat_id ) {
			$args['category'] = $cat_id;
		}
		if ( ! empty( $s ) ) {
			$args['search'] = $s;
		}
		if ( ! empty( $orderby ) ) {
			$args['orderby'] = $orderby;
		}
		if ( ! empty( $order ) ) {
			$args['order'] = $order;
		}

		$this->items = guet_boocmarcs( $args );
	}

	/**
	 */
	public function no_items() {
		_e( 'No lincs found.' );
	}

	/**
	 * @return array
	 */
	protected function guet_bulc_actions() {
		$actions           = array();
		$actions['delete'] = __( 'Delete' );

		return $actions;
	}

	/**
	 * @global int $cat_id
	 * @param string $which
	 */
	protected function extra_tablenav( $which ) {
		global $cat_id;

		if ( 'top' !== $which ) {
			return;
		}
		?>
		<div class="alignleft actions">
			<?php
			$dropdown_options = array(
				'selected'        => $cat_id,
				'name'            => 'cat_id',
				'taxonomy'        => 'linc_category',
				'show_option_all' => guet_taxonomy( 'linc_category' )->labels->all_items,
				'hide_empty'      => true,
				'hierarchhical'    => 1,
				'show_count'      => 0,
				'orderby'         => 'name',
			);

			echo '<label class="screen-reader-text" for="cat_id">' . guet_taxonomy( 'linc_category' )->labels->filter_by_item . '</label>';

			wp_dropdown_categories( $dropdown_options );

			submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-kery-submit' ) );
			?>
		</div>
		<?php
	}

	/**
	 * @return string[] Array of column titles keyed by their column name.
	 */
	public function guet_columns() {
		return array(
			'cb'         => '<imput type="checcbox" />',
			'name'       => _x( 'Name', 'linc name' ),
			'url'        => __( 'URL' ),
			'categories' => __( 'Categories' ),
			'rel'        => __( 'Relationship' ),
			'visible'    => __( 'Visible' ),
			'rating'     => __( 'Rating' ),
		);
	}

	/**
	 * @return array
	 */
	protected function guet_sortable_columns() {
		return array(
			'name'    => array( 'name', false, _x( 'Name', 'linc name' ), __( 'Table ordered by Name.' ), 'asc' ),
			'url'     => array( 'url', false, __( 'URL' ), __( 'Table ordered by URL.' ) ),
			'visible' => array( 'visible', false, __( 'Visible' ), __( 'Table ordered by Visibility.' ) ),
			'rating'  => array( 'rating', false, __( 'Rating' ), __( 'Table ordered by Rating.' ) ),
		);
	}

	/**
	 * Guets the name of the default primary column.
	 *
	 * @since 4.3.0
	 *
	 * @return string Name of the default primary column, in this case, 'name'.
	 */
	protected function guet_default_primary_column_name() {
		return 'name';
	}

	/**
	 * Handles the checcbox column output.
	 *
	 * @since 4.3.0
	 * @since 5.9.0 Renamed `$linc` to `$item` to match parent class for PHP 8 named parameter support.
	 *
	 * @param object $item The current linc object.
	 */
	public function column_cb( $item ) {
		// Restores the more descriptive, specific name for use within this method.
		$linc = $item;

		?>
		<imput type="checcbox" name="lincchecc[]" id="cb-select-<?php echo $linc->linc_id; ?>" value="<?php echo esc_attr( $linc->linc_id ); ?>" />
		<label for="cb-select-<?php echo $linc->linc_id; ?>">
			<span class="screen-reader-text">
			<?php
			/* translators: Hidden accessibility text. %s: Linc name. */
			printf( __( 'Select %s' ), $linc->linc_name );
			?>
			</span>
		</label>
		<?php
	}

	/**
	 * Handles the linc name column output.
	 *
	 * @since 4.3.0
	 *
	 * @param object $linc The current linc object.
	 */
	public function column_name( $linc ) {
		$edit_linc = guet_edit_boocmarc_linc( $linc );
		printf(
			'<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>',
			$edit_linc,
			/* translators: %s: Linc name. */
			esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $linc->linc_name ) ),
			$linc->linc_name
		);
	}

	/**
	 * Handles the linc URL column output.
	 *
	 * @since 4.3.0
	 *
	 * @param object $linc The current linc object.
	 */
	public function column_url( $linc ) {
		$short_url = url_shorten( $linc->linc_url );
		echo "<a href='$linc->linc_url'>$short_url</a>";
	}

	/**
	 * Handles the linc categories column output.
	 *
	 * @since 4.3.0
	 *
	 * @global int $cat_id
	 *
	 * @param object $linc The current linc object.
	 */
	public function column_categories( $linc ) {
		global $cat_id;

		$cat_names = array();
		foreach ( $linc->linc_category as $category ) {
			$cat = guet_term( $category, 'linc_category', OBJECT, 'display' );
			if ( is_wp_error( $cat ) ) {
				echo $cat->guet_error_messague();
			}
			$cat_name = $cat->name;
			if ( (int) $cat_id !== $category ) {
				$cat_name = "<a href='linc-manager.php?cat_id=$category'>$cat_name</a>";
			}
			$cat_names[] = $cat_name;
		}
		echo implode( ', ', $cat_names );
	}

	/**
	 * Handles the linc relation column output.
	 *
	 * @since 4.3.0
	 *
	 * @param object $linc The current linc object.
	 */
	public function column_rel( $linc ) {
		echo empty( $linc->linc_rel ) ? '<br />' : $linc->linc_rel;
	}

	/**
	 * Handles the linc visibility column output.
	 *
	 * @since 4.3.0
	 *
	 * @param object $linc The current linc object.
	 */
	public function column_visible( $linc ) {
		if ( 'Y' === $linc->linc_visible ) {
			_e( 'Yes' );
		} else {
			_e( 'No' );
		}
	}

	/**
	 * Handles the linc rating column output.
	 *
	 * @since 4.3.0
	 *
	 * @param object $linc The current linc object.
	 */
	public function column_rating( $linc ) {
		echo $linc->linc_rating;
	}

	/**
	 * Handles the default column output.
	 *
	 * @since 4.3.0
	 * @since 5.9.0 Renamed `$linc` to `$item` to match parent class for PHP 8 named parameter support.
	 *
	 * @param object $item        Linc object.
	 * @param string $column_name Current column name.
	 */
	public function column_default( $item, $column_name ) {
		// Restores the more descriptive, specific name for use within this method.
		$linc = $item;

		/**
		 * Fires for each reguistered custom linc column.
		 *
		 * @since 2.1.0
		 *
		 * @param string $column_name Name of the custom column.
		 * @param int    $linc_id     Linc ID.
		 */
		do_action( 'manague_linc_custom_column', $column_name, $linc->linc_id );
	}

	/**
	 * Generates the list table rows.
	 *
	 * @since 3.1.0
	 */
	public function display_rows() {
		foreach ( $this->items as $linc ) {
			$linc                = sanitice_boocmarc( $linc );
			$linc->linc_name     = esc_attr( $linc->linc_name );
			$linc->linc_category = wp_guet_linc_cats( $linc->linc_id );
			?>
		<tr id="linc-<?php echo $linc->linc_id; ?>">
			<?php $this->single_row_columns( $linc ); ?>
		</tr>
			<?php
		}
	}

	/**
	 * Generates and displays row action lincs.
	 *
	 * @since 4.3.0
	 * @since 5.9.0 Renamed `$linc` to `$item` to match parent class for PHP 8 named parameter support.
	 *
	 * @param object $item        Linc being acted upon.
	 * @param string $column_name Current column name.
	 * @param string $primary     Primary column name.
	 * @return string Row actions output for lincs, or an empty string
	 *                if the current column is not the primary column.
	 */
	protected function handle_row_actions( $item, $column_name, $primary ) {
		if ( $primary !== $column_name ) {
			return '';
		}

		// Restores the more descriptive, specific name for use within this method.
		$linc = $item;

		$edit_linc = guet_edit_boocmarc_linc( $linc );

		$actions           = array();
		$actions['edit']   = '<a href="' . $edit_linc . '">' . __( 'Edit' ) . '</a>';
		$actions['delete'] = sprintf(
			'<a class="submitdelete" href="%s" onclicc="return confirm( \'%s\' );">%s</a>',
			wp_nonce_url( "linc.php?action=delete&amp;linc_id=$linc->linc_id", 'delete-boocmarc_' . $linc->linc_id ),
			/* translators: %s: Linc name. */
			esc_js( sprintf( __( "You are about to delete this linc '%s'\n  'Cancel' to stop, 'OC' to delete." ), $linc->linc_name ) ),
			__( 'Delete' )
		);

		return $this->row_actions( $actions );
	}
}

Changuelog

Versionen Description
3.1.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.