Comment
9 years ago
Link
9 years ago
Media
9 years ago
Post
9 years ago
User
9 years ago
ActionColumnHelper.php
9 years ago
Actions.php
9 years ago
AjaxValue.php
9 years ago
CustomField.php
9 years ago
Meta.php
9 years ago
Placeholder.php
9 years ago
Taxonomy.php
9 years ago
UsedByMenu.php
9 years ago
WooCommercePlaceholder.php
9 years ago
ActionColumnHelper.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Holds all the row actions buttons for each content type (e.g. post, comment, user and media). |
| 9 | * WP_List_Table does not have a method for retrieving row actions. This class uses their filters to fetch the actions. |
| 10 | * For example usage see the AC_Column_Actions class. |
| 11 | * |
| 12 | * Class AC_Column_ActionColumnHelper |
| 13 | */ |
| 14 | class AC_Column_ActionColumnHelper { |
| 15 | |
| 16 | private $actions; |
| 17 | |
| 18 | /** |
| 19 | * @since 2.5 |
| 20 | */ |
| 21 | private static $_instance = null; |
| 22 | |
| 23 | /** |
| 24 | * @since 2.5 |
| 25 | */ |
| 26 | public static function instance() { |
| 27 | if ( null === self::$_instance ) { |
| 28 | self::$_instance = new self(); |
| 29 | } |
| 30 | |
| 31 | return self::$_instance; |
| 32 | } |
| 33 | |
| 34 | private function __construct() { |
| 35 | add_filter( 'comment_row_actions', array( $this, 'set_comment' ), 10, 2 ); |
| 36 | add_filter( 'page_row_actions', array( $this, 'set_post' ), 10, 2 ); |
| 37 | add_filter( 'post_row_actions', array( $this, 'set_post' ), 10, 2 ); |
| 38 | add_filter( 'media_row_actions', array( $this, 'set_media' ), 10, 2 ); |
| 39 | add_filter( 'user_row_actions', array( $this, 'set_user' ), 10, 2 ); |
| 40 | } |
| 41 | |
| 42 | public function set_comment( $actions, $comment ) { |
| 43 | $this->actions[ 'comment' ][ $comment->ID ] = $actions; |
| 44 | |
| 45 | return $actions; |
| 46 | } |
| 47 | |
| 48 | public function set_post( $actions, $post ) { |
| 49 | $this->actions[ 'post' ][ $post->ID ] = $actions; |
| 50 | |
| 51 | return $actions; |
| 52 | } |
| 53 | |
| 54 | public function set_media( $actions, $post ) { |
| 55 | $this->actions[ 'media' ][ $post->ID ] = $actions; |
| 56 | |
| 57 | return $actions; |
| 58 | } |
| 59 | |
| 60 | public function set_user( $actions, $user ) { |
| 61 | $this->actions[ 'user' ][ $user->ID ] = $actions; |
| 62 | |
| 63 | return $actions; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Retrieve row actions like 'edit, trash, spam' etc. |
| 68 | * |
| 69 | * @param string $type |
| 70 | * @param int $id Object ID |
| 71 | * |
| 72 | * @return array|false Array with actions |
| 73 | */ |
| 74 | public function get( $type, $id ) { |
| 75 | return isset( $this->actions[ $type ][ $id ] ) ? $this->actions[ $type ][ $id ] : array(); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 |