time(), 'm' => (string) $module, 'l' => (string) $level, 's' => wp_strip_all_tags( (string) $message ), ) ); update_option( self::OPT_LOG, array_slice( $log, 0, self::LOG_MAX ), false ); } /** * Activity log entries, newest first. * * @return array */ public static function log_entries() { $log = get_option( self::OPT_LOG, array() ); return is_array( $log ) ? $log : array(); } /** * Folder for the plugin's own files (origin lock config, gate state, backup temp files). It sits * in the uploads folder, so plugin updates keep it. The path is worked out once with wp_upload_dir() * and stored, so the PHP origin lock, which runs before WordPress has finished loading, can read it. * * @param bool $create Create the folder (with deny rules) when missing. * @return string Absolute path without trailing slash, or '' when the uploads folder is unknown. */ public static function data_dir( $create = false ) { $dir = (string) get_option( self::OPT_DATA_DIR, '' ); if ( '' === $dir && function_exists( 'wp_upload_dir' ) && did_action( 'plugins_loaded' ) ) { $uploads = wp_upload_dir( null, false ); if ( empty( $uploads['error'] ) && ! empty( $uploads['basedir'] ) ) { $dir = untrailingslashit( wp_normalize_path( $uploads['basedir'] ) ) . '/' . self::DATA_DIR; update_option( self::OPT_DATA_DIR, $dir, true ); } } if ( '' === $dir || ! $create ) { return $dir; } if ( ! is_dir( $dir ) ) { wp_mkdir_p( $dir ); } if ( is_dir( $dir ) ) { if ( ! file_exists( $dir . '/.htaccess' ) ) { file_put_contents( $dir . '/.htaccess', "Require all denied\nDeny from all\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents } if ( ! file_exists( $dir . '/index.php' ) ) { file_put_contents( $dir . '/index.php', "isDir() && ! $item->isLink() ) { @rmdir( $item->getPathname() ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_rmdir } else { wp_delete_file( $item->getPathname() ); } } @rmdir( $dir ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_rmdir } /** * Remove everything (uninstall). */ public static function wipe() { delete_option( self::OPT_SETTINGS ); delete_option( self::OPT_SECRETS ); delete_option( self::OPT_LOG ); delete_option( self::OPT_DATA_DIR ); self::$secrets = null; } }