HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/wedocs/includes/Admin/Docs_List_Table.php
<?php

namespace WeDevs\WeDocs\Admin;

/**
 * Modifier functions in docs list table.
 */
class Docs_List_Table {

    /**
     * Constructor
     */
    public function __construct() {
        add_filter( 'manage_docs_posts_columns', [ $this, 'docs_list_columns' ] );
        add_action( 'manage_docs_posts_custom_column', [ $this, 'docs_list_columns_row' ], 10, 2 );
        add_filter( 'manage_edit-docs_sortable_columns', [ $this, 'docs_sortable_columns' ] );

        add_action( 'load-edit.php', [ $this, 'edit_docs_load' ] );
        add_action( 'load-post.php', [ $this, 'add_meta_box' ] );

        // load css
        add_action( 'admin_print_styles-post.php', [ $this, 'helpfulness_css' ] );
        add_action( 'admin_print_styles-edit.php', [ $this, 'helpfulness_css' ] );
    }

    public function add_meta_box() {
        add_meta_box( 'op-menu-meta-box-id', __( 'Helpfulness', 'wedocs' ), [ $this, 'helpfulness_metabox' ], 'docs', 'side', 'core' );
    }

    public function helpfulness_css() {
        if ( 'docs' != get_current_screen()->post_type ) {
            return;
        } ?>
        <style type="text/css">
            .wedocs-positive { color: green; }
            .wedocs-negative { color: red; text-align: right; }
        </style>
        <?php
    }

    public function helpfulness_metabox() {
        global $post; ?>
        <table style="width: 100%;">
            <tr>
                <td class="wedocs-positive">
                    <span class="dashicons dashicons-thumbs-up"></span>
                    <?php printf( '%d', get_post_meta( $post->ID, 'positive', true ) ); ?>
                </td>

                <td class="wedocs-negative">
                    <span class="dashicons dashicons-thumbs-down"></span>
                    <?php printf( '%d', get_post_meta( $post->ID, 'negative', true ) ); ?>
                </td>
            </tr>
        </table>
        <?php
    }

    /**
     * Vote column in the class UI.
     *
     * @param array $column
     *
     * @return array
     */
    public function docs_list_columns( $columns ) {
        $vote = [ 'votes' => __( 'Votes', 'wedocs' ) ];

        // insert before last element, date
        $first_items = array_splice( $columns, 0, 3 ); // remove first 3 items and store to $first_items, date remains to $columns
        $new_columns = array_merge( $first_items, $vote, $columns ); // merge all those

        return $new_columns;
    }

    public function docs_sortable_columns( $columns ) {
        $columns['votes'] = [ 'votes', true ];

        return $columns;
    }

    public function docs_list_columns_row( $column_name, $post_id ) {
        if ( 'votes' == $column_name ) {
            $positive = get_post_meta( $post_id, 'positive', true );
            $negative = get_post_meta( $post_id, 'negative', true );

            printf( '<span class="wedocs-positive">%d</span>/<span class="wedocs-negative">%d</span>', $positive, $negative );
        }
    }

    public function edit_docs_load() {
        add_filter( 'request', [ $this, 'sort_docs' ] );
    }

    // Sorts the movies.
    public function sort_docs( $vars ) {
        // Check if we're viewing the 'movie' post type.
        if ( isset( $vars['post_type'] ) && 'docs' == $vars['post_type'] ) {
            // Check if 'orderby' is set to 'duration'.
            if ( isset( $vars['orderby'] ) && 'votes' == $vars['orderby'] ) {
                $vars = array_merge(
                    $vars,
                    [
                        'meta_key' => 'positive',
                        'orderby'  => 'meta_value_num',
                    ]
                );
            }
        }

        return $vars;
    }
}