HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/zaklada/wp-content/plugins/dinamo-foundation-plugin/heart-messages/messages_table.php
<?php

if(!class_exists('WP_List_Table')){
    require_once( ABSPATH . 'wp-admin/includes/screen.php' );
    require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}

class Dinamo_Orders_List_Table extends WP_List_Table {

/**
* Constructor, we override the parent to pass our own arguments
* We usually focus on three parameters: singular and plural labels, as well as whether the class supports AJAX.
*/
function __construct() {
parent::__construct( array(
'singular'=> 'wp_list_text_link', //Singular label
'plural' => 'wp_list_test_links', //plural label, also this well be one of the table css class
'ajax'   => false //We won't support Ajax for this table
) );
}

function extra_tablenav( $which ) {

add_thickbox(); ?>

  <?php if ( $which == "top" ){
    echo "<h1>Messages</h1>";
  }
}

function get_columns() {
    return $columns= array(
        'id'=>('ID'),
        'message'=>__('Message'),
        'actions'=>__('Actions'),
    );
}

/**
 * Display the rows of records in the table
 * @return string, echo the markup of the rows
 */
function display_rows() {

  //Get the records registered in the prepare_items method
  $records = $this->items;

    //Get the columns registered in the get_columns and get_sortable_columns methods
  list( $columns, $hidden ) = $this->get_column_info();


  $message_serv = new dinamo_donator_messages_service();

  //Loop for each record
  if(!empty($records)){foreach($records as $rec){
                
    //Open the line
    echo '<tr id="">';
    foreach ( $columns as $column_name => $column_display_name ) {

      //Style attributes for each col
      $class = "class='$column_name column-$column_name'";
      $style = "";
      if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"';
      $attributes = $class . $style;
      $message_item = $rec;
      //edit link
      $editlink  = '/wp-admin/link.php?action=edit';
      //Display the cell
      switch ( $column_name ) {
        case "id" :
          if(!is_null($message_item)) {
            echo '<td ' . $attributes . '>' . $message_item->id . '</td>';

          } else {            
            echo '<td></td>';
          }
          break;
        case "message" :
          if(!is_null($message_item)) {
            echo '<td ' . $attributes . '><span class="'. ($message_item->approved ? 'message-approved' : 'message-disapproved')  .'">' . $message_item->message . '</span>';
            echo '</td>';
          }else{
            echo '<td></td>';
          }
          break;
        case "actions":
          echo '<td '.$attributes. '>';

          if($message_item) {
            
            if (current_user_can('administrator')) {
              echo '<button class="button button-secondary edit-message-button" onclick="ShowModal(' . $message_item->id . ');">Edit</button>';
              echo '<div id="myModal-' . $message_item->id . '" data-id="' . $message_item->id . '" class="modal">
          <div class="modal-content" >
          <span class="close"onclick="closeEdit(' . $message_item->id . ')">&times;</span> 
          <p id="alert-' . $message_item->id . '" class="alert-class"></p>               
          <textarea id="message-' . $message_item->id . '"  class="msg-class msgId-' . $message_item->id . '" name="message"> ' . $message_item->message . '</textarea>
            <br>
          <button class="btn-full button-secondary" onclick="edit(' . $message_item->id . ');">Save</button>
          </div> </div>';
            echo '<a data-message-id="' . $rec->id . '" class="table-button delete-message button-secondary">Delete</a>';

          }
            if ($message_item->approved) {
                echo '<a data-message-id="' . $rec->id . '" class="table-button approve-message button-primary">Disapprove Message</a>';
            } else {
                echo '<a data-message-id="' . $rec->id . '" class="table-button approve-message button-primary">Approve Message</a>';
            }
          }
          echo '</td>';
        break;
      }
    }

    //Close the line
    echo'</tr>';
  }}
}

function display_tablenav( $which ) {
  ?>
  <div class="tablenav <?php echo esc_attr( $which ); ?>">

      <div class="alignleft">
        <?php $this->extra_tablenav( $which ); ?>
      </div>
      <div class="alignright">
        <?php $this->pagination( $which );?>
      </div>
      
      <br class="clear" />
  </div>
  <?php
}


/**
 * Prepare the table with different parameters, pagination, columns and table elements
 */
function prepare_items() {
    global $wpdb, $_wp_column_headers;
    $screen = get_current_screen();
    $order_status = null;
    $language = get_current_language();
    if(!empty($_GET["order_status"])) {
        $order_status = $_GET["order_status"];
    }
    $search = "";
    
    if(!empty($_GET["search"])) {
        $search = $_GET["search"];
    }
    
    //How many to display per page?
    $perpage = 80;
    //Which page is this?
   
    $paged = !empty($_GET["paged"]) ? $_GET["paged"] : '';
    if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }


    //order status
    // 0 - active
    // 1 - cancelled


    $cancelled = null;
    if($order_status == "1"){
        $cancelled = 1;
    }
       
       
    $messages_service = new dinamo_donator_messages_service();
    $filtered_messages = $messages_service->get_filter_messages($perpage, $paged, $language);    
    $totalpages = ceil($filtered_messages["total"]/$perpage);

    $this->set_pagination_args( array(
        "total_items" =>$filtered_messages["total"],
        "total_pages" => $totalpages,
        "per_page" => $perpage,
    ) );

    //The pagination links are automatically built according to those parameters

    /* -- Register the Columns -- */
    $columns = $this->get_columns();
    $this->_column_headers = array(
        $this->get_columns(),
        array(), //hidden columns if applicable
        $this->get_sortable_columns()
    );


    /* -- Fetch the items -- */
    $this->items = $filtered_messages["data"];
}

}


add_action( 'admin_menu', 'heart_messages_menu' );

function heart_messages_menu() {
    add_menu_page(
        'Messages',
        'Messages',
        'manage_options',
        'heart-messages',
        'heart_messages_page',
        'dashicons-heart'
    );
}



function heart_messages_page(){
    
    $wp_list_table = new Dinamo_Orders_List_Table();
    $wp_list_table->prepare_items();
    echo '<div class="wrap">';
      $wp_list_table->display();
    echo '</div>';
    
}

add_action('admin_head', 'custom_messages_table_styles');

function custom_messages_table_styles() {
  echo '<style>
  
  </style>';
}

?>