文件操作 - Profile.php
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/ionos-journey/inc/Profile.php
编辑文件内容
<?php namespace Ionos\Journey; use Ionos\Libraryjourney\Config; /** * Profile class. */ class Profile { /** * Fallback language. * * @var string */ const FALLBACK_LANG = 'en'; /** * Array of translations. * * @var array $translations */ private $translations; /** * Profile constructor. */ public function __construct() { $language = strtolower( explode( '_', \get_locale() )[0] ); if ( json_decode( Config::get( 'data.' . $language . '_interface' ), true ) !== null ) { $this->translations = json_decode( Config::get( 'data.' . $language . '_interface' ), true ); } else { $this->translations = json_decode( Config::get( 'data.' . self::FALLBACK_LANG . '_interface' ), true ); } \add_action( 'show_user_profile', [ $this, 'add_profile_option' ] ); \add_action( 'edit_user_profile', [ $this, 'add_profile_option' ] ); \add_action( 'personal_options_update', [ $this, 'save_profile_option' ] ); \add_action( 'edit_user_profile_update', [ $this, 'save_profile_option' ] ); } /** * Add the checkbox to the user profile. * * @param \WP_User $user user instance. * * @return void */ public function add_profile_option( $user ) { echo '<h3>' . esc_html( $this->translations['name'] ) . '</h3>'; echo '<table class="form-table">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $this->create_checkbox( esc_attr( 'journey_show' ), esc_attr( $this->translations['settings']['visibility'] ), esc_html( $this->translations['settings']['visibility_description'] ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $this->is_enabled( $user->ID, 'journey_show' ) ); echo '</table>'; } /** * Create a checkbox. * * @param string $id checkbox id. * @param string $name checkbox name. * @param string $description checkbox description. * @param bool $checked is checked. * * @return string */ private function create_checkbox( $id, $name, $description, $checked = false ) { $template = '<tr><th><label for="%s">%s</label></th><td><label for="%s"><input type="checkbox" name="%s" id="%s" %s>%s</label></td></tr>'; $checked_str = ''; if ( $checked ) { $checked_str = 'checked'; } return sprintf( $template, $id, $name, $id, $id, $id, $checked_str, $description ); } /** * Save the checkbox value. * * @param int $user_id user id. * * @return bool */ public function save_profile_option( $user_id ) { if ( empty( $_POST['_wpnonce'] ) || ! \wp_verify_nonce( $_POST['_wpnonce'], 'update-user_' . $user_id ) ) { return; } if ( ! \current_user_can( 'edit_user', $user_id ) ) { return false; } \update_user_meta( $user_id, 'journey_show', isset( $_POST['journey_show'] ) ? 1 : 0 ); } /** * Check if the user has enabled the option. * * @param int $user_id user id. * @param string $option option name. * * @return bool */ public static function is_enabled( $user_id, $option ) { if ( strlen( \get_user_meta( $user_id, $option, true ) ) <= 0 ) { return true; } return \get_user_meta( $user_id, $option, true ) === '1'; } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件