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/Upgrader/Upgrades/V_2_0_2.php
<?php

namespace WeDevs\WeDocs\Upgrader\Upgrades;


use WeDevs\WeDocs\Upgrader\Abstracts\UpgradeHandler;

/**
 * Car handler class.
 */
class V_2_0_2 extends UpgradeHandler {

    /**
     * Upgrade version.
     *
     * @since 2.0.2
     *
     * @var string
     */
    protected $version = '2.0.2';

    /**
     * Upgrade necessary data in database.
     *
     * @since 2.0.2
     *
     * @return void
     */
    public function handle_upgrade() {
        $this->clean_beta_notice();
        $this->update_settings_db();
        $this->add_documentation_handling_capabilities();
    }

    /**
     * Remove beta notice data.
     *
     * @since 2.0.2
     *
     * @return void
     */
    public function clean_beta_notice() {
        $user_id         = get_current_user_id();
        $has_beta_notice = get_user_meta( $user_id, 'wedocs_hide_beta_notice', true );

        if ( ! empty( $has_beta_notice ) ) {
            delete_user_meta( $user_id, 'wedocs_hide_beta_notice', 1 );
        }
    }

    /**
     * Update weDocs settings db.
     *
     * @since 2.0.2
     *
     * @return void
     */
    private function update_settings_db() {
        $value = get_option( 'wedocs_settings', [] );

        // Check if data already updated.
        if ( empty( $value['general'] ) ) {
            // Set default value if general data not found.
            $value['general'] = [
                'print'     => wedocs_get_general_settings( 'print', 'on' ),
                'email'     => wedocs_get_general_settings( 'email', 'on' ),
                'helpful'   => wedocs_get_general_settings( 'helpful', 'on' ),
                'comments'  => wedocs_get_general_settings( 'comments', 'off' ),
                'email_to'  => wedocs_get_general_settings( 'email_to' ),
                'docs_home' => wedocs_get_general_settings( 'docs_home' ),
            ];

            // Remove all unnecessary data.
            unset( $value['print'] );
            unset( $value['email'] );
            unset( $value['helpful'] );
            unset( $value['comments'] );
            unset( $value['email_to'] );
            unset( $value['docs_home'] );
        }

        // Update settings data with plugin version.
        update_option( 'wedocs_settings', $value );
    }

    /**
     * Add weDocs documentation handling capabilities for users.
     *
     * @since 2.0.2
     *
     * @return void
     */
    private function add_documentation_handling_capabilities() {
        global $wp_roles;

        if ( class_exists( 'WP_Roles' ) && ! isset( $wp_roles ) ) {
            $wp_roles = new \WP_Roles(); // @codingStandardsIgnoreLine
        }

        $roles        = $wp_roles->get_names();
        $capabilities = array(
            'edit_post',
            'edit_docs',
            'publish_docs',
            'edit_others_docs',
            'read_private_docs',
            'edit_private_docs',
            'edit_published_docs'
        );

        // Push documentation handling access to users.
        foreach ( $capabilities as $capability ) {
            foreach ( $roles as $role_key => $role ) {
                $wp_roles->add_cap( $role_key, $capability );
            }
        }
    }
}