37 ? strlen( $filename ) - 37 : strlen( $filename ) - 4 ); } /** * Scan the template files. * * @param string $template_path Template Path. * * @return array */ public static function scan_template_files( $template_path ) { $files = @scandir( $template_path ); $result = array(); if ( ! empty( $files ) ) { foreach ( $files as $key => $value ) { if ( ! in_array( $value, array( '.', '..' ) ) ) { if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); foreach ( $sub_files as $sub_file ) { $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; } } else { $result[] = $value; } } } } return $result; } /** * Scan the log files. * * @return array */ public static function scan_log_files() { $files = @scandir( UR_LOG_DIR ); $result = array(); if ( ! empty( $files ) ) { foreach ( $files as $key => $value ) { if ( ! in_array( $value, array( '.', '..' ) ) && null !== $value ) { if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) { $result[ sanitize_title( $value ) ] = $value; } } } } return $result; } /** * Remove/delete the chosen file. */ public static function remove_log() { if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'remove_log' ) ) { // phpcs:ignore WordPress.Security.NonceVerification wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'user-registration' ) ); } if ( ! empty( $_REQUEST['handle'] ) ) { $log_handler = new UR_Log_Handler_File(); $log_handler->remove( sanitize_text_field( wp_unslash( $_REQUEST['handle'] ) ) ); } wp_safe_redirect( esc_url_raw( admin_url( 'admin.php?page=user-registration-status&tab=logs' ) ) ); exit(); } /** * Remove/delete all logs. */ public static function remove_all_logs() { if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'remove_all_logs' ) ) { wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'user-registration' ) ); } if ( ! empty( $_REQUEST['handle_all'] ) ) { $log_handler = new UR_Log_Handler_File(); $log_handler->remove_all(); } wp_safe_redirect( esc_url_raw( admin_url( 'admin.php?page=user-registration-status&tab=logs' ) ) ); exit(); } }