# posts-data-table/1.3/src/Table_Shortcode.php

Posts Table with Search &amp; Sort, version 1.3. 41 lines.

- Page: https://pluginprobe.com/plugins/posts-data-table/1.3/code/src/Table_Shortcode.php
- Raw: https://pluginprobe.com/plugins/posts-data-table/1.3/raw/src/Table_Shortcode.php
- Modified: 2019-11-16T17:52:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/posts-data-table/1.3/code/src/Table_Shortcode.php#L10-L20`.

```php
<?php

namespace Barn2\Plugin\Posts_Table_Search_Sort;

use Barn2\Lib\Registerable,
    Barn2\Lib\Service;

/**
 * This class handles the posts table shortcode registration.
 *
 * @author    Barn2 Media <info@barn2.co.uk>
 * @license   GPL-3.0
 * @copyright Barn2 Media Ltd
 */
class Table_Shortcode implements Registerable, Service {

    const SHORTCODE = 'posts_table';

    public function register() {
        add_shortcode( self::SHORTCODE, array( $this, 'do_shortcode' ) );
        add_shortcode( 'posts_data_table', array( $this, 'do_shortcode' ) ); // back compat: support old shortcode
    }

    /**
     * Handles our posts data table shortcode.
     *
     * @param array $atts The shortcode attributes specified by the user.
     * @param string $content The content between the open and close shortcode tags (not used)
     * @return string The shortcode output
     */
    public function do_shortcode( $atts, $content = '' ) {
        // Parse attributes
        $atts = \shortcode_atts( Simple_Posts_Table::get_defaults(), $atts, self::SHORTCODE );

        // Create table and return output
        $table = new Simple_Posts_Table();
        return $table->get_table( $atts );
    }

}

```
